Package com.yahoo.jrt

Class Request

java.lang.Object
com.yahoo.jrt.Request

public class Request extends 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 a Target to invoke the request. The RPC server registers a Method with the Supervisor. Note that RPC client/server roles are independent of connection client/server roles, since invocations can be performed both ways across a Target.
  • Constructor Details

    • Request

      public Request(String methodName)
      Create a new Request with the given method name.
      Parameters:
      methodName - name of the method you want to invoke
  • Method Details

    • setContext

      public void setContext(Object context)
      Set the application context associated with this request.
      Parameters:
      context - application context
    • getContext

      public Object getContext()
      Obtain the application context associated with this request.
      Returns:
      application context
    • methodName

      public 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:
      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:
      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 the returnRequest method when it wants the request to be returned.
      Throws:
      IllegalStateException - if invoked inappropriately
    • returnRequest

      public void returnRequest()
      Return this request. This method may only be invoked after the detach 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:
      IllegalStateException - if invoked inappropriately
    • setError

      public void setError(int errorCode, String errorMessage)
      Register the fact that an error has occurred.
      Parameters:
      errorCode - the error code (see ErrorCode)
      errorMessage - the error message
    • checkReturnTypes

      public boolean checkReturnTypes(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, the ErrorCode.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 the Method 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 String errorMessage()
      Obtain the error message associated with this Request, if any
      Returns:
      error message
    • toString

      public String toString()
      Overrides:
      toString in class Object