- All Superinterfaces:
AbstractLinkToAgent<T,
,A> Serializable
- All Known Implementing Classes:
LinkToAgentCollectionImpl
,LinkToAgentStandardImpl
public interface LinkToAgentCollection<T extends Agent,A extends Agent> extends AbstractLinkToAgent<T,A>
Modifier and Type | Method | Description |
---|---|---|
boolean | connectTo |
Creates a connection to a given other agent.
|
void | deliver |
Delivers a message to a given agent immediately during this method call.
|
void | deliverToAllConnected |
Delivers a message to all connected agents.
|
void | deliverToRandomConnected |
Delivers a message to a randomly chosen connected agent.
|
default int | disconnectByCondition |
Disconnects this agent from other agents which satisfy the given condition.
|
boolean | disconnectFrom |
Disconnects this agent from another given agent.
|
void | disconnectFromAll() |
Disconnects the agent from all other agents.
|
T | getConnectedAgent |
Returns the connected agent with a given index.
|
<E extends T> | getConnections() |
Returns a collection of agents connected to this agent (bi-directionally),
or empty collection if there have not been any connections yet.
|
int | getConnectionsNumber() |
Returns the number of agents connected to this agent.
|
T | getRandomConnectedAgent() |
Returns the randomly chosen connected agent.
|
boolean | isConnectedTo |
Tests if this agent is connected to a given other agent.
|
void | send |
Sends a message to a given agent.
|
void | sendToAllConnected |
Sends a message to all connected agents.
|
void | sendToRandomConnected |
Sends a message to a randomly chosen connected agent.
|
int | size() |
Returns the number of agents connected to this agent.
The same as getConnectionsNumber() |
<E extends T> List<E> getConnections()
Returns a collection of agents connected to this agent (bi-directionally),
or empty collection if there have not been any connections yet. You should not
modify this collection.
- Returns:
- collection of connected agents, may be empty
int getConnectionsNumber()
Returns the number of agents connected to this agent.
- Returns:
- the number of agents connected to this agent
int size()
Returns the number of agents connected to this agent.
The same as
The same as
getConnectionsNumber()
- Returns:
- the number of agents connected to this agent
- Since:
- 7.0.3
T getConnectedAgent(int index)
Returns the connected agent with a given index.
- Parameters:
index
- the index of connection- Returns:
- the connected agent with a given index
T getRandomConnectedAgent()
Returns the randomly chosen connected agent.
- Returns:
- the connected agent
boolean connectTo(T a)
Creates a connection to a given other agent. Raises error if you try
to connect to itself. Does
nothing and returns
false
if agents are already connected.- Parameters:
a
- another agent- Returns:
true
if was not connected before,false
if was already connected
boolean isConnectedTo(Agent a)
Tests if this agent is connected to a given other agent.
- Parameters:
a
- another agent- Returns:
true
if the agents are connected,false
otherwise
boolean disconnectFrom(Agent a)
Disconnects this agent from another given agent.
- Parameters:
a
- another agent- Returns:
true
if the agents were connected,false
otherwise
default int disconnectByCondition(Predicate<T> condition)
Disconnects this agent from other agents which satisfy the given condition.
Usage:
vipClients.disconnectByCondition( p -> p.expenses < 10000 );
- Parameters:
condition
- condition- Returns:
- the number of disconnected agents
void disconnectFromAll()
Disconnects the agent from all other agents.
void send(Object msg, T dest)
Sends a message to a given agent. The message will be delivered during
a separate event scheduled to occur in zero time after the current one.
If you are OK with the message delivered immediately during this event,
use
deliver(Object, Agent)
method, which has better performance.- Parameters:
msg
- a messagedest
- the destination agent
void sendToAllConnected(Object msg)
Sends a message to all connected agents.
The message will be delivered during a separate event
scheduled to occur in zero time after the current one. If you are OK
with the message delivered immediately during this event,
use
deliverToAllConnected(Object)
method, which has better performance.- Parameters:
msg
- a message
void sendToRandomConnected(Object msg)
Sends a message to a randomly chosen connected agent.
The message will be delivered during a separate event
scheduled to occur in zero time after the current one. If you are OK
with the message delivered immediately during this event,
use
deliverToRandomConnected(Object)
method, which has better performance.- Parameters:
msg
- a message
void deliver(Object msg, T dest)
Delivers a message to a given agent immediately during this method call.
If you wish this to happen in a separate event, use
send(Object, Agent)
method.- Parameters:
msg
- a messagedest
- the destination agent
void deliverToAllConnected(Object msg)
Delivers a message to all connected agents.
If you wish this to happen in a separate event, use
sendToAllConnected(Object)
method.- Parameters:
msg
- the messagemode
- specifies the message sending mode (ALL, RANDOM, ...)
void deliverToRandomConnected(Object msg)
Delivers a message to a randomly chosen connected agent.
If you wish this to happen in a separate event, use
sendToRandomConnected(Object)
method.- Parameters:
msg
- a message