Package java.util.concurrent.atomic

Examples of java.util.concurrent.atomic.AtomicReference


        final CountDownLatch latch = new CountDownLatch(1);
        servletLatch = new CountDownLatch(1);
        AsyncHttpClient c = new AsyncHttpClient();
        try {
            long currentTime = System.currentTimeMillis();
            final AtomicReference<Response> r = new AtomicReference();
            c.prepareGet(urlTarget).execute(new AsyncCompletionHandler<Response>() {

                @Override
                public Response onCompleted(Response response) throws Exception {
                    r.set(response);
                    latch.countDown();
                    return response;
                }
            });

            servletLatch.await();

            Broadcaster b = BroadcasterFactory.getDefault().lookup(DefaultBroadcaster.class, "/*");
            assertNotNull(b);
            b.broadcast("resume").get();

            try {
                latch.await();
            } catch (InterruptedException e) {
                fail(e.getMessage());
                return;
            }

            long time = System.currentTimeMillis() - currentTime;
            if (time < 5000) {
                assertTrue(true);
            } else {
                assertFalse(false);
            }
            assertNotNull(r.get());
            assertEquals(r.get().getStatusCode(), 200);
            String resume = r.get().getResponseBody();
            assertEquals(resume, "resumeresume");
        } catch (Exception e) {
            logger.error("test failed", e);
            fail(e.getMessage());
        }
View Full Code Here


        servletLatch = new CountDownLatch(1);
        AsyncHttpClient c = new AsyncHttpClient();
        Broadcaster b = null;
        try {
            long currentTime = System.currentTimeMillis();
            final AtomicReference<Response> r = new AtomicReference();
            c.prepareGet(urlTarget).execute(new AsyncCompletionHandler<Response>() {

                @Override
                public Response onCompleted(Response response) throws Exception {
                    r.set(response);
                    latch.countDown();
                    return response;
                }
            });

            servletLatch.await();

            String id = broadcasterId.get();

            b = BroadcasterFactory.getDefault().lookup(DefaultBroadcaster.class, id);
            assertNotNull(b);
            b.broadcast("resume").get();

            try {
                latch.await();
            } catch (InterruptedException e) {
                fail(e.getMessage());
                return;
            }

            long time = System.currentTimeMillis() - currentTime;
            if (time < 5000) {
                assertTrue(true);
            } else {
                assertFalse(false);
            }
            assertNotNull(r.get());
            assertEquals(r.get().getStatusCode(), 200);
            String resume = r.get().getResponseBody();
            assertEquals(resume, "resumeresume");

            c.prepareGet(urlTarget).execute(new AsyncCompletionHandler<Response>() {

                @Override
                public Response onCompleted(Response response) throws Exception {
                    r.set(response);
                    latch2.countDown();
                    return response;
                }
            });
View Full Code Here

        m_executor = executor;
        m_task = task;
        m_timeout = timeout;
        m_timeUnit = unit;
       
        m_futureRef = new AtomicReference();
    }
View Full Code Here

     * @param backgroundWriteEnabled <code>true</code> if background writing should be enabled, <code>false</code> to disable it.
     */
    public RoleRepositoryFileStore(File baseDir, boolean backgroundWriteEnabled) {
        m_file = new File(baseDir, FILE_NAME);
       
        m_timerRef = new AtomicReference();

        if (backgroundWriteEnabled) {
            m_timerRef.set(new ResettableTimer(this, DEFAULT_WRITE_DELAY_VALUE, DEFAULT_WRITE_DELAY_TIMEUNIT));
        }
    }
View Full Code Here

        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

    }

    @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

        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

    // 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

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

        called.set(true);
    }

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

TOP

Related Classes of java.util.concurrent.atomic.AtomicReference

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.