Beispiel #1
0
 private void handleReceive(MessageExchange exchange) throws MessagingException {
   if (!(exchange instanceof MessageExchangeProxy)) {
     throw new MessagingException("exchange should be created with MessageExchangeFactory");
   }
   MessageExchangeProxy me = (MessageExchangeProxy) exchange;
   me.handleAccept();
 }
Beispiel #2
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);
 }
Beispiel #3
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);
     }
   }
 }
Beispiel #4
0
 public boolean sendSync(MessageExchange exchange, long timeout) 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(true);
   DeliveryChannelImpl ch =
       (DeliveryChannelImpl) this.container.getRegistry().getComponent(target).getChannel();
   ch.enqueue(me.getTwin());
   try {
     synchronized (exchange) {
       exchange.wait(timeout);
       if (me.getSyncState() == MessageExchangeProxy.SYNC_STATE_SYNC_RECEIVED) {
         me.handleAccept();
         return true;
       } else {
         return false;
       }
     }
   } catch (InterruptedException e) {
     throw new MessagingException(e);
   }
 }