Package org.cyclos.impl
Class InvocationContext
- java.lang.Object
-
- org.cyclos.impl.InvocationContext
-
public final class InvocationContext extends Object
Contains the context of a service method execution
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInvocationContext.ConversionContextContains the context used for bean conversion within an invocation
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBeforeEndListener(Runnable callback)Adds a callback to run right before committing the current database transactionvoidaddCommitListener(boolean requiresTransaction, boolean afterAwakingPollingTasks, Runnable callback)Adds a callback to run after the current transaction commitsvoidaddCommitListener(boolean requiresTransaction, Runnable callback)Adds a callback to run after the current transaction commitsvoidaddRollbackListener(boolean requiresTransaction, boolean afterAwakingPollingTasks, Runnable callback)Adds a callback to run after the current transaction rolls-backvoidaddRollbackListener(boolean requiresTransaction, Runnable callback)Adds a callback to run after the current transaction rolls-backvoidaddTransactionEndListener(boolean requiresTransaction, boolean afterAwakingPollingTasks, Runnable callback)Adds a callback both as commit and rollback listenervoidaddTransactionEndListener(boolean requiresTransaction, Runnable callback)Adds a callback both as commit and rollback listenerApplicationContextapplicationContext()voidawakePollingTask(PollingTask pollingTask)Registers the givenPollingTaskto be awaked when this invocation endsstatic <T> Tbean(Class<T> beanType)Returns a Spring bean with the given class.voidclearCache(CacheType<?,?> type)Registers the givenCacheTypeto be cleared when this invocation endsvoiddelegateAcquiredResources(InvocationContext context)Passes the acquired resources to the given context, so that when it is released, those resources will be released as wellstatic InvocationContextensure()Returns the current context, throwing an IllegalStateException if none<K extends Serializable>
voidevictCacheKeyPredicate(CacheType<K,?> type, SerializablePredicate<K> predicate)voidevictCacheKeys(CacheType<?,?> type, Set<? extends Serializable> keys)Registers the given keys to be evicted from the cache described atCacheTypeto be cleared when this invocation endsFormatterImplformatter(ConfigurationAccessor configuration)Returns a formatter which is suitable for the given configuration accessor, or null if it is to represent the current session's configurationstatic InvocationContextget()Returns the current contextstatic ApplicationContextgetApplicationContext()Returns the current application context<T> TgetAttribute(Object key)Returns the value of an attribute.<T> TgetAttribute(Object key, Supplier<T> supplier)Returns the value of an attribute, producing it if not bound to the keystatic InvocationContext.ConversionContextgetConversionContext()Returns theInvocationContext.ConversionContextalready associated with this thread, cleaning the processed objects, as they may change per invocationstatic CacheFlushergetCurrentCacheFlusher()Returns the currentCacheFlusherin the stackjavax.persistence.EntityManagergetEntityManager()Returns the currentEntityManagerstatic FormatterImplgetFormatter(ConfigurationAccessor configuration)Returns a formatter which is suitable for the given configuration accessor, or null if it is to represent the current session's configurationStoredFileContentActiongetLastStoredFileContentAction()static SessionDatagetSessionData()Returns the current session dataTransactionLevelgetTransactionLevel()TransactionStatusgetTransactionStatus()booleanhasLock(LockKey key)Returns whether the current thread owns the given lockbooleanhasWrite()static InvocationContextinit(SessionData sessionData, ApplicationContext applicationContext)Initializes the current invocation contextbooleanisEvicted(CacheType<?,?> type, Serializable key)Returns whether the given cache key has been evicted in this invocationstatic voidmarkWrite()static InvocationContextnested(SessionData sessionData, InvocationContext oldContext)Creates a new invocation context based on the given onestatic CacheFlushernewCacheFlusher()Creates a newCacheFlusher, keeping trace of it on a stackvoidregisterLock(LockKey key)Registers the given lockvoidreleaseAfterTransaction(boolean commit)Releases any acquired resources.voidreleaseWithinTransaction()Releases resources which should be released while still within a transactionvoidreleaseWithoutTransaction()Releases those acquired resources when there is no transaction.static voidremove()Removes the current contextSessionDatasessionData()static voidset(InvocationContext context)Sets the current invocation contextvoidsetAttribute(Object key, Object value)voidsetEntityManager(javax.persistence.EntityManager entityManager)voidsetLastStoredFileContentAction(StoredFileContentAction lastContentAction)voidsetTransactionLevel(TransactionLevel transactionLevel)voidsetTransactionStatus(TransactionStatus transactionStatus)static BeanWrapperwrap(Object bean)Returns aBeanWrapperfor the given bean
-
-
-
Method Detail
-
bean
public static <T> T bean(Class<T> beanType)
Returns a Spring bean with the given class. Equivalent togetApplicationContext()thenBeanFactory.getBean(Class)
-
ensure
public static InvocationContext ensure()
Returns the current context, throwing an IllegalStateException if none
-
get
public static InvocationContext get()
Returns the current context
-
getApplicationContext
public static ApplicationContext getApplicationContext()
Returns the current application context
-
getConversionContext
public static InvocationContext.ConversionContext getConversionContext()
Returns theInvocationContext.ConversionContextalready associated with this thread, cleaning the processed objects, as they may change per invocation
-
getCurrentCacheFlusher
public static CacheFlusher getCurrentCacheFlusher()
Returns the currentCacheFlusherin the stack
-
getFormatter
public static FormatterImpl getFormatter(ConfigurationAccessor configuration)
Returns a formatter which is suitable for the given configuration accessor, or null if it is to represent the current session's configuration
-
getSessionData
public static SessionData getSessionData()
Returns the current session data
-
init
public static InvocationContext init(SessionData sessionData, ApplicationContext applicationContext)
Initializes the current invocation context
-
markWrite
public static void markWrite()
-
nested
public static InvocationContext nested(SessionData sessionData, InvocationContext oldContext)
Creates a new invocation context based on the given one
-
newCacheFlusher
public static CacheFlusher newCacheFlusher()
Creates a newCacheFlusher, keeping trace of it on a stack
-
remove
public static void remove()
Removes the current context
-
set
public static void set(InvocationContext context)
Sets the current invocation context
-
wrap
public static BeanWrapper wrap(Object bean)
Returns aBeanWrapperfor the given bean
-
addBeforeEndListener
public void addBeforeEndListener(Runnable callback)
Adds a callback to run right before committing the current database transaction
-
addCommitListener
public void addCommitListener(boolean requiresTransaction, boolean afterAwakingPollingTasks, Runnable callback)Adds a callback to run after the current transaction commits
-
addCommitListener
public void addCommitListener(boolean requiresTransaction, Runnable callback)Adds a callback to run after the current transaction commits
-
addRollbackListener
public void addRollbackListener(boolean requiresTransaction, boolean afterAwakingPollingTasks, Runnable callback)Adds a callback to run after the current transaction rolls-back
-
addRollbackListener
public void addRollbackListener(boolean requiresTransaction, Runnable callback)Adds a callback to run after the current transaction rolls-back
-
addTransactionEndListener
public void addTransactionEndListener(boolean requiresTransaction, boolean afterAwakingPollingTasks, Runnable callback)Adds a callback both as commit and rollback listener
-
addTransactionEndListener
public void addTransactionEndListener(boolean requiresTransaction, Runnable callback)Adds a callback both as commit and rollback listener
-
applicationContext
public ApplicationContext applicationContext()
-
awakePollingTask
public void awakePollingTask(PollingTask pollingTask)
Registers the givenPollingTaskto be awaked when this invocation ends
-
clearCache
public void clearCache(CacheType<?,?> type)
Registers the givenCacheTypeto be cleared when this invocation ends
-
delegateAcquiredResources
public void delegateAcquiredResources(InvocationContext context)
Passes the acquired resources to the given context, so that when it is released, those resources will be released as well
-
evictCacheKeyPredicate
public <K extends Serializable> void evictCacheKeyPredicate(CacheType<K,?> type, SerializablePredicate<K> predicate)
-
evictCacheKeys
public void evictCacheKeys(CacheType<?,?> type, Set<? extends Serializable> keys)
Registers the given keys to be evicted from the cache described atCacheTypeto be cleared when this invocation ends
-
formatter
public FormatterImpl formatter(ConfigurationAccessor configuration)
Returns a formatter which is suitable for the given configuration accessor, or null if it is to represent the current session's configuration
-
getAttribute
public <T> T getAttribute(Object key)
Returns the value of an attribute. If is an entity, makes sure it is attached to the current entityManager
-
getAttribute
public <T> T getAttribute(Object key, Supplier<T> supplier)
Returns the value of an attribute, producing it if not bound to the key
-
getEntityManager
public javax.persistence.EntityManager getEntityManager()
Returns the currentEntityManager
-
getLastStoredFileContentAction
public StoredFileContentAction getLastStoredFileContentAction()
-
getTransactionLevel
public TransactionLevel getTransactionLevel()
-
getTransactionStatus
public TransactionStatus getTransactionStatus()
-
hasLock
public boolean hasLock(LockKey key)
Returns whether the current thread owns the given lock
-
hasWrite
public boolean hasWrite()
-
isEvicted
public boolean isEvicted(CacheType<?,?> type, Serializable key)
Returns whether the given cache key has been evicted in this invocation
-
registerLock
public void registerLock(LockKey key)
Registers the given lock
-
releaseAfterTransaction
public void releaseAfterTransaction(boolean commit)
Releases any acquired resources. Must be invoked after the caller transaction has ended
-
releaseWithinTransaction
public void releaseWithinTransaction()
Releases resources which should be released while still within a transaction
-
releaseWithoutTransaction
public void releaseWithoutTransaction()
Releases those acquired resources when there is no transaction.
-
sessionData
public SessionData sessionData()
-
setEntityManager
public void setEntityManager(javax.persistence.EntityManager entityManager)
-
setLastStoredFileContentAction
public void setLastStoredFileContentAction(StoredFileContentAction lastContentAction)
-
setTransactionLevel
public void setTransactionLevel(TransactionLevel transactionLevel)
-
setTransactionStatus
public void setTransactionStatus(TransactionStatus transactionStatus)
-
-