org.otfeed.protocol.request
Class AbstractRequest

java.lang.Object
  extended by org.otfeed.protocol.request.AbstractRequest
Direct Known Subclasses:
AbstractSessionRequest, HeartbeatRequest, LoginRequest

public abstract class AbstractRequest
extends java.lang.Object

Common base for all OpenTick requests.


Nested Class Summary
static class AbstractRequest.JobStatus
          Request status.
 
Method Summary
 void fireCompleted(OTError error)
          Internal method: used to wake up threads sleeping in waitForCompletion().
 CommandEnum getCommand()
          Returns command type of this request.
 OTError getError()
           
 int getRequestId()
          Returns request id number.
 AbstractRequest.JobStatus handleMessage(Header header, java.nio.ByteBuffer in)
          Abstract method to handle response message.
 boolean isCompleted()
           
 java.lang.String toString()
           
 void waitForCompletion()
          Convenience method: blocks calling thread until request finishes.
 boolean waitForCompletion(long millis)
          Convenience method: blocks calling thread until request finishes, or the specified number of milliseconds elapses.
 void writeRequest(java.nio.ByteBuffer out)
          Abstract method that writes out request body.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getCommand

public final CommandEnum getCommand()
Returns command type of this request.


getRequestId

public final int getRequestId()
Returns request id number.


writeRequest

public void writeRequest(java.nio.ByteBuffer out)
Abstract method that writes out request body. This implementation only writes the request header. It is meant to be overwritten by concrete request implementation. Concrete implementation must call super.writeRequest at the top of its method body.

Parameters:
out - output buffer.

handleMessage

public AbstractRequest.JobStatus handleMessage(Header header,
                                               java.nio.ByteBuffer in)
Abstract method to handle response message. This implementation only validates request and command. Must be overwritten by concrete implementation. Some concrete implementations may call this one at the beginning to check the sanity of the response.

Parameters:
header - parsed response header.
in - input buffer with the rest of the data (after header has been parsed).

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getError

public final OTError getError()

fireCompleted

public final void fireCompleted(OTError error)
Internal method: used to wake up threads sleeping in waitForCompletion().


isCompleted

public final boolean isCompleted()

waitForCompletion

public final boolean waitForCompletion(long millis)
Convenience method: blocks calling thread until request finishes, or the specified number of milliseconds elapses. Note that if request was not submitted, this method returns immediately with no error.

Parameters:
millis - how long to wait for completion.

waitForCompletion

public final void waitForCompletion()
Convenience method: blocks calling thread until request finishes. Note that if request was not submitted, this method returns immediately with no error.



Copyright © 2007 Mike Kroutikov. All Rights Reserved.