Package org.atmosphere.wasync

Examples of org.atmosphere.wasync.Socket


                        // 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>() {
View Full Code Here


                        // 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();

        elatch.await(5, TimeUnit.SECONDS);
View Full Code Here

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

        server.stop();
View Full Code Here

                        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();

        xlatch.await(5, TimeUnit.SECONDS);

        assertNotNull(response.get());
        assertNotNull(open.get());
View Full Code Here

                .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();
                }
View Full Code Here

        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());

        assertEquals(response.get(), "HELLO");
        assertEquals(socket.status(), Socket.STATUS.OPEN);

        socket.close();

        assertEquals(socket.status(), Socket.STATUS.CLOSE);
    }
View Full Code Here

                .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();
            }
View Full Code Here

                .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

        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();

        assertEquals(response.get(), RESUME);
    }
View Full Code Here

        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();

        assertEquals(response.get().toString(), "PINGPONG");
    }
View Full Code Here

TOP

Related Classes of org.atmosphere.wasync.Socket

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.