AnyLogic AnyLogic
Expand
Font size
All Superinterfaces:
AbstractLinkToAgent<T,​A>, java.io.Serializable
All Known Implementing Classes:
LinkToAgentCollectionImpl, LinkToAgentStandardImpl

public interface LinkToAgentCollection<T extends Agent,​A extends Agent>
extends AbstractLinkToAgent<T,​A>

Method Summary

All Methods Instance Methods Abstract Methods Default Methods 
boolean connectTo​(T a)
Creates a connection to a given other agent.
void deliver​(java.lang.Object msg, T dest)
Delivers a message to a given agent immediately during this method call.
void deliverToAllConnected​(java.lang.Object msg)
Delivers a message to all connected agents.
void deliverToRandomConnected​(java.lang.Object msg)
Delivers a message to a randomly chosen connected agent.
default int disconnectByCondition​(java.util.function.Predicate<T> condition)
Disconnects this agent from other agents which satisfy the given condition.
boolean disconnectFrom​(Agent a)
Disconnects this agent from another given agent.
void disconnectFromAll()
Disconnects the agent from all other agents.
T getConnectedAgent​(int index)
Returns the connected agent with a given index.
<E extends T>
java.util.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.
int getConnectionsNumber()
Returns the number of agents connected to this agent.
T getRandomConnectedAgent()
Returns the randomly chosen connected agent.
boolean isConnectedTo​(Agent a)
Tests if this agent is connected to a given other agent.
void send​(java.lang.Object msg, T dest)
Sends a message to a given agent.
void sendToAllConnected​(java.lang.Object msg)
Sends a message to all connected agents.
void sendToRandomConnected​(java.lang.Object msg)
Sends a message to a randomly chosen connected agent.
int size()
Returns the number of agents connected to this agent.
The same as getConnectionsNumber()
Modifier and Type Method Description

Methods inherited from interface com.anylogic.engine.AbstractLinkToAgent

doConnect_xjal, doDisconnect_xjal, getBidirectionalPeer_xjal, getLinkToAgentCommonAnimationSettings, getLinkToAgentMyAnimationSettings, getOwner, isDeliverToAgent_xjal, onDestroy, onReceive

Method Detail

getConnections

<E extends T> java.util.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​(java.util.function.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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
How can we improve this article?