Package org.cyclos.impl.utils.cluster
Class AbstractClusterHandlerImpl
- java.lang.Object
-
- org.cyclos.impl.utils.cluster.AbstractClusterHandlerImpl
-
- All Implemented Interfaces:
CustomBean,ClusterHandler
- Direct Known Subclasses:
HazelcastClusterHandlerImpl,NoClusterHandlerImpl
public abstract class AbstractClusterHandlerImpl extends Object implements ClusterHandler
Base implementation forClusterHandler
-
-
Field Summary
Fields Modifier and Type Field Description protected ApplicationContextapplicationContextprotected BackgroundTaskHandlerImplementorbackgroundTaskHandlerprotected BeanHandlerbeanHandlerprotected ConversionHandlerconversionHandlerprotected CyclosPropertiescyclosPropertiesprotected DatabaseManagerdatabaseManagerprotected DataSourcedataSourceprotected InvokerHandlerinvokerHandlerprotected PollingTaskHandlerImplementorpollingTaskHandlerprotected RawEntityManagerHandlerrawEntityManagerHandlerprotected TaskSchedulertaskScheduler
-
Constructor Summary
Constructors Constructor Description AbstractClusterHandlerImpl()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidawakePollingTasks(Set<PollingTask> pollingTasksToAwake)Awakes the givenPollingTasksprotected <K,V>
LocalStorage<K,V>createLocalStorage(LocalStorageType<K,V> type)protected <K extends Serializable,V extends Serializable>
SharedStorage<K,V>createSharedStorage(SharedStorageType<K,V> type)Actually creates a new shared storage.protected voiddoRunBackgroundTask(Long id)CacheHandlerImplementorgetCacheHandler()Returns theCacheHandlermanaged by this cluster<K,V>
LocalStorage<K,V>getLocalStorage(LocalStorageType<K,V> type)Returns the local storage for the given typePushNotificationHandlergetPushNotificationHandler()Returns thePushNotificationHandlerwhich can be used to publish / subscribe to push notification events<K extends Serializable,V extends Serializable>
SharedStorage<K,V>getSharedStorage(SharedStorageType<K,V> type)Returns a shared storage with a given nameprotected voidinitialize()protected abstract CacheHandlerImplementorinstantiateCacheHandler()protected abstract PushNotificationHandlerinstantiatePushNotificationHandler()booleanlockDatabase()Checks that there is no other Cyclos instance using the database and afterwards, locks the database.protected voidrunBackgroundTask(Long id)voidrunBackgroundTasks(List<Long> ids)Executes the background tasks with the given ids.booleanrunInitialization(ApplicationInitializationListener listener)Attempts to execute the givenApplicationInitializationListener#onApplicationInitialization(org.cyclos.impl.ApplicationHandler).booleanrunPollingTask(PollingTask task, boolean awake, Date nextExecution)Attempts to execute the givenPollingTask, except if it is already running in some other cluster node (in this case, returning false).protected abstract booleanshouldEnsureDatabaseIsNotLocked()protected abstract booleanshouldUnlockDatabase()protected voidshutdown()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.cyclos.impl.utils.cluster.ClusterHandler
getHostId, getStartupTime, isAlive, isCluster
-
-
-
-
Field Detail
-
applicationContext
@Autowired protected ApplicationContext applicationContext
-
beanHandler
@Autowired protected BeanHandler beanHandler
-
taskScheduler
@Autowired protected TaskScheduler taskScheduler
-
cyclosProperties
@Autowired protected CyclosProperties cyclosProperties
-
pollingTaskHandler
@Autowired protected PollingTaskHandlerImplementor pollingTaskHandler
-
backgroundTaskHandler
@Autowired @Lazy protected BackgroundTaskHandlerImplementor backgroundTaskHandler
-
invokerHandler
@Autowired protected InvokerHandler invokerHandler
-
rawEntityManagerHandler
@Autowired @Lazy protected RawEntityManagerHandler rawEntityManagerHandler
-
conversionHandler
@Autowired @Lazy protected ConversionHandler conversionHandler
-
dataSource
@Autowired protected DataSource dataSource
-
databaseManager
@Autowired protected DatabaseManager databaseManager
-
-
Method Detail
-
awakePollingTasks
public void awakePollingTasks(Set<PollingTask> pollingTasksToAwake)
Description copied from interface:ClusterHandlerAwakes the givenPollingTasks- Specified by:
awakePollingTasksin interfaceClusterHandler
-
getCacheHandler
public final CacheHandlerImplementor getCacheHandler()
Description copied from interface:ClusterHandlerReturns theCacheHandlermanaged by this cluster- Specified by:
getCacheHandlerin interfaceClusterHandler
-
getLocalStorage
public <K,V> LocalStorage<K,V> getLocalStorage(LocalStorageType<K,V> type)
Description copied from interface:ClusterHandlerReturns the local storage for the given type- Specified by:
getLocalStoragein interfaceClusterHandler
-
getPushNotificationHandler
public final PushNotificationHandler getPushNotificationHandler()
Description copied from interface:ClusterHandlerReturns thePushNotificationHandlerwhich can be used to publish / subscribe to push notification events- Specified by:
getPushNotificationHandlerin interfaceClusterHandler
-
getSharedStorage
public final <K extends Serializable,V extends Serializable> SharedStorage<K,V> getSharedStorage(SharedStorageType<K,V> type)
Description copied from interface:ClusterHandlerReturns a shared storage with a given name- Specified by:
getSharedStoragein interfaceClusterHandler
-
lockDatabase
public boolean lockDatabase()
Description copied from interface:ClusterHandlerChecks that there is no other Cyclos instance using the database and afterwards, locks the database. Returns whether the database was actually locked.- Specified by:
lockDatabasein interfaceClusterHandler
-
runBackgroundTasks
public void runBackgroundTasks(List<Long> ids)
Description copied from interface:ClusterHandlerExecutes the background tasks with the given ids. TheCyclosProperties.getMaxBackgroundTasks()is respected.- Specified by:
runBackgroundTasksin interfaceClusterHandler
-
runInitialization
public boolean runInitialization(ApplicationInitializationListener listener)
Description copied from interface:ClusterHandlerAttempts to execute the givenApplicationInitializationListener#onApplicationInitialization(org.cyclos.impl.ApplicationHandler). In some cases (for example, the initialization was already executed), it might do nothing, and just return false- Specified by:
runInitializationin interfaceClusterHandler
-
runPollingTask
public boolean runPollingTask(PollingTask task, boolean awake, Date nextExecution)
Description copied from interface:ClusterHandlerAttempts to execute the givenPollingTask, except if it is already running in some other cluster node (in this case, returning false). TheCyclosProperties.getMaxBackgroundTasks()is respected.- Specified by:
runPollingTaskin interfaceClusterHandler- Parameters:
task- The task to runawake- A flag indicating whether the given task has been manually awake (true) or is executing after a timeout (false)nextExecution- The date it is scheduled the next execution
-
createLocalStorage
protected <K,V> LocalStorage<K,V> createLocalStorage(LocalStorageType<K,V> type)
-
createSharedStorage
protected <K extends Serializable,V extends Serializable> SharedStorage<K,V> createSharedStorage(SharedStorageType<K,V> type)
Actually creates a new shared storage. The resulting value will be cached for the given name.
-
doRunBackgroundTask
protected void doRunBackgroundTask(Long id)
-
initialize
protected void initialize()
-
instantiateCacheHandler
protected abstract CacheHandlerImplementor instantiateCacheHandler()
-
instantiatePushNotificationHandler
protected abstract PushNotificationHandler instantiatePushNotificationHandler()
-
runBackgroundTask
protected void runBackgroundTask(Long id)
-
shouldEnsureDatabaseIsNotLocked
protected abstract boolean shouldEnsureDatabaseIsNotLocked()
-
shouldUnlockDatabase
protected abstract boolean shouldUnlockDatabase()
-
shutdown
protected void shutdown()
-
-