Package org.apache.servicemix.nmr.api

Examples of org.apache.servicemix.nmr.api.Exchange


                    Channel client = null;
                    try {
                        client = nmr1.createChannel();
                        lock.readLock().lock();
                        for (int i = 0; i < nbExchanges; i++) {
                            Exchange exchange = client.createExchange(Pattern.InOnly);
                            exchange.getIn().setBody(new StringSource("<hello id='" + id.getAndIncrement() + "'/>"));
                            exchange.setTarget(nmr1.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, PROXY_ENDPOINT_NAME)));
                            client.sendSync(exchange);
                            assertEquals(Status.Done, exchange.getStatus());
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        lock.readLock().unlock();
View Full Code Here


            this.channel = channel;
        }

        public void process(Exchange exchange) {
            Holder<Exchange> holder = (Holder<Exchange>) exchange.getProperty("correlated");
            Exchange correlated = holder != null ? holder.get() : null;
            if (exchange.getStatus() == Status.Error) {
                correlated.setError(exchange.getError());
                correlated.setStatus(Status.Error);
            } else if (exchange.getStatus() == Status.Done) {
                correlated.setStatus(Status.Done);
            } else if (exchange.getFault(false) != null) {
                correlated.setFault(exchange.getFault());
            } else if (exchange.getOut(false) != null) {
                correlated.setOut(exchange.getOut());
            } else if (exchange.getIn(false) != null) {
                correlated = channel.createExchange(exchange.getPattern());
                exchange.setProperty("correlated", new Holder<Exchange>(correlated));
                correlated.setProperty("correlated", new Holder<Exchange>(exchange));

                //correlated.setProperty(JbiConstants.SENDER_ENDPOINT, getService() + ":" + getEndpoint());
                correlated.setProperty(MessageExchangeImpl.SERVICE_NAME_PROP, service);
                DeliveryChannelImpl.createTarget(channel.getNMR(), correlated);
                correlated.setIn(exchange.getIn());
            } else {
                throw new IllegalStateException();
            }
            channel.send(correlated);
        }
View Full Code Here

        IMocksControl control = EasyMock.createControl();
        ExchangeListener listener = control.createMock(ExchangeListener.class);
        control.makeThreadSafe(true);
        nmr.getListenerRegistry().register(listener, null);

        final Exchange e = ep1.channel.createExchange(Pattern.InOnly);

        listener.exchangeSent(same(e));
        listener.exchangeDelivered(same(e));
        replay(listener);

        e.setTarget(ep1.channel.getNMR().getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, "ep2")));
        ep1.channel.send(e);
        Thread.sleep(1000);
        verify(listener);

        reset(listener);
View Full Code Here

        IMocksControl control = EasyMock.createControl();
        ExchangeListener listener = control.createMock(ExchangeListener.class);
        control.makeThreadSafe(true);
        nmr.getListenerRegistry().register(listener, null);

        final Exchange e = ep1.channel.createExchange(Pattern.InOnly);
        final CountDownLatch latch = new CountDownLatch(1);

        listener.exchangeSent(same(e));
        listener.exchangeDelivered(same(e));
        replay(listener);

        synchronized (ep2) {
            new Thread() {
                public void run() {
                    e.setTarget(ep1.channel.getNMR().getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, "ep2")));
                    ep1.channel.sendSync(e);
                    latch.countDown();
                }
            }.start();
            ep2.wait();
View Full Code Here

        ExchangeListener listener = control.createMock(ExchangeListener.class);
        control.makeThreadSafe(true);
        nmr.getListenerRegistry().register(listener, null);

        Channel channel = nmr.createChannel();
        Exchange e = channel.createExchange(Pattern.InOnly);
        e.setTarget(nmr.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, "zz")));

        listener.exchangeSent(same(e));
        listener.exchangeFailed(same(e));

        replay(listener);
View Full Code Here

        IMocksControl control = EasyMock.createControl();
        ExchangeListener listener = control.createMock(ExchangeListener.class);
        control.makeThreadSafe(true);
        nmr.getListenerRegistry().register(listener, null);

        final Exchange e = ep1.channel.createExchange(Pattern.InOnly);

        listener.exchangeSent(same(e));
        listener.exchangeDelivered(same(e));
        listener.exchangeSent(same(e));
        listener.exchangeDelivered(same(e));
        replay(listener);

        ep2.throwException = true;
        e.setTarget(ep1.channel.getNMR().getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, "ep2")));
        ep1.channel.sendSync(e);

        verify(listener);
        assertNotNull(ep2.exchange);
        assertEquals(Status.Error, e.getStatus());
    }
View Full Code Here

        }, null);
       
       
        final CountDownLatch done = new CountDownLatch(1);
        final Channel channel = nmr.createChannel();
        final Exchange exchange = channel.createExchange(Pattern.InOnly);
        exchange.setTarget(nmr.getEndpointRegistry().lookup(props));
       
        Thread thread = new Thread(new Runnable() {
            public void run() {
                channel.sendSync(exchange);
                done.countDown();
            }
        });
        thread.start();
       
        //let's wait a sec for the exchange to be sent
        sent.await(1, TimeUnit.SECONDS);
        assertNotNull(exchange);
        assertNotNull("There should be a thread waiting for the exchange",
                      findThread(exchange.getId()));
       
        blocking.lock.release();
        //let's wait another sec for the exchange to be done
        done.await(1, TimeUnit.SECONDS);
        assertNull("There shouldn't be any thread waiting for the exchange",
                   findThread(exchange.getId()));
    }
View Full Code Here


public class ExchangeImplTest extends TestCase {

    public void testWrite() throws Exception {
        Exchange e = new ExchangeImpl(Pattern.InOnly);
        e.setOperation(new QName("op"));
        e.setProperty("key", "value");
        e.setStatus(Status.Done);
        Message msg = e.getIn();
        msg.setHeader("header", "value");
        msg.addAttachment("id", "att");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(baos);
        os.writeObject(e);
        os.close();
        ObjectInputStream is = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
        Exchange cpy = (Exchange) is.readObject();
        assertNotNull(cpy);
        assertEquals(e.getId(), cpy.getId());
        assertEquals(e.getStatus(), cpy.getStatus());
        assertEquals(e.getRole(), cpy.getRole());
        assertEquals(e.getPattern(), cpy.getPattern());
        assertEquals(e.getOperation(), cpy.getOperation());
        assertEquals(e.getProperty("key"), cpy.getProperty("key"));
        assertNotNull(cpy.getIn());
        assertNotNull(cpy.getIn().getHeader("header"));
        assertNotNull(cpy.getIn().getAttachment("id"));
    }
View Full Code Here

                }
                return super.loadClass(name, resolve);
            }
        };
        Class cls = cl.loadClass(ExchangeImpl.class.getName());
        Exchange e = (Exchange) cls.getConstructor(Pattern.class).newInstance(Pattern.InOut);
        e.setProperty("key", "<hello>world</hello>");
        assertNull(e.getProperty("key", byte[].class));
    }
View Full Code Here

        e.setProperty("key", "<hello>world</hello>");
        assertNull(e.getProperty("key", byte[].class));
    }

    public void testCopy() {
        Exchange e = new ExchangeImpl(Pattern.InOut);
        Exchange cpy = e.copy();
        assertNotNull(cpy);
        assertNull(cpy.getIn(false));
        assertNull(cpy.getOut(false));
        assertNull(cpy.getFault(false));

        e = new ExchangeImpl(Pattern.InOut);
        e.setProperty("header", "value");
        e.getIn();
        cpy = e.copy();
        assertNotNull(cpy);
        assertNotNull(cpy.getProperty("header"));
        assertNotNull(cpy.getIn(false));
    }
View Full Code Here

TOP

Related Classes of org.apache.servicemix.nmr.api.Exchange

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.