Package org.scictrl.csshell
Class RequestImpl<C extends AbstractConnector<?>>
java.lang.Object
org.scictrl.csshell.RequestImpl<C>
- Type Parameters:
C
- connector implementation
- Direct Known Subclasses:
EPICSConnection.GetRequest
,EPICSConnection.PutRequest
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 Summary
Modifier and TypeFieldDescriptionprotected ResponseListener
<C> Listener.protected LinkedList
<Response<C>> Collected responses.protected Connection
<C, ?, ?> Source.protected Object
Tag for events to be distinguished. -
Constructor Summary
ConstructorDescriptionRequestImpl
(Connection<C, ?, ?> source, ResponseListener<C> l, Object tag) Creates new instance.RequestImpl
(Connection<C, ?, ?> source, ResponseListener<C> l, Object tag, int capacity) Creates new instance with defined capacity for responses. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addResponse
(Response<C> r) Adds new response to this request object and dispatches it to listener.int
Capacity number defines how many of last responses is stored in this request.Connection
<C, ?, ?> Returns the source of the requestReturns the first response to this request.Returns the last arrived response.getResponseListener.getTag()
Optional identification tag of the response.boolean
Returns true if there are any responses availableboolean
Returnstrue
if request has been completed.iterator()
Returns the Iterator for the response storage.Blocks call until last response is received.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
responses
Collected responses. -
source
Source. -
listener
Listener. -
tag
Tag for events to be distinguished.
-
-
Constructor Details
-
RequestImpl
Creates new instance. Default response capacity is 1.- Parameters:
source
- the source of responsesl
- response listenertag
- aObject
object- See Also:
-
RequestImpl
Creates new instance with defined capacity for responses.- Parameters:
source
- the source of reponsesl
- listenertag
- aObject
objectcapacity
- number of last responses stored, if 0 all responses are stored.- See Also:
-
-
Method Details
-
getConnection
Returns the source of the request- Specified by:
getConnection
in interfaceRequest<C extends AbstractConnector<?>>
- Returns:
- source of the request
-
hasResponse
public boolean hasResponse()Returns true if there are any responses available- Specified by:
hasResponse
in interfaceRequest<C extends AbstractConnector<?>>
- Returns:
- true if response available
-
responses
Returns the Iterator for the response storage.- Specified by:
responses
in interfaceRequest<C extends AbstractConnector<?>>
- Returns:
- Response iterator
-
getTag
Optional identification tag of the response. Interpretation depends on asynchronus methods which generated this response.- Specified by:
getTag
in interfaceRequest<C extends AbstractConnector<?>>
- Returns:
- identification tag.
-
addResponse
Adds new response to this request object and dispatches it to listener.- Parameters:
r
- new response to be dispatched- Throws:
NullPointerException
- if response is nullIllegalArgumentException
- if source of response and source of this request is not equal
-
isCompleted
public boolean isCompleted()Returnstrue
if request has been completed.- Specified by:
isCompleted
in interfaceRequest<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
getResponseListener.
- Returns:
- a
ResponseListener
object
-
getFirstResponse
Returns the first response to this request.- Specified by:
getFirstResponse
in interfaceRequest<C extends AbstractConnector<?>>
- Returns:
- the first response
-
getLastResponse
Returns the last arrived response.- Specified by:
getLastResponse
in interfaceRequest<C extends AbstractConnector<?>>
- Returns:
- the last response
-
iterator
- Specified by:
iterator
in interfaceIterable<C extends AbstractConnector<?>>
-
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 interfaceRequest<C extends AbstractConnector<?>>
- Returns:
- final value received with done event.
-