public class ChannelInformationCacheImpl extends Object implements ChannelInformationCache, DisposableBean, InitializingBean, SmartInitializingSingleton
ChannelInformationCache
.Modifier and Type | Field and Description |
---|---|
protected org.apache.commons.logging.Log |
log
Logger for this class.
|
Constructor and Description |
---|
ChannelInformationCacheImpl() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
void |
afterSingletonsInstantiated() |
void |
destroy() |
ChannelMetaDataDAO.ChannelInformation |
getChannel(String channelName)
Returns the channel information for the specified channel name or
null if the channel does not exist. |
ListenableFuture<ChannelMetaDataDAO.ChannelInformation> |
getChannelAsync(String channelName,
boolean forceUpdate)
Returns the channel information for the specified channel name or
null if the channel does not exist. |
SortedMap<String,ChannelMetaDataDAO.ChannelInformation> |
getChannels()
Returns a map containing all channels in the cluster.
|
SortedMap<String,ChannelMetaDataDAO.ChannelInformation> |
getChannels(UUID serverId)
Returns a map containing all channels for the specified server.
|
Map<UUID,SortedMap<String,ChannelMetaDataDAO.ChannelInformation>> |
getChannelsSortedByServer()
Returns a map containing all channels in the cluster.
|
void |
onServerOnlineStatusEvent(ServerOnlineStatusEvent event)
Notifies the channel information cache that the server's online status
changed.
|
ListenableFuture<Void> |
processUpdate(List<ChannelMetaDataDAO.ChannelInformation> channelInformationUpdates,
List<String> missingChannels,
Iterable<UUID> forwardToServers,
long remoteTime)
Process an update that has been received from a remote server.
|
void |
setChannelMetaDataDAO(ChannelMetaDataDAO channelMetaDataDAO)
Sets the DAO for reading and modifying meta-data related to channels.
|
void |
setClusterManagementService(ClusterManagementService clusterManagementService)
Sets the cluster management service.
|
void |
setInterNodeCommunicationService(InterNodeCommunicationService interNodeCommunicationService)
Sets the inter-node communication service.
|
ListenableFuture<Void> |
updateChannels(Iterable<String> channelNames)
Updates the channel information for the specified channel name.
|
@Autowired public void setChannelMetaDataDAO(ChannelMetaDataDAO channelMetaDataDAO)
channelMetaDataDAO
- channel meta-data DAO to be used by this object.@Autowired public void setClusterManagementService(ClusterManagementService clusterManagementService)
clusterManagementService
- cluster manager used by the archiving server.@Autowired public void setInterNodeCommunicationService(InterNodeCommunicationService interNodeCommunicationService)
interNodeCommunicationService
- inter-node communication service.@EventListener public void onServerOnlineStatusEvent(ServerOnlineStatusEvent event)
Notifies the channel information cache that the server's online status
changed. Typically, this method is automatically called by the Spring
container when the ClusterManagementService
publishes
ServerOnlineStatusEvent
.
This method takes care of updating the cache when the server goes online and invalidating the cache when the server goes offline. These operations are performed asynchronously so that the thread sending the notification does not block.
event
- event specifying the server's new online status.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
public ChannelMetaDataDAO.ChannelInformation getChannel(String channelName)
ChannelInformationCache
Returns the channel information for the specified channel name or
null
if the channel does not exist.
The cache works in a way that it should be updated when channels are
modifies, so in general it should return up-to-date information about
channels. However, due to the asynchronous nature of cache updates, it is
possible that this method returns obsolete information. If it is
important that the most up-to-date information is returned, the
ChannelInformationCache.getChannelAsync(String, boolean)
method should be preferred.
This method throws an IllegalStateException
if the cache is not
ready. Reasons for the cache not being ready might be that it has not
been properly initialized yet or that updates have failed and thus the
cache has been invalidated in order to avoid serving obsolete
information.
getChannel
in interface ChannelInformationCache
channelName
- name of the channel for which the channel information shall be
retrieved.null
if the channel does not exist.public ListenableFuture<ChannelMetaDataDAO.ChannelInformation> getChannelAsync(String channelName, boolean forceUpdate)
ChannelInformationCache
Returns the channel information for the specified channel name or
null
if the channel does not exist. The operation completes
asynchronously (without blocking), so the channel information is returned
through a future.
If the cache is not ready to be queried, this method queries the database
directly. If the forceUpdate
flag is true
, the
database is always queried directly and the information in the cache is
updated with the information retrieved from the database.
The future returned by this method might throw the following exceptions:
NullPointerException
if the channelName
is
null
.RuntimeException
if the database is queried and that query
fails.getChannelAsync
in interface ChannelInformationCache
channelName
- name of the channel for which the channel information shall be
retrieved.forceUpdate
- true
if the database shall always be queried,
even if the cache is ready. false
if the
information from the cache should be used if the cache is
ready.public SortedMap<String,ChannelMetaDataDAO.ChannelInformation> getChannels()
ChannelInformationCache
Returns a map containing all channels in the cluster. The channel names are used as keys and the corresponding channel information objects are stored as values.
All the information is served from the cache. The cache works in a way that it should be updated when channels are modifies, so in general it should return up-to-date information about channels. However, due to the asynchronous nature of cache updates, it is possible that this method returns obsolete information.
This method throws an IllegalStateException
if the cache is not
ready. Reasons for the cache not being ready might be that it has not
been properly initialized yet or that updates have failed and thus the
cache has been invalidated in order to avoid serving obsolete
information.
getChannels
in interface ChannelInformationCache
public SortedMap<String,ChannelMetaDataDAO.ChannelInformation> getChannels(UUID serverId)
ChannelInformationCache
Returns a map containing all channels for the specified server. The channel names are used as keys and the corresponding channel information objects are stored as values. If the specified server is unknown, an empty map is returned.
All the information is served from the cache. The cache works in a way that it should be updated when channels are modifies, so in general it should return up-to-date information about channels. However, due to the asynchronous nature of cache updates, it is possible that this method returns obsolete information.
This method throws an IllegalStateException
if the cache is not
ready. Reasons for the cache not being ready might be that it has not
been properly initialized yet or that updates have failed and thus the
cache has been invalidated in order to avoid serving obsolete
information.
getChannels
in interface ChannelInformationCache
serverId
- id of the server for which the channels shall be returned.public Map<UUID,SortedMap<String,ChannelMetaDataDAO.ChannelInformation>> getChannelsSortedByServer()
ChannelInformationCache
Returns a map containing all channels in the cluster. The channels are aggregated by their associated server, having one map for each server ID.
All the information is served from the cache. The cache works in a way that it should be updated when channels are modifies, so in general it should return up-to-date information about channels. However, due to the asynchronous nature of cache updates, it is possible that this method returns obsolete information.
This method throws an IllegalStateException
if the cache is not
ready. Reasons for the cache not being ready might be that it has not
been properly initialized yet or that updates have failed and thus the
cache has been invalidated in order to avoid serving obsolete
information.
getChannelsSortedByServer
in interface ChannelInformationCache
public ListenableFuture<Void> processUpdate(List<ChannelMetaDataDAO.ChannelInformation> channelInformationUpdates, List<String> missingChannels, Iterable<UUID> forwardToServers, long remoteTime)
ChannelInformationCache
Process an update that has been received from a remote server. This
method should only be called by remote servers (through the corresponding
web-service API). It updates the cache with the information supplied in
the request, merging the entries in the cache with the entries from the
update. The cache is updated synchronously, but the servers specified in
forwardToServers
are notified asynchronously.
The notification of other servers works in a cascaded way: Only a limited number of servers from the specified list are notified directly. Those servers are in turn asked to notify a subset of the remaining servers. This way, each server only has to handle a limited number of notifications, even if the cluster is very large.
The returned future throws a NullPointerException
if
channelInformationUpdates
, missingChannels
, or
forwardToServers
is null
or they contain
null
elements.
processUpdate
in interface ChannelInformationCache
channelInformationUpdates
- updated channel-information objects.missingChannels
- channels that are missing now (the channel information is
null
- typically because the channel has been
deleted).forwardToServers
- list of servers which should be notified with the information
from the update.remoteTime
- time stamp (as returned by System.currentTimeMillis()
of the point in time before the channel information that is
sent with this update was retrieved from the database. This
information is used when resolving conflicting updates for the
same channel.public ListenableFuture<Void> updateChannels(Iterable<String> channelNames)
ChannelInformationCache
Updates the channel information for the specified channel name. This
method does not only update the local cache but also forwards the updated
information to all remote servers by calling their
ChannelInformationCache.processUpdate(List, List, Iterable, long)
method with the
updated information.
This method is intended for the ArchiveConfigurationService
which
calls it when it modifies channel configurations.
The future returned by this method might throw the following exceptions:
NullPointerException
if the channelNames
is
null
or contains null
elements.RuntimeException
if one of the database queries needed for
the update fails.updateChannels
in interface ChannelInformationCache
channelNames
- names of the channels to be updated.Copyright © 2011–2017 aquenos GmbH. All rights reserved.