Interface ContextObserver<T>
-
public interface ContextObserver<T>Observe context updates for a particular class of ContextManager.Create your context observer by implementing this interface and registering your class to the
ServiceLoaderSPI by adding the fully qualified class name to the resource/META-INF/services/nl.talsmasoftware.context.observer.ContextObserver.It is the responsibility of the context implementor to update observers of context updates. SPI lookup of appropriate observers is facilitated by the ContextManagers.onActivate(Class, Object, Object) and ContextManagers.onDeactivate(Class, Object, Object) utility methods.
All subclasses of AbstractThreadLocalContext are already observable.- Author:
- Sjoerd Talsma
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Class<? extends ContextManager<T>>getObservedContextManager()The observed context manager(s).voidonActivate(T activatedContextValue, T previousContextValue)Indicates that a context was just activated.voidonDeactivate(T deactivatedContextValue, T restoredContextValue)Indicates that a context was just deactivated.
-
-
-
Method Detail
-
getObservedContextManager
Class<? extends ContextManager<T>> getObservedContextManager()
The observed context manager(s).Context observers can indicate which type of context manager must be observed using this method. For instance, returning
LocaleContextManager.classhere, updates for theLocaleContextwill be offered to this observer.To observe all context updates, return the ContextManager interface class itself, since all context managers must implement it.
Return
nullto disable the observer.- Returns:
- The observed context manager class or
nullto disable this observer.
-
onActivate
void onActivate(T activatedContextValue, T previousContextValue)
Indicates that a context was just activated.- Parameters:
activatedContextValue- The now active context value.previousContextValue- The previous context value ornullif unknown or unsupported.
-
-