public class

NetworkController

extends Object
implements TimeDriven NetworkChannel RequiresRegistration
java.lang.Object
   ↳ uk.ac.imperial.presage2.core.network.NetworkController
Known Direct Subclasses

Class Overview

This is a central controller through which all messages go.

Like the environment it ensures agents obey the rules of the system. In this case these are to do with the network, such as transmission ranges etc.

Summary

Fields
protected boolean DELIVER_MESSAGE_EVENTS_ENABLED Whether or not to fire MessageDeliveryEvent for every message that is delivered.
protected int HANDLER_DRAIN_LIMIT Maximum number of Messages a MessageHandler will take from the queue at once.
protected int HANDLER_FORK_THRESHOLD Queue size required to cause a MessageHandler to try and fork a new thread.
protected int MAX_THREADS Maximum number of extra threads we will spawn to process messages with.
protected int TODELIVER_CAPACITY Maximum capacity of the toDeliver queue.
protected boolean allowDelivery
protected BlockingQueue<NetworkController.Delivery> awaitingDelivery
protected Map<NetworkAddressNetworkChannel> devices Map of devices registered to this controller.
protected EnvironmentSharedStateAccess environment Access to environment shared state.
protected EventBus eventBus
protected ScheduleExecutor threadPool
protected List<NetworkController.MessageHandler> threads
protected Time time
protected BlockingQueue<Message> toDeliver Queue of messages sent by agents which require processing.
Public Constructors
NetworkController(Time time, EnvironmentSharedStateAccess environment, Scenario s)
Public Methods
void deliverMessage(Message m)

Invoked by a NetworkConnector when it wishes to send a message.

void incrementTime()
void onParticipantsComplete()
synchronized void register(NetworkRegistrationRequest req)
Register a network device with this NetworkController
void setEventBus(EventBus e)
void setThreadPool(ScheduleExecutor pool)
Protected Methods
void deliverMessageTo(NetworkAddress to, Message m)
Deliver a message m to recipient to.
void doBroadcast(BroadcastMessage m)
Send a broadcast message
void doMulticast(MulticastMessage m)
Send a multicast message
void doUnicast(UnicastMessage m)
Send a unicast message
Pong getPong(Ping p)
Return a Pong for the given Ping.
void handleMessage(Message m)
[Expand]
Inherited Methods
From class java.lang.Object
From interface uk.ac.imperial.presage2.core.TimeDriven
From interface uk.ac.imperial.presage2.core.network.NetworkChannel
From interface uk.ac.imperial.presage2.core.network.RequiresRegistration

Fields

protected boolean DELIVER_MESSAGE_EVENTS_ENABLED

Whether or not to fire MessageDeliveryEvent for every message that is delivered.

protected int HANDLER_DRAIN_LIMIT

Maximum number of Messages a MessageHandler will take from the queue at once.

protected int HANDLER_FORK_THRESHOLD

Queue size required to cause a MessageHandler to try and fork a new thread.

protected int MAX_THREADS

Maximum number of extra threads we will spawn to process messages with. Defaults to the same size as the threadpool.

protected int TODELIVER_CAPACITY

Maximum capacity of the toDeliver queue. Using 0 gives a maximum sized queue.

protected boolean allowDelivery

protected BlockingQueue<NetworkController.Delivery> awaitingDelivery

protected Map<NetworkAddressNetworkChannel> devices

Map of devices registered to this controller.

protected EnvironmentSharedStateAccess environment

Access to environment shared state.

protected EventBus eventBus

protected ScheduleExecutor threadPool

protected List<NetworkController.MessageHandler> threads

protected Time time

protected BlockingQueue<Message> toDeliver

Queue of messages sent by agents which require processing.

Public Constructors

public NetworkController (Time time, EnvironmentSharedStateAccess environment, Scenario s)

Public Methods

public void deliverMessage (Message m)

Invoked by a NetworkConnector when it wishes to send a message.

In this implementation we deliver at the end of time cycle, therefore this function just adds the message to the delivery queue

public void incrementTime ()

See Also

public void onParticipantsComplete ()

public synchronized void register (NetworkRegistrationRequest req)

Register a network device with this NetworkController

Parameters
req a Registration request.
Throws
If the request is null, or one of the request's parameters is null (Address or link).

public void setEventBus (EventBus e)

public void setThreadPool (ScheduleExecutor pool)

Protected Methods

protected void deliverMessageTo (NetworkAddress to, Message m)

Deliver a message m to recipient to.

protected void doBroadcast (BroadcastMessage m)

Send a broadcast message

protected void doMulticast (MulticastMessage m)

Send a multicast message

protected void doUnicast (UnicastMessage m)

Send a unicast message

protected Pong getPong (Ping p)

Return a Pong for the given Ping. This is a message containing the set of NetworkAddresses of devices we're connected with.

Returns
  • Pong

protected void handleMessage (Message m)