com.xj.anylogic.engine
Class Port<InMessageType,OutMessageType>

java.lang.Object
  extended by com.xj.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.xj.anylogic.engine.internal.Child, java.io.Serializable

public class Port<InMessageType,OutMessageType>
extends java.lang.Object
implements java.io.Serializable, com.xj.anylogic.engine.internal.Child

Port is a universal interface of an active object 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 active object) 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:
XJ Technologies Company Ltd. www.anylogic.com
See Also:
Serialized Form

Constructor Summary
Port(ActiveObject ao)
           
 
Method Summary
 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.
 ActiveObject getActiveObject()
          Returns the active object that owns the port.
 java.util.List<Port<InMessageType,OutMessageType>> getDownLinks()
          Returns an unmodifiable list with mapped ports on active objects embedded in the current active object (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 active object.
 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 active object (owner of this port)
 java.util.List<Port<InMessageType,OutMessageType>> getUpLinks()
          Returns an unmodifiable list with mapped ports on active objects which own the current active object (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 active object.
 void onDestroy()
          Should be called when the port is destroyed, e.g. when the owner active object is destroyed.
 void receive(InMessageType msg)
          Receives an incoming message.
 void restoreOwner(java.lang.Object owner)
          This method normally should not be called by user
This method restores owner of this object
The method is used in snapshot saving/loading
 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 active object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Port

public Port(ActiveObject 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 active object.

Returns:
The full name of the port.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getActiveObject

public ActiveObject getActiveObject()
Returns the active object that owns the port.

Returns:
The active object owning this port.

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 active object. 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 active object.

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 active object 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

getFlatLinks

public java.util.List<Port<OutMessageType,InMessageType>> getFlatLinks()
Returns an unmodifiable list with connected ports

Returns:
unmodifiable list with connected ports

getUpLinks

public java.util.List<Port<InMessageType,OutMessageType>> getUpLinks()
Returns an unmodifiable list with mapped ports on active objects which own the current active object (owner of port)

Returns:
unmodifiable list with mapped ports on active objects which own current active object (owner of port)
See Also:
map(Port)

getDownLinks

public java.util.List<Port<InMessageType,OutMessageType>> getDownLinks()
Returns an unmodifiable list with mapped ports on active objects embedded in the current active object (owner of port)

Returns:
unmodifiable list with mapped ports on active objects embedded in the current active object (owner of port)
See Also:
map(Port)

getStatechartLinks

public java.util.List<Statechart> getStatechartLinks()
Returns an unmodifiable list with mapped statecharts of the current active object (owner of this port)

Returns:
unmodifiable list with mapped statecharts of the current active object (owner of this port)
See Also:
map(Statechart)

onDestroy

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


restoreOwner

public void restoreOwner(java.lang.Object owner)
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.xj.anylogic.engine.internal.Child
Parameters:
owner - owner of this object, usually ActiveObject, Experiment or ShapeGroup


Copyright © 1991-2008 XJ Technlogies. All Rights Reserved.