Package org.km3net.clb.remote.msg
Class Response<T>
- java.lang.Object
-
- org.km3net.clb.remote.msg.Response<T>
-
- Type Parameters:
T
- the type of the repsonse.
public class Response<T> extends java.lang.Object
Encapsulates a (delayed) response from the remote CLB board.
-
-
Field Summary
Fields Modifier and Type Field Description long
createTime
int
id
static java.lang.Object
NO_RESULT
MessageProcessor
processor
int
type
java.lang.Object
user
-
Constructor Summary
Constructors Constructor Description Response(MessageDecoder<T> decoder, MessageProcessor messageProcessor, int id, int type, java.lang.Object user)
Create a new response.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MessageContext
context()
Returns the message context of the response.protected ResponseException
decodeError(MessageContext ctx, MessageReader mr)
Decodes an error into an exceptionT
get()
Gets the object from the response.java.lang.Exception
getException()
boolean
hasException()
boolean
isCompleted()
Returns whether or not the response is complete.boolean
isLost()
T
poll()
java.lang.Object
pollAny()
void
setHandler(ResponseHandler<T> handler)
java.lang.String
toString()
void
waitForValue()
-
-
-
Field Detail
-
NO_RESULT
public static final java.lang.Object NO_RESULT
-
processor
public final MessageProcessor processor
-
id
public final int id
-
type
public final int type
-
user
public final java.lang.Object user
-
createTime
public final long createTime
-
-
Constructor Detail
-
Response
public Response(MessageDecoder<T> decoder, MessageProcessor messageProcessor, int id, int type, java.lang.Object user)
Create a new response.- Parameters:
decoder
- The decoder used to decode the message into an object or value.user
- Custom user objectid
- The ID of the transactionmessageProcessor
- The message processor
-
-
Method Detail
-
isCompleted
public boolean isCompleted()
Returns whether or not the response is complete.- Returns:
- true - Response complete, has value, false - Response net complete
-
hasException
public boolean hasException()
-
getException
public java.lang.Exception getException()
-
isLost
public boolean isLost()
-
poll
public T poll()
-
pollAny
public java.lang.Object pollAny()
-
waitForValue
public void waitForValue()
-
context
public MessageContext context()
Returns the message context of the response.
-
decodeError
protected ResponseException decodeError(MessageContext ctx, MessageReader mr)
Decodes an error into an exception- Parameters:
mr
- Message reader containing the body of the message.- Returns:
- The decoded exception.
-
setHandler
public void setHandler(ResponseHandler<T> handler)
-
get
public T get() throws CommandException
Gets the object from the response. If no response has yet been received this will wait for it. It will also flush the Control's batched commands.- Returns:
- The return value.
- Throws:
ResponseException
- When the command executed failed on the remote side.CommandException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-