|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dimawo.agents.AbstractAgent dimawo.agents.LoggingAgent dimawo.MasterAgent
public abstract class MasterAgent
This class represents the Master Agent (MA). It implements the master process of a master/worker application. The Master Agent is instantiated by one, and only one, Distributed Agent (DA) part of the group of DAs implementing the same DiMaWo application (note that each DA is generally executed in a different process, each process being executed by a different computer). This potentially implies the solving of leader election problem in order to select the DA that will instantiate the MA.
The base MA provides common functionalities but requires some key elements of its behavior to be implemented. In general, MA's behavior is more or less as follows:
onTopologyChange(DAId, ChangeType)
).shutdown()
.The common functionalities provided by the base implementation are:
broadcastWorkerMessage(WorkerMessage, WorkerMessage)
)sendMessage(WorkerMessage)
)shutdown()
).
The shutdown generally occurs after the detection of a fatal error or
when the application successfully reached the end of its execution.Following elements of the behavior of the MA must be implemented by the user:
handleMasterEvent(Object)
and handleUserDefinedAgentMessage(MasterMessage)
).handleWorkerExit(WorkerExitMessage)
).onTopologyChange(DAId, ChangeType)
).onStartup()
and onExit()
respectively).The master implements following agent's behavior:
DistributedAgent
,
be.ulg.montefiore.dimawo.middleware.WorkerAgent
Nested Class Summary | |
---|---|
protected static class |
MasterAgent.ChangeType
This enumeration provides the types of topology changes. |
Nested classes/interfaces inherited from class dimawo.agents.AbstractAgent |
---|
AbstractAgent.AgentState |
Field Summary |
---|
Fields inherited from class dimawo.agents.AbstractAgent |
---|
agentName, errorHandler |
Constructor Summary | |
---|---|
MasterAgent(DistributedAgent hostingDa,
String name)
Instantiates the Master Agent (MA) giving it a name and associating it to a DA. |
Method Summary | |
---|---|
protected void |
broadcastWorkerMessage(WorkerMessage toLocal,
WorkerMessage toRemote)
Broadcasts a message to all workers. |
DistributedAgent |
getHostingDA()
Returns the DA that instantiated the MA. |
String |
getWorkingDir()
Returns the working directory of hosting DA. |
protected void |
handleChildException(UncaughtThrowable o)
Causes the whole application to terminate its execution, potentially before completion. |
protected void |
handleDaError(DaError msg)
Handles an error message sent by a DA. |
protected abstract void |
handleMasterEvent(Object o)
Handles a user defined or unknown master event. |
protected void |
handleMessage(Object o)
Handles a new message taken from the queue. |
protected abstract void |
handleUserDefinedAgentMessage(MasterMessage msg)
Handles a received message that is not handled by base implementation. |
protected void |
handleUserDefinedMessageSent(Message msg)
Handles a "message sent" event for a user defined sent message. |
protected abstract void |
handleWorkerExit(WorkerExitMessage msg)
Handles a message indicating the end of the execution of a worker. |
protected void |
init()
Implements the operations to be executed when agent enters INIT state. |
protected void |
logAgentExit()
Implements the operations to be executed when logging agent enters STOPPED state. |
protected abstract void |
onExit()
Called when Master Agent terminates its execution. |
protected abstract void |
onStartup()
Called when Master Agent (MA) is initialized i.e. directly after the agent is started and before any message is handled. |
protected abstract void |
onTopologyChange(DAId subject,
MasterAgent.ChangeType type)
Called when the Master Agent (MA) handles a message signaling a local change in DA's topology (i.e. a new DA joined or a DA left the overlay). |
protected void |
sendMessage(WorkerMessage msg)
Sends a message to a worker agent. |
protected void |
shutdown()
Terminates the execution of the application. |
void |
signalBroken(BrokenDA bda)
|
void |
signalSent(Message m,
boolean success)
Signals that a message was successfully sent or an error occurred and the message could not be sent. |
void |
submitMasterMessage(MasterMessage m)
Inserts a MasterMessage message in MA's message queue. |
Methods inherited from class dimawo.agents.LoggingAgent |
---|
exit, getFilePrefix, setPrintStream |
Methods inherited from class dimawo.agents.AbstractAgent |
---|
agentPrintMessage, agentPrintMessage, agentPrintMessage, flushPendingMessages, getDefaultVerbosityLevel, getState, getVerbosityLevel, join, join, run, setAgentName, setDaemon, setDefaultVerbosityLevel, setErrorHandler, setPrintStream, setVerbosityLevel, signalChildError, start, stop, submitError, submitMessage |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MasterAgent(DistributedAgent hostingDa, String name)
hostingDa
- The DA that instantiates the MA.name
- The name of the MA.Method Detail |
---|
public DistributedAgent getHostingDA()
public void submitMasterMessage(MasterMessage m) throws InterruptedException
MasterMessage
message in MA's message queue.
InterruptedException
- Thrown if executing thread is interrupted
during a blocking insertion (happens when message queue is full).public String getWorkingDir()
protected void logAgentExit()
LoggingAgent
logAgentExit
in class LoggingAgent
AbstractAgent.exit()
protected void init() throws Throwable
AbstractAgent
init
in class AbstractAgent
Throwable
- If an error occurred during initialization.protected void handleMessage(Object o)
AbstractAgent
handleMessage
in class AbstractAgent
o
- A message.protected void handleChildException(UncaughtThrowable o) throws AgentException
handleChildException
in class AbstractAgent
o
- The error.
AgentException
- If the agent does not have an error handler.protected void shutdown()
protected void sendMessage(WorkerMessage msg)
msg
- The message to send to the worker agent.public void signalSent(Message m, boolean success)
MOSCallBack
signalSent
in interface MOSCallBack
m
- The message.success
- A boolean indicating if the message was successfully sent
or an error occurred. If success
is true, the message was
successfully sent. An error occurred otherwise.public void signalBroken(BrokenDA bda)
signalBroken
in interface MOSCallBack
protected void broadcastWorkerMessage(WorkerMessage toLocal, WorkerMessage toRemote)
toLocal
- The message copy to transmit to local worker.toRemote
- The message copy to transmit to remote workers.protected void handleDaError(DaError msg)
msg
- The error message.protected void handleUserDefinedMessageSent(Message msg) throws Exception
o
- The "message sent" event.
Exception
- If an error occurred during event's handling.handleMessageSent(MessageSent)
protected abstract void handleUserDefinedAgentMessage(MasterMessage msg) throws Exception
msg
- The message to handle.
Exception
- If an error occurred during message handling.protected abstract void handleWorkerExit(WorkerExitMessage msg) throws Exception
msg
- The message indicating the end of the execution of a worker.
Exception
- If an error occurred during the handling of the message.WorkerExitMessage.getResult()
protected abstract void onExit()
protected abstract void onStartup() throws Throwable
Throwable
- If an error occurs during MA's initialization.protected abstract void onTopologyChange(DAId subject, MasterAgent.ChangeType type) throws Exception
subject
- The DA that joined or left the overlay.type
- The type of topology change (join, leave).
Exception
- If an error occurred during event handling.protected abstract void handleMasterEvent(Object o) throws Exception
o
- The event.
Exception
- If an error occurred during event handling.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |