Interface AgentEngine

  • All Superinterfaces:
    MessageComparator, MessageConsumer
    All Known Implementing Classes:
    Engine

    public interface AgentEngine
    extends MessageConsumer
    The AgentEngine provides multiprogramming of agents. It realizes the program loop which successively gets the notifications from the message queue and calls the relevant reaction function member of the target agent. The engine's basic behaviour is:
     While (true) {
       // get next message in channel
       Message msg = qin.get();
       // get the agent to process event
       Agent agent = load(msg.to);
       // execute relevant reaction, all notification sent during this
       // reaction is inserted into persistent queue in order to processed
       // by the channel.
       agent.react(msg.from, msg.not);
       // save changes, then commit.
       <BEGIN TRANSACTION>
       qin.pop();
       channel.dispatch();
       agent.save();
       <COMMIT TRANSACTION>
     }
     

    The AgentEngine ensures the atomic handling of an agent reacting to a notification:

    • if the reaction completes, a COMMIT ensures all changes related to the reaction are committed (state change of the agent, notifications signaled during the reaction, deletion of the handled notification);
    • if anything goes wrong during the reaction, a ROLLBACK undoes the changes; depending on the error kind it may be necessary to execute additional operations to resynchronize the database and the memory objects, and to allow the main program to continue.

    Handling errors.

    Two types of errors may occur: errors of first type are detected in the source code and signaled by an Exception; serious errors lead to an Error being raised then the engine exits. In the first case the exception may be handled at any level, even partially. Most of them are signaled up to the engine loop. Two cases are then distinguished depending on the recovery policy:

    • if recoveryPolicy is set to RP_EXC_NOT (default value) then the agent state and the message queue are restored (ROLLBACK); an ExceptionNotification notification is sent to the sender and the engine may then proceed with next notification;
    • if recoveryPolicy is set to RP_EXIT the engine stops the agent server.
    • Method Detail

      • isEngineThread

        boolean isEngineThread()
        Checks if the current thread calling this method belongs to the engine.
        Returns:
        true if the current thread calling this method belongs to the engine
      • resetAverageLoad

        void resetAverageLoad()
      • getAverageLoad1

        float getAverageLoad1()
        Returns the load averages for the last minute.
        Specified by:
        getAverageLoad1 in interface MessageConsumer
        Returns:
        the load averages for the last minute.
      • getAverageLoad5

        float getAverageLoad5()
        Returns the load averages for the past 5 minutes.
        Specified by:
        getAverageLoad5 in interface MessageConsumer
        Returns:
        the load averages for the past 5 minutes.
      • getAverageLoad15

        float getAverageLoad15()
        Returns the load averages for the past 15 minutes.
        Specified by:
        getAverageLoad15 in interface MessageConsumer
        Returns:
        the load averages for the past 15 minutes.
      • isAgentProfiling

        boolean isAgentProfiling()
        Returns true if the agent profiling is on.
        Returns:
        true if the agent profiling is on.
        See Also:
        EngineMBean.isAgentProfiling()
      • setAgentProfiling

        void setAgentProfiling​(boolean agentProfiling)
        Sets the agent profiling.
        Parameters:
        agentProfiling - if true sets the agent profiling.
        See Also:
        EngineMBean.setAgentProfiling(boolean)
      • getReactTime

        long getReactTime()
        Returns:
        the reactTime
      • getCommitTime

        long getCommitTime()
        Returns:
        the commitTime
      • init

        void init​(AgentEngineContext agentEngineContext)
           throws Exception
        Initializes the engine. The AgentEngineContext parameter should be for the unique private use of this AgentEngine and should not be shared with any other components otherwise the agent server security would be broken.
        Parameters:
        agentEngineContext - context enabling this AgentEngine to invoke operations that cannot be accessed outside of the fr.dyade.aaa.agent package. The AgentEngineContext should be for the unique private use of this AgentEngine and should not be shared with any other components otherwise the agent server security would be broken.
        Throws:
        Exception - an error occurs.
      • getNbWaitingMessages

        int getNbWaitingMessages()
        Gets the number of waiting messages in this engine.
        Returns:
        the number of waiting messages.
      • getNbReactions

        long getNbReactions()
        Returns the number of agent's reaction since last boot.
        Returns:
        the number of agent's reaction since last boot
      • getRunningAgent

        String getRunningAgent()
        Returns the unique id. of the running agent if any, null otherwise.
        Returns:
        the unique id. of the running agent if any, null otherwise.
      • dumpAgent

        String dumpAgent​(AgentId id)
                  throws IOException,
                         ClassNotFoundException
        Returns a string representation of the specified agent. If the agent is not present it is loaded in memory, be careful it is not initialized (agentInitialize) nor cached in agents vector.
        Parameters:
        id - The agent's unique identification.
        Returns:
        A string representation of specified agent.
        Throws:
        IOException - an error occurs.
        ClassNotFoundException - an error occurs.
      • push

        void push​(AgentId to,
                  Notification not)
        Puts a notification in the output queue.
        Parameters:
        to - the destination
        not - the notification to push
      • push

        void push​(AgentId from,
                  AgentId to,
                  Notification not)
        Puts a notification in the output queue.
        Parameters:
        from - the source
        to - the destination
        not - the notification to push
      • createAgent

        void createAgent​(AgentId id,
                         Agent agent)
                  throws Exception
        Creates and initializes an agent.
        Parameters:
        id - the unique identifier
        agent - agent object to create
        Throws:
        Exception - unspecialized exception
      • deleteAgent

        void deleteAgent​(AgentId agent)
                  throws Exception
        Deletes an agent.
        Parameters:
        agent - agent to delete
        Throws:
        Exception - unspecialized exception
      • isNoTxIfTransient

        boolean isNoTxIfTransient()
        Returns the flag to avoid transactions.
        Returns:
        the flag to avoid transactions
      • incWorkInProgress

        void incWorkInProgress()
        Increments the tick counter that reflects activity in server.