public class PogamutJVMComm extends Object
IWorldView.
You can use getInstance() to obtain singleton-instance
and register your agent to some channel using registerAgent(IObservingAgent, int).
DO NOT FORGET TO USE unregisterAgent(IObservingAgent) once your agent has finished its lifecycle,
otherwise you would likely to leak memory.
Any agent may send events to registered agents at any time via send(IWorldChangeEvent, int)
or broadcast(IWorldChangeEvent).
The object uses IWorldChangeEventInput.notify(IWorldChangeEvent) to propagate events to respective agents' worldviews.| Modifier and Type | Class and Description |
|---|---|
protected class |
PogamutJVMComm.Broadcast |
protected class |
PogamutJVMComm.BroadcastToOthers |
protected class |
PogamutJVMComm.RegisterAgent |
protected class |
PogamutJVMComm.Send |
protected class |
PogamutJVMComm.SendToOthers |
protected class |
PogamutJVMComm.UnregisterAgent |
protected class |
PogamutJVMComm.UnregisterAgentFromChannel |
| Modifier and Type | Field and Description |
|---|---|
static int |
ALL_CHANNELS
If you wish to listen on all CHANNELS you can use this constant.
|
protected Set<IObservingAgent> |
allChannels
Agents registered for "ALL_CHANNELS".
|
protected cz.cuni.amis.utils.maps.HashMapSet<Integer,IObservingAgent> |
channels
Agents registered for respective channels.
|
protected static ConcurrentLinkedQueue<PogamutJVMComm> |
comms |
protected ThreadPoolExecutor |
executor |
protected Object |
executorMutex |
protected static PogamutJVMComm |
instance |
protected static Object |
instanceMutex |
protected ReadWriteLock |
lock
Mutex for reading/writing channels/allChannels and sending events.
|
protected Logger |
log |
protected int |
numberOfRegisterAgentPending |
protected Object |
numberOfRegisterAgentPendingMutex |
protected Lock |
readLock |
protected Map<IAgentId,cz.cuni.amis.utils.Tuple2<IObservingAgent,Integer>> |
registeredAgents
AbstractAgent.getComponentId() maps to actual 'agent' registered + number of registration for a given agent. |
protected Lock |
writeLock |
| Constructor and Description |
|---|
PogamutJVMComm() |
PogamutJVMComm(Logger log) |
| Modifier and Type | Method and Description |
|---|---|
void |
broadcast(IWorldChangeEvent event)
Broadcast 'event' to all channels == all listening agents.
|
protected void |
broadcastSyncImpl(IWorldChangeEvent event) |
void |
broadcastToOthers(IWorldChangeEvent event,
IObservingAgent sender)
Broadcast 'event' to all channels == all listening agents.
|
protected void |
broadcastToOthersSyncImpl(IWorldChangeEvent event,
IObservingAgent sender) |
protected void |
broadcastToOthersUnsyncImpl(IWorldChangeEvent event,
IObservingAgent sender) |
protected void |
broadcastUnsyncImpl(IWorldChangeEvent event) |
protected int |
decRegisteredAgent(IObservingAgent agent) |
void |
destroy()
UTILITY METHOD FOR DESTROYING THE COMMUNICATION.
|
protected void |
execute(Runnable job,
boolean forceStart) |
protected Set<IObservingAgent> |
getChannel(int channel) |
static PogamutJVMComm |
getInstance()
Getter for JVM singleton.
|
Logger |
getLog() |
protected int |
incRegisteredAgent(IObservingAgent agent) |
boolean |
isAgentRegistered(IObservingAgent agent,
int channel)
Whether an 'agent' is listening on 'channel'.
|
static void |
platformClose() |
void |
registerAgent(IObservingAgent agent,
int channel)
Register an agent to receive events send through 'channel'.
|
protected void |
registerAgentSyncImpl(IObservingAgent agent,
int channel) |
protected void |
registerAgentUnsyncImpl(IObservingAgent agent,
int channel) |
void |
send(IWorldChangeEvent event,
int channel)
Send 'event' to 'channel'.
|
protected void |
sendSyncImpl(IWorldChangeEvent event,
int channel) |
protected void |
sendToAgentUnsyncImpl(IObservingAgent agent,
IWorldChangeEvent event) |
void |
sendToOthers(IWorldChangeEvent event,
int channel,
IObservingAgent sender)
Send 'event' to 'channel' but does not notify 'sender'.
|
protected void |
sendToOthersSyncImpl(IWorldChangeEvent event,
int channel,
IObservingAgent sender) |
protected void |
sendToOthersUnsyncImpl(IWorldChangeEvent event,
int channel,
IObservingAgent sender) |
protected void |
sendUnsyncImpl(IWorldChangeEvent event,
int channel) |
protected void |
shutdown(boolean forced) |
void |
unregisterAgent(IObservingAgent agent)
Totally unregister the agent (all channels + ALL_CHANNELS).
|
void |
unregisterAgent(IObservingAgent agent,
int channel)
Removes agent from listening to some channels.
|
protected void |
unregisterAgentSyncImpl(IObservingAgent agent) |
protected void |
unregisterAgentSyncImpl(IObservingAgent agent,
int channel) |
protected void |
unregisterAgentUnsyncImpl(IObservingAgent agent) |
protected void |
unregisterAgentUnsyncImpl(IObservingAgent agent,
int channel) |
protected static Object instanceMutex
protected static PogamutJVMComm instance
protected static ConcurrentLinkedQueue<PogamutJVMComm> comms
public static final int ALL_CHANNELS
protected Map<IAgentId,cz.cuni.amis.utils.Tuple2<IObservingAgent,Integer>> registeredAgents
AbstractAgent.getComponentId() maps to actual 'agent' registered + number of registration for a given agent.protected Set<IObservingAgent> allChannels
protected cz.cuni.amis.utils.maps.HashMapSet<Integer,IObservingAgent> channels
protected ReadWriteLock lock
protected Lock readLock
protected Lock writeLock
protected Logger log
protected Object executorMutex
protected ThreadPoolExecutor executor
protected Object numberOfRegisterAgentPendingMutex
protected int numberOfRegisterAgentPending
public PogamutJVMComm()
public PogamutJVMComm(Logger log)
log - can be null, default will be providedpublic static PogamutJVMComm getInstance()
public static void platformClose()
public Logger getLog()
protected int incRegisteredAgent(IObservingAgent agent)
agent - protected int decRegisteredAgent(IObservingAgent agent)
agent - public void registerAgent(IObservingAgent agent, int channel)
ALL_CHANNELS constant to listen to all channels (existing or future).agent - channel - protected void registerAgentSyncImpl(IObservingAgent agent, int channel)
protected void registerAgentUnsyncImpl(IObservingAgent agent, int channel)
public boolean isAgentRegistered(IObservingAgent agent, int channel)
ALL_CHANNELS constant to check whether an agent is listening to ALL CHANNELS (existing and future).
Potentially BLOCKING METHOD, waiting for readLock to be locked.agent - channel - protected Set<IObservingAgent> getChannel(int channel)
public void unregisterAgent(IObservingAgent agent, int channel)
agent - channel - protected void unregisterAgentSyncImpl(IObservingAgent agent, int channel)
protected void unregisterAgentUnsyncImpl(IObservingAgent agent, int channel)
public void unregisterAgent(IObservingAgent agent)
bot - protected void unregisterAgentSyncImpl(IObservingAgent agent)
protected void unregisterAgentUnsyncImpl(IObservingAgent agent)
public void send(IWorldChangeEvent event, int channel)
sendToOthers(IWorldChangeEvent, int, IObservingAgent).event - channel - public void sendToOthers(IWorldChangeEvent event, int channel, IObservingAgent sender)
event - channel - protected void sendSyncImpl(IWorldChangeEvent event, int channel)
protected void sendToOthersSyncImpl(IWorldChangeEvent event, int channel, IObservingAgent sender)
protected void sendUnsyncImpl(IWorldChangeEvent event, int channel)
protected void sendToOthersUnsyncImpl(IWorldChangeEvent event, int channel, IObservingAgent sender)
protected void sendToAgentUnsyncImpl(IObservingAgent agent, IWorldChangeEvent event)
public void broadcast(IWorldChangeEvent event)
broadcastToOthers(IWorldChangeEvent, IObservingAgent).event - public void broadcastToOthers(IWorldChangeEvent event, IObservingAgent sender)
event - sender - protected void broadcastSyncImpl(IWorldChangeEvent event)
protected void broadcastToOthersSyncImpl(IWorldChangeEvent event, IObservingAgent sender)
protected void broadcastUnsyncImpl(IWorldChangeEvent event)
protected void broadcastToOthersUnsyncImpl(IWorldChangeEvent event, IObservingAgent sender)
public void destroy()
PogamutPlatform.close() will call this for you on getInstance().protected void execute(Runnable job, boolean forceStart)
protected void shutdown(boolean forced)
Copyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.