net.tomp2p.futures
Class FutureResponse

java.lang.Object
  extended by net.tomp2p.futures.BaseFutureImpl<FutureResponse>
      extended by net.tomp2p.futures.FutureResponse
All Implemented Interfaces:
BaseFuture, Cancellable

public class FutureResponse
extends BaseFutureImpl<FutureResponse>

Each response has one request messages. The corresponding response message is set only if the request has been successful. This is indicated with isFailed.

Author:
Thomas Bocek

Nested Class Summary
 
Nested classes/interfaces inherited from interface net.tomp2p.futures.BaseFuture
BaseFuture.FutureType
 
Field Summary
 
Fields inherited from class net.tomp2p.futures.BaseFutureImpl
completed, lock, reason, type
 
Constructor Summary
FutureResponse(Message requestMessage)
          Create the future and set the request message
FutureResponse(Message requestMessage, boolean raw)
           
FutureResponse(Message requestMessage, FutureSuccessEvaluator futureSuccessEvaluator)
           
FutureResponse(Message requestMessage, FutureSuccessEvaluator futureSuccessEvaluator, boolean raw)
          Create the future and set the request message
 
Method Summary
 org.jboss.netty.buffer.ChannelBuffer getBuffer()
          Returns the raw buffer or null if the answer was empty.
 Object getObject()
          Returns the object or null if the underlying buffer was raw or the answer was empty.
 Message getRequest()
          The future response always keeps a reference to the request.
 Message getResponse()
          Returns the response message.
 boolean isShared()
           
 FutureResponse setFailed(String reason)
          Sets the failed flat to true and the completed flag to true.
 void setReplyTimeoutHandler(ReplyTimeoutHandler replyTimeoutHandler)
          Set the cancel operation for the timeout handler.
 void setResponse()
          If we don't get a reply message, which is the case for fire-and-forget messages, then set the reply to null and set this future to complete with the type Success.
 void setResponse(Message responseMessage)
          Gets called if a peer responds.
 void share()
           
 
Methods inherited from class net.tomp2p.futures.BaseFutureImpl
addCancellation, addListener, addListener, await, await, awaitListeners, awaitUninterruptibly, awaitUninterruptibly, cancel, getFailedReason, getType, isCompleted, isFailed, isSuccess, notifyListerenrs, removeListener, self, setCompletedAndNotify, setFailed, setFailed, setFailed, setFailed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FutureResponse

public FutureResponse(Message requestMessage)
Create the future and set the request message

Parameters:
requestMessage - The request message that will be send over the wire.

FutureResponse

public FutureResponse(Message requestMessage,
                      boolean raw)

FutureResponse

public FutureResponse(Message requestMessage,
                      FutureSuccessEvaluator futureSuccessEvaluator)

FutureResponse

public FutureResponse(Message requestMessage,
                      FutureSuccessEvaluator futureSuccessEvaluator,
                      boolean raw)
Create the future and set the request message

Parameters:
requestMessage - The request message that will be send over the wire.
futureSuccessEvaluator - Evaluates if the future was a success or failure
Method Detail

setResponse

public void setResponse()
If we don't get a reply message, which is the case for fire-and-forget messages, then set the reply to null and set this future to complete with the type Success.


setResponse

public void setResponse(Message responseMessage)
Gets called if a peer responds. Note that either this method or responseFailed() is always called. This does not notify any listeners. The listeners gets notified if channel is closed

Parameters:
message - The received message

getBuffer

public org.jboss.netty.buffer.ChannelBuffer getBuffer()
Returns the raw buffer or null if the answer was empty. This is used for direct messages.

Returns:
The transferred buffer

getObject

public Object getObject()
Returns the object or null if the underlying buffer was raw or the answer was empty. This is used for direct messages.

Returns:
The transferred object

setFailed

public FutureResponse setFailed(String reason)
Description copied from interface: BaseFuture
Sets the failed flat to true and the completed flag to true. This will notify listeners and set the reason

Specified by:
setFailed in interface BaseFuture
Overrides:
setFailed in class BaseFutureImpl<FutureResponse>
Parameters:
reason - The reason of failure
Returns:
this

getResponse

public Message getResponse()
Returns the response message. This is the same message as in response(Message message). If no response where send, then this will return null.

Returns:
The successful response message or null if failed

getRequest

public Message getRequest()
The future response always keeps a reference to the request.

Returns:
The request message.

setReplyTimeoutHandler

public void setReplyTimeoutHandler(ReplyTimeoutHandler replyTimeoutHandler)
Set the cancel operation for the timeout handler.

Parameters:
replyTimeoutHandler - The timeout that needs to be canceled if the future returns successfully.

share

public void share()

isShared

public boolean isShared()


Copyright © 2013. All Rights Reserved.