@Override public void publishExports( Instance instance ) throws IOException { // For all the exported variables... // ... find the component or facet name... Set<String> names = VariableHelpers.findPrefixesForExportedVariables( instance ); if( names.isEmpty()) this.logger.fine( "Agent '" + getAgentId() + "' is publishing its exports." ); else for( String facetOrComponentName : names ) { publishExports( instance, facetOrComponentName ); } }
@Override public void publishExports( Instance instance ) throws IOException { // For all the exported variables... // ... find the component or facet name... Set<String> names = VariableHelpers.findPrefixesForExportedVariables( instance ); if( names.isEmpty()) this.logger.fine( "Agent '" + getAgentId() + "' is publishing its exports." ); else for( String facetOrComponentName : names ) { publishExports( instance, facetOrComponentName ); } }
private void listenToTheDm( IMessagingClient client, ListenerCommand command ) throws IOException { // The context match the one used by the DM to send a message to an agent. // The agent client MUST have a scoped instance path! String topicName = MessagingUtils.buildTopicNameForAgent( this.scopedInstancePath ); MessagingContext ctx = new MessagingContext( RecipientKind.AGENTS, this.domain, topicName, this.applicationName ); if( command == ListenerCommand.START ) { this.logger.fine( "Agent '" + getAgentId() + "' starts listening to the DM." ); client.subscribe( ctx ); } else { this.logger.fine( "Agent '" + getAgentId() + "' stops listening to the DM." ); client.unsubscribe( ctx ); } }
private void listenToTheDm( IMessagingClient client, ListenerCommand command ) throws IOException { // The context match the one used by the DM to send a message to an agent. // The agent client MUST have a scoped instance path! String topicName = MessagingUtils.buildTopicNameForAgent( this.scopedInstancePath ); MessagingContext ctx = new MessagingContext( RecipientKind.AGENTS, this.domain, topicName, this.applicationName ); if( command == ListenerCommand.START ) { this.logger.fine( "Agent '" + getAgentId() + "' starts listening to the DM." ); client.subscribe( ctx ); } else { this.logger.fine( "Agent '" + getAgentId() + "' stops listening to the DM." ); client.unsubscribe( ctx ); } }
@Override public void sendMessageToTheDm( Message message ) throws IOException { // The context match the one used by the DM to listen to messages sent by agents. this.logger.fine( "Agent '" + getAgentId() + "' is sending a " + message.getClass().getSimpleName() + " message to the DM." ); MessagingContext ctx = new MessagingContext( RecipientKind.DM, this.domain, this.applicationName ); getMessagingClient().publish( ctx, message ); }
@Override public void sendMessageToTheDm( Message message ) throws IOException { // The context match the one used by the DM to listen to messages sent by agents. this.logger.fine( "Agent '" + getAgentId() + "' is sending a " + message.getClass().getSimpleName() + " message to the DM." ); MessagingContext ctx = new MessagingContext( RecipientKind.DM, this.domain, this.applicationName ); getMessagingClient().publish( ctx, message ); }
@Override public void requestExportsFromOtherAgents( Instance instance ) throws IOException { this.logger.fine( "Agent '" + getAgentId() + "' is requesting exports from other agents." ); // For all the imported variables... // ... find the component or facet name... for( MessagingContext ctx : MessagingContext.forImportedVariables( this.domain, this.applicationName, instance, ThoseThat.EXPORT )) { // Log here, for debug this.logger.fine( "Agent '" + getAgentId() + "' is requesting exports from other agents (" + ctx + ")." ); // ... and ask to publish them. // Grouping variable requests by prefix reduces the number of messages. MsgCmdRequestImport message = new MsgCmdRequestImport( this.applicationName, ctx.getComponentOrFacetName()); getMessagingClient().publish( ctx, message ); } }
@Override public void requestExportsFromOtherAgents( Instance instance ) throws IOException { this.logger.fine( "Agent '" + getAgentId() + "' is requesting exports from other agents." ); // For all the imported variables... // ... find the component or facet name... for( MessagingContext ctx : MessagingContext.forImportedVariables( this.domain, this.applicationName, instance, ThoseThat.EXPORT )) { // Log here, for debug this.logger.fine( "Agent '" + getAgentId() + "' is requesting exports from other agents (" + ctx + ")." ); // ... and ask to publish them. // Grouping variable requests by prefix reduces the number of messages. MsgCmdRequestImport message = new MsgCmdRequestImport( this.applicationName, ctx.getComponentOrFacetName()); getMessagingClient().publish( ctx, message ); } }
@Override public void listenToRequestsFromOtherAgents( ListenerCommand command, Instance instance ) throws IOException { // Find the right contexts to subscribe. // This depends on the exported variables. for( MessagingContext ctx : MessagingContext.forExportedVariables( this.domain, this.applicationName, instance, this.externalExports, ThoseThat.EXPORT )) { if( command == ListenerCommand.START ) { this.logger.fine( "Agent '" + getAgentId() + "' starts listening requests from other agents (" + ctx + ")." ); getMessagingClient().subscribe( ctx ); } else { this.logger.fine( "Agent '" + getAgentId() + "' stops listening requests from other agents (" + ctx + ")." ); getMessagingClient().unsubscribe( ctx ); } } }
@Override public void listenToExportsFromOtherAgents( ListenerCommand command, Instance instance ) throws IOException { // With RabbitMQ, and for agents, listening to others means // create a binding between the "agents" exchange and the agent's queue. for( MessagingContext ctx : MessagingContext.forImportedVariables( this.domain, this.applicationName, instance, ThoseThat.IMPORT )) { // On which routing key do export go? Those.that.import... if( command == ListenerCommand.START ) { this.logger.fine( "Agent '" + getAgentId() + "' starts listening exports from other agents (" + ctx + ")." ); getMessagingClient().subscribe( ctx ); } else { this.logger.fine( "Agent '" + getAgentId() + "' stops listening exports from other agents (" + ctx + ")." ); getMessagingClient().unsubscribe( ctx ); } } }
@Override public void listenToRequestsFromOtherAgents( ListenerCommand command, Instance instance ) throws IOException { // Find the right contexts to subscribe. // This depends on the exported variables. for( MessagingContext ctx : MessagingContext.forExportedVariables( this.domain, this.applicationName, instance, this.externalExports, ThoseThat.EXPORT )) { if( command == ListenerCommand.START ) { this.logger.fine( "Agent '" + getAgentId() + "' starts listening requests from other agents (" + ctx + ")." ); getMessagingClient().subscribe( ctx ); } else { this.logger.fine( "Agent '" + getAgentId() + "' stops listening requests from other agents (" + ctx + ")." ); getMessagingClient().unsubscribe( ctx ); } } }
@Override public void listenToExportsFromOtherAgents( ListenerCommand command, Instance instance ) throws IOException { // With RabbitMQ, and for agents, listening to others means // create a binding between the "agents" exchange and the agent's queue. for( MessagingContext ctx : MessagingContext.forImportedVariables( this.domain, this.applicationName, instance, ThoseThat.IMPORT )) { // On which routing key do export go? Those.that.import... if( command == ListenerCommand.START ) { this.logger.fine( "Agent '" + getAgentId() + "' starts listening exports from other agents (" + ctx + ")." ); getMessagingClient().subscribe( ctx ); } else { this.logger.fine( "Agent '" + getAgentId() + "' stops listening exports from other agents (" + ctx + ")." ); getMessagingClient().unsubscribe( ctx ); } } }
@Override public void unpublishExports( Instance instance ) throws IOException { this.logger.fine( "Agent '" + getAgentId() + "' is un-publishing its exports." ); // For all the exported variables... // ... find the component or facet name... for( MessagingContext ctx : MessagingContext.forExportedVariables( this.domain, this.applicationName, instance, this.externalExports, ThoseThat.IMPORT )) { // Log here, for debug this.logger.fine( "Agent '" + getAgentId() + "' is un-publishing its exports (" + ctx + ")." ); // Un-publish them MsgCmdRemoveImport message = new MsgCmdRemoveImport( this.applicationName, ctx.getComponentOrFacetName(), InstanceHelpers.computeInstancePath( instance )); getMessagingClient().publish( ctx, message ); } }
@Override public void unpublishExports( Instance instance ) throws IOException { this.logger.fine( "Agent '" + getAgentId() + "' is un-publishing its exports." ); // For all the exported variables... // ... find the component or facet name... for( MessagingContext ctx : MessagingContext.forExportedVariables( this.domain, this.applicationName, instance, this.externalExports, ThoseThat.IMPORT )) { // Log here, for debug this.logger.fine( "Agent '" + getAgentId() + "' is un-publishing its exports (" + ctx + ")." ); // Un-publish them MsgCmdRemoveImport message = new MsgCmdRemoveImport( this.applicationName, ctx.getComponentOrFacetName(), InstanceHelpers.computeInstancePath( instance )); getMessagingClient().publish( ctx, message ); } }
@Override public void publishExports( Instance instance, String facetOrComponentName ) throws IOException { this.logger.fine( "Agent '" + getAgentId() + "' is publishing its exports prefixed by " + facetOrComponentName + "." );
@Override public void publishExports( Instance instance, String facetOrComponentName ) throws IOException { this.logger.fine( "Agent '" + getAgentId() + "' is publishing its exports prefixed by " + facetOrComponentName + "." );