AnyLogic
Expand
Font size
Type Parameters:
InMessageType - the type of messages being received by the port
OutMessageType - the type of messages being sent by the port
All Implemented Interfaces:
com.anylogic.engine.internal.Child, Serializable
Direct Known Subclasses:
FlowchartPort

public class Port<InMessageType,OutMessageType>
extends Object
implements Serializable, com.anylogic.engine.internal.Child
Port is a universal interface of an agent via which it can send and receive messages - arbitrary objects. Ports are used to graphically connect objects that do not need to know anything about each other type or structure. There are two major types of links a port maintains: connections to the ports of objects on the same hierarchy level (embedded in the same agent) or "mappings" to the ports of embedded objects or statecharts. In the first case a message sent at one port is received at the other. In case of mapping the message sent at the inner port is forwarded out at the outer port, and vice versa: message received at the outer port is received by the inner port or by the statechart. The user may define his own actions that are executed upon reception or sending the message that may prevent the port from continuing the message processing. The port class is generic with two parameters - the classes of messages being received and sent. Once instantiated and parameterized, it will only accept the messages of those classes. Moreover, the port can only be connected / mapped to a port with the corresponding message types.
Memory: sizeof(Object) + 20 bytes = 34 bytes + sizeof up to 4 LinkedList's
Author:
AnyLogic North America, LLC https://anylogic.com
See Also:
Serialized Form

Constructor Summary

ConstructorDescription
Port(Agent ao) 

Method Summary

Modifier and TypeMethodDescription
voidconnect(Port<OutMessageType,InMessageType> port)
Connects the port to another port of an object on the same level.
voiddisconnect(Port<OutMessageType,InMessageType> port)
Disconnects the port from another port of an object on the same level.
voiddisconnectAndUnmapAll()
Disconnects and unmaps the port from all ports and statechart it is connected and/or mapped to.
AgentgetActiveObject()
Deprecated.
Use getAgent() instead
AgentgetAgent()
Returns the agent that owns the port.
List<Port<InMessageType,OutMessageType>>getDownLinks()
Returns an unmodifiable list with mapped ports on agents embedded in the current agent (owner of port)
List<Port<OutMessageType,InMessageType>>getFlatLinks()
Returns an unmodifiable list with connected ports
StringgetFullName()
Returns the name of the port prefixed by the full name of its agent.
StringgetName()
Returns the name of the port as specified by the user.
List<Statechart>getStatechartLinks()
Returns an unmodifiable list with mapped statecharts of the current agent (owner of this port)
List<Port<InMessageType,OutMessageType>>getUpLinks()
Returns an unmodifiable list with mapped ports on agents which own the current agent (owner of port)
voidmap(Port<InMessageType,OutMessageType> port)
Maps (connects) the port to a port of an embedded object.
voidmap(Statechart statechart)
Maps (connects) the port to a statechart of the same agent.
voidonDestroy()
Should be called when the port is destroyed, e.g.
voidreceive(InMessageType msg)
Receives an incoming message.
voidrestoreOwner(Object owner)
Deprecated.
voidsend(OutMessageType msg)
Send the message out.
StringtoString() 
voidunmap(Port<InMessageType,OutMessageType> port)
Unmaps (disconnects) the port from a port of an embedded object.
voidunmap(Statechart statechart)
Unmaps (disconnects) the port from the statechart of the same agent.

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Details

Port

public Port(Agent ao)

Method Details

getName

public String getName()
Returns the name of the port as specified by the user.
Returns:
The name of the port

getFullName

public String getFullName()
Returns the name of the port prefixed by the full name of its agent.
Returns:
The full name of the port.

toString

public String toString()
Overrides:
toString in class Object

getAgent

public Agent getAgent()
Returns the agent that owns the port.
Returns:
The agent owning this port.

getActiveObject

@Deprecated
public Agent getActiveObject()
Deprecated.
Use getAgent() instead

connect

public void connect(Port<OutMessageType,InMessageType> port)
Connects the port to another port of an object on the same level. If the ports are already connected, does nothing. send(msg) called on either of the ports will result in receive(msg) called on another
Parameters:
port - another port

disconnect

public void disconnect(Port<OutMessageType,InMessageType> port)
Disconnects the port from another port of an object on the same level.
Parameters:
port - another port

map

public void map(Port<InMessageType,OutMessageType> port)
Maps (connects) the port to a port of an embedded object. send(msg) called on another port will result in send(msg) called on this port and receive(msg) called on this port will result in receive(msg) called on another port.
Parameters:
port - port of an embedded object

unmap

public void unmap(Port<InMessageType,OutMessageType> port)
Unmaps (disconnects) the port from a port of an embedded object.
Parameters:
port - port of an embedded object

map

public void map(Statechart statechart)
Maps (connects) the port to a statechart of the same agent. receive(msg) called on this port will result in receiveMessage(msg) called on the statechart.
Parameters:
statechart - the statechart

unmap

public void unmap(Statechart statechart)
Unmaps (disconnects) the port from the statechart of the same agent.
Parameters:
statechart - the statechart

disconnectAndUnmapAll

public void disconnectAndUnmapAll()
Disconnects and unmaps the port from all ports and statechart it is connected and/or mapped to.

send

public void send(OutMessageType msg)
Send the message out. First, calls user's on send code, and, if it returns true, forwards the message to all connected ports on the same level and to all container agent ports mapped to this one.
Parameters:
msg - the message being sent.

receive

public void receive(InMessageType msg)
Receives an incoming message. First, calls user's on receive code, and, if it returns true, forwards the message to all ports of embedded objects and to all statecharts this port is mapped to.
Parameters:
msg - the message being received
public List<Port<OutMessageType,InMessageType>> getFlatLinks()
Returns an unmodifiable list with connected ports
Returns:
unmodifiable list with connected ports
public List<Port<InMessageType,OutMessageType>> getUpLinks()
Returns an unmodifiable list with mapped ports on agents which own the current agent (owner of port)
Returns:
unmodifiable list with mapped ports on agents which own current agent (owner of port)
See Also:
map(Port)
public List<Port<InMessageType,OutMessageType>> getDownLinks()
Returns an unmodifiable list with mapped ports on agents embedded in the current agent (owner of port)
Returns:
unmodifiable list with mapped ports on agents embedded in the current agent (owner of port)
See Also:
map(Port)
public List<Statechart> getStatechartLinks()
Returns an unmodifiable list with mapped statecharts of the current agent (owner of this port)
Returns:
unmodifiable list with mapped statecharts of the current agent (owner of this port)
See Also:
map(Statechart)

onDestroy

@AnyLogicInternalCodegenAPI
public void onDestroy()
Should be called when the port is destroyed, e.g. when the owner agent is destroyed. Disconnects and unmaps the port from all other ports and statecharts.

restoreOwner

@AnyLogicInternalCodegenAPI
@Deprecated
public void restoreOwner(Object owner)
Deprecated.
This method normally should not be called by user
This method restores owner of this object
The method is used in snapshot saving/loading
Specified by:
restoreOwner in interface com.anylogic.engine.internal.Child
Parameters:
owner - owner of this object, usually Agent, Experiment or ShapeGroup