Package org.cyclos.impl.utils.cluster
Interface ClusterHandler
-
- All Superinterfaces:
CustomBean
public interface ClusterHandler extends CustomBean
Handler for Cyclos 4 cluster, providing aspects like caches and task synchronization
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceClusterHandler.FinishedExecutionsHandler
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidawakeRecurringTasks(Set<RecurringTask> recurringTasksToAwake)Awakes the givenRecurringTasksdefault voidcheckConsistency()This method is invoked after theApplicationContextgets started.voidclearCaches()Clear all caches from all members in the clustervoidfinishBackgroundTaskExecution(BackgroundTaskExecutionContext task)Masks as finished the given task executionMap<String,Integer>getBackgroundTaskExecutions()Returns a map from background task name to the number of executions it has.intgetBackgroundTasksQueueSize()Returns the current size of the background tasks queueCacheHandlerImplementorgetCacheHandler()Returns theCacheHandlermanaged by this clusterList<CacheVO>getCachesInformation(CacheQuery query)Returns information of each local cache summarized over all members.Map<String,List<CacheVO>>getCachesInformationByMember(CacheQuery query)Returns the same information as withgetCachesInformation(CacheQuery)
This method should not be in theClusterHandlerinterface because it's defined by debugging purposes and only has sense for this implementation but the dynamic proxy we use only proxies the methods in interfaces.ClusterHandler.FinishedExecutionsHandlergetFinishedBackgroundTaskExecutions()Returns a handler with the already finished executions at the moment of the invocation.Map<String,Object>getGlobal(String key)Returns the value of the 'globals' map for each cluster node, keyed bygetHostId().StringgetHostId()Returns the current host identifier<K,V>
LocalStorage<K,V>getLocalStorage(LocalStorageType<K,V> type)Returns the local storage for the given typeintgetMaxBackgroundTaskCapacity()Returns number ofBackgroundTaskExecutionthe cluster can accept as max.StringgetMemberConfiguration()Return the cluster configuration only ifisCluster()returns true.MemberRunningTaskDescriptorgetMemberRunningTask(String taskName)Returns information with the member running the given recurring task or null if the task is not being executed.List<ServerData>getMembersData()Returns information about each cluster member.
In caseisCluster()returns false then the list will contain a single element with the information of the local host.ProfilingManagergetProfilingManager()Returns the cluster-specific profiling handlerPushNotificationHandlerImplementorgetPushNotificationHandler()Returns thePushNotificationHandlerImplementorwhich can be used to publish / subscribe to push notification eventsRecurringTaskHandlerImplementorgetRecurringTaskHandler()Returns theRecurringTaskHandlermanaged by this clusterintgetRemainingBackgroundTaskCapacity()Returns number ofBackgroundTaskExecutionthe cluster can accept.<K extends Serializable,V extends Serializable>
ReplicatedStorage<K,V>getReplicatedStorage(ReplicatedStorageType type)Returns a simple storage with a given nameMap<String,MemberRunningTaskDescriptor>getRunningRecurringTasks()Returns a map from recurring task name to a descriptor with information about the member that is executing it.<K extends Serializable,V extends Serializable>
SharedStorage<K,V>getSharedStorage(SharedStorageType<K,V> type)Returns a shared storage with a given namebooleanisAlive()Returns whether the cluster (or local instance) is still alivebooleanisCausedByShutdown(Throwable e)Returns whether the given exception was caused by a server shutdown.booleanisCluster()Returns whether we're actually running in a cluster or as a single node installationbooleanlockDatabase()Checks that there is no other Cyclos instance using the database and afterwards, locks the database.voidrunBackgroundTasks(List<BackgroundTaskExecutionContext> tasks)Executes the background tasks with the given ids.booleanrunInitialization(ApplicationInitializationListener listener)Attempts to execute the givenApplicationInitializationListener.onApplicationInitialization().booleanrunUpgradeInitialization(ApplicationUpgradeInitializationListener listener)Attempts to execute the givenApplicationUpgradeInitializationListener.onApplicationUpgradeInitialization().voidstarTaskTimers()Starts the timers for schedule tasks, send lock keep-alive, etc.
This method is guaranteed to be called only after all initialisations run.
-
-
-
Method Detail
-
awakeRecurringTasks
void awakeRecurringTasks(Set<RecurringTask> recurringTasksToAwake)
Awakes the givenRecurringTasks
-
checkConsistency
default void checkConsistency() throws IllegalStateExceptionThis method is invoked after theApplicationContextgets started. Implementors can add custom logic to ensure the cluster is in the appropriate state.- Throws:
IllegalStateException- if the state is not the expected one causing the application to shutdown. NOTE: We decided to implement this with a specific method that will be invoked from theApplicationHandlerinstead of doing the check in thePostConstructmethod to avoid flood the log with errors.
-
clearCaches
void clearCaches()
Clear all caches from all members in the cluster
-
finishBackgroundTaskExecution
void finishBackgroundTaskExecution(BackgroundTaskExecutionContext task)
Masks as finished the given task execution
-
getBackgroundTaskExecutions
Map<String,Integer> getBackgroundTaskExecutions()
Returns a map from background task name to the number of executions it has. A task no contained in the map means it's not running at the moment of the invocation.
-
getBackgroundTasksQueueSize
int getBackgroundTasksQueueSize()
Returns the current size of the background tasks queue
-
getCacheHandler
CacheHandlerImplementor getCacheHandler()
Returns theCacheHandlermanaged by this cluster
-
getCachesInformation
List<CacheVO> getCachesInformation(CacheQuery query)
Returns information of each local cache summarized over all members.
-
getCachesInformationByMember
Map<String,List<CacheVO>> getCachesInformationByMember(CacheQuery query)
Returns the same information as withgetCachesInformation(CacheQuery)
This method should not be in theClusterHandlerinterface because it's defined by debugging purposes and only has sense for this implementation but the dynamic proxy we use only proxies the methods in interfaces.- Parameters:
query-
-
getFinishedBackgroundTaskExecutions
ClusterHandler.FinishedExecutionsHandler getFinishedBackgroundTaskExecutions()
Returns a handler with the already finished executions at the moment of the invocation.
-
getGlobal
Map<String,Object> getGlobal(String key)
Returns the value of the 'globals' map for each cluster node, keyed bygetHostId(). For this to succeed, the associated value must beSerializable. Null values are not returned.- See Also:
ScriptHelper.getGlobals()
-
getHostId
String getHostId()
Returns the current host identifier
-
getLocalStorage
<K,V> LocalStorage<K,V> getLocalStorage(LocalStorageType<K,V> type)
Returns the local storage for the given type
-
getMaxBackgroundTaskCapacity
int getMaxBackgroundTaskCapacity()
Returns number ofBackgroundTaskExecutionthe cluster can accept as max.
-
getMemberConfiguration
String getMemberConfiguration()
Return the cluster configuration only ifisCluster()returns true. Otherwise return null.
-
getMemberRunningTask
MemberRunningTaskDescriptor getMemberRunningTask(String taskName)
Returns information with the member running the given recurring task or null if the task is not being executed.
-
getMembersData
List<ServerData> getMembersData()
Returns information about each cluster member.
In caseisCluster()returns false then the list will contain a single element with the information of the local host.
-
getProfilingManager
ProfilingManager getProfilingManager()
Returns the cluster-specific profiling handler
-
getPushNotificationHandler
PushNotificationHandlerImplementor getPushNotificationHandler()
Returns thePushNotificationHandlerImplementorwhich can be used to publish / subscribe to push notification events
-
getRecurringTaskHandler
RecurringTaskHandlerImplementor getRecurringTaskHandler()
Returns theRecurringTaskHandlermanaged by this cluster
-
getRemainingBackgroundTaskCapacity
int getRemainingBackgroundTaskCapacity()
Returns number ofBackgroundTaskExecutionthe cluster can accept.
-
getReplicatedStorage
<K extends Serializable,V extends Serializable> ReplicatedStorage<K,V> getReplicatedStorage(ReplicatedStorageType type)
Returns a simple storage with a given name
-
getRunningRecurringTasks
Map<String,MemberRunningTaskDescriptor> getRunningRecurringTasks()
Returns a map from recurring task name to a descriptor with information about the member that is executing it. A task no contained in the map means it's not running at the moment of the invocation.
-
getSharedStorage
<K extends Serializable,V extends Serializable> SharedStorage<K,V> getSharedStorage(SharedStorageType<K,V> type)
Returns a shared storage with a given name
-
isAlive
boolean isAlive()
Returns whether the cluster (or local instance) is still alive
-
isCausedByShutdown
boolean isCausedByShutdown(Throwable e)
Returns whether the given exception was caused by a server shutdown. For example,InterruptedExceptions are considered to be caused by a shutdown.
-
isCluster
boolean isCluster()
Returns whether we're actually running in a cluster or as a single node installation
-
lockDatabase
boolean lockDatabase()
Checks that there is no other Cyclos instance using the database and afterwards, locks the database. Returns whether the database was actually locked.
-
runBackgroundTasks
void runBackgroundTasks(List<BackgroundTaskExecutionContext> tasks)
Executes the background tasks with the given ids. TheCyclosProperties.getMaxBackgroundTasks()is respected.
-
runInitialization
boolean runInitialization(ApplicationInitializationListener listener)
Attempts to execute the givenApplicationInitializationListener.onApplicationInitialization(). In some cases (for example, the initialization was already executed), it might do nothing, and just return false
-
runUpgradeInitialization
boolean runUpgradeInitialization(ApplicationUpgradeInitializationListener listener)
Attempts to execute the givenApplicationUpgradeInitializationListener.onApplicationUpgradeInitialization(). In some cases (for example, the initialization was already executed), it might do nothing, and just return false
-
starTaskTimers
void starTaskTimers()
Starts the timers for schedule tasks, send lock keep-alive, etc.
This method is guaranteed to be called only after all initialisations run.
-
-