Package xal.ca

Class AbstractBatchGetRequest<T extends ChannelRecord>

java.lang.Object
xal.ca.AbstractBatchGetRequest<T>
All Implemented Interfaces:
BatchConnectionRequestListener
Direct Known Subclasses:
BatchGetValueRequest, BatchGetValueTimeRequest

public abstract class AbstractBatchGetRequest<T extends ChannelRecord> extends Object implements BatchConnectionRequestListener
AbstractBatchGetRequest
  • Constructor Details

    • AbstractBatchGetRequest

      protected AbstractBatchGetRequest(Collection<Channel> channels)
      Primary Constructor
      Parameters:
      channels - the channels for which get requests will be handled
  • Method Details

    • finalize

      protected void finalize() throws Throwable
      dispose of the executors
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • addBatchGetRequestListener

      public void addBatchGetRequestListener(BatchGetRequestListener<T> listener)
      add the specified listener as a receiver of batch get request events from this instance
      Parameters:
      listener - a receiver which will receive events
    • removeBatchGetRequestListener

      public void removeBatchGetRequestListener(BatchGetRequestListener<T> listener)
      remove the specified listener from receiving batch get request events from this instance
      Parameters:
      listener - receiver to remove from receiving events
    • addChannel

      public void addChannel(Channel channel)
      add a new channel to the batch request
      Parameters:
      channel - a channel to add to the batch request
    • getChannels

      public Collection<Channel> getChannels()
      get the collection of channels to process
      Returns:
      a copy of the list of channels in the batch request
    • submit

      public void submit()
      submit as a batch the get requests for each channel
    • submitAndWait

      public boolean submitAndWait(double timeout)
      Submit a batch of get requests and wait for the requests to be completed or timeout. Note that if this is called, within a channel access callback, requests will not be processed until the callback completes, so it is useless to wait. Instead, call waitForCompletion separately outside of the callback.
      Parameters:
      timeout - the maximum time in seconds to wait for completion
      Returns:
      true if complete or false if not
    • await

      public boolean await(double timeout)
      Synonym for waitForCompletion. Wait up to the specified timeout for completion. This method should be called outside of a Channel Access callback otherwise events will not be processed.
      Parameters:
      timeout - the maximum time in seconds to wait for completion
      Returns:
      true if complete or false if not
    • waitForCompletion

      public boolean waitForCompletion(double timeout)
      Wait up to the specified timeout for completion. This method should be called outside of a Channel Access callback otherwise events will not be processed.
      Parameters:
      timeout - the maximum time in seconds to wait for completion
      Returns:
      true if complete or false if not
    • requestChannelData

      protected abstract void requestChannelData(Channel channel) throws ConnectionException, GetException
      Request to get the data for the channel
      Parameters:
      channel - the channel for which to request data
      Throws:
      Exception - when the request fails
      ConnectionException
      GetException
    • processRequest

      protected void processRequest(Channel channel)
      Process the get request for a single channel
      Parameters:
      channel - the channel for which to process the request
    • isComplete

      public boolean isComplete()
      determine if there are any channels pending for either an exception or a completed get request
      Returns:
      true if complete and false if not
    • hasExceptions

      public boolean hasExceptions()
      determine if there were any exceptions
      Returns:
      true if there are any exceptions and false if not
    • getRecordCount

      public int getRecordCount()
      get the number of records
      Returns:
      the number of records
    • getExceptionCount

      public int getExceptionCount()
      Get the number of exceptions
      Returns:
      the number of channels for which there was an exception during the request
    • getRecord

      public T getRecord(Channel channel)
      Get the record if any for the specified channel
      Parameters:
      channel - the channel for which the record is fetched
      Returns:
      the record for the specified channel or null if there is none
    • getException

      public Exception getException(Channel channel)
      Get the exception if any for the specified channel
      Parameters:
      channel - the channel for which the exception is fetched
      Returns:
      the exception for the specified channel or null if there is none
    • getFailedChannels

      public Set<Channel> getFailedChannels()
      Get the failed channels for which exceptions were thrown during the request
      Returns:
      the set of failed channels
    • getResultChannels

      public Set<Channel> getResultChannels()
      Get the channels which produced a result
      Returns:
      the set of channels each for which a record was successfully fetched
    • processRecordEvent

      protected void processRecordEvent(Channel channel, T channelRecord)
      Process the receipt of a new record event
      Parameters:
      channel - the channel for which the event will be processed
      channelRecord - the fetched record
    • processCurrentStatus

      protected void processCurrentStatus()
      check for the current status and post notifications if necessary
    • batchConnectionRequestCompleted

      public void batchConnectionRequestCompleted(BatchConnectionRequest connectionRequest, int connectedCount, int disconnectedCount, int exceptionCount)
      event indicating that the batch request is complete
      Specified by:
      batchConnectionRequestCompleted in interface BatchConnectionRequestListener
      Parameters:
      connectionRequest - request for which the connection completed
      connectedCount - number of channels connected
      disconnectedCount - number of channels disconnected
      exceptionCount - number of channels for which there were connection exceptions
    • connectionExceptionInBatch

      public void connectionExceptionInBatch(BatchConnectionRequest connectionRequest, Channel channel, Exception exception)
      event indicating that an exception has been thrown for a channel
      Specified by:
      connectionExceptionInBatch in interface BatchConnectionRequestListener
      Parameters:
      connectionRequest - in which the exception occurred
      channel - for which the exception occurred
      exception - the exception thrown while attempting to connect
    • connectionChangeInBatch

      public void connectionChangeInBatch(BatchConnectionRequest connectionRequest, Channel channel, boolean connected)
      event indicating that a connection change has occurred for a channel
      Specified by:
      connectionChangeInBatch in interface BatchConnectionRequestListener
      Parameters:
      connectionRequest - in which the connection changed
      channel - for which the connection changed
      connected - status of the connection (true for connected and false for disconnected)