Package org.mule.util.concurrent

Examples of org.mule.util.concurrent.Latch


            assertEquals("Queue size", 1, q.size());
            o = q.poll(0);
            assertEquals("Queue size", 0, q.size());
            assertEquals("Queue content", "String1", o);

            final Latch putExecutionLatch = new Latch();
            Thread putExecutionThread = new Thread(new Runnable()
            {
                public void run()
                {
                    try
                    {
                        QueueSession s = mgr.getQueueSession();
                        Queue q = s.getQueue("queue1");
                        putExecutionLatch.release();
                        q.put("String1");
                    }
                    catch (Exception e)
                    {
                        //unlikely to happen. But if it does lets show it in the test logs.
                        logger.warn(e);
                    }
                }
            });
            putExecutionThread.start();
            if (!putExecutionLatch.await(THREAD_EXECUTION_TIMEOUT, TimeUnit.MILLISECONDS))
            {
                fail("Thread executing put over queue was not executed");
            }
            o = q.poll(RECEIVE_TIMEOUT);
            putExecutionThread.join(THREAD_EXECUTION_TIMEOUT);
View Full Code Here


            assertTrue(q.offer("String1", 0L));
            assertEquals("Queue size", 1, q.size());
            assertFalse(q.offer("String2", 1000));
            assertEquals("Queue size", 1, q.size());

            final Latch takeExecutionLatch = new Latch();
            final Thread takeExecutionThread = new Thread(new Runnable()
            {
                public void run()
                {
                    try
                    {
                        takeExecutionLatch.release();
                        QueueSession s = mgr.getQueueSession();
                        Queue q = s.getQueue("queue1");
                        assertEquals("Queue content", "String1", q.take());
                    }
                    catch (Exception e)
                    {
                        //unlikely to happen. But if it does lets show it in the test logs.
                        logger.warn(e);
                    }
                }
            });
            takeExecutionThread.start();
            if (!takeExecutionLatch.await(THREAD_EXECUTION_TIMEOUT, TimeUnit.MILLISECONDS))
            {
                fail("Thread executing put over queue was not executed");
            }
            assertTrue(q.offer("String2", 1000));
            takeExecutionThread.join(THREAD_EXECUTION_TIMEOUT);
View Full Code Here

     * Creates the lock used to synchronize a given event
     * @return a new Latch instance
     */
    protected Latch createEventLock()
    {
        return new Latch();
    }
View Full Code Here

    }

    protected MuleEvent receiveAsyncReply(MuleEvent event) throws MessagingException
    {
        String asyncReplyCorrelationId = getAsyncReplyCorrelationId(event);
        Latch asyncReplyLatch = locks.get(asyncReplyCorrelationId);
        // flag for catching the interrupted status of the Thread waiting for a
        // result
        boolean interruptedWhileWaiting = false;
        boolean resultAvailable = false;
        MuleEvent result = null;

        try
        {
            if (logger.isDebugEnabled())
            {
                logger.debug("Waiting for async reply message with id: " + asyncReplyCorrelationId);
            }
            // how long should we wait for the lock?
            if (timeout <= 0)
            {
                asyncReplyLatch.await();
                resultAvailable = true;
            }
            else
            {
                resultAvailable = asyncReplyLatch.await(timeout, TimeUnit.MILLISECONDS);
            }
            if (!resultAvailable)
            {
                postLatchAwait(asyncReplyCorrelationId);
                asyncReplyLatch.await(1000, TimeUnit.MILLISECONDS);
                resultAvailable = asyncReplyLatch.getCount() == 0;
            }
        }
        catch (InterruptedException e)
        {
            interruptedWhileWaiting = true;
View Full Code Here

public class StartWorkExecutor implements WorkExecutor
{

    public void doExecute(WorkerContext work, Executor executor) throws WorkException, InterruptedException
    {
        Latch latch = work.provideStartLatch();
        executor.execute(work);
        latch.await();
    }
View Full Code Here

{

    @Test
    public void workManagerRecreatedCorrectlyAfterRestart() throws Exception
    {
        final Latch workExecutedLatch = new Latch();
        AbstractMessageReceiver receiver = createMessageReceiver();
        Connector receiverConnector = receiver.getConnector();
        receiverConnector.stop();
        receiverConnector.start();
        receiver.getWorkManager().scheduleWork(new Work()
        {
            @Override
            public void release()
            {
            }

            @Override
            public void run()
            {
                workExecutedLatch.release();
            }
        });
        if (!workExecutedLatch.await(1000, TimeUnit.MILLISECONDS))
        {
            fail("Work should be executed and it was not");
        }
    }
View Full Code Here

    }

    @Test
    public void testServerClientProxyWithWsdl() throws Exception
    {
        final Latch latch = new Latch();
        ((FunctionalTestComponent)getComponent("serverClientProxyWithWsdl")).setEventCallback(new EventCallback()
        {
            @Override
            public void eventReceived(MuleEventContext context, Object component) throws Exception
            {
                latch.countDown();
            }
        });

        String msg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                     + "<soap:Body> <test xmlns=\"http://foo\"></test>" + "</soap:Body>" + "</soap:Envelope>";

        MuleClient client = muleContext.getClient();
        MuleMessage result = client.send("http://localhost:" + dynamicPort.getNumber()
                                         + "/services/proxyWithWsdl", msg, null);
        String resString = result.getPayloadAsString();
        assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
        assertTrue(resString.indexOf("<test xmlns=\"http://foo\"") != -1);
    }
View Full Code Here

    }

    @Test
    public void testServerClientProxyWithWsdl2() throws Exception
    {
        final Latch latch = new Latch();
        ((FunctionalTestComponent)getComponent("serverClientProxyWithWsdl2")).setEventCallback(new EventCallback()
        {

            @Override
            public void eventReceived(MuleEventContext context, Object component) throws Exception
            {
                latch.countDown();
            }
        });

        String msg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                     + "<soap:Body> <test xmlns=\"http://foo\"></test>" + "</soap:Body>" + "</soap:Envelope>";

        MuleClient client = muleContext.getClient();
        MuleMessage result = client.send("http://localhost:" + dynamicPort.getNumber()
                                         + "/services/proxyWithWsdl2", msg, null);
        String resString = result.getPayloadAsString();
        assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
        assertTrue(resString.indexOf("<test xmlns=\"http://foo\"") != -1);
    }
View Full Code Here

    }

    @Test
    public void testPollingHttpConnectorSentCredentials() throws Exception
    {
        final Latch latch = new Latch();
        muleContext.registerListener(new SecurityNotificationListener<SecurityNotification>()
        {
            @Override
            public void onNotification(SecurityNotification notification)
            {
                latch.countDown();
            }
        });

        MuleClient client = muleContext.getClient();
        MuleMessage result = client.request("vm://toclient", 5000);
        assertNotNull(result);
        assertEquals("foo", result.getPayloadAsString());

        result = client.request("vm://toclient2", 1000);
        //This seems a little odd that we forward the exception to the outbound endpoint, but I guess users
        // can just add a filter
        assertNotNull(result);
        int status = result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0);
        assertEquals(401, status);
        assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
    }
View Full Code Here

        assertNotNull(subscriptionBean);
        MuleEventMulticaster multicaster = (MuleEventMulticaster) muleContext.getRegistry().lookupObject(
            AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME);
        assertNotNull(multicaster);

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

        multicaster.removeApplicationListener(subscriptionBean);

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

        assertEquals(0, eventCounter1.get());

        multicaster.addApplicationListener(subscriptionBean);
        client.send("vm://event.multicaster", "Test Spring MuleEvent", null);

        assertTrue(whenFinished.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS));
        assertEquals(1, eventCounter1.get());
        eventCounter1.set(0);

        multicaster.removeAllListeners();
        client.send("vm://event.multicaster", "Test Spring MuleEvent", null);
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.