Package org.apache.servicemix.nmr.api.internal

Examples of org.apache.servicemix.nmr.api.internal.InternalExchange


    public void send(MessageExchange exchange) throws MessagingException {
        assert exchange != null;
        createTarget(context.getNmr(), exchange);
        exchange.setProperty(SEND_SYNC, null);
        ((MessageExchangeImpl) exchange).afterSend();
        InternalExchange ie = (InternalExchange) ((MessageExchangeImpl) exchange).getInternalExchange();
        getChannelToUse(ie).send(ie);
    }
View Full Code Here


    public boolean sendSync(MessageExchange exchange) throws MessagingException {
        assert exchange != null;
        createTarget(context.getNmr(), exchange);
        exchange.setProperty(SEND_SYNC, Boolean.TRUE);
        ((MessageExchangeImpl) exchange).afterSend();
        InternalExchange ie = (InternalExchange) ((MessageExchangeImpl) exchange).getInternalExchange();
        return getChannelToUse(ie).sendSync(ie);
    }
View Full Code Here

    public boolean sendSync(MessageExchange exchange, long timeout) throws MessagingException {
        assert exchange != null;
        createTarget(context.getNmr(), exchange);
        exchange.setProperty(SEND_SYNC, Boolean.TRUE);
        ((MessageExchangeImpl) exchange).afterSend();
        InternalExchange ie = (InternalExchange) ((MessageExchangeImpl) exchange).getInternalExchange();
        return getChannelToUse(ie).sendSync(ie, timeout);
    }
View Full Code Here

        InternalEndpoint endpoint = new InternalEndpointWrapper(new EndpointImpl(ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, "endpoint")),
                                                                ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, "internal-endpoint"));
        listener.endpointRegistered(endpoint);
        listener.setAssembly(null);
       
        InternalExchange exchange = new ExchangeImpl(Pattern.InOnly);
        exchange.setSource(endpoint);
        exchange.setProperty(DeliveryChannelImpl.SEND_SYNC, Boolean.TRUE);
        listener.exchangeSent(exchange);
       
        assertEquals(1, listener.getPending(sa).size());
       
        exchange.setStatus(Status.Done);
        listener.exchangeDelivered(exchange);
       
        assertEquals(0, listener.getPending(sa).size());
    }
View Full Code Here

        InternalEndpoint endpoint = new InternalEndpointWrapper(new EndpointImpl(ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, "endpoint")),
                                                                ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, "internal-endpoint"));
        listener.endpointRegistered(endpoint);
        listener.setAssembly(null);
       
        InternalExchange exchange = new ExchangeImpl(Pattern.InOnly);
        exchange.setSource(endpoint);
        exchange.setProperty(DeliveryChannelImpl.SEND_SYNC, Boolean.TRUE);
        listener.exchangeSent(exchange);
       
        assertEquals(1, listener.getPending(sa).size());
       
        exchange.setStatus(Status.Error);
        listener.exchangeFailed(exchange);
       
        assertEquals(0, listener.getPending(sa).size());
    }
View Full Code Here

        InternalEndpoint endpoint = new InternalEndpointWrapper(new EndpointImpl(ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, "endpoint")),
                                                                ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, "internal-endpoint"));
        listener.endpointRegistered(endpoint);
        listener.setAssembly(null);
       
        InternalExchange exchange = new ExchangeImpl(Pattern.InOnly);
        exchange.setSource(endpoint);
        exchange.setProperty(DeliveryChannelImpl.SEND_SYNC, Boolean.TRUE);
        exchange.getConsumerLock(true);
        listener.exchangeSent(exchange);
       
        assertEquals(1, listener.getPending(sa).size());
       
        listener.cancelPendingSyncExchanges(sa);
        assertEquals(Status.Error, exchange.getStatus());
    }
View Full Code Here

    assertNotNull(e.getOut());
    assertNotNull(e.getFault());
  }

  public void testCancel() throws InterruptedException {
      final InternalExchange e = new ExchangeImpl(Pattern.InOnly);
      final CountDownLatch latch = new CountDownLatch(1);
      Thread thread = new Thread() {
          @Override
          public void run() {
              try {
                  e.getConsumerLock(true).acquire();
                  latch.countDown();
              } catch (InterruptedException e) {
                  fail(e.getMessage());
              }
          }
      };
      thread.start();
      //let's sleep for a moment to make sure the thread has acquired the lock
      Thread.sleep(150);
      e.cancel();
      assertTrue("Exchange should have been cancelled", latch.await(1, TimeUnit.SECONDS));
      assertEquals(Status.Error, e.getStatus());
  }
View Full Code Here

     * An asynchronous invocation of the service
     *
     * @param exchange the exchange to send
     */
    public void send(Exchange exchange) {
        InternalExchange e = (InternalExchange) exchange;
        dispatch(e);
    }
View Full Code Here

     * @param exchange the exchange to send
     * @param timeout  time to wait in milliseconds
     * @return <code>true</code> if the exchange has been processed succesfully
     */
    public boolean sendSync(Exchange exchange, long timeout) {
        InternalExchange e = (InternalExchange) exchange;
        Semaphore lock = e.getRole() == Role.Consumer ? e.getConsumerLock(true)
                : e.getProviderLock(true);
        dispatch(e);
        Thread thread = Thread.currentThread();
        String original = thread.getName();
        try {
            if (timeout > 0) {
                if (!lock.tryAcquire(timeout, TimeUnit.MILLISECONDS)) {
                    throw new TimeoutException();
                }
            } else {
                thread.setName(original + " (waiting for exchange " + exchange.getId() + ")");
                lock.acquire();
            }
            e.setRole(e.getRole() == Role.Consumer ? Role.Provider : Role.Consumer);
        } catch (InterruptedException ex) {
            exchange.setError(ex);
            for (ExchangeListener l : nmr.getListenerRegistry().getListeners(ExchangeListener.class)) {
                l.exchangeFailed(exchange);
            }
View Full Code Here

        // Check if this is a new exchange
        if (exchange.getStatus() == Status.Active && exchange.getRole() == Role.Consumer &&
                exchange.getOut(false) == null && exchange.getFault(false) == null) {
            if (exchange instanceof InternalExchange) {
                // Increment reference to the source SA
                InternalExchange ie = (InternalExchange) exchange;
                reference(ie.getSource());
                if (isSync(exchange)) {
                    pending(ie);
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.servicemix.nmr.api.internal.InternalExchange

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.