Exemple #1
0
 public void send(MessageExchange exchange) throws MessagingException {
   if (this.closed) {
     throw new MessagingException("Channel is closed");
   }
   if (!(exchange instanceof MessageExchangeProxy)) {
     throw new MessagingException("exchange should be created with MessageExchangeFactory");
   }
   MessageExchangeProxy me = (MessageExchangeProxy) exchange;
   String target;
   if (me.getRole() == MessageExchange.Role.CONSUMER) {
     if (me.getConsumer() == null) {
       me.setConsumer(this.componentName);
       ServiceEndpoint se = this.container.getRouter().getTargetEndpoint(exchange);
       me.setEndpoint(se);
       target = ((AbstractServiceEndpoint) se).getComponent();
       me.setProvider(target);
     } else {
       target = me.getProvider();
     }
   } else {
     target = me.getConsumer();
   }
   me.handleSend(false);
   container.getRouter().send(me);
 }
Exemple #2
0
 public void setUp() throws Exception {
   // Remove jbi workspace
   // IOUtils.deleteFile(new File("target/.mule-jbi"));
   // Create jbi container
   JbiContainerImpl jbi = new JbiContainerImpl();
   jbi.setWorkingDir(new File("target/.mule-jbi"));
   container = jbi;
   // Initialize jbi
   container.initialize();
   // Create components
   provider = new TestComponent("provider");
   consumer = new TestComponent("consumer");
   // Register components
   container
       .getRegistry()
       .addTransientComponent("provider", ComponentType.JBI_ENGINE_COMPONENT, provider, null);
   container
       .getRegistry()
       .addTransientComponent("consumer", ComponentType.JBI_ENGINE_COMPONENT, consumer, null);
   // Start jbi
   container.start();
   // Activate endpoint
   endpoint = provider.getContext().activateEndpoint(SERVICE_NAME, ENDPOINT_NAME);
 }
Exemple #3
0
 public MessageExchange accept(long timeout) throws MessagingException {
   if (this.closed) {
     throw new MessagingException("Channel is closed");
   }
   try {
     QueueSession qs = container.getQueueSession();
     Queue queue = qs.getQueue(componentName);
     MessageExchange me = (MessageExchange) queue.poll(timeout);
     if (me != null) {
       handleReceive(me);
     }
     return me;
   } catch (InterruptedException e) {
     throw new MessagingException(e);
   }
 }
Exemple #4
0
 public void enqueue(MessageExchange exchange) throws MessagingException {
   if (!(exchange instanceof MessageExchangeProxy)) {
     throw new MessagingException("exchange should be created with MessageExchangeFactory");
   }
   MessageExchangeProxy me = (MessageExchangeProxy) exchange;
   if (me.getSyncState() == MessageExchangeProxy.SYNC_STATE_SYNC_SENT) {
     synchronized (me) {
       me.setSyncState(MessageExchangeProxy.SYNC_STATE_SYNC_RECEIVED);
       me.notify();
     }
   } else {
     try {
       QueueSession qs = container.getQueueSession();
       Queue queue = qs.getQueue(componentName);
       queue.put(me);
     } catch (InterruptedException e) {
       logger.error(e);
     }
   }
 }
Exemple #5
0
 public DeploymentService(JbiContainer container) {
   this.container = container;
   this.registry = container.getRegistry();
 }
Exemple #6
0
 public void tearDown() throws Exception {
   if (container != null) {
     container.shutDown();
   }
   container = null;
 }