public class AlarmSourceFactory
extends java.lang.Object
AlarmSourceFactory is in charge of instantiating and releasing AlarmSource objects
avoid dependencies in the ACSAlarmSystemInterfaceFactory, ComponentClient and
ContainerServices.
AlarmSourceFactory should be used by ComponentClient and ContainerServices
to return a AlarmSource and to release all the AlarmSource objects before exiting.
The purpose of AlarmSourceFactory is to store and delivery AlarmSource objects to components,
being sure that a component instantiates at the most one and only one AlarmSource.
The AlarmSourceFactory keep a reference to all the instantiated AlarmSource objects to ensure, during the
shutdown of a component, to flush all the alarms and finally release all the resources used by those
objects.
Life cycle: while there is no special initialization method,
tearDown() must be called when done with this object.
Concurrency: We use a ConcurrentHashMap that reduces the number of lock outs in respect
of the traditional HashMap resulting in better performances, especially when the number of get's
is relevant as we expect during normal activities. To avoid using another lock for releasing
all the alarm sources, we preferred a volatile boolean to reject operations when the factory has been closed.
Under some circumstances, it could happen that the tearDown cleans the map when another method is still running.
This should not be a big deal because tearDown runs just before terminating the container (or
component client).
| Constructor and Description |
|---|
AlarmSourceFactory(ContainerServicesBase contSvcs)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
AlarmSource |
getAlarmSource(ContainerServicesBase containerServices)
Return the
AlarmSource for the component whose name is read from
passed the ContainerServicesBase. |
AlarmSource |
getAlarmSource(java.lang.String componentName)
Return the
AlarmSource for the component with the passed name. |
void |
releaseAlarmSource(ContainerServicesBase containerServices)
Release the
AlarmSource object of the component whose name is read from
passed the ContainerServicesBase. |
void |
releaseAlarmSource(java.lang.String componentName)
Release the
AlarmSource object of the component whose name is read from
passed the ContainerServicesBase. |
void |
tearDown() |
public AlarmSourceFactory(ContainerServicesBase contSvcs)
logger - The loggerclosed - public AlarmSource getAlarmSource(ContainerServicesBase containerServices)
AlarmSource for the component whose name is read from
passed the ContainerServicesBase.
If a AlarmSource already exists for the component then a reference is returned,
otherwise a new AlarmSource is built.
containerServices - The not null ContainerServicesBaseAlarmSourcepublic AlarmSource getAlarmSource(java.lang.String componentName)
AlarmSource for the component with the passed name.
If a AlarmSource already exists for the component then a reference is returned,
otherwise a new AlarmSource is built.
Note that the component name is used as a key to return the same AlarmSource
for the same component so in principle the parameter componentName
can be freely set.
componentName - The not null and not empty name of the component.AlarmSourcepublic void releaseAlarmSource(ContainerServicesBase containerServices)
AlarmSource object of the component whose name is read from
passed the ContainerServicesBase.containerServices - public void releaseAlarmSource(java.lang.String componentName)
AlarmSource object of the component whose name is read from
passed the ContainerServicesBase.componentName - The name of the componentpublic void tearDown()