Source:
void processMsgSetScopedInstance( MsgCmdSetScopedInstance msg ) throws IOException, PluginException, InterruptedException { Instance newScopedInstance = msg.getScopedInstance(); List<Instance> instancesToProcess = new ArrayList<> (); if( ! InstanceHelpers.isTarget( newScopedInstance )) { this.logger.severe( "The received instance is not a scoped one. Request to update the local model is dropped." ); } else if( this.scopedInstance == null ) { this.logger.fine( "Setting the scoped instance." ); this.scopedInstance = newScopedInstance; InstanceHelpers.removeOffScopeInstances( newScopedInstance ); this.agent.setScopedInstance( newScopedInstance ); instancesToProcess.addAll( InstanceHelpers.buildHierarchicalList( this.scopedInstance )); this.messagingClient.setExternalMapping( msg.getExternalExports()); this.applicationBindings.putAll( msg.getApplicationBindings()); AgentUtils.copyInstanceResources( this.scopedInstance, msg.getscriptResources()); AgentUtils.excuteScriptResource( this.scopedInstance, this.agent.getApplicationName(), this.scopedInstance.getName()); if( this.scopedInstance.getStatus() != InstanceStatus.DEPLOYED_STARTED ) { this.scopedInstance.setStatus( InstanceStatus.DEPLOYED_STARTED ); this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.agent.getApplicationName(), this.scopedInstance )); } this.messagingClient.listenToRequestsFromOtherAgents( ListenerCommand.START, this.scopedInstance ); } for( Instance instanceToProcess : instancesToProcess ) { this.messagingClient.listenToExportsFromOtherAgents( ListenerCommand.START, instanceToProcess ); this.messagingClient.requestExportsFromOtherAgents( instanceToProcess ); } }

Target:
void processMsgSetScopedInstance( MsgCmdSetScopedInstance msg ) throws IOException, PluginException { Instance newScopedInstance = msg.getScopedInstance(); List<Instance> instancesToProcess = new ArrayList<> (); if( ! InstanceHelpers.isTarget( newScopedInstance )) { this.logger.severe( "The received instance is not a scoped one. Request to update the local model is dropped." ); } else if( this.scopedInstance == null ) { this.logger.fine( "Setting the scoped instance." ); this.scopedInstance = newScopedInstance; InstanceHelpers.removeOffScopeInstances( newScopedInstance ); this.agent.setScopedInstance( newScopedInstance ); instancesToProcess.addAll( InstanceHelpers.buildHierarchicalList( this.scopedInstance )); this.messagingClient.setExternalMapping( msg.getExternalExports()); this.applicationBindings.putAll( msg.getApplicationBindings()); AgentUtils.copyInstanceResources( this.scopedInstance, msg.getscriptResources()); AgentUtils.executeScriptResources( InstanceHelpers.findInstanceDirectoryOnAgent( this.scopedInstance )); if( this.scopedInstance.getStatus() != InstanceStatus.DEPLOYED_STARTED ) { this.scopedInstance.setStatus( InstanceStatus.DEPLOYED_STARTED ); this.messagingClient.sendMessageToTheDm( new MsgNotifInstanceChanged( this.agent.getApplicationName(), this.scopedInstance )); } this.messagingClient.listenToRequestsFromOtherAgents( ListenerCommand.START, this.scopedInstance ); } for( Instance instanceToProcess : instancesToProcess ) { this.messagingClient.listenToExportsFromOtherAgents( ListenerCommand.START, instanceToProcess ); this.messagingClient.requestExportsFromOtherAgents( instanceToProcess ); } }