Package it.tidalwave.role.spi
Class DefaultContextManager
- java.lang.Object
-
- it.tidalwave.role.spi.DefaultContextManager
-
- All Implemented Interfaces:
ContextManager
public class DefaultContextManager extends java.lang.Object implements ContextManager
- Author:
- Fabrizio Giudici
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface it.tidalwave.role.ContextManager
ContextManager.Binder, ContextManager.Locator, ContextManager.RunnableWithException<E extends java.lang.Throwable>, ContextManager.SupplierWithException<T,E extends java.lang.Throwable>
-
-
Constructor Summary
Constructors Constructor Description DefaultContextManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addGlobalContext(java.lang.Object context)
Adds a global context.void
addLocalContext(java.lang.Object context)
Adds a local context.<T> T
findContextOfType(java.lang.Class<T> contextType)
Finds a current context instance of the given type.java.util.List<java.lang.Object>
getContexts()
Returns the list of current contexts, ordered by their priority.void
removeGlobalContext(java.lang.Object context)
Removes a global context.void
removeLocalContext(java.lang.Object context)
Removes a local context.<T,E extends java.lang.Throwable>
TrunEWithContexts(ContextManager.SupplierWithException<T,E> supplier, java.lang.Object... contexts)
Calls a task with some local contexts.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface it.tidalwave.role.ContextManager
binder, runEWithContexts, runWithContext, runWithContext, runWithContexts, runWithContexts, runWithContexts, runWithContexts
-
-
-
-
Method Detail
-
getContexts
@Nonnull public java.util.List<java.lang.Object> getContexts()
Returns the list of current contexts, ordered by their priority.- Specified by:
getContexts
in interfaceContextManager
- Returns:
- the list of current contexts
-
findContextOfType
@Nonnull public <T> T findContextOfType(@Nonnull java.lang.Class<T> contextType) throws NotFoundException
Finds a current context instance of the given type.- Specified by:
findContextOfType
in interfaceContextManager
- Type Parameters:
T
- the static context type- Parameters:
contextType
- the dynamic context type- Returns:
- the requested context
- Throws:
NotFoundException
- if no context of that type is found
-
addGlobalContext
public void addGlobalContext(@Nonnull java.lang.Object context)
Adds a global context.- Specified by:
addGlobalContext
in interfaceContextManager
- Parameters:
context
- the new context
-
removeGlobalContext
public void removeGlobalContext(@Nonnull java.lang.Object context)
Removes a global context.- Specified by:
removeGlobalContext
in interfaceContextManager
- Parameters:
context
- the context
-
addLocalContext
public void addLocalContext(@Nonnull java.lang.Object context)
Adds a local context.- Specified by:
addLocalContext
in interfaceContextManager
- Parameters:
context
- the new context
-
removeLocalContext
public void removeLocalContext(@Nonnull java.lang.Object context)
Removes a local context.- Specified by:
removeLocalContext
in interfaceContextManager
- Parameters:
context
- the context
-
runEWithContexts
@Nonnull public <T,E extends java.lang.Throwable> T runEWithContexts(@Nonnull ContextManager.SupplierWithException<T,E> supplier, @Nonnull java.lang.Object... contexts) throws E extends java.lang.Throwable
Calls a task with some local contexts. This method fits functional interfaces.- Specified by:
runEWithContexts
in interfaceContextManager
- Type Parameters:
T
- the type of the returned valueE
- the type of the thrown exception- Parameters:
supplier
- the task to callcontexts
- the contexts- Returns:
- the value returned by the supplier
- Throws:
E
- the original exception thrown by taskE extends java.lang.Throwable
-
-