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

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


    public void exchangeDelivered(Exchange exchange) {
        // Check if the exchange is finished
        if (exchange.getStatus() != Status.Active) {
            if (exchange instanceof InternalExchange) {
                InternalExchange ie = (InternalExchange) exchange;
                // Decrement references to source and destination SA
                unreference(ie.getSource());
                unreference(ie.getDestination());
                pending.remove(exchange);
            }
            // Check if this is a new exchange
        } else if (exchange.getStatus() == Status.Active && exchange.getRole() == Role.Provider &&
                exchange.getOut(false) == null && exchange.getFault(false) == null) {
            if (exchange instanceof InternalExchange) {
                // Increment reference to the destination SA
                InternalExchange ie = (InternalExchange) exchange;
                reference(ie.getDestination());
            }
        }
    }
View Full Code Here


        }
    }

    public void exchangeFailed(Exchange exchange) {
        if (exchange instanceof InternalExchange) {
            InternalExchange ie = (InternalExchange) exchange;
            // Decrement references to source and destination SA
            unreference(ie.getSource());
            unreference(ie.getDestination());
            pending.remove(exchange);
        }
    }
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);
        try {
            dispatch(e);
            if (timeout > 0) {
                if (!lock.tryAcquire(timeout, TimeUnit.MILLISECONDS)) {
                    throw new TimeoutException();
                }
            } else {
                lock.acquire();
            }
            e.setRole(e.getRole() == Role.Consumer ? Role.Provider : Role.Consumer);
        } catch (InterruptedException ex) {
            exchange.setError(ex);
            exchange.setStatus(Status.Error);
            return false;
        } catch (TimeoutException ex) {
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

    public void testNoExceptionsOnUnknownExchange() throws Exception {
        AssemblyReferencesListener listener = new AssemblyReferencesListener();
        InternalEndpoint endpoint = new InternalEndpointWrapper(new EndpointImpl(ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, "endpoint")),
                                                                ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, "internal-endpoint"));
       
        InternalExchange exchange = new ExchangeImpl(Pattern.InOnly);
        exchange.setSource(endpoint);
        exchange.setProperty(DeliveryChannelImpl.SEND_SYNC, Boolean.TRUE);
        exchange.getConsumerLock(true);
       
        // this should not throw an exception
        listener.exchangeSent(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

    public void exchangeDelivered(Exchange exchange) {
        // Check if the exchange is finished
        if (exchange.getStatus() != Status.Active) {
            if (exchange instanceof InternalExchange) {
                InternalExchange ie = (InternalExchange) exchange;
                // Decrement references to source and destination SA
                unreference(ie.getSource());
                unreference(ie.getDestination());
                pending.remove(exchange);
            }
            // Check if this is a new exchange
        } else if (exchange.getStatus() == Status.Active && exchange.getRole() == Role.Provider &&
                exchange.getOut(false) == null && exchange.getFault(false) == null) {
            if (exchange instanceof InternalExchange) {
                // Increment reference to the destination SA
                InternalExchange ie = (InternalExchange) exchange;
                reference(ie.getDestination());
            }
        }
    }
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.