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, the Moxie 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:
- Moxie 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 |
---|---|
Moxie Installation | You must have installed Moxie and have the prerequisites for developing delegates for Moxie. |
Tutorial Project | You must start this section with the UAV Mission simulation project and delegate module project from the previous section. If you did not complete the previous section, you can use the files from the Moxie installation: \documentation\tutorialFiles\03\DelegateCodeGeneration, but you may still 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
- If you did not complete the previous section, re-install the delegate module.
- Open the UAVMission.mdzip project from the previous section.
-
Run () the simulation
and observe that the simulation fails with the following exception:
This indicates that the Moxie Engine encountered a circular dependency while attempting to instantiate the Java delegates.
ERROR: com.agi.moxie.plugin.InstantiationCycleException
-
In the System Definition (the BDD),
notice the bi-directional 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 the Moxie 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 the Moxie 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 the Moxie 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 re-install the delegate module.
The Moxie Engine's hot code reloading capability allows you to do this without having to restart your No Magic modeling tool.
-
Run () the simulation again
and observe that the simulation no longer throws a
com.agi.moxie.plugin.InstantiationCycleException
.The simulation still fails, but with a different exception now, which you will debug in the next section.
Next Section >