Examples of BayeuxClient


Examples of org.cometd.client.BayeuxClient

            default:
                throw new IllegalArgumentException();
        }
        prepareAndStart(initParams);

        BayeuxClient client = newBayeuxClient();
        client.handshake();
        Assert.assertTrue(client.waitFor(5000, BayeuxClient.State.CONNECTED));
        Thread.sleep(1000);

        client.disconnect();

        switch (wsTransportType)
        {
            case WEBSOCKET_JSR_356:
                CloseLatchWebSocketTransport jsrTransport = (CloseLatchWebSocketTransport)bayeux.getTransport("websocket");
View Full Code Here

Examples of org.cometd.client.BayeuxClient

            default:
                throw new IllegalArgumentException();
        }
        prepareAndStart(initParams);

        BayeuxClient client = newBayeuxClient();
        client.handshake();
        Assert.assertTrue(client.waitFor(5000, BayeuxClient.State.CONNECTED));
        Thread.sleep(1000);

        client.disconnect(1000);

        switch (wsTransportType)
        {
            case WEBSOCKET_JSR_356:
                CloseLatchWebSocketTransport jsrTransport = (CloseLatchWebSocketTransport)bayeux.getTransport("websocket");
View Full Code Here

Examples of org.cometd.client.BayeuxClient

        Seti seti2 = startSeti(oort2);

        new SetiService(seti1);
        new SetiService(seti2);

        BayeuxClient client1 = startClient(oort1, null);
        Assert.assertTrue(client1.waitFor(5000, BayeuxClient.State.CONNECTED));
        BayeuxClient client2 = startClient(oort2, null);
        Assert.assertTrue(client2.waitFor(5000, BayeuxClient.State.CONNECTED));

        CountDownLatch presenceAddedLatch = new CountDownLatch(4);
        seti1.addPresenceListener(new UserPresentListener(presenceAddedLatch));
        seti2.addPresenceListener(new UserPresentListener(presenceAddedLatch));

        // Login user1
        final CountDownLatch loginLatch1 = new CountDownLatch(1);
        Map<String, Object> login1 = new HashMap<String, Object>();
        String userId1 = "user1";
        login1.put("user", userId1);
        ClientSessionChannel loginChannel1 = client1.getChannel("/service/login");
        loginChannel1.publish(login1, new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
                loginLatch1.countDown();
            }
        });
        Assert.assertTrue(loginLatch1.await(5, TimeUnit.SECONDS));

        // Login user2
        final CountDownLatch loginLatch2 = new CountDownLatch(1);
        Map<String, Object> login2 = new HashMap<String, Object>();
        String userId2 = "user2";
        login2.put("user", userId2);
        ClientSessionChannel loginChannel2 = client2.getChannel("/service/login");
        loginChannel2.publish(login2, new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
                loginLatch2.countDown();
            }
        });
        Assert.assertTrue(loginLatch2.await(5, TimeUnit.SECONDS));

        // Make sure all Setis see all users
        Assert.assertTrue(presenceAddedLatch.await(5, TimeUnit.SECONDS));

        // Setup test: register a service for the service channel
        // that broadcasts to another channel that is not observed
        final String serviceChannel = "/service/foo";
        final String broadcastChannel = "/foo";

        if (forward)
        {
            oort2.observeChannel(broadcastChannel);
            // Give some time for the subscribe to happen
            Thread.sleep(1000);
        }

        new BroadcastService(seti1, serviceChannel, broadcastChannel);

        // Subscribe user2
        LatchListener subscribeListener = new LatchListener(1);
        final CountDownLatch messageLatch = new CountDownLatch(1);
        client2.getChannel(Channel.META_SUBSCRIBE).addListener(subscribeListener);
        client2.getChannel(broadcastChannel).subscribe(new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
                messageLatch.countDown();
            }
View Full Code Here

Examples of org.cometd.client.BayeuxClient

        Map<String, String> options = new HashMap<>();
        long maxInterval = 1000;
        options.put(AbstractServerTransport.MAX_INTERVAL_OPTION, String.valueOf(maxInterval));
        prepareAndStart(options);

        BayeuxClient client = newBayeuxClient();
        client.handshake();
        Assert.assertTrue(client.waitFor(5000, BayeuxClient.State.CONNECTED));

        // Allow long poll to establish
        Thread.sleep(1000);

        final CountDownLatch latch = new CountDownLatch(1);
        ServerSession session = bayeux.getSession(client.getId());
        session.addListener(new ServerSession.RemoveListener()
        {
            @Override
            public void removed(ServerSession session, boolean timeout)
            {
                latch.countDown();
            }
        });

        client.abort();

        Assert.assertTrue(latch.await(2 * maxInterval, TimeUnit.MILLISECONDS));
    }
View Full Code Here

Examples of org.cometd.client.BayeuxClient

        final long maxNetworkDelay = 2000L;
        Map<String, Object> clientOptions = new HashMap<>();
        clientOptions.put("maxNetworkDelay", maxNetworkDelay);
        ClientTransport webSocketTransport = newWebSocketTransport(clientOptions);
        BayeuxClient client = new BayeuxClient(cometdURL, webSocketTransport);

        client.handshake();
        Assert.assertTrue(client.waitFor(5000, BayeuxClient.State.CONNECTED));

        // Wait for the /meta/connect to be held on server
        TimeUnit.MILLISECONDS.sleep(1000);

        final CountDownLatch latch = new CountDownLatch(1);
        client.getChannel(Channel.META_CONNECT).addListener(new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
                if (!message.isSuccessful())
                    latch.countDown();
            }
        });

        client.disconnect();

        // Only wait for the maxNetworkDelay: when the /meta/disconnect response arrives,
        // the connection is closed, so the /meta/connect is failed on the client side.
        Assert.assertTrue(latch.await(2 * maxNetworkDelay, TimeUnit.MILLISECONDS));
    }
View Full Code Here

Examples of org.cometd.client.BayeuxClient

    @Test
    public void testDeliverDuringHandshakeProcessing() throws Exception
    {
        final String channelName = "/service/test";
        BayeuxClient client = newBayeuxClient();

        final CountDownLatch latch = new CountDownLatch(1);
        client.getChannel(channelName).addListener(new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
                if (!message.isPublishReply())
                    latch.countDown();
            }
        });

        // SessionListener is the first listener notified after the ServerSession is created.
        bayeux.addListener(new BayeuxServer.SessionListener()
        {
            public void sessionAdded(ServerSession session, ServerMessage message)
            {
                session.deliver(null, channelName, "data");
            }

            public void sessionRemoved(ServerSession session, boolean timedout)
            {
            }
        });

        client.handshake();
        Assert.assertTrue(client.waitFor(5000, BayeuxClient.State.CONNECTED));

        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));

        disconnectBayeuxClient(client);
    }
View Full Code Here

Examples of org.cometd.client.BayeuxClient

    public void testDeliverDuringHandshakeProcessingWithAckExtension() throws Exception
    {
        bayeux.addExtension(new AcknowledgedMessagesExtension());

        final String channelName = "/service/test";
        BayeuxClient client = newBayeuxClient();
        client.addExtension(new AckExtension());

        final CountDownLatch latch = new CountDownLatch(1);
        client.getChannel(channelName).addListener(new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
                if (!message.isPublishReply())
                    latch.countDown();
            }
        });

        // SessionListener is the first listener notified after the ServerSession is created.
        bayeux.addListener(new BayeuxServer.SessionListener()
        {
            public void sessionAdded(ServerSession session, ServerMessage message)
            {
                session.deliver(null, channelName, "data");
            }

            public void sessionRemoved(ServerSession session, boolean timedout)
            {
            }
        });

        client.handshake();
        Assert.assertTrue(client.waitFor(5000, BayeuxClient.State.CONNECTED));

        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));

        disconnectBayeuxClient(client);
    }
View Full Code Here

Examples of org.cometd.client.BayeuxClient

    @Test
    public void testExtensionIsInvokedAfterNetworkFailure() throws Exception
    {
        bayeux.addExtension(new AcknowledgedMessagesExtension());

        final BayeuxClient client = newBayeuxClient();
        final String channelName = "/test";
        final AtomicReference<CountDownLatch> rcv = new AtomicReference<CountDownLatch>(new CountDownLatch(1));
        client.addExtension(new AckExtension());
        client.addExtension(new ClientSession.Extension.Adapter()
        {
            @Override
            public boolean rcv(ClientSession session, Message.Mutable message)
            {
                if (channelName.equals(message.getChannel()))
                    rcv.get().countDown();
                return true;
            }

            @Override
            public boolean rcvMeta(ClientSession session, Message.Mutable message)
            {
                return true;
            }
        });
        client.handshake(new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
                client.getChannel(channelName).subscribe(new ClientSessionChannel.MessageListener()
                {
                    public void onMessage(ClientSessionChannel channel, Message message)
                    {
                    }
                });
            }
        });
        Assert.assertTrue(client.waitFor(5000, BayeuxClient.State.CONNECTED));

        // This message will be delivered via /meta/connect.
        bayeux.createChannelIfAbsent(channelName).getReference().publish(null, "data1");
        Assert.assertTrue(rcv.get().await(5, TimeUnit.SECONDS));
        // Wait for the /meta/connect to be established again.
        Thread.sleep(1000);

        // Stopping HttpClient will also stop the WebSocketClients (both Jetty's and JSR's).
        httpClient.stop();
        Assert.assertTrue(client.waitFor(5000, BayeuxClient.State.UNCONNECTED));

        // Send a message while disconnected.
        bayeux.createChannelIfAbsent(channelName).getReference().publish(null, "data2");

        rcv.set(new CountDownLatch(1));
        httpClient.start();

        Assert.assertTrue(client.waitFor(5000, BayeuxClient.State.CONNECTED));
        Assert.assertTrue(rcv.get().await(5, TimeUnit.SECONDS));

        disconnectBayeuxClient(client);
    }
View Full Code Here

Examples of org.cometd.client.BayeuxClient

    protected BayeuxClient startClient(Oort oort, Map<String, Object> handshakeFields) throws Exception
    {
        HttpClient httpClient = new HttpClient();
        httpClient.start();
        BayeuxClient client = new BayeuxClient(oort.getURL(), new LongPollingTransport(null, httpClient));
        client.setAttribute(HttpClient.class.getName(), httpClient);
        client.handshake(handshakeFields);
        clients.add(client);
        return client;
    }
View Full Code Here

Examples of org.cometd.client.BayeuxClient

            public void sessionRemoved(ServerSession session, boolean timedout)
            {
            }
        });

        BayeuxClient client = newBayeuxClient();

        final CountDownLatch messageLatch = new CountDownLatch(1);
        final CountDownLatch handshakeLatch = new CountDownLatch(1);

        client.getChannel(Channel.META_HANDSHAKE).addListener(new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
                Assert.assertEquals(1, messageLatch.getCount());
                handshakeLatch.countDown();
            }
        });
        client.getChannel(channelName).addListener(new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
                Assert.assertEquals(0, handshakeLatch.getCount());
                messageLatch.countDown();
            }
        });
        client.handshake();
        Assert.assertTrue(client.waitFor(5000, BayeuxClient.State.CONNECTED));
        Assert.assertTrue(handshakeLatch.await(5, TimeUnit.SECONDS));
        Assert.assertTrue(messageLatch.await(5, TimeUnit.SECONDS));

        disconnectBayeuxClient(client);
    }
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.