All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.shedhack.thread.context.handler.ThreadContextHandler Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
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