AnyLogic
Expand
Font size
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>

Method Summary

Modifier and TypeMethodDescription
booleanconnectTo(T a)
Creates a connection to a given other agent.
voiddeliver(Object msg, T dest)
Delivers a message to a given agent immediately during this method call.
voiddeliverToAllConnected(Object msg)
Delivers a message to all connected agents.
voiddeliverToRandomConnected(Object msg)
Delivers a message to a randomly chosen connected agent.
default intdisconnectByCondition(Predicate<T> condition)
Disconnects this agent from other agents which satisfy the given condition.
booleandisconnectFrom(Agent a)
Disconnects this agent from another given agent.
voiddisconnectFromAll()
Disconnects the agent from all other agents.
TgetConnectedAgent(int index)
Returns the connected agent with a given index.
<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.
intgetConnectionsNumber()
Returns the number of agents connected to this agent.
TgetRandomConnectedAgent()
Returns the randomly chosen connected agent.
booleanisConnectedTo(Agent a)
Tests if this agent is connected to a given other agent.
voidsend(Object msg, T dest)
Sends a message to a given agent.
voidsendToAllConnected(Object msg)
Sends a message to all connected agents.
voidsendToRandomConnected(Object msg)
Sends a message to a randomly chosen connected agent.
intsize()
Returns the number of agents connected to this agent.
The same as getConnectionsNumber()

Method Details

getConnections

<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

getConnectionsNumber

int getConnectionsNumber()
Returns the number of agents connected to this agent.
Returns:
the number of agents connected to this agent

size

int size()
Returns the number of agents connected to this agent.
The same as getConnectionsNumber()
Returns:
the number of agents connected to this agent
Since:
7.0.3

getConnectedAgent

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

getRandomConnectedAgent

T getRandomConnectedAgent()
Returns the randomly chosen connected agent.
Returns:
the connected agent

connectTo

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

isConnectedTo

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

disconnectFrom

boolean disconnectFrom(Agent a)
Disconnects this agent from another given agent.
Parameters:
a - another agent
Returns:
true if the agents were connected, false otherwise

disconnectByCondition

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

disconnectFromAll

void disconnectFromAll()
Disconnects the agent from all other agents.

send

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 message
dest - the destination agent

sendToAllConnected

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

sendToRandomConnected

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

deliver

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 message
dest - the destination agent

deliverToAllConnected

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 message
mode - specifies the message sending mode (ALL, RANDOM, ...)

deliverToRandomConnected

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