voldemort.store.socket.clientrequest
Class BlockingClientRequest<T>

java.lang.Object
  extended by voldemort.store.socket.clientrequest.BlockingClientRequest<T>
Type Parameters:
T - Type of data that is returned by the request
All Implemented Interfaces:
ClientRequest<T>

public class BlockingClientRequest<T>
extends java.lang.Object
implements ClientRequest<T>

BlockingClientRequest is used to implement blocking IO using the non-blocking IO-based ClientRequest logic. Essentially it wraps a vanilla ClientRequest and adds an method on which the caller will wait for completion (either success or failure).


Constructor Summary
BlockingClientRequest(ClientRequest<T> delegate, long timeoutMs)
           
 
Method Summary
 boolean await()
           
 void complete()
          Called by the ClientRequestExecutor once all the processing (normal or abnormal) has occurred on the ClientRequest object.
 boolean formatRequest(java.io.DataOutputStream outputStream)
          This eventually calls into a nested RequestFormat instance's writeXxx method.
 T getResult()
          Once completed has been called, this will return the result of the request or thrown an error if the request wasn't completed.
 boolean isComplete()
          Returns true if ClientRequest.complete() was called.
 boolean isCompleteResponse(java.nio.ByteBuffer buffer)
          isCompleteResponse determines if the response that the ClientRequestExecutor's received thus far is inclusive of the entire response.
 boolean isTimedOut()
          Returns true if ClientRequestExecutor timed out.
 void parseResponse(java.io.DataInputStream inputStream)
          Parses the response from the server to turn it into a result.
 void timeOut()
          Called by the ClientRequestExecutor after it has timed out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockingClientRequest

public BlockingClientRequest(ClientRequest<T> delegate,
                             long timeoutMs)
Method Detail

complete

public void complete()
Description copied from interface: ClientRequest
Called by the ClientRequestExecutor once all the processing (normal or abnormal) has occurred on the ClientRequest object. This exists mainly to implement blocking operations whereby we need to have a mechanism to unblock the caller waiting for the response.

This is used internally by the ClientRequest logic and should not be invoked by users of the sub-system.

Specified by:
complete in interface ClientRequest<T>

isComplete

public boolean isComplete()
Description copied from interface: ClientRequest
Returns true if ClientRequest.complete() was called.

Specified by:
isComplete in interface ClientRequest<T>
Returns:
true if completed, false otherwise

await

public boolean await()
              throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

getResult

public T getResult()
            throws VoldemortException,
                   java.io.IOException
Description copied from interface: ClientRequest
Once completed has been called, this will return the result of the request or thrown an error if the request wasn't completed.

Specified by:
getResult in interface ClientRequest<T>
Returns:
Result or an exception is thrown if the request failed
Throws:
VoldemortException
java.io.IOException

isCompleteResponse

public boolean isCompleteResponse(java.nio.ByteBuffer buffer)
Description copied from interface: ClientRequest
isCompleteResponse determines if the response that the ClientRequestExecutor's received thus far is inclusive of the entire response. This relies on the RequestFormat instance's isCompleteXxxResponse methods.

This is used internally by the ClientRequest logic and should not be invoked by users of the sub-system.

Specified by:
isCompleteResponse in interface ClientRequest<T>
Parameters:
buffer - ByteBuffer containing the data received thus far
Returns:
True if the buffer contains the complete response, false if it only includes part of the response.

parseResponse

public void parseResponse(java.io.DataInputStream inputStream)
Description copied from interface: ClientRequest
Parses the response from the server to turn it into a result. If this causes an application-level error to arise, it should not be thrown here, but instead stored until ClientRequest.getResult() is called.

This is used internally by the ClientRequest logic and should not be invoked by users of the sub-system.

Specified by:
parseResponse in interface ClientRequest<T>
Parameters:
inputStream - InputStream from which to read the response

formatRequest

public boolean formatRequest(java.io.DataOutputStream outputStream)
Description copied from interface: ClientRequest
This eventually calls into a nested RequestFormat instance's writeXxx method. The ClientRequest actually buffers all I/O, so the data written via formatRequest is actually inserted into a ByteBuffer which is later sent over the wire to the server.

This is used internally by the ClientRequest logic and should not be invoked by users of the sub-system.

Specified by:
formatRequest in interface ClientRequest<T>
Parameters:
outputStream - Write the request to this output stream

timeOut

public void timeOut()
Description copied from interface: ClientRequest
Called by the ClientRequestExecutor after it has timed out. This is different from the complete call, since the timeout event needs to be notified to the caller in a special way.

This is used internally by the ClientRequest logic and should not be invoked by users of the sub-system.

Specified by:
timeOut in interface ClientRequest<T>

isTimedOut

public boolean isTimedOut()
Description copied from interface: ClientRequest
Returns true if ClientRequestExecutor timed out.

Specified by:
isTimedOut in interface ClientRequest<T>
Returns:
true if timed out, false otherwise


Jay Kreps, Roshan Sumbaly, Alex Feinberg, Bhupesh Bansal, Lei Gao, Chinmay Soman, Vinoth Chandar, Zhongjie Wu