Package org.atmosphere.wasync

Examples of org.atmosphere.wasync.RequestBuilder


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

        Client client = ClientFactory.getDefault().newClient();
        RequestBuilder clientRequest = client.newRequestBuilder().method(Request.METHOD.GET).uri(targetUrl)
                .decoder(new Decoder<String, Reader>() {
                    @Override
                    public Reader decode(Event e, String s) {
                        // Fool the decoder mapping
                        return new StringReader(s);
                    }
                }).transport(transport());

        Socket socket = client.create();
        socket.on(Event.CLOSE, new Function<String>() {
            @Override
            public void on(String t) {
                b.get().append(t);
            }
        }).on(new Function<IOException>() {
            @Override
            public void on(IOException ioe) {
                ioe.printStackTrace();
                b.get().append("ERROR");
                elatch.countDown();
            }
        }).on(Event.OPEN, new Function<String>() {
            @Override
            public void on(String t) {
                b.get().append(t);
            }
        }).open(clientRequest.build());

        latch.await(5, TimeUnit.SECONDS);

        server.stop();
View Full Code Here


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

        Client client = ClientFactory.getDefault().newClient();
        RequestBuilder clientRequest = client.newRequestBuilder().method(Request.METHOD.GET).uri(targetUrl)
                .decoder(new Decoder<String, String>() {
                    @Override
                    public String decode(Event e, String s) {
                        // Fool the decoder mapping
                        return s;
                    }
                }).transport(transport());

        Socket socket = client.create();
        socket.on("message", new Function<String>() {
            @Override
            public void on(String t) {
                b.get().append(t);
                flatch.countDown();
            }
        }).on(Event.CLOSE, new Function<String>() {
            @Override
            public void on(String t) {
                b.get().append(t);
            }
        }).on(Event.REOPENED, new Function<String>() {
            @Override
            public void on(String t) {
                b.get().append(t);
                latch.countDown();
            }
        }).on(new Function<IOException>() {
            @Override
            public void on(IOException ioe) {
                ioe.printStackTrace();
                b.get().append("ERROR");
                elatch.countDown();
            }
        }).on(Event.OPEN, new Function<String>() {
            @Override
            public void on(String t) {
                b.get().append(t);
            }
        }).open(clientRequest.build());

        socket.fire("PING");
        flatch.await(5, TimeUnit.SECONDS);

        server.stop();
View Full Code Here

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

        Client client = ClientFactory.getDefault().newClient();
        RequestBuilder clientRequest = client.newRequestBuilder().method(Request.METHOD.GET).uri(targetUrl)
                .encoder(new Encoder<String, String>() {
                    @Override
                    public String encode(String s) {
                        System.out.println("[Encode]:" + s);
                        return s;
                    }
                })
                .decoder(new Decoder<String, String>() {
                    @Override
                    public String decode(Event e, String s) {
                        // Fool the decoder mapping
                        return s;
                    }
                }).transport(transport());

        final Socket socket = client.create();
        socket.on("message", new Function<String>() {
            @Override
            public void on(String t) {
                //System.out.println("=>" + t);

                b.get().append(t);
                flatch.countDown();
            }
        }).on(Event.CLOSE, new Function<String>() {
            @Override
            public void on(String t) {
                b.get().append(t);
            }
        }).on(Event.REOPENED, new Function<String>() {
            @Override
            public void on(String t) {
                b.get().append(t);
                try {
                    socket.fire("PONG");
                } catch (IOException e) {
                    e.printStackTrace();
                }
                latch.countDown();
            }
        }).on(new Function<IOException>() {
            @Override
            public void on(IOException ioe) {
                ioe.printStackTrace();
                b.get().append("ERROR");
                elatch.countDown();
            }
        }).on(Event.OPEN, new Function<String>() {
            @Override
            public void on(String t) {
                b.get().append(t);
            }
        }).open(clientRequest.build());

        socket.fire("PING");
        latch.await(10, TimeUnit.SECONDS);
        flatch.await(10, TimeUnit.SECONDS);
View Full Code Here

        final AtomicReference<EventPOJO> open = new AtomicReference<EventPOJO>();
        final AtomicReference<EventPOJO> close = new AtomicReference<EventPOJO>();

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

        RequestBuilder request = client.newRequestBuilder()
                .method(Request.METHOD.GET)
                .uri(targetUrl + "/suspend")
                .decoder(new Decoder<String, POJO>() {
                    @Override
                    public POJO decode(Event e, String s) {
                        if (e.equals(Event.MESSAGE)) {
                            return new POJO(s);
                        } else {
                            return null;
                        }
                    }
                })
                .decoder(new Decoder<String, EventPOJO>() {
                    @Override
                    public EventPOJO decode(Event e, String s) {
                        return new EventPOJO(e, s);
                    }
                })
                .transport(transport());

        Socket socket = client.create();
        socket.on(new Function<POJO>() {
            @Override
            public void on(POJO t) {
                response.set(t);
                latch.countDown();
            }
        }).on(Event.OPEN, new Function<EventPOJO>() {
            @Override
            public void on(EventPOJO t) {
                open.set(t);
                latch.countDown();
            }
        }).on(Event.CLOSE, new Function<EventPOJO>() {
            @Override
            public void on(EventPOJO t) {
                close.set(t);
                xlatch.countDown();
            }
        }).open(request.build()).fire("echo");

        latch.await(5, TimeUnit.SECONDS);

        socket.close();
View Full Code Here

    @Test
    public void testTimeoutAtmosphereClient() throws IOException, InterruptedException {
        final CountDownLatch latch = new CountDownLatch(1);
        AtmosphereClient client = ClientFactory.getDefault().newClient(AtmosphereClient.class);
        RequestBuilder request = client.newRequestBuilder()
                .method(Request.METHOD.GET)
                .uri(targetUrl)
                .trackMessageLength(true)
                .transport(transport());

        Socket socket = client.create();
        IOException ioException = null;
        try {
            socket.on(new Function<ConnectException>() {

                @Override
                public void on(ConnectException t) {
                    latch.countDown();
                }

            }).on(Event.CLOSE.name(), new Function<String>() {
                @Override
                public void on(String t) {
                    logger.info("Connection closed");
                }
            }).open(request.build());
        } catch (IOException ex) {
            ioException = ex;
        }

        assertTrue(latch.await(10, TimeUnit.SECONDS));
View Full Code Here

        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference<String> response = new AtomicReference<String>();
        Client client = ClientFactory.getDefault().newClient();

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

        Socket socket = client.create();

        socket.on("message", new Function<String>() {
            @Override
            public void on(String t) {
// the status should have been updated to something else than INIT
                response.set(t);
                latch.countDown();
            }
        }).on(new Function<Throwable>() {

            @Override
            public void on(Throwable t) {
                t.printStackTrace();
                latch.countDown();
            }

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

        latch.await();


        logger.error("SOCKET STATUS [{}]", socket.status());
View Full Code Here

        server.start();

        final CountDownLatch latch = new CountDownLatch(1);
        Client client = ClientFactory.getDefault().newClient();

        RequestBuilder request = client.newRequestBuilder()
                .method(Request.METHOD.GET)
                .header("X-Test", "foo")
                .uri(targetUrl + "/suspend")
                .transport(transport());

        Socket socket = client.create(client.newOptionsBuilder().reconnect(false).build());
        socket.on(Event.CLOSE.name(), new Function<String>() {

            @Override
            public void on(String t) {
                latch.countDown();
            }

        }).open(request.build()).fire("PING");

        l.await(5, TimeUnit.SECONDS);
        server.stop();
        latch.await(5, TimeUnit.SECONDS);
View Full Code Here

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

        AtmosphereClient client = ClientFactory.getDefault().newClient(AtmosphereClient.class);
        RequestBuilder request = client.newRequestBuilder()
                .method(Request.METHOD.GET)
                .uri(targetUrl + "/suspend")
                .enableProtocol(true)
                .header("X-Test", "foo")
                .transport(transport());

        Socket socket = client.create();

        socket.open(request.build()).close();

        closedByClient.await(10, TimeUnit.SECONDS);
        assertEquals(ref.get(), "foo");

    }
View Full Code Here

        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference<String> response = new AtomicReference<String>();
        Client client = ClientFactory.getDefault().newClient();

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

        Socket socket = client.create();

        socket.on("message", new Function<String>() {
            @Override
            public void on(String t) {
                logger.info("Function invoked {}", t);
                response.set(t);
                latch.countDown();
            }
        }).on(new Function<Throwable>() {

            @Override
            public void on(Throwable t) {
                t.printStackTrace();
                latch.countDown();
            }

        }).open(request.build()).fire("PING").get();

        latch.await(5, TimeUnit.SECONDS);
        server.stop();
        socket.close();
View Full Code Here

        SerializedClient client = ClientFactory.getDefault().newClient(SerializedClient.class);

        SerializedOptionsBuilder b = client.newOptionsBuilder();
        b.serializedFireStage(new DefaultSerializedFireStage());

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

        Socket socket = client.create(b.build());

        socket.on("message", new Function<String>() {
            @Override
            public void on(String t) {
                logger.info("Serialized Function invoked {}", t);
                response.get().append(t);
                latch.countDown();
            }
        }).open(request.build())
                .fire("PING")
                .fire("PONG").get();

        latch.await(10, TimeUnit.SECONDS);
        socket.close();
View Full Code Here

TOP

Related Classes of org.atmosphere.wasync.RequestBuilder

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.