Package org.mule.util.concurrent

Examples of org.mule.util.concurrent.Latch


    {
        TestApplicationEventBean bean = (TestApplicationEventBean) muleContext.getRegistry().lookupObject(
            "testEventSpringBean");
        assertNotNull(bean);

        final Latch whenFinished = new Latch();
        EventCallback callback = new EventCallback()
        {
            @Override
            public void eventReceived(MuleEventContext context, Object o) throws Exception
            {
                assertNull(context);
                if (o instanceof TestApplicationEvent)
                {
                    if (eventCounter1.incrementAndGet() == 1)
                    {
                        whenFinished.countDown();
                    }
                }
            }
        };

        bean.setEventCallback(callback);

        ApplicationContext context = ((MuleEventMulticaster) muleContext.getRegistry().lookupObject(
            "applicationEventMulticaster")).applicationContext;
        context.publishEvent(new TestApplicationEvent(context));

        whenFinished.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
        assertEquals(1, eventCounter1.get());
    }
View Full Code Here


    public void testReceivingAllEvents() throws Exception
    {
        TestAllEventBean bean = (TestAllEventBean) muleContext.getRegistry().lookupObject("testAllEventBean");
        assertNotNull(bean);

        Latch whenFinished = new Latch();
        bean.setEventCallback(new CountingEventCallback(eventCounter1, 2, whenFinished));

        MuleClient client = muleContext.getClient();
        client.send("vm://event.multicaster", "Test Spring MuleEvent", null);
        ApplicationContext context = ((MuleEventMulticaster) muleContext.getRegistry().lookupObject(
            "applicationEventMulticaster")).applicationContext;
        context.publishEvent(new TestApplicationEvent(context));

        whenFinished.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
        assertEquals(2, eventCounter1.get());
    }
View Full Code Here

    {
        TestSubscriptionEventBean subscriptionBean = (TestSubscriptionEventBean) muleContext.getRegistry()
            .lookupObject("testSubscribingEventBean1");
        assertNotNull(subscriptionBean);

        Latch whenFinished = new Latch();
        subscriptionBean.setEventCallback(new CountingEventCallback(eventCounter1, 1, whenFinished));

        MuleClient client = muleContext.getClient();
        client.send("vm://event.multicaster", "Test Spring MuleEvent", null);

        whenFinished.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
        assertEquals(1, eventCounter1.get());
    }
View Full Code Here

    @Test
    public void testRollback() throws Exception
    {
        totalSeen = new AtomicInteger(0);
        totalAccepted = new AtomicInteger(0);
        latch = new Latch();
        MuleClient client = muleContext.getClient();
        Map<String, Object> props = new HashMap<String, Object>();
        for (int i = 0; i < 100; i++)
        {
            client.dispatch("vm://async", "Hello " + i, props);
View Full Code Here

    {
        TestSubscriptionEventBean bean1 = (TestSubscriptionEventBean) muleContext.getRegistry().lookupObject(
            "testSubscribingEventBean1");
        assertNotNull(bean1);

        final Latch whenFinished1 = new Latch();
        EventCallback callback = new EventCallback()
        {
            @Override
            public void eventReceived(MuleEventContext context, Object o) throws Exception
            {
                MuleApplicationEvent returnEvent = new MuleApplicationEvent("MuleEvent from a spring bean",
                    "vm://testBean2");
                MuleApplicationEvent e = (MuleApplicationEvent) o;
                e.getApplicationContext().publishEvent(returnEvent);
                if (eventCounter1.incrementAndGet() == NUMBER_OF_MESSAGES)
                {
                    whenFinished1.countDown();
                }
            }
        };
        bean1.setEventCallback(callback);

        TestSubscriptionEventBean bean2 = (TestSubscriptionEventBean) muleContext.getRegistry().lookupObject(
            "testSubscribingEventBean2");
        assertNotNull(bean2);

        Latch whenFinished2 = new Latch();
        bean2.setEventCallback(new CountingEventCallback(eventCounter2, NUMBER_OF_MESSAGES, whenFinished2));

        // send asynchronously
        this.doSend("vm://event.multicaster", "Test Spring MuleEvent", NUMBER_OF_MESSAGES);

        whenFinished1.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
        whenFinished2.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
        assertEquals(NUMBER_OF_MESSAGES, eventCounter1.get());
        assertEquals(NUMBER_OF_MESSAGES, eventCounter2.get());
    }
View Full Code Here

        TestSubscriptionEventBean bean2 = (TestSubscriptionEventBean) muleContext.getRegistry().lookupObject(
            "testSubscribingEventBean2");
        assertNotNull(bean2);

        Latch whenFinished = new Latch();
        bean2.setEventCallback(new CountingEventCallback(eventCounter1, NUMBER_OF_MESSAGES, whenFinished));

        // publish asynchronously
        this.doPublish(event, NUMBER_OF_MESSAGES);

        whenFinished.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
        assertEquals(NUMBER_OF_MESSAGES, eventCounter1.get());
    }
View Full Code Here

        TestSubscriptionEventBean bean2 = (TestSubscriptionEventBean) muleContext.getRegistry().lookupObject(
            "testSubscribingEventBean2");
        assertNotNull(bean2);

        Latch whenFinished = new Latch();
        bean2.setEventCallback(new CountingEventCallback(eventCounter1, 1, whenFinished));

        // publish asynchronously
        this.doPublish(event, 1);

        whenFinished.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
        assertTrue(transformerLatch.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS));
        assertEquals(1, eventCounter1.get());
    }
View Full Code Here

    }

    @Test
    public void testProxyServerSoap11() throws Exception
    {
         final Latch latch = new Latch();
         TestCxfEventCallback testCxfEventCallback = new TestCxfEventCallback(latch);
         FunctionalTestComponent testComponent = (FunctionalTestComponent) getComponent("soap11Flow");
         testComponent.setEventCallback(testCxfEventCallback);

         String msgEchoOperation1 = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:new=\"http://new.webservice.namespace\">"
                 + "<soapenv:Header/>"
                 + "  <soapenv:Body>"
                 + "    <new:parameter1>hello world</new:parameter1>"
                 + "  </soapenv:Body>"
                 + "</soapenv:Envelope>";

         String msgEchoOperation2 = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:new=\"http://new.webservice.namespace\">"
                 + "<soapenv:Header/>"
                 + "  <soapenv:Body>"
                 + "    <new:parameter2>hello world</new:parameter2>"
                 + "  </soapenv:Body>"
                 + "</soapenv:Envelope>";

         String soapOperation = "EchoOperation1";
         MuleMessage response = executeSoap11Call(msgEchoOperation1, soapOperation);
         assertTrue(latch.await(1000L, TimeUnit.MILLISECONDS));
         String cxfOperationName = testCxfEventCallback.getCxfOperationName();
         assertEquals(soapOperation, cxfOperationName);
         assertTrue(response.getPayloadAsString().contains("<new:parameter1"));
         assertTrue(response.getPayloadAsString().contains("hello world"));

         soapOperation = "EchoOperation2";
         response = executeSoap11Call(msgEchoOperation2, soapOperation);
         assertTrue(latch.await(1000L, TimeUnit.MILLISECONDS));
         cxfOperationName = testCxfEventCallback.getCxfOperationName();
         assertEquals(soapOperation, cxfOperationName);
         assertTrue(response.getPayloadAsString().contains("<new:parameter2"));
         assertTrue(response.getPayloadAsString().contains("hello world"));
    }
View Full Code Here

    }

    @Test
    public void testProxyServerSoap12() throws Exception
    {
         final Latch latch = new Latch();
         TestCxfEventCallback testCxfEventCallback = new TestCxfEventCallback(latch);
         FunctionalTestComponent testComponent = (FunctionalTestComponent) getComponent("soap12Flow");
         testComponent.setEventCallback(testCxfEventCallback);

         String msgEchoOperation1 = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:new=\"http://new.webservice.namespace\">"
                 + "<soap:Header/>"
                 + "  <soap:Body>"
                 + "    <new:parameter1>hello world</new:parameter1>"
                 + "  </soap:Body>"
                 + "</soap:Envelope>";

         String msgEchoOperation2 = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:new=\"http://new.webservice.namespace\">"
                 + "<soap:Header/>"
                 + "  <soap:Body>"
                 + "    <new:parameter2>hello world</new:parameter2>"
                 + "  </soap:Body>"
                 + "</soap:Envelope>";

         String soapOperation = "EchoOperation1";
         MuleMessage response = executeSoap12Call(msgEchoOperation1, soapOperation);
         assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
         String cxfOperationName = testCxfEventCallback.getCxfOperationName();
         assertEquals(soapOperation, cxfOperationName);
         assertTrue(response.getPayloadAsString().contains("<new:parameter1"));
         assertTrue(response.getPayloadAsString().contains("hello world"));

         soapOperation = "EchoOperation2";
         response = executeSoap12Call(msgEchoOperation2, soapOperation);
         assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
         cxfOperationName = testCxfEventCallback.getCxfOperationName();
         assertEquals(soapOperation, cxfOperationName);
         assertTrue(response.getPayloadAsString().contains("<new:parameter2"));
         assertTrue(response.getPayloadAsString().contains("hello world"));
    }
View Full Code Here

                                new RoutingNotification(event.getMessage(), event.getMessageSourceURI().toString(),
                                    RoutingNotification.MISSED_ASYNC_REPLY));
                        }
                        else
                        {
                            Latch l = locks.get(correlationId);
                            if (l != null)
                            {
                                MuleEvent event = retrieveEvent(correlationId);

                                MuleEvent previousResult = responseEvents.putIfAbsent(correlationId, event);
                                if (previousResult != null)
                                {
                                    // this would indicate that we need a better way to prevent
                                    // continued aggregation for a group that is currently being
                                    // processed. Can this actually happen?
                                    throw new IllegalStateException("Detected duplicate result message with id: " + correlationId);
                                }
                                addProcessed(correlationId);
                                deleteEvent = true;
                                l.countDown();
                            }
                        }
                        if (deleteEvent)
                        {
                            store.remove(correlationId);
View Full Code Here

TOP

Related Classes of org.mule.util.concurrent.Latch

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.