Examples of AtomicReference


Examples of java.util.concurrent.atomic.AtomicReference

        final CountDownLatch latch = new CountDownLatch(1);
        final CountDownLatch ioLatch = new CountDownLatch(1);

        final AtomicInteger status = new AtomicInteger();
        final AtomicReference response2 = new AtomicReference();

        Client client = ClientFactory.getDefault().newClient();

        RequestBuilder request = client.newRequestBuilder()
                .method(Request.METHOD.GET)
                .uri(targetUrl + "/suspend")
                .transport(transport());

        final Socket socket = client.create();
        socket.on(new Function<Integer>() {
            @Override
            public void on(Integer statusCode) {
                status.set(statusCode);
                socket.close();
                latch.countDown();
            }
        }).on(new Function<IOException>() {

            @Override
            public void on(IOException t) {
                response2.set(t);
                ioLatch.countDown();
            }

        }).open(request.build());

        latch.await(5, TimeUnit.SECONDS);

        socket.fire("Yo");

        ioLatch.await(5, TimeUnit.SECONDS);

        assertNotNull(response2.get());
        assertEquals(response2.get().getClass(), IOException.class);

    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

    }

    @Test
    public void serverDownTest() throws Exception {
        final CountDownLatch latch = new CountDownLatch(3);
        final AtomicReference response = new AtomicReference();
        final AtomicReference response2 = new AtomicReference();

        Client client = ClientFactory.getDefault().newClient();

        String unreachableUrl = "http://localhost:815";
        RequestBuilder request = client.newRequestBuilder()
                .method(Request.METHOD.GET)
                .uri(unreachableUrl + "/suspend")
                .transport(transport());

        final Socket socket = client.create();
        IOException ioException = null;
        try {

            socket.on(new Function<ConnectException>() {

                @Override
                public void on(ConnectException t) {
                    socket.close(); // I close it here, remove this close, issue will not happen
                    response.set(t);
                    latch.countDown();
                }

            }).on(new Function<IOException>() {

                @Override
                public void on(IOException t) {
                    response2.set(t);
                    latch.countDown();
                }

            }).open(request.build());
        } catch (IOException ex) {
            ioException = ex;
        }
        socket.fire("echo");
        latch.await(5, TimeUnit.SECONDS);

        assertEquals(response.get().getClass(), ConnectException.class);
        assertTrue(IOException.class.isAssignableFrom(response2.get().getClass()));
        assertTrue(IOException.class.isAssignableFrom(ioException.getClass()));

    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

        server = new Nettosphere.Builder().config(config).build();
        assertNotNull(server);
        server.start();

        final AtomicReference response = new AtomicReference();
        Client client = ClientFactory.getDefault().newClient();

        RequestBuilder request = client.newRequestBuilder()
                .method(Request.METHOD.GET)
                .uri(targetUrl + "/suspend")
                .transport(transport());

        Socket socket = client.create(client.newOptionsBuilder().reconnect(false).build());
        socket.on(Event.CLOSE, new Function<String>() {
            @Override
            public void on(String t) {
                //Can I receive close message when server is stopped?
                logger.info("Function invoked {}", t);
                response.set(t);
            }
        }).on(new Function<Throwable>() {

            @Override
            public void on(Throwable t) {
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

    // Downloads large file in the remote directory specified in config
    public void testIdentityFile() throws Exception
    {
        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference message = new AtomicReference();
        final AtomicInteger loopCount = new AtomicInteger(0);

        EventCallback callback = new EventCallback()
        {
            public synchronized void eventReceived(MuleEventContext context, Object component)
            {
                try
                {
                    logger.info("called " + loopCount.incrementAndGet() + " times");
                    // without this we may have problems with the many repeats
                    if (1 == latch.getCount())
                    {
                        String o = IOUtils.toString((SftpInputStream) context.getMessage().getPayload());
                        message.set(o);
                        latch.countDown();
                    }
                }
                catch (Exception e)
                {
                    logger.error(e.getMessage(), e);
                }
            }
        };

        MuleClient client = new MuleClient(muleContext);

        // Ensure that no other files exists
        // cleanupRemoteFtpDirectory(client, INBOUND_ENDPOINT_NAME);

        Map properties = new HashMap();
        // properties.put("filename", "foo.bar");

        Object component = getComponent("testComponent");
        assertTrue("FunctionalTestComponent expected", component instanceof FunctionalTestComponent);
        FunctionalTestComponent ftc = (FunctionalTestComponent) component;
        assertNotNull(ftc);

        ftc.setEventCallback(callback);

        logger.debug("before dispatch");
        // Send an file to the SFTP server, which the inbound-endpoint then can pick
        // up
        client.dispatch(getAddressByEndpoint(client, INBOUND_ENDPOINT_NAME), TEST_MESSAGE, properties);
        logger.debug("before retrieve");

        latch.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);

        assertEquals(TEST_MESSAGE, message.get());
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

    private synchronized void initAccessControl()
    {
        if (null == ownerThread)
        {
            ownerThread = new AtomicReference();
        }
        if (null == mutable)
        {
            mutable = new AtomicBoolean(true);
        }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

        called.set(true);
    }

    public void clear()
    {
        certificates = new AtomicReference();
        called = new AtomicBoolean(false);
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

//        assertNotNull(ftc);
//        assertEquals(1, ftc.getNumber());


        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference message = new AtomicReference();
        ((FunctionalStreamingTestComponent) ftc).setEventCallback(newCallback(latch, message), TEST_MESSAGE.length());
        client.dispatch(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("testInbound")).getAddress(),
            TEST_MESSAGE, new HashMap());
        latch.await(10, TimeUnit.SECONDS);
        assertEquals(RESULT, message.get());

        final CountDownLatch latch2 = new CountDownLatch(1);
        final AtomicReference message2 = new AtomicReference();
        ((FunctionalStreamingTestComponent) ftc).setEventCallback(newCallback(latch2, message2), TEST_MESSAGE_2.length());
        client.dispatch(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("testInbound")).getAddress(),
            TEST_MESSAGE_2, new HashMap());
        latch2.await(10, TimeUnit.SECONDS);
        assertEquals(RESULT_2, message2.get());
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

    }
  
    public void testSendAndRequest() throws Exception
    {
        CountDownLatch latch = new CountDownLatch(1);
        AtomicReference message = new AtomicReference();

        Object component = getComponent("testComponent");
        assertNotNull(component);
        assertTrue("FunctionalTestComponent expected", component instanceof FunctionalTestComponent);
        FunctionalTestComponent ftc = (FunctionalTestComponent) component;
        ftc.setEventCallback(new FunctionalEventCallback(latch, message));

        MuleClient client = new MuleClient(muleContext);
        client.dispatch(getMuleFtpEndpoint(), TEST_MESSAGE, null);
       
        // TODO DZ: need a reliable way to check the file once it's been written to
        // the ftp server. Currently, once mule processes the ftp'd file, it
        // auto-deletes it, so we can't check it
        //assertTrue(getFtpClient().expectFileCount("/", 1, 10000));
       
        latch.await(getTimeout(), TimeUnit.MILLISECONDS);
        assertEquals(TEST_MESSAGE, message.get());               
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

    }

    public void testFileAge() throws Exception
    {
        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference message = new AtomicReference();
        final AtomicInteger loopCount = new AtomicInteger(0);

        EventCallback callback = new EventCallback()
        {
            public synchronized void eventReceived(MuleEventContext context, Object component)
            {
                try
                {
                    logger.info("called " + loopCount.incrementAndGet() + " times");
                    // without this we may have problems with the many repeats
                    if (1 == latch.getCount())
                    {
                        String o = IOUtils.toString((SftpInputStream) context.getMessage().getPayload());
                        message.set(o);
                        latch.countDown();
                    }
                }
                catch (Exception e)
                {
                    logger.error(e.getMessage(), e);
                }
            }
        };

        MuleClient client = new MuleClient(muleContext);

        // Ensure that no other files exists
        // cleanupRemoteFtpDirectory(client, INBOUND_ENDPOINT_NAME);

        Object component = getComponent("testComponent");
        assertTrue("FunctionalTestComponent expected", component instanceof FunctionalTestComponent);
        FunctionalTestComponent ftc = (FunctionalTestComponent) component;
        assertNotNull(ftc);

        ftc.setEventCallback(callback);

        // Use one specific filename so that the file is overwritten if necessarily
        Map properties = new HashMap();
        // properties.put("filename", "fileage-test.tmp");

        long startTime = System.currentTimeMillis();

        logger.debug("before dispatch");
        // Send an file to the SFTP server, which the inbound-endpoint then can pick
        // up
        client.dispatch(getAddressByEndpoint(client, INBOUND_ENDPOINT_NAME), TEST_MESSAGE, properties);
        logger.debug("before retrieve");

        latch.await(TIMEOUT, TimeUnit.MILLISECONDS);

        // We assume that the total time never should be less than fileAge. That
        // means that the fileAge value
        // in this test must be rather high
        long time = System.currentTimeMillis() - startTime;

        int maxTimeDiff = 1000; // Max time diff between localhost and the server.
                                // Ie. the time can differ up to this and the test
        // will be okay. This is used because localhost/developer machine is not
        // always synchronized with the server(s)
        int expectedMinTime = 2000 - maxTimeDiff;
        assertTrue("The total time should never be less the 'fileAge' ms (was " + time + ", expected "
                   + expectedMinTime + ")", time > expectedMinTime);

        assertEquals(TEST_MESSAGE, message.get());
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicReference

    }

    public void testRequest() throws Exception
    {
        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference messageHolder = new AtomicReference();

        EventCallback callback = new EventCallback()
        {
            public synchronized void eventReceived(MuleEventContext context, Object component)
            {
                try
                {
                    if (1 == latch.getCount())
                    {
                        messageHolder.set(context.getMessage());
                        latch.countDown();
                    }
                }
                catch (Exception e)
                {
                    fail();
                }
            }
        };

        Object component = getComponent("testComponent");
        assertTrue("FunctionalStreamingTestComponent expected",
            component instanceof FunctionalStreamingTestComponent);
        FunctionalStreamingTestComponent ftc = (FunctionalStreamingTestComponent) component;
        ftc.setEventCallback(callback, TEST_MESSAGE.length());
      
        createFileOnFtpServer("input.txt");
              
        // poll and pull back through test service
        assertTrue(latch.await(getTimeout(), TimeUnit.MILLISECONDS));

        MuleMessage message = (MuleMessage) messageHolder.get();
        assertNotNull(message);
        assertTrue(message.getPayload() instanceof InputStream);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.