Class Channel
- java.lang.Object
-
- fr.dyade.aaa.agent.Channel
-
public class Channel extends Object
ClassChannelrealizes 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.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedChannel()Constructs a newChannelobject (can only be used by subclasses).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voiddirectSendTo(AgentId from, AgentId to, Notification not)Sends an immediately validated notification to an agent.(package private) static ChannelnewInstance()Creates a new instance of channel (result depends of server type).(package private) static voidpost(Message msg)Adds a message in "ready to deliver" list of right consumer.(package private) static voidpostAndValidate(Message msg)(package private) static voidsave()Save state of all modified consumer.static voidsendTo(AgentId to, Notification not)Sends a notification to an agent.StringtoString()Returns a string representation of thisChannelobject.(package private) static voidvalidate()Validates all messages previously dispatched.
-
-
-
Field Detail
-
logmon
private Logger logmon
-
DEBUG
private static final boolean DEBUG
-
channel
static Channel channel
-
consumers
static Vector<MessageConsumer> consumers
-
-
Method Detail
-
newInstance
static Channel newInstance() throws Exception
Creates a new instance of channel (result depends of server type).- Returns:
- the corresponding
Channel's instance. - Throws:
Exception- an error occurs.
-
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 thesendTofunction defined in classAgentfrom 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
isNullIdfunction of classAgentId. 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.
-
post
static final void post(Message msg) throws 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:
Exception- an error occurs.
-
save
static final void save() throws IOExceptionSave state of all modified consumer.- Throws:
IOException- an error occurs.
-
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 inEngine. 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 theMessageConsumer. Does not queue the notification in the local message queue.Normally used uniquely in
sendTomethod. This function is designed to be indirectly used by secondary threads, such asDrivers.- Parameters:
from- source agent.to- destination agent.not- notification.
-
-