@Override protected void configureMessageProcessor( AbstractMessageProcessor<IAgentClient> messageProcessor ) { messageProcessor.setMessagingClient( this ); }
/** * Associates a message processor with this instance. * <p> * The message processor cannot be started before. This method will start it. * </p> * <p> * This method must be invoked only once. * </p> * @param messageProcessor the message processor */ public void associateMessageProcessor( AbstractMessageProcessor<T> messageProcessor ) { if( this.messageProcessor != null ) throw new IllegalArgumentException( "The message processor was already defined." ); this.messageProcessor = messageProcessor; configureMessageProcessor( messageProcessor ); this.messageProcessor.start(); }
@Override public final void run() { this.running.set( true ); while( this.running.get()) { try { Message message = this.messageQueue.take(); if( this.running.get()) processMessage( message ); } catch( InterruptedException e ) { break; } } Logger.getLogger( getClass().getName()).fine( "Roboconf's message processing thread is stopping." ); this.running.set( false ); }
if( this.messagingClient.isConnected()) { this.messagingClient.sendMessageToTheDm( new MsgNotifMachineDown( this.applicationName, this.scopedInstancePath )); this.logger.fine( "Agent " + getAgentId() + " notified the DM it was about to stop." ); this.messagingClient.getMessageProcessor().stopProcessor(); this.messagingClient.getMessageProcessor().interrupt(); this.messagingClient.closeConnection();
JmxWrapperForMessagingClient newMessagingClient = null; try { IMessagingClient rawClient = createMessagingClient( factoryName ); if( rawClient != null ) { newMessagingClient = new JmxWrapperForMessagingClient( rawClient ); newMessagingClient.setMessageQueue( this.messageProcessor.getMessageQueue()); openConnection( newMessagingClient ); this.messagingClient = newMessagingClient; else resetInternalClient(); terminateClient( oldClient, "The previous client could not be terminated correctly.", this.logger );
@Test public void testProcessing() throws Exception { // The message is processed... this.processor.start(); this.processor.storeMessage( new MsgCmdResynchronize()); Thread.sleep( 1000 ); this.processor.stopProcessor(); Assert.assertEquals( 0, this.processor.getMessageQueue().size()); }
@After public void releaseClients() throws Exception { for( ReconfigurableClient<?> client : this.clients ) { client.getMessageProcessor().stopProcessor(); client.getMessageProcessor().interrupt(); client.closeConnection(); } this.clients.clear(); }
@Test public void testStartAndStop() throws Exception { Assert.assertFalse( this.processor.isRunning()); this.processor.start(); Thread.sleep( 200 ); Assert.assertTrue( this.processor.isRunning()); this.processor.stopProcessor();; Thread.sleep( 200 ); Assert.assertFalse( this.processor.isRunning()); }
this.messagingClient.getMessageProcessor().stopProcessor(); this.messagingClient.getMessageProcessor().interrupt(); try { this.messagingClient.closeConnection();
@Override public String agentStatus() { StringBuilder sb = new StringBuilder(); // Messages LinkedBlockingQueue<Message> agentQueue = this.messagingClient.getMessageProcessor().getMessageQueue(); if( agentQueue.isEmpty() ) { sb.append( "There is no message being processed in agent queue\n" ); } else { sb.append( "Agent " + getScopedInstancePath() + " (" + getApplicationName() + ")\n" ); sb.append( "The number total of messages in agent queue is : " + agentQueue.size() + "\n" ); sb.append( "The types of messages being processed are : " + "\n"); for( Message msg : agentQueue ) { sb.append( msg.getClass().getSimpleName() + "\n" ); } } // Running processes Process p = ProcessStore.getProcess(this.applicationName, this.scopedInstancePath); if( p != null ) sb.append( "Be careful. A recipe is under execution." ); else sb.append( "No recipe is under execution." ); return sb.toString(); } }
@After public void terminateProcessor() { if( this.processor != null ) this.processor.stopProcessor(); }
JmxWrapperForMessagingClient newMessagingClient = null; try { IMessagingClient rawClient = createMessagingClient( factoryName ); if( rawClient != null ) { newMessagingClient = new JmxWrapperForMessagingClient( rawClient ); newMessagingClient.setMessageQueue( this.messageProcessor.getMessageQueue()); openConnection( newMessagingClient ); this.messagingClient = newMessagingClient; else resetInternalClient(); terminateClient( oldClient, "The previous client could not be terminated correctly.", this.logger );
/** * Associates a message processor with this instance. * <p> * The message processor cannot be started before. This method will start it. * </p> * <p> * This method must be invoked only once. * </p> * @param messageProcessor the message processor */ public void associateMessageProcessor( AbstractMessageProcessor<T> messageProcessor ) { if( this.messageProcessor != null ) throw new IllegalArgumentException( "The message processor was already defined." ); this.messageProcessor = messageProcessor; configureMessageProcessor( messageProcessor ); this.messageProcessor.start(); }
@Override public final void run() { this.running.set( true ); while( this.running.get()) { try { Message message = this.messageQueue.take(); if( this.running.get()) processMessage( message ); } catch( InterruptedException e ) { break; } } Logger.getLogger( getClass().getName()).fine( "Roboconf's message processing thread is stopping." ); this.running.set( false ); }
@Override protected void configureMessageProcessor( AbstractMessageProcessor<IAgentClient> messageProcessor ) { messageProcessor.setMessagingClient( this ); }
@Override protected void configureMessageProcessor( AbstractMessageProcessor<IDmClient> messageProcessor ) { messageProcessor.setMessagingClient( this ); }
@Override protected void configureMessageProcessor( AbstractMessageProcessor<IDmClient> messageProcessor ) { messageProcessor.setMessagingClient( this ); }