Class RequestImpl<C extends AbstractConnector<?>>

java.lang.Object
org.scictrl.csshell.RequestImpl<C>
Type Parameters:
C - connector implementation
All Implemented Interfaces:
Iterable<Response<C>>, Request<C>
Direct Known Subclasses:
EPICSConnection.GetRequest, EPICSConnection.PutRequest

public class RequestImpl<C extends AbstractConnector<?>> extends Object implements Request<C>
Default implementation of request object. It conveniently stores responses up to the capacity and notifies request listener about new responses.
Author:
igor@scictrl.com
  • Field Details

  • Constructor Details

    • RequestImpl

      public RequestImpl(Connection<C,?,?> source, ResponseListener<C> l, Object tag)
      Creates new instance. Default response capacity is 1.
      Parameters:
      source - the source of responses
      l - response listener
      tag - a Object object
      See Also:
    • RequestImpl

      public RequestImpl(Connection<C,?,?> source, ResponseListener<C> l, Object tag, int capacity)
      Creates new instance with defined capacity for responses.
      Parameters:
      source - the source of reponses
      l - listener
      tag - a Object object
      capacity - number of last responses stored, if 0 all responses are stored.
      See Also:
  • Method Details

    • getConnection

      public Connection<C,?,?> getConnection()
      Returns the source of the request
      Specified by:
      getConnection in interface Request<C extends AbstractConnector<?>>
      Returns:
      source of the request
    • hasResponse

      public boolean hasResponse()
      Returns true if there are any responses available
      Specified by:
      hasResponse in interface Request<C extends AbstractConnector<?>>
      Returns:
      true if response available
    • responses

      public Iterator<Response<C>> responses()
      Returns the Iterator for the response storage.
      Specified by:
      responses in interface Request<C extends AbstractConnector<?>>
      Returns:
      Response iterator
    • getTag

      public Object getTag()
      Optional identification tag of the response. Interpretation depends on asynchronus methods which generated this response.
      Specified by:
      getTag in interface Request<C extends AbstractConnector<?>>
      Returns:
      identification tag.
    • addResponse

      public void addResponse(Response<C> r)
      Adds new response to this request object and dispatches it to listener.
      Parameters:
      r - new response to be dispatched
      Throws:
      NullPointerException - if response is null
      IllegalArgumentException - if source of response and source of this request is not equal
    • isCompleted

      public boolean isCompleted()
      Returns true if request has been completed.
      Specified by:
      isCompleted in interface Request<C extends AbstractConnector<?>>
      Returns:
      true if request was completed.
    • getCapacity

      public int getCapacity()
      Capacity number defines how many of last responses is stored in this request. 0 means that all are stored.
      Returns:
      Returns the capacity.
    • getResponseListener

      public ResponseListener<C> getResponseListener()

      getResponseListener.

      Returns:
      a ResponseListener object
    • getFirstResponse

      public Response<C> getFirstResponse()
      Returns the first response to this request.
      Specified by:
      getFirstResponse in interface Request<C extends AbstractConnector<?>>
      Returns:
      the first response
    • getLastResponse

      public Response<C> getLastResponse()
      Returns the last arrived response.
      Specified by:
      getLastResponse in interface Request<C extends AbstractConnector<?>>
      Returns:
      the last response
    • iterator

      public Iterator<Response<C>> iterator()
      Specified by:
      iterator in interface Iterable<C extends AbstractConnector<?>>
    • waitUntilDone

      public Response<C> waitUntilDone()
      Blocks call until last response is received.
      NOTE: call from this method is returned after events are dispatched on ResponseListeners. Blocks call until last response is received.
      NOTE: call from this method is returned after events are dispatched on ResponseListeners.
      Specified by:
      waitUntilDone in interface Request<C extends AbstractConnector<?>>
      Returns:
      final value received with done event.