AnyLogic
Expand
Font size
  • java.lang.Object
    • com.anylogic.engine.Port<InMessageType,​OutMessageType>
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, java.io.Serializable
Direct Known Subclasses:
FlowchartPort

public class Port<InMessageType,​OutMessageType>
extends java.lang.Object
implements java.io.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

Constructors 
Port​(Agent ao)  
Constructor Description

Method Summary

All Methods Instance Methods Concrete Methods Deprecated Methods 
void connect​(Port<OutMessageType,​InMessageType> port)
Connects the port to another port of an object on the same level.
void disconnect​(Port<OutMessageType,​InMessageType> port)
Disconnects the port from another port of an object on the same level.
void disconnectAndUnmapAll()
Disconnects and unmaps the port from all ports and statechart it is connected and/or mapped to.
Agent getActiveObject()
Deprecated.
Use getAgent() instead
Agent getAgent()
Returns the agent that owns the port.
java.util.List<Port<InMessageType,​OutMessageType>> getDownLinks()
Returns an unmodifiable list with mapped ports on agents embedded in the current agent (owner of port)
java.util.List<Port<OutMessageType,​InMessageType>> getFlatLinks()
Returns an unmodifiable list with connected ports
java.lang.String getFullName()
Returns the name of the port prefixed by the full name of its agent.
java.lang.String getName()
Returns the name of the port as specified by the user.
java.util.List<Statechart> getStatechartLinks()
Returns an unmodifiable list with mapped statecharts of the current agent (owner of this port)
java.util.List<Port<InMessageType,​OutMessageType>> getUpLinks()
Returns an unmodifiable list with mapped ports on agents which own the current agent (owner of port)
void map​(Port<InMessageType,​OutMessageType> port)
Maps (connects) the port to a port of an embedded object.
void map​(Statechart statechart)
Maps (connects) the port to a statechart of the same agent.
void onDestroy()
Should be called when the port is destroyed, e.g.
void receive​(InMessageType msg)
Receives an incoming message.
void restoreOwner​(java.lang.Object owner)
Deprecated.
void send​(OutMessageType msg)
Send the message out.
java.lang.String toString()  
void unmap​(Port<InMessageType,​OutMessageType> port)
Unmaps (disconnects) the port from a port of an embedded object.
void unmap​(Statechart statechart)
Unmaps (disconnects) the port from the statechart of the same agent.
Modifier and Type Method Description

Methods inherited from class java.lang.Object

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

Constructor Detail

Port

public Port​(Agent ao)

Method Detail

getName

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

getFullName

public java.lang.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 java.lang.String toString()
Overrides:
toString in class java.lang.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 java.util.List<Port<OutMessageType,​InMessageType>> getFlatLinks()
Returns an unmodifiable list with connected ports
Returns:
unmodifiable list with connected ports
public java.util.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 java.util.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 java.util.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​(java.lang.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