Package com.yahoo.jrt
Class Request
- java.lang.Object
-
- com.yahoo.jrt.Request
-
public class Request extends java.lang.Object
A Request bundles information about a single RPC invocation. A Request contains the name of the method, the method parameters, the method return values and also error information if something went wrong. Request objects are used by both RPC clients and RPC servers. An RPC client is the one requesting the invocation. An RPC server is the one performing the invocation. The RPC client uses aTarget
to invoke the request. The RPC server registers aMethod
with theSupervisor
. Note that RPC client/server roles are independent of connection client/server roles, since invocations can be performed both ways across aTarget
.
-
-
Constructor Summary
Constructors Constructor Description Request(java.lang.String methodName)
Create a new Request with the given method name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort()
Abort a request.boolean
checkReturnTypes(java.lang.String returnTypes)
Check if this Request contains return types compatible with the given type string.void
detach()
Detach a method invocation.void
discardParameters()
Create a new empty set of parameters for this request.int
errorCode()
Obtain the error code associated with this Requestjava.lang.String
errorMessage()
Obtain the error message associated with this Request, if anyjava.lang.Object
getContext()
Obtain the application context associated with this request.boolean
isError()
Check if an error has occurred with this Requestjava.lang.String
methodName()
Obtain the method nameValues
parameters()
Obtain the parametersvoid
returnRequest()
Return this request.Values
returnValues()
Obtain the return valuesvoid
setContext(java.lang.Object context)
Set the application context associated with this request.void
setError(int errorCode, java.lang.String errorMessage)
Register the fact that an error has occurred.Target
target()
Obtain the Target representing our end of the connection over which this request was invoked.java.lang.String
toString()
-
-
-
Method Detail
-
setContext
public void setContext(java.lang.Object context)
Set the application context associated with this request.- Parameters:
context
- application context
-
getContext
public java.lang.Object getContext()
Obtain the application context associated with this request.- Returns:
- application context
-
methodName
public java.lang.String methodName()
Obtain the method name- Returns:
- method name
-
parameters
public Values parameters()
Obtain the parameters- Returns:
- request parameters
-
returnValues
public Values returnValues()
Obtain the return values- Returns:
- request return values
-
discardParameters
public void discardParameters()
Create a new empty set of parameters for this request. The old set of parameters will still be valid, but will no longer be part of this request. This method may be used to allow earlier garbage collection of large parameters that are no longer needed. While the obvious use of this method is to get rid of parameters when being an RPC server it can also be used after starting an RPC request on a client.
-
target
public Target target()
Obtain the Target representing our end of the connection over which this request was invoked. This method may only be invoked during method handling (RPC server aspect).- Returns:
- Target representing our end of the connection over which this request was invoked
- Throws:
java.lang.IllegalStateException
- if invoked inappropriately
-
abort
public void abort()
Abort a request. This method may only be called by the RPC client after an asynchronous method invocation was requested.- Throws:
java.lang.IllegalStateException
- if invoked inappropriately
-
detach
public void detach()
Detach a method invocation. This method may only be invoked during method handling (RPC server aspect). If this method is invoked, the method is not returned when the method handler returns. Instead, the application must invoke thereturnRequest
method when it wants the request to be returned.- Throws:
java.lang.IllegalStateException
- if invoked inappropriately
-
returnRequest
public void returnRequest()
Return this request. This method may only be invoked after thedetach
method has been invoked, and only once per request. Note that if you detach a method without invoking this method, it will never be returned, causing a resource leak (NB: not good).- Throws:
java.lang.IllegalStateException
- if invoked inappropriately
-
setError
public void setError(int errorCode, java.lang.String errorMessage)
Register the fact that an error has occurred.- Parameters:
errorCode
- the error code (seeErrorCode
)errorMessage
- the error message
-
checkReturnTypes
public boolean checkReturnTypes(java.lang.String returnTypes)
Check if this Request contains return types compatible with the given type string. If this Request contains an error it is considered incompatible with all possible type strings. If the return values are not compatible with the given type string and an error condition is not set, theErrorCode.WRONG_RETURN
error will be set. This method is intended to be used by the RPC client after a method has been invoked to verify the return value types. Please refer to theMethod
class description for an explanation of type strings.- Parameters:
returnTypes
- type string- Returns:
- true if all is ok and the return types are compatible with 'returnTypes'
-
isError
public boolean isError()
Check if an error has occurred with this Request- Returns:
- true if an error has occurred
-
errorCode
public int errorCode()
Obtain the error code associated with this Request- Returns:
- error code
-
errorMessage
public java.lang.String errorMessage()
Obtain the error message associated with this Request, if any- Returns:
- error message
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-