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
Modifier and TypeClassDescriptionclass
Default implementation of connection cache interface. -
Field Summary
Modifier and TypeFieldDescriptionprotected ConnectionCache
<C> Connection cache.protected boolean
Debug flag.static final String
Property name for core threads property:coreThreads
static final String
Property name for max threads property:maxThreads
static final String
Property name for setting whole connector in read-only mode by disabling write functionality. -
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractConnector
(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)
).int
GetscoreThreads
property.getDefaultMetaData
(String name, DataType dataType) getDefaultMetaData.In order to use this method thePROPERTY_MAX_THREADS
must 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.Logger
Returns the Logger used by this plug.int
GetsmaxThreads
property.abstract MetaData
getMetaData
(String name, DataType type) getMetaData.abstract void
getMetaDataAsync
(gov.aps.jca.Channel channel, PropertyChangeListener l) getMetaDataAsync.abstract String
getType()
Returns connector type string.abstract Object
getValue.boolean
isAlive()
isAlive.boolean
isDebug()
isDebug.boolean
Returnstrue
when this connector is not setting values to underlying remote connections.abstract C
newConnection
(String name, DataType dataType) newConnection.protected ConnectionCache
<C> Creates new instance of default connection cache.protected void
registerDefaultMetaData
(String name, DataType dataType, MetaData data) registerDefaultMetaData.Schedule task for execution.void
setConnectionCache
(ConnectionCache<C> connectionCache) Sets connection cache to the connector instance.void
shutdown()
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:coreThreads
The number of core threads must be non-negative.
- See Also:
-
PROPERTY_MAX_THREADS
Property name for max threads property:maxThreads
The 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
- aProperties
object
-
-
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
Logger
object
-
schedule
Schedule task for execution.- Parameters:
r
- ask to be scheduled.delay
- delay in milliseconds before task is to be executed.rate
- reschedule perion, if0
periodic rescheduling is disabled.- Returns:
TimerTask
instance, 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
- aChannel
objectl
- aPropertyChangeListener
object- Throws:
Exception
- if any.
-
getCoreThreads
public int getCoreThreads()GetscoreThreads
property.- Returns:
- the number of core threads.
-
getExecutor
In order to use this method thePROPERTY_MAX_THREADS
must be greater than 0.- Returns:
- a
ThreadPoolExecutor
- Throws:
IllegalStateException
- if useCommonExecutor property is set tofalse
or maximum number of threads is equal to 0.
-
getMaxThreads
public int getMaxThreads()GetsmaxThreads
property.- Returns:
- the maximum number of threads.
-
newConnection
newConnection.
- Parameters:
name
- aString
objectdataType
- aDataType
object- Returns:
- a C object
- Throws:
RemoteException
- if any.
-
getDefaultMetaData
getDefaultMetaData.
-
registerDefaultMetaData
registerDefaultMetaData.
-
getValue
getValue.
- Parameters:
name
- aString
objecttype
- aDataType
object- Returns:
- a
Object
object - 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()Returnstrue
when this connector is not setting values to underlying remote connections.- Returns:
true
when this connector is not setting values
-