public class ClusterServersDAOImpl extends Object implements ApplicationEventPublisherAware, ClusterServersDAO, SmartInitializingSingleton
cluster_servers
table in the Apache Cassandra database.ClusterServersDAO.ClusterServer
Modifier and Type | Field and Description |
---|---|
protected org.slf4j.Logger |
log
Logger for this object.
|
Constructor and Description |
---|
ClusterServersDAOImpl() |
Modifier and Type | Method and Description |
---|---|
void |
afterSingletonsInstantiated() |
ListenableFuture<Void> |
createOrUpdateServer(UUID serverId,
String serverName,
String interNodeCommunicationUrl,
Date lastOnlineTime)
Creates or updates the record for an archive server.
|
ListenableFuture<Void> |
deleteServer(UUID serverId)
Removes the server with the specified ID from the database.
|
ListenableFuture<? extends ClusterServersDAO.ClusterServer> |
getServer(UUID serverId)
Reads the server object for the specified ID from the database.
|
ListenableFuture<? extends Iterable<? extends ClusterServersDAO.ClusterServer>> |
getServers()
Reads the server objects for all servers from the database.
|
boolean |
isInitialized()
Tells whether this DAO has finished initialization and is ready to be
used.
|
void |
onCassandraProviderInitializedEvent(CassandraProviderInitializedEvent event)
Handles
CassandraProviderInitializedEvent s. |
void |
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) |
void |
setCassandraProvider(CassandraProvider cassandraProvider)
Sets the Cassandra provider that provides access to the Apache Cassandra
database.
|
ListenableFuture<Void> |
updateServerLastOnlineTime(UUID serverId,
Date lastOnlineTime)
Updates the last-online time for an archive server.
|
protected final org.slf4j.Logger log
@EventListener @Order(value=1000) public void onCassandraProviderInitializedEvent(CassandraProviderInitializedEvent event)
CassandraProviderInitializedEvent
s. This event is used
when the CassandraProvider
set using
setCassandraProvider(CassandraProvider)
is not ready yet when
this object is initialized. In this case, some actions that usually are
performed during initialization (like creating tables, initializing
access objects) have to be deferred until the Apache Cassandra database
becomes available.event
- initialization event sent by the CassandraProvider
.@Autowired public void setCassandraProvider(CassandraProvider cassandraProvider)
cassandraProvider
- provider that provides a connection to the Apache Cassandra
database.public void afterSingletonsInstantiated()
afterSingletonsInstantiated
in interface SmartInitializingSingleton
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface ApplicationEventPublisherAware
public ListenableFuture<Void> createOrUpdateServer(UUID serverId, String serverName, String interNodeCommunicationUrl, Date lastOnlineTime)
ClusterServersDAO
serverId
does not exist yet, it is created.
Otherwise, it is updated. The operation is performed in an asynchronous
way so that it will not block for network communication. The result of
the operation can be checked through the returned future.createOrUpdateServer
in interface ClusterServersDAO
serverId
- unique ID identifying the server within the cluster. This ID
must be different for each server.serverName
- name (typically the hostname) of the server. The name is used
to help the user in identifying a server. It should be unique
for each server, but this condition is not enforced.interNodeCommunicationUrl
- base URL for the web-service interface of the server that can
be used by other servers within the cluster to communicate
with the server.lastOnlineTime
- time the server last updated its status. This time is used by
other servers to determine if the server is online. Typically,
this parameter should be the current time when calling this
method. The last-online time needs to be updated periodically,
but the ClusterServersDAO.updateServerLastOnlineTime(UUID, Date)
should
be preferred for this purpose.get()
method will throw an exception.public ListenableFuture<Void> deleteServer(UUID serverId)
ClusterServersDAO
deleteServer
in interface ClusterServersDAO
serverId
- unique identifier of the server that shall be removed from the
database.get()
method will throw an exception.public ListenableFuture<? extends ClusterServersDAO.ClusterServer> getServer(UUID serverId)
ClusterServersDAO
getServer
in interface ClusterServersDAO
serverId
- unique identifier identifying the server.get
method returns
null
. In case of failure, the future's
get()
method will throw an exception.public ListenableFuture<? extends Iterable<? extends ClusterServersDAO.ClusterServer>> getServers()
ClusterServersDAO
Reads the server objects for all servers from the database. The server objects are not returned directly but through a listenable future, so that the calling code can wait for the database operation to finish asynchronously.
The iterable returned by the future is only safe for iterating once. Subsequent requests to create an iterator might result in the new iterator only returning the elements that have not been returned by a previously created iterator yet. Besides, the iterator might block while iterating, waiting for additional elements to arrive from the network.
getServers
in interface ClusterServersDAO
get()
method will throw an exception.public boolean isInitialized()
ClusterServersDAO
true
, operations might
still fail because of transient problems.isInitialized
in interface ClusterServersDAO
true
if this DAO has been initialized and is ready
to be used, false
if initialization has not
completed yet.public ListenableFuture<Void> updateServerLastOnlineTime(UUID serverId, Date lastOnlineTime)
ClusterServersDAO
ClusterServersDAO.createOrUpdateServer(UUID, String, String, Date)
method.
However, implementations might not enforce this limitation, silently
creating a partially initialized record when this method is called first.updateServerLastOnlineTime
in interface ClusterServersDAO
serverId
- unique ID identifying the server within the cluster. This ID
must be different for each server.lastOnlineTime
- time the server last updated its status. This time is used by
other servers to determine if the server is online. Typically,
this parameter should be the current time when calling this
method. The last-online time needs to be updated periodically.get()
method will throw an exception.Copyright © 2011–2017 aquenos GmbH. All rights reserved.