Handling Circular Dependencies with Delegate Wire-Up
Overview
SysML permits circular dependencies, and it can be very useful for two blocks to each have a reference to the other, but it can also cause instantiation problems in executable software. Fortunately, Behavior Execution Engine wires up the delegates in such a way that you can avoid these problems while retaining the usefulness of mutual references. In this section, you will use the delegate wire-up to safely establish the circular dependencies between the UAV, computer, and ground station delegates.
This section covers the following concept:
- Behavior Execution Engine delegate wire-up
public GroundStationDelegate(@InjectByName("timeProvider") TimeProvider timeProvider,
@OptionalInjectBySlot("flightPlanUploadDuration") TimeDuration flightPlanUploadDuration,
@OptionalInjectBySlot("dataDownloadDuration") TimeDuration dataDownloadDuration,
@OptionalInjectBySlot("referencePoint") SpatialPoint referencePoint) {
uavProperty = new BasicProperty<>(timeProvider);
flightPlanUploadDurationProperty = new BasicProperty<>(timeProvider, flightPlanUploadDuration);
dataDownloadDurationProperty = new BasicProperty<>(timeProvider, dataDownloadDuration);
referencePointProperty = new BasicProperty<>(timeProvider, referencePoint);
}
Figure A1: An independent delegate constructor
Prerequisites
Prerequisite | Description |
---|---|
Behavior Execution Engine Installation | You must have installed Behavior Execution Engine and have the prerequisites for developing delegates for Behavior Execution Engine. |
Tutorial Project | Start with the files from the Behavior Execution Engine installation: \documentation\tutorialFiles\03\DelegateCodeGeneration, and you will need to configure the delegate module for your environment. |
Recommended Reading |
Before completing this section, you may want to read the following help topic:
|
Instructions
Examine the circular dependencies
- Open the UAVMission.mdzip project from the previous section.
- Execute the simulation
and observe that the simulation fails with the following exception:
This indicates that Behavior Execution Engine encountered a circular dependency while attempting to instantiate the Java delegates.
ERROR: com.agi.moxie.uml.engine.InstantiationCycleException
-
In the System Definition (the BDD),
notice the bidirectional relationships between the
UAV
andGroundStation
blocks and between theUAV
andComputer
blocks. Each relationship represents two properties, one on each block that references the other block. -
In the UAVMissionDelegateModule\src\com\agi\moxie\tutorial\uavmission\structure\impl directory,
open the
UAVDelegate
,GroundStationDelegate
, andComputerDelegate
classes and notice that they expect each other as constructor parameters. This means that none of them can be instantiated until the others have been instantiated.
Remove the mutual recursion
After Behavior Execution Engine instantiates the Java delegates, it wires them up to their SysML instance specifications, setting the Java fields with the SysML property values. By setting the instance specification properties, you can establish the circular dependencies with this wire-up instead of trying to establish them in the constructors. This in turn allows Behavior Execution Engine to instantiate the delegates in the first place.
-
In the Instance Specification Diagram,
notice that the
computer
andgroundStation
properties on theuav
instance specification, theuav
property on thegroundStation
instance specification, and theuav
property on theuav.computer
instance specification are all set to the other instance specifications. -
In the
GroundStationDelegate
class, remove theuav
parameter both from the constructor header and from theuavProperty
initialization in the constructor body. The constructor should now look like the following:This will initialize thepublic GroundStationDelegate(@InjectByName("timeProvider") TimeProvider timeProvider,
@OptionalInjectBySlot("flightPlanUploadDuration") TimeDuration flightPlanUploadDuration,
@OptionalInjectBySlot("dataDownloadDuration") TimeDuration dataDownloadDuration,
@OptionalInjectBySlot("referencePoint") SpatialPoint referencePoint) {
uavProperty = new BasicProperty<>(timeProvider);
flightPlanUploadDurationProperty = new BasicProperty<>(timeProvider, flightPlanUploadDuration);
dataDownloadDurationProperty = new BasicProperty<>(timeProvider, dataDownloadDuration);
referencePointProperty = new BasicProperty<>(timeProvider, referencePoint);
}uavProperty
value tonull
in the constructor, but Behavior Execution Engine will wire it up to the correctUAVDelegate
instance before the simulation starts. -
In the
ComputerDelegate
class, again remove theuav
parameter both from the constructor header and from theuavProperty
initialization in the constructor body:public ComputerDelegate(@InjectByName("timeProvider") TimeProvider timeProvider,
@OptionalInjectBySlot("powerSystem") PowerSystem powerSystem,
... ) {
uavProperty = new BasicProperty<>(timeProvider);
...
} - Save your work and reinstall the delegate module.
- Execute the simulation again
and observe that the simulation no longer throws a
com.agi.moxie.uml.engine.InstantiationCycleException
.The simulation still fails, but with a different exception now, which you will debug in the next section.
Next Section >