Package org.serviceconnector.util
Class SynchronousCallback
java.lang.Object
org.serviceconnector.util.SynchronousCallback
- All Implemented Interfaces:
ISCMPMessageCallback,ISCMPSynchronousCallback
- Direct Known Subclasses:
CommandCallback,SCServiceCallback,SCSessionServer.SCServerCallback
The Class SynchronousCallback. Base functionality for getting messages synchronous. Means to wait for a call for the callback. This class is designed to be extended by various
callback's. It provides synchronous flag to to save state if somebody is waiting for a message. Synchronous flag might be useful in subclasses. It only gets access to the newest
message - it only queues one item. Queuing an arrived message happens only if someone is expecting (synchronous = true) a reply. This restriction prevents race conditions - late
messages are ignored.
- Author:
- JTraber
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final BlockingQueue<SCMPMessage>Queue to store the answer.protected booleanThe synchronous, marks if somebody waits for the message. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetMessageSync(int timeoutMillis) Careful, be aware of timeout concept if you use this method.voidCallback.voidreceive(SCMPMessage scmpReply) Callback.
-
Field Details
-
answer
Queue to store the answer. -
synchronous
protected volatile boolean synchronousThe synchronous, marks if somebody waits for the message.
-
-
Constructor Details
-
SynchronousCallback
public SynchronousCallback()Instantiates a new synchronous callback.
-
-
Method Details
-
receive
Callback. This method gets informed when a message received.- Specified by:
receivein interfaceISCMPMessageCallback- Specified by:
receivein interfaceISCMPSynchronousCallback- Parameters:
scmpReply- the scmp reply
-
receive
Callback. This method gets informed in case of an error.- Specified by:
receivein interfaceISCMPMessageCallback- Specified by:
receivein interfaceISCMPSynchronousCallback- Parameters:
ex- the ex
-
getMessageSync
Careful, be aware of timeout concept if you use this method. Gets the message synchronous. Waits until message/fault received or time you hand over runs out.
- Specified by:
getMessageSyncin interfaceISCMPSynchronousCallback- Parameters:
timeoutMillis- the timeout in milliseconds- Returns:
- the message sync
-