Package org.servicemix.examples

Examples of org.servicemix.examples.SenderComponent


    }
   
    protected void runSimpleTest(final boolean syncSend, final boolean syncReceive) throws Exception {
        //final int numMessages = 1;
        final int numMessages = NUM_MESSAGES;
        final SenderComponent sender = new SenderComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));
        final Receiver receiver;
        final Map delivered = new ConcurrentHashMap();
        if (syncReceive) {
          receiver = new ReceiverComponent() {
              public void onMessageExchange(MessageExchange exchange) throws MessagingException {
                try {
                  if (delivered.get(exchange.getExchangeId()) == null) {
                      System.err.println("Message delivery rolled back: " + exchange.getExchangeId());
                    delivered.put(exchange.getExchangeId(), Boolean.TRUE);
                    tm.setRollbackOnly();
                    done(exchange);
                  } else {
                      System.err.println("Message delivery accepted: " + exchange.getExchangeId());
                    super.onMessageExchange(exchange);
                  }
              } catch (Exception e) {
                throw new MessagingException(e);
              }
              }
          };
        } else {
          receiver = new AsyncReceiverPojo() {
              public void onMessageExchange(MessageExchange exchange) throws MessagingException {
                try {
                  if (delivered.get(exchange.getExchangeId()) == null) {
                      System.err.println("Message delivery rolled back: " + exchange.getExchangeId());
                      delivered.put(exchange.getExchangeId(), Boolean.TRUE);
                    tm.setRollbackOnly();
                        exchange.setStatus(ExchangeStatus.DONE);
                        getContext().getDeliveryChannel().send(exchange);
                  } else {
                      System.err.println("Message delivery accepted: " + exchange.getExchangeId());
                    super.onMessageExchange(exchange);
                  }
              } catch (Exception e) {
                throw new MessagingException(e);
              }
              }
          };
        }

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        senderContainer.activateComponent(new ActivationSpec("receiver", receiver));
       
        tt.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
                try {
                    sender.sendMessages(numMessages, syncSend);
                } catch (JBIException e) {
                    throw new RuntimeJBIException(e);
                }
          return null;
        }
View Full Code Here


   
    protected void setUp() throws Exception {
        container = new JBIContainer();
        container.init();
        container.start();
        SenderComponent component = new SenderComponent();
        container.activateComponent(new ActivationSpec("sender", component));
        channel = component.getDeliveryChannel();
    }
View Full Code Here

        assertTrue(receiverFlow instanceof JMSFlow);

        Thread.sleep(2000);
       
        receiver = new ReceiverComponent();
        sender = new SenderComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        receiverContainer.activateComponent(new ActivationSpec("receiver", receiver));
View Full Code Here

      Thread.sleep(3000);
      receiver.getMessageList().assertMessagesReceived(NUM_MESSAGES);
    }

    public void testClusteredInOnly() throws Exception {
        final SenderComponent sender = new SenderComponent();
        final ReceiverComponent receiver1 =  new ReceiverComponent();
        final ReceiverComponent receiver2 =  new ReceiverComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        senderContainer.activateComponent(new ActivationSpec("receiver", receiver1));
        receiverContainer.activateComponent(new ActivationSpec("receiver", receiver2));
        Thread.sleep(1000);

        sender.sendMessages(NUM_MESSAGES);
        Thread.sleep(3000);
        assertTrue(receiver1.getMessageList().hasReceivedMessage());
        assertTrue(receiver2.getMessageList().hasReceivedMessage());
        receiver1.getMessageList().flushMessages();
        receiver2.getMessageList().flushMessages();
       
        senderContainer.deactivateComponent("receiver");
        Thread.sleep(1000);
       
        sender.sendMessages(NUM_MESSAGES);
        Thread.sleep(3000);
        assertFalse(receiver1.getMessageList().hasReceivedMessage());
        assertTrue(receiver2.getMessageList().hasReceivedMessage());
        receiver1.getMessageList().flushMessages();
        receiver2.getMessageList().flushMessages();
       
        senderContainer.activateComponent(new ActivationSpec("receiver", receiver1));
        receiverContainer.deactivateComponent("receiver");
        Thread.sleep(1000);
       
        sender.sendMessages(NUM_MESSAGES);
        Thread.sleep(3000);
        assertTrue(receiver1.getMessageList().hasReceivedMessage());
        assertFalse(receiver2.getMessageList().hasReceivedMessage());
        receiver1.getMessageList().flushMessages();
        receiver2.getMessageList().flushMessages();
View Full Code Here

            // a 5 seconds pause when Management stuff is initialized
      //container.setCreateMBeanServer(true);
      container.init();
      container.start();
     
      Sender sender = new SenderComponent();
            ActivationSpec senderActivationSpec = new ActivationSpec("sender", sender);
            senderActivationSpec.setFailIfNoDestinationEndpoint(false);
            container.activateComponent(senderActivationSpec);
     
      ReceiverListener receiver1 = new ReceiverListener();
      container.activateComponent(createReceiverAS("receiver1", receiver1));
 
      ReceiverListener receiver2 = new ReceiverListener();
      container.activateComponent(createReceiverAS("receiver2", receiver2));
     
      sender.sendMessages(1);
     
      Thread.sleep(100);
     
            assertFalse(receiver1.isPropertySetOnExchange());
            assertFalse(receiver2.isPropertySetOnExchange());
View Full Code Here

        assertEquals("containerName", reg.getContainerName());
    }
   
    public void testRegister() throws Exception {
        ComponentRegistry reg = new ComponentRegistry();
        Component component = new SenderComponent();
        LocalComponentConnector con = reg.registerComponent(
                              new ComponentNameSpace("container", "name", "id"),
                              "description",
                              component,
                              null,
View Full Code Here

    }
   
    protected abstract Flow createFlow();
   
    protected void runSimpleTest(final boolean syncSend, final boolean syncReceive) throws Exception {
        final SenderComponent sender = new SenderComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));
        final Receiver receiver;
        if (syncReceive) {
          receiver = new ReceiverComponent();
        } else {
          receiver = new AsyncReceiverPojo();
        }

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        senderContainer.activateComponent(new ActivationSpec("receiver", receiver));
       
        tt.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
                try {
                    sender.sendMessages(NUM_MESSAGES, syncSend);
                } catch (JBIException e) {
                    throw new RuntimeJBIException(e);
                }
          return null;
        }
View Full Code Here

        receiverContainer.shutDown();
      super.tearDown();
    }
   
    protected void runClusteredTest(final boolean syncSend, final boolean syncReceive) throws Exception {
        final SenderComponent sender = new SenderComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));
        final Receiver receiver;
        if (syncReceive) {
          receiver = new ReceiverComponent();
        } else {
          receiver = new AsyncReceiverPojo();
        }

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        receiverContainer.activateComponent(new ActivationSpec("receiver", receiver));
        Thread.sleep(1000);
       
        tt.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
                try {
                    sender.sendMessages(NUM_MESSAGES, syncSend);
                } catch (JBIException e) {
                    throw new RuntimeJBIException(e);
                }
          return null;
        }
View Full Code Here

        receiverContainer.init();
        receiverContainer.start();
        ClusterFlow receiverFlow = (ClusterFlow)receiverContainer.getFlow();

        receiver = new ReceiverComponent();
        sender = new SenderComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        receiverContainer.activateComponent(new ActivationSpec("receiver", receiver));
View Full Code Here

        receiverContainer.shutDown();
        broker.stop();
    }
   
    public void testInOnly() throws Exception {
        final SenderComponent sender = new SenderComponent();
        final ReceiverComponent receiver =  new ReceiverComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        receiverContainer.activateComponent(new ActivationSpec("receiver", receiver));

        Thread.sleep(5000);

        sender.sendMessages(NUM_MESSAGES);
        Thread.sleep(3000);
        receiver.getMessageList().assertMessagesReceived(NUM_MESSAGES);
    }
View Full Code Here

TOP

Related Classes of org.servicemix.examples.SenderComponent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.