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:
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 |
port.map(source.out); |
port.unmap(source.out); |
source.out.map(port); |
||
Ports of embedded objects |
source.out.connect(sink.in); |
source.out.disconnect(sink.in); |
|
AnyLogic also provides you the ability to programmatically disconnect a port from all connected ports using the following method of Port class:
void disconnectAndUnmapAll();
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:
myService.release.out.refreshConnections();
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.