![JAR search and dependency download from the Maven repository](/logo.png)
com.shedhack.thread.context.handler.ThreadContextHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of thread-context-handler Show documentation
Show all versions of thread-context-handler Show documentation
Context enabler, for helping with debugging/logging
package com.shedhack.thread.context.handler;
import java.util.List;
import java.util.Optional;
/**
*
* API for handling thread contexts. This will store the type T to the current thread.
* Several implementations have been provided:
*
* {@link com.shedhack.thread.context.handler.JsonThreadContextHandler}
* {@link com.shedhack.thread.context.handler.ListThreadContextHandler}
* {@link com.shedhack.thread.context.handler.SimpleThreadContextHandler}
*
* Each implementations could use a matching {@link com.shedhack.thread.context.adapter.ThreadContextAdapter}
* if you wish to provide a consistent API.
*
*
* @param Type of object that will be stored in the context and also to be returned if required.
*
* @author imamchishty
*/
public interface ThreadContextHandler {
/**
* Sets the thread context based on the generic type.
*/
void setThreadContext(T context);
/**
* Optional returns back the thread context.
*/
Optional getThreadContext();
/**
* Converts from a String to the type T.
*/
Optional convertFromString(String original) ;
/**
* Returns the raw value without any type conversions.
*/
default String getRawContext() {
return Thread.currentThread().getName();
}
/**
* Method is called after the thread context has been set. Allows you to do some extra stuff with
* the context, e.g. logging
*/
default void afterSettingThreadContext(String context, List afterSetList) {
for(ThreadContextAfterSet after : afterSetList) {
after.afterSet(context);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy