public class ClusterManagementService extends Object implements ApplicationEventPublisherAware, DisposableBean, InitializingBean, SmartInitializingSingleton
Manages the cluster of archive servers. This class takes care of registering the server in the cluster and periodically updating its online state so that other servers can detect it as being online.
The isOnline()
method can be used to check whether this server is
currently online. Components that are interested in this information can also
register as ApplicationListener
s listening for the
ServerOnlineStatusEvent
. As event notification is performed in an
asynchronous way, calls to the isOnline()
method may reflect an
updated online status before the corresponding event is received. Please note
that listeners that are registered after events have been sent will only be
notified when the status changes again. Therefore, when registering a new
listener, the listener should query the current state explicitly because it
might not receive an event with this state.
Modifier and Type | Field and Description |
---|---|
protected org.apache.commons.logging.Log |
log
Logger for this class.
|
Constructor and Description |
---|
ClusterManagementService() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
void |
afterSingletonsInstantiated() |
void |
destroy() |
String |
getInterNodeCommunicationUrl(UUID serverId)
Returns the inter-node communication URL for the specified server.
|
ServerStatus |
getServer(UUID serverId)
Returns the status for the server with the specified ID.
|
List<ServerStatus> |
getServers()
Returns the status for all servers in the cluster.
|
ServerStatus |
getThisServer()
Returns the current status of this server.
|
boolean |
isOnline()
Returns
true if the server is currently considered online
(has recently registered itself in the Cassandra database),
false otherwise. |
void |
onClusterServersDAOInitializedEvent(ClusterServersDAOInitializedEvent event)
Handles the
ClusterServersDAOInitializedEvent . |
void |
onInterNodeCommunicationServiceInitializedEvent(InterNodeCommunicationServiceInitializedEvent event)
Handles the
InterNodeCommunicationServiceInitializedEvent . |
void |
removeServer(UUID serverId)
Removes the server with the specified ID from the cluster.
|
void |
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) |
void |
setClusterServersDAO(ClusterServersDAO clusterServersDAO)
Sets the cluster-servers DAO that is used for accessing the database.
|
void |
setControlSystemSupportRegistry(ControlSystemSupportRegistry controlSystemSupportRegistry)
Sets the control-system support registry.
|
void |
setInterNodeCommunicationService(InterNodeCommunicationService interNodeCommunicationService)
Sets the inter-node communication service.
|
void |
setServerProperties(ServerProperties serverProperties)
Sets the server-specific configuration properties.
|
ListenableFuture<Boolean> |
verifyServerOffline(UUID serverId)
Verifies that a server is actually offline.
|
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface InitializingBean
Exception
public void afterSingletonsInstantiated()
afterSingletonsInstantiated
in interface SmartInitializingSingleton
public void destroy() throws Exception
destroy
in interface DisposableBean
Exception
@EventListener public void onClusterServersDAOInitializedEvent(ClusterServersDAOInitializedEvent event)
ClusterServersDAOInitializedEvent
. This event signals
that the cluster servers DAO needed by this service is ready for
operation. This service uses this information in order to start the
registration process that registers this server in the cluster and
eventually switch to the online state, if the registration attempt is
successful.event
- event signaling that the cluster servers DAO is ready for
operation.@EventListener public void onInterNodeCommunicationServiceInitializedEvent(InterNodeCommunicationServiceInitializedEvent event)
InterNodeCommunicationServiceInitializedEvent
. This
event signals that the inter-node communication service needed by this
service is ready for operation. This service uses this information in
order start its internal clock-skew monitor (which depends on remote
communication) and subsequently switch to the online state, if all other
conditions are met as well.event
- event signaling that the inter-node communication service is
ready for operation.public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface ApplicationEventPublisherAware
@Autowired public void setClusterServersDAO(ClusterServersDAO clusterServersDAO)
clusterServersDAO
- cluster-server DAO for accessing the database.@Autowired public void setControlSystemSupportRegistry(ControlSystemSupportRegistry controlSystemSupportRegistry)
controlSystemSupportRegistry
- control-system support registry for this archiving server.@Autowired public void setInterNodeCommunicationService(InterNodeCommunicationService interNodeCommunicationService)
interNodeCommunicationService
- inter-node communication service.@Autowired public void setServerProperties(ServerProperties serverProperties)
serverProperties
- configuration properties used by this server.public String getInterNodeCommunicationUrl(UUID serverId)
Returns the inter-node communication URL for the specified server. This
is the URL that is contacted by the InterNodeCommunicationService
in order to communicate with that server.
If the specified server ID is unknown of if the server is not online,
null
is returned.
This service serves the query from an internal cache. For this reason, the information returned might be outdated. However, this has the advantage that this method will never block.
serverId
- ID of the server for which the inter-node communication URL
shall be returned.null
if the specified server ID is unknown or the
server is considered offline.NullPointerException
- if serverId
is null
.public ServerStatus getServer(UUID serverId)
Returns the status for the server with the specified ID. The status is
retrieved from a cache that is updated periodically. Therefore, it might
be outdated. Code that needs to ensure that a server is offline should
use the verifyServerOffline(UUID)
method which bypasses the
cache.
By using the cache, this method ensures that it will never block.
serverId
- unique identifier identifying the server.null
if no status information is available for the
specified ID.NullPointerException
- if serverId
is null
.public List<ServerStatus> getServers()
Returns the status for all servers in the cluster. The list is ordered by
the server IDs. The status is retrieved from a cache that is updated
periodically. Therefore, it might be outdated. Code that needs to ensure
that a server is offline should use the
verifyServerOffline(UUID)
method which bypasses the cache.
By using the cache, this method ensures that it will never block.
null
).public ServerStatus getThisServer()
getServer(UUID)
, this reflects this server's actual
state and does not involve caching. In particular, the online information
returned with the server status reflects the current return value of
isOnline()
.null
).public boolean isOnline()
true
if the server is currently considered online
(has recently registered itself in the Cassandra database),
false
otherwise. In general, other components should only
run actions that might interfer with the operation of other servers when
this server has been registered in the database and thus this method
returns true
.true
if this server is considered online,
false
otherwise.public void removeServer(UUID serverId)
Removes the server with the specified ID from the cluster. A server can
only be removed if it has been offline for a sufficient amount of time.
This method calls verifyServerOffline(UUID)
to check that. This
method does not take care of resources associated with the specified
server (e.g. channels). The calling code should move such resources to a
different server before removing a server.
This method blocks while it is waiting for the verification of the server's offline status and the removal of the server to finish.
serverId
- unique identifier identifying the server to be removed.IllegalArgumentException
- if the specified server cannot be deleted because it has not
been offline for a sufficient amount of time.RuntimeException
- if there is an error accessing the underlying database.public ListenableFuture<Boolean> verifyServerOffline(UUID serverId)
getServer(UUID)
, this method does not use a
cache, but always queries the database directly. The result is returned
through a future so that this method does not block. If there is an
error, the future's get()
method throws an exception.serverId
- unique identifier of the server which should be checked.true
if the
server is currently not online or if there is no status
information for the specified ID in the database and
false
if the server with the specified ID is online.Copyright © 2011–2017 aquenos GmbH. All rights reserved.