re base code
[sdc.git] / openecomp-be / lib / openecomp-sdc-logging-lib / openecomp-sdc-logging-api / src / main / java / org / openecomp / sdc / logging / spi / LoggingContextService.java
1 /*
2  * Copyright © 2016-2018 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 org.openecomp.sdc.logging.api.ContextData;
20
21 import java.util.concurrent.Callable;
22
23 /**
24  * Should be used to implement a framework-specific mechanism of managing a per-thread diagnostic context (for instance
25  * <a href="http://www.slf4j.org/manual.html#mdc">MDC</a>), and propagating it to child threads if needed. Context
26  * propagation should be used when creating a child thread directly, or submitting tasks for potentially postponed
27  * execution via an <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html">Executor</a>
28  * (including any of the <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html">
29  * executor services</a> and <a href="http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html">
30  * ForkJoinPool</a>).
31  *
32  * @author evitaliy
33  * @since 07 Jan 2018
34  */
35
36 public interface LoggingContextService {
37
38     /**
39      * Put logging data on the context.
40      */
41     void put(ContextData contextData);
42
43     /**
44      * Return logging context's data.
45      */
46     ContextData get();
47
48     /**
49      * Clear logging thread context.
50      */
51     void clear();
52
53     /**
54      * Copies logging context of current thread onto a {@link Runnable}, so that the context is available when this
55      * {@link Runnable} runs in another thread.
56      */
57     Runnable copyToRunnable(Runnable runnable);
58
59     /**
60      * Copies logging context of current thread onto a {@link Callable}, so that the context is available when this
61      * {@link Callable} runs in another thread
62      */
63     <V> Callable<V> copyToCallable(Callable<V> callable);
64 }