Class RequestEvaluator

  • All Implemented Interfaces:
    java.lang.Runnable

    public final class RequestEvaluator
    extends java.lang.Object
    implements java.lang.Runnable
    This class does the work for incoming requests. It holds a transactor thread and an EcmaScript evaluator to get the work done. Incoming threads are blocked until the request has been serviced by the evaluator, or the timeout specified by the application has passed. In the latter case, the evaluator thread is killed and an error message is returned.
    • Field Detail

      • EMPTY_ARGS

        public static final java.lang.Object[] EMPTY_ARGS
      • skinDepth

        protected int skinDepth
    • Constructor Detail

      • RequestEvaluator

        public RequestEvaluator​(Application app)
        Create a new RequestEvaluator for this application.
        Parameters:
        app - the application
    • Method Detail

      • initScriptingEngine

        protected void initScriptingEngine()
      • shutdown

        protected void shutdown()
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • invokeHttp

        public ResponseTrans invokeHttp​(RequestTrans req,
                                        Session session)
                                 throws java.lang.Exception
        Invoke an action function for a HTTP request. The function is dispatched in a new thread and waits for it to finish.
        Parameters:
        req - the incoming HTTP request
        session - the client's session
        Returns:
        the result returned by the invocation
        Throws:
        java.lang.Exception - any exception thrown by the invocation
      • attachHttpRequest

        public ResponseTrans attachHttpRequest​(RequestTrans req)
                                        throws java.lang.Exception
        This checks if the Evaluator is already executing an equal request. If so, attach to it and wait for it to complete. Otherwise return null, so the application knows it has to run the request.
        Throws:
        java.lang.Exception
      • invokeXmlRpc

        public java.lang.Object invokeXmlRpc​(java.lang.String functionName,
                                             java.lang.Object[] args)
                                      throws java.lang.Exception
        Invoke a function for an XML-RPC request. The function is dispatched in a new thread and waits for it to finish.
        Parameters:
        functionName - the name of the function to invoke
        args - the arguments
        Returns:
        the result returned by the invocation
        Throws:
        java.lang.Exception - any exception thrown by the invocation
      • invokeExternal

        public java.lang.Object invokeExternal​(java.lang.String functionName,
                                               java.lang.Object[] args)
                                        throws java.lang.Exception
        Invoke a function for an external request. The function is dispatched in a new thread and waits for it to finish.
        Parameters:
        functionName - the name of the function to invoke
        args - the arguments
        Returns:
        the result returned by the invocation
        Throws:
        java.lang.Exception - any exception thrown by the invocation
      • invokeDirectFunction

        public java.lang.Object invokeDirectFunction​(java.lang.Object obj,
                                                     java.lang.Object function,
                                                     java.lang.Object[] args)
                                              throws java.lang.Exception
        Invoke a function internally and directly, using the thread we're running on.
        Parameters:
        obj - the object to invoke the function on
        function - the function or name of the function to invoke
        args - the arguments
        Returns:
        the result returned by the invocation
        Throws:
        java.lang.Exception - any exception thrown by the invocation
      • invokeInternal

        public java.lang.Object invokeInternal​(java.lang.Object object,
                                               java.lang.Object function,
                                               java.lang.Object[] args)
                                        throws java.lang.Exception
        Invoke a function internally. The function is dispatched in a new thread and waits for it to finish.
        Parameters:
        object - the object to invoke the function on
        function - the function or name of the function to invoke
        args - the arguments
        Returns:
        the result returned by the invocation
        Throws:
        java.lang.Exception - any exception thrown by the invocation
      • invokeInternal

        public java.lang.Object invokeInternal​(java.lang.Object object,
                                               java.lang.Object function,
                                               java.lang.Object[] args,
                                               long timeout)
                                        throws java.lang.Exception
        Invoke a function internally. The function is dispatched in a new thread and waits for it to finish.
        Parameters:
        object - the object to invoke the function on
        function - the function or name of the function to invoke
        args - the arguments
        timeout - the time in milliseconds to wait for the function to return, or -1 to wait indefinitely
        Returns:
        the result returned by the invocation
        Throws:
        java.lang.Exception - any exception thrown by the invocation
      • getAction

        public java.lang.String getAction​(java.lang.Object obj,
                                          java.lang.String action,
                                          RequestTrans req)
        Check if an action with a given name is defined for a scripted object. If it is, return the action's function name. Otherwise, return null.
      • getScriptingEngine

        public ScriptingEngine getScriptingEngine()
        Returns this evaluator's scripting engine
      • getRequest

        public RequestTrans getRequest()
        Get the request object for the current request.
        Returns:
        the request object
      • getResponse

        public ResponseTrans getResponse()
        Get the response object for the current request.
        Returns:
        the response object
      • getThread

        public java.lang.Thread getThread()
        Get the current transactor thread
        Returns:
        the current transactor thread
      • getSession

        public Session getSession()
        Return the current session
        Returns:
        the session for the current request