Class AbstractConnector<C extends Connection<?,?,?>>

java.lang.Object
org.scictrl.csshell.AbstractConnector<C>
Type Parameters:
C - connection implementation type
Direct Known Subclasses:
DummyConnector, EPICSConnector

public abstract class AbstractConnector<C extends Connection<?,?,?>> extends Object
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
  • Field Details

    • debug

      protected boolean debug
      Debug flag.
    • connectionCache

      protected ConnectionCache<C extends Connection<?,?,?>> connectionCache
      Connection cache.
    • PROPERTY_CORE_THREADS

      public static final String PROPERTY_CORE_THREADS
      Property name for core threads property: coreThreads

      The number of core threads must be non-negative.

      See Also:
    • PROPERTY_MAX_THREADS

      public static final String 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

      public static final String PROPERTY_READ_ONLY
      Property name for setting whole connector in read-only mode by disabling write functionality. Default value is false.
      See Also:
  • Constructor Details

    • AbstractConnector

      protected AbstractConnector(Properties configuration)
      Creates new plug instance.
      Parameters:
      configuration - a Properties object
  • Method Details

    • newDefaultConnectionCache

      protected ConnectionCache<C> 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

      public abstract String getType()
      Returns connector type string.
      Returns:
      distinguishing type name
    • getInstance

      public static AbstractConnector<?> getInstance(Properties configuration) throws RemoteException

      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

      public void shutdown() throws Exception
      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

      public Properties 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

      public TimerTask schedule(Runnable r, long delay, long rate)
      Schedule task for execution.
      Parameters:
      r - ask to be scheduled.
      delay - delay in milliseconds before task is to be executed.
      rate - reschedule perion, if 0 periodic rescheduling is disabled.
      Returns:
      TimerTask instance, used to cancel the task scheduling.
    • getMetaData

      public abstract MetaData getMetaData(String name, DataType type) throws Exception

      getMetaData.

      Parameters:
      name - a String object
      type - a DataType object
      Returns:
      a MetaData object
      Throws:
      Exception - if any.
    • getMetaDataAsync

      public abstract void getMetaDataAsync(gov.aps.jca.Channel channel, PropertyChangeListener l) throws Exception

      getMetaDataAsync.

      Parameters:
      channel - a Channel object
      l - a PropertyChangeListener object
      Throws:
      Exception - if any.
    • getCoreThreads

      public int getCoreThreads()
      Gets coreThreads property.
      Returns:
      the number of core threads.
    • getExecutor

      public ThreadPoolExecutor getExecutor()
      In order to use this method the PROPERTY_MAX_THREADS must be greater than 0.
      Returns:
      a ThreadPoolExecutor
      Throws:
      IllegalStateException - if useCommonExecutor property is set to false or maximum number of threads is equal to 0.
    • getMaxThreads

      public int getMaxThreads()
      Gets maxThreads property.
      Returns:
      the maximum number of threads.
    • newConnection

      public abstract C newConnection(String name, DataType dataType) throws RemoteException

      newConnection.

      Parameters:
      name - a String object
      dataType - a DataType object
      Returns:
      a C object
      Throws:
      RemoteException - if any.
    • getDefaultMetaData

      public MetaData getDefaultMetaData(String name, DataType dataType)

      getDefaultMetaData.

      Parameters:
      name - a String object
      dataType - a DataType object
      Returns:
      a MetaData object
    • registerDefaultMetaData

      protected void registerDefaultMetaData(String name, DataType dataType, MetaData data)

      registerDefaultMetaData.

      Parameters:
      name - a String object
      dataType - a DataType object
      data - a MetaData object
    • getValue

      public abstract Object getValue(String name, DataType type) throws RemoteException

      getValue.

      Parameters:
      name - a String object
      type - a DataType object
      Returns:
      a Object object
      Throws:
      RemoteException - if any.
    • getConnectionCache

      public ConnectionCache<C> 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

      public void setConnectionCache(ConnectionCache<C> connectionCache)
      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()
      Returns true when this connector is not setting values to underlying remote connections.
      Returns:
      true when this connector is not setting values