fr.dyade.aaa.agent
Class Channel

java.lang.Object
  extended by fr.dyade.aaa.agent.Channel

public class Channel
extends java.lang.Object

Class Channel realizes the interface for sending messages. It defines function member SendTo to send a notification to an identified agent.

Notifications are then routed to a message queue where they are stored in chronological order. The Channel object is responsible for localizing the target agent.


Field Summary
(package private) static Channel channel
           
(package private) static java.util.Vector consumers
           
protected  org.objectweb.util.monolog.api.Logger logmon
           
 
Constructor Summary
protected Channel()
          Constructs a new Channel object (can only be used by subclasses).
 
Method Summary
(package private)  void directSendTo(AgentId from, AgentId to, Notification not)
          Sends an immediately validated notification to an agent.
(package private) static Channel newInstance()
          Creates a new instance of channel (result depends of server type).
(package private) static void post(Message msg)
          Adds a message in "ready to deliver" list of right consumer.
(package private) static void save()
          Save state of all modified consumer.
static void sendTo(AgentId to, Notification not)
          Sends a notification to an agent.
 java.lang.String toString()
          Returns a string representation of this Channel object.
(package private) static void validate()
          Validates all messages previously dispatched.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

channel

static Channel channel

logmon

protected org.objectweb.util.monolog.api.Logger logmon

consumers

static java.util.Vector consumers
Constructor Detail

Channel

protected Channel()
Constructs a new Channel object (can only be used by subclasses).

Method Detail

newInstance

static Channel newInstance()
                    throws java.lang.Exception
Creates a new instance of channel (result depends of server type).

Returns:
the corresponding Channel's instance.
Throws:
java.lang.Exception

sendTo

public static final void sendTo(AgentId to,
                                Notification not)
Sends a notification to an agent. It may be used anywhere, from any object and any thread. However it is best practice to call the sendTo function defined in class Agent from an agent code executed during a reaction.

The destination agent receives the notification with a declared null source agent id, which may be recognized using the isNullId function of class AgentId. This is not true when this call is performed during an standard agent reaction. In that case the current reacting agent, known by the engine, is provided as source agent.

The notification is immediately validated, that is made persistent, if it is not sent from an agent reaction. Be careful, does not use this method in the engine thread, sometime engine.agent is null and it throws a NullPointerException.

Parameters:
to - destination agent.
not - notification.
Throws:
java.io.IOException - error when accessing the local persistent storage

post

static final void post(Message msg)
                throws java.lang.Exception
Adds a message in "ready to deliver" list of right consumer. This method set the logical date of message, push it in the corresponding queue, and save it.

Parameters:
msg - The message to deliver.
Throws:
java.lang.Exception

save

static final void save()
                throws java.io.IOException
Save state of all modified consumer.

Throws:
java.io.IOException

validate

static final void validate()
Validates all messages previously dispatched. There is two separate methods for dispatch and validate messages because of use of transactions in Engine. The messages are only validated in queues after the commit of transaction.


Be careful, this method must only be used during a transaction in order to ensure the mutual exclusion.

See Also:
Engine.commit()

directSendTo

void directSendTo(AgentId from,
                  AgentId to,
                  Notification not)
Sends an immediately validated notification to an agent. Post and directly dispatches the notification to the MessageConsumer. Does not queue the notification in the local message queue.

Normally used uniquely in sendTo method. This function is designed to be indirectly used by secondary threads, such as Drivers.

Parameters:
from - source agent.
to - destination agent.
not - notification.
Throws:
java.io.IOException - error when accessing the local persistent storage

toString

public final java.lang.String toString()
Returns a string representation of this Channel object.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of this object.


Copyright © 2010 ScalAgent D.T.. All Rights Reserved.