@Override public void listenToTheDm( ListenerCommand command ) throws IOException { listenToTheDm( getMessagingClient(), command ); }
@Override public void setMessageQueue( RoboconfMessageQueue messageQueue ) { getMessagingClient().setMessageQueue( messageQueue ); }
@Override public boolean isConnected() { return getMessagingClient().isConnected(); }
@Override public void setMessageQueue( RoboconfMessageQueue messageQueue ) { getMessagingClient().setMessageQueue( messageQueue ); }
@Override public void openConnection() throws IOException { openConnection( getMessagingClient()); }
@Override public boolean isConnected() { return getMessagingClient().isConnected(); }
@Override public void listenToTheDm( ListenerCommand command ) throws IOException { listenToTheDm( getMessagingClient(), command ); }
@Override public void openConnection() throws IOException { openConnection( getMessagingClient()); }
@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 setApplicationName( String applicationName ) { this.applicationName = applicationName; // Propagate the information to the internal client. getMessagingClient().setOwnerProperties( getOwnerKind(), this.domain, applicationName, this.scopedInstancePath ); }
@Override public void setApplicationName( String applicationName ) { this.applicationName = applicationName; // Propagate the information to the internal client. getMessagingClient().setOwnerProperties( getOwnerKind(), this.domain, applicationName, this.scopedInstancePath ); }
@Override public void setScopedInstancePath( String scopedInstancePath ) { this.scopedInstancePath = scopedInstancePath; // Propagate the information to the internal client. getMessagingClient().setOwnerProperties( getOwnerKind(), this.domain, this.applicationName, scopedInstancePath ); }
@Override public void setScopedInstancePath( String scopedInstancePath ) { this.scopedInstancePath = scopedInstancePath; // Propagate the information to the internal client. getMessagingClient().setOwnerProperties( getOwnerKind(), this.domain, this.applicationName, scopedInstancePath ); }
@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 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 ); } }
@Test public void testAgent() throws Exception { // The messaging client is never null ReconfigurableClientAgent client = new ReconfigurableClientAgent(); Assert.assertNotNull( client.getMessagingClient()); // Invoke other method, no matter in which order client.setMessageQueue( new RoboconfMessageQueue()); Assert.assertFalse( client.hasValidClient()); Assert.assertFalse( client.isConnected()); }