Package org.scictrl.csshell
Class AbstractConnector<C extends Connection<?,?,?>>
java.lang.Object
org.scictrl.csshell.AbstractConnector<C>
- Type Parameters:
C- connection implementation type
- Direct Known Subclasses:
DummyConnector,EPICSConnector
This is abstract plug class which helps plug implementators write own
plug. This plug has implemented support for following features: proxy
object sharing.
- Author:
- igor@scictrl.com
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassDefault implementation of connection cache interface. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConnectionCache<C> Connection cache.protected booleanDebug flag.static final StringProperty name for core threads property:coreThreadsstatic final StringProperty name for max threads property:maxThreadsstatic final StringProperty name for setting whole connector in read-only mode by disabling write functionality. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractConnector(Properties configuration) Creates new plug instance. -
Method Summary
Modifier and TypeMethodDescriptionReturn active configuration of this plug.Returns connection cache, if it was set (setConnectionCache(ConnectionCache)).intGetscoreThreadsproperty.getDefaultMetaData(String name, DataType dataType) getDefaultMetaData.In order to use this method thePROPERTY_MAX_THREADSmust be greater than 0.static AbstractConnector<?> getInstance(Properties configuration) This method MUST be implemented by plug implementation if plug want to support default behavior with shared plug instanceorg.apache.logging.log4j.LoggerReturns the Logger used by this plug.intGetsmaxThreadsproperty.abstract MetaDatagetMetaData(String name, DataType type) getMetaData.abstract voidgetMetaDataAsync(gov.aps.jca.Channel channel, PropertyChangeListener l) getMetaDataAsync.abstract StringgetType()Returns connector type string.abstract ObjectgetValue.booleanisAlive()isAlive.booleanisDebug()isDebug.booleanReturnstruewhen this connector is not setting values to underlying remote connections.abstract CnewConnection(String name, DataType dataType) newConnection.protected ConnectionCache<C> Creates new instance of default connection cache.protected voidregisterDefaultMetaData(String name, DataType dataType, MetaData data) registerDefaultMetaData.Schedule task for execution.voidsetConnectionCache(ConnectionCache<C> connectionCache) Sets connection cache to the connector instance.voidshutdown()This method is used all destroy connector instance and releases all connection and resources.
-
Field Details
-
debug
protected boolean debugDebug flag. -
connectionCache
Connection cache. -
PROPERTY_CORE_THREADS
Property name for core threads property:coreThreadsThe number of core threads must be non-negative.
- See Also:
-
PROPERTY_MAX_THREADS
Property name for max threads property:maxThreadsThe number of core threads must be non-negative and greater than the number of core threads.
- See Also:
-
PROPERTY_READ_ONLY
Property name for setting whole connector in read-only mode by disabling write functionality. Default value isfalse.- See Also:
-
-
Constructor Details
-
AbstractConnector
Creates new plug instance.- Parameters:
configuration- aPropertiesobject
-
-
Method Details
-
newDefaultConnectionCache
Creates new instance of default connection cache. Default connector cache uses weak reference, therefore not used connection are automatically removed from the cache. Also deleted connection are removed, when spotted.- Returns:
- new instance of default connection cache
-
getType
Returns connector type string.- Returns:
- distinguishing type name
-
getInstance
This method MUST be implemented by plug implementation if plug want to support default behavior with shared plug instance
.This method is used by default DAL factories to access plug instances. Implementation may choose one of the following strategies how this method is implemented:
- Singleton plug: This method always returns the same instance, thus singleton. This means that this particular DAL implementation will always use same plug.
- Multiple plugs: Implementation may decide to return different plug instance. In this case it may be wiser to declare in AbstractFactorySupport this plug to be non-shared.
Which strategy will be used could be hard-coded in AbstractFactorySupport or dynamically decided from application context configuration with AbstractFactory.SHARE_PLUG property.
- Parameters:
configuration- Properties with configuration, whcih is provided by application context, which initiated plug construction.- Returns:
- new or reused plug instance, depends on plug implementation strategy
- Throws:
RemoteException- if construction fails.
-
shutdown
This method is used all destroy connector instance and releases all connection and resources. After this call connector is no longer alive.- Throws:
Exception- if shutdown fails.
-
isAlive
public boolean isAlive()isAlive.
- Returns:
- a boolean
-
getConfiguration
Return active configuration of this plug.- Returns:
- Returns the configuration.
-
isDebug
public boolean isDebug()isDebug.
- Returns:
- a boolean
-
getLogger
public org.apache.logging.log4j.Logger getLogger()Returns the Logger used by this plug. This logger logs all exceptions and printouts within the DAL implementation.- Returns:
- a
Loggerobject
-
schedule
Schedule task for execution.- Parameters:
r- ask to be scheduled.delay- delay in milliseconds before task is to be executed.rate- reschedule perion, if0periodic rescheduling is disabled.- Returns:
TimerTaskinstance, used to cancel the task scheduling.
-
getMetaData
getMetaData.
-
getMetaDataAsync
public abstract void getMetaDataAsync(gov.aps.jca.Channel channel, PropertyChangeListener l) throws Exception getMetaDataAsync.
- Parameters:
channel- aChannelobjectl- aPropertyChangeListenerobject- Throws:
Exception- if any.
-
getCoreThreads
public int getCoreThreads()GetscoreThreadsproperty.- Returns:
- the number of core threads.
-
getExecutor
In order to use this method thePROPERTY_MAX_THREADSmust be greater than 0.- Returns:
- a
ThreadPoolExecutor - Throws:
IllegalStateException- if useCommonExecutor property is set tofalseor maximum number of threads is equal to 0.
-
getMaxThreads
public int getMaxThreads()GetsmaxThreadsproperty.- Returns:
- the maximum number of threads.
-
newConnection
newConnection.
- Parameters:
name- aStringobjectdataType- aDataTypeobject- Returns:
- a C object
- Throws:
RemoteException- if any.
-
getDefaultMetaData
getDefaultMetaData.
-
registerDefaultMetaData
registerDefaultMetaData.
-
getValue
getValue.
- Parameters:
name- aStringobjecttype- aDataTypeobject- Returns:
- a
Objectobject - Throws:
RemoteException- if any.
-
getConnectionCache
Returns connection cache, if it was set (setConnectionCache(ConnectionCache)). If no connection cache was set, then it is not used.- Returns:
- connection cache in use, or null
-
setConnectionCache
Sets connection cache to the connector instance. If not set, then it is not used. By default connection cache is not set or used.- Parameters:
connectionCache- connection cache to be used
-
isReadOnly
public boolean isReadOnly()Returnstruewhen this connector is not setting values to underlying remote connections.- Returns:
truewhen this connector is not setting values
-