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
FieldsModifier and TypeFieldDescriptionprotected ResponseListener<C> Listener.protected LinkedList<Response<C>> Collected responses.protected Connection<C, ?, ?> Source.protected ObjectTag for events to be distinguished. -
Constructor Summary
ConstructorsConstructorDescriptionRequestImpl(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 TypeMethodDescriptionvoidaddResponse(Response<C> r) Adds new response to this request object and dispatches it to listener.intCapacity 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.booleanReturns true if there are any responses availablebooleanReturnstrueif 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, waitMethods 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- aObjectobject- See Also:
-
RequestImpl
Creates new instance with defined capacity for responses.- Parameters:
source- the source of reponsesl- listenertag- aObjectobjectcapacity- number of last responses stored, if 0 all responses are stored.- See Also:
-
-
Method Details
-
getConnection
Returns the source of the request- Specified by:
getConnectionin interfaceRequest<C extends AbstractConnector<?>>- Returns:
- source of the request
-
hasResponse
public boolean hasResponse()Returns true if there are any responses available- Specified by:
hasResponsein interfaceRequest<C extends AbstractConnector<?>>- Returns:
- true if response available
-
responses
Returns the Iterator for the response storage.- Specified by:
responsesin 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:
getTagin 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()Returnstrueif request has been completed.- Specified by:
isCompletedin interfaceRequest<C extends AbstractConnector<?>>- Returns:
trueif 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
ResponseListenerobject
-
getFirstResponse
Returns the first response to this request.- Specified by:
getFirstResponsein interfaceRequest<C extends AbstractConnector<?>>- Returns:
- the first response
-
getLastResponse
Returns the last arrived response.- Specified by:
getLastResponsein interfaceRequest<C extends AbstractConnector<?>>- Returns:
- the last response
-
iterator
- Specified by:
iteratorin 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:
waitUntilDonein interfaceRequest<C extends AbstractConnector<?>>- Returns:
- final value received with done event.
-