7aed0fc7dc58b9e4bcf200f901fa4d46043ef79a
[sdc.git] /
1 /*
2  * Copyright © 2016-2017 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.logging.spi;
18
19 import java.util.concurrent.Callable;
20
21 /**
22  * Should be used to implement a framework-specific mechanism of managing a per-thread diagnostic context
23  * (for instance <a href="http://www.slf4j.org/manual.html#mdc">MDC</a>), and propagating it to child threads if needed.
24  * Context propagation should be used when creating a child thread directly, or submitting tasks for potentially
25  * postponed execution via an
26  * <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html">Executor</a> (including any of
27  * the
28  * <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html">executor services</a>
29  * and <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html">ForkJoinPool</a>).
30  *
31  * @author evitaliy
32  * @since 07/01/2018.
33  */
34
35 public interface LoggingContextService {
36
37     /**
38      * Allows to store a key-value pair on thread context
39      */
40     void put(String key, String value);
41
42     /**
43      * Returns the value associated with a key stored on thread context
44      *
45      * @return value or <code>null</code> if the key does not exits
46      */
47     String get(String key);
48
49     /**
50      * Removes a particular key from thread context
51      */
52     void remove(String key);
53
54     /**
55      * Clear logging thread context
56      */
57     void clear();
58
59     /**
60      * Copies logging context of current thread onto a {@link Runnable}, so that the context is available
61      * when this {@link Runnable} runs in another thread.
62      */
63     Runnable copyToRunnable(Runnable runnable);
64
65     /**
66      * Copies logging context of current thread onto a {@link Callable}, so that the context is available
67      * when this {@link Callable} runs in another thread
68      */
69     <V> Callable<V> copyToCallable(Callable<V> callable);
70 }