Connecting Ports

To establish message passing you should connect the respective ports by connectors. Connectors are paths used by messages to flow through the model.

You can establish message passing between:

To connect two ports
  1. Double-click on one port.
  2. Click at each connector's turning point on the diagram.
  3. Finally, click on another port to finish the process.
  4. Alternatively, you can drag the Connector element from the Agent palette into the graphical editor (right on one port) and then drag the hanging edge of the connector onto the other port you want to connect.
When drawing connectors, you can notice that connector's points put correctly inside a port are indicated with small green circles. In the case you select the connector and do not see green circles, it means that you put connector's point close by a port and need to move it exactly onto the port.

Connecting ports at runtime

AnyLogic supports creation of truly dynamic models – the ones with dynamically evolving structure and component interconnection.

You can programmatically change port connections at runtime to model systems with dynamically changing connections, in particular, systems with mobile objects. It can be also helpful when you need to create a complex structure of objects with sophisticated topologies that cannot be established graphically.

You can write this code anywhere you like in the agent class.

Connection case
Connection method

Disconnection method
A port with a port of an embedded object;


Note that it is significant that the method map()/unmap() of the port and not of the port of an embedded object should be called. The following line of code is invalid:;

Ports of embedded objects



Note that in case you connect or disconnect a port of some Process Modeling Library object, you should call a special method of this port afterwards: source.out.refreshConnections().

AnyLogic also provides you the ability to programmatically disconnect a port from all connected ports using the following method of Port class:

void disconnectAndUnmapAll();

Connecting ports of Process Modeling Library objects

If you rewire the connections dynamically (by calling connect()/disconnect() or map()/unmap() methods of ports of Process Modeling Library objects), the end ports will not notice that and will continue behaving according to the out-of-date connections that were established at startup.

To bring the end port connections up to date you need to call method refreshConnections() of the end ports that are dynamically reconnected. For example, if the out port of myService is connected programmatically, you should call:


Demonstration model: Connecting Library Objects Dynamically

This demo model illustrates how to connect Process Modeling Library objects dynamically. It has two separate parts of a flowchart that are connected by clicking on the button placed between them. Please have a look at the button's Action to understand the approach.

Related topics

Message passing

Message routing rules

Changing connector's appearance