Package org.cometd.bayeux.client

Examples of org.cometd.bayeux.client.ClientSessionChannel


        // Wait for the long poll
        Thread.sleep(1000);

        String channelName = "/foo";
        ClientSessionChannel channel = client.getChannel(channelName);
        channel.addListener(new ClientSessionChannel.ClientSessionChannelListener()
        {
        });
        boolean released = channel.release();

        Assert.assertFalse(released);

        ClientSessionChannel newChannel = client.getChannel(channelName);
        Assert.assertNotNull(newChannel);
        Assert.assertSame(channel, newChannel);

        disconnectBayeuxClient(client);
    }
View Full Code Here


        // Wait for the long poll
        Thread.sleep(1000);

        final CountDownLatch latch = new CountDownLatch(1);
        String channelName = "/foo";
        final ClientSessionChannel channel = client.getChannel(channelName);
        client.batch(new Runnable()
        {
            public void run()
            {
                channel.subscribe(new ClientSessionChannel.MessageListener()
                {
                    public void onMessage(ClientSessionChannel channel, Message message)
                    {
                        latch.countDown();
                    }
                });
                channel.publish("");
            }
        });
        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
        boolean released = channel.release();

        Assert.assertFalse(released);

        ClientSessionChannel newChannel = client.getChannel(channelName);
        Assert.assertNotNull(newChannel);
        Assert.assertSame(channel, newChannel);

        disconnectBayeuxClient(client);
    }
View Full Code Here

        // Wait for the long poll
        Thread.sleep(1000);

        String channelName = "/foo";
        ClientSessionChannel channel = client.getChannel(channelName);
        ClientSessionChannel.ClientSessionChannelListener listener = new ClientSessionChannel.ClientSessionChannelListener()
        {
        };
        channel.addListener(listener);
        boolean released = channel.release();

        Assert.assertFalse(released);

        channel.removeListener(listener);
        Assert.assertTrue(channel.getListeners().isEmpty());
        released = channel.release();

        Assert.assertTrue(released);

        disconnectBayeuxClient(client);
    }
View Full Code Here

        // Wait for the long poll
        Thread.sleep(1000);

        final CountDownLatch latch = new CountDownLatch(1);
        String channelName = "/foo";
        final ClientSessionChannel channel = client.getChannel(channelName);
        final ClientSessionChannel.MessageListener listener = new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
                latch.countDown();
            }
        };
        client.batch(new Runnable()
        {
            public void run()
            {
                channel.subscribe(listener);
                channel.publish("");
            }
        });
        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
        boolean released = channel.release();

        Assert.assertFalse(released);

        final CountDownLatch unsubscribe = new CountDownLatch(1);
        client.getChannel(Channel.META_UNSUBSCRIBE).addListener(new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
                unsubscribe.countDown();
            }
        });
        channel.unsubscribe(listener);
        Assert.assertTrue(unsubscribe.await(5, TimeUnit.SECONDS));
        Assert.assertTrue(channel.getSubscribers().isEmpty());
        released = channel.release();

        Assert.assertTrue(released);

        disconnectBayeuxClient(client);
    }
View Full Code Here

        // Wait for the long poll
        Thread.sleep(1000);

        String channelName = "/foo";
        ClientSessionChannel channel = client.getChannel(channelName);
        Assert.assertTrue(channel.release());
        Assert.assertTrue(channel.isReleased());

        ClientSessionChannel.ClientSessionChannelListener channelListener = new ClientSessionChannel.ClientSessionChannelListener()
        {
        };
        try
        {
            channel.addListener(channelListener);
            Assert.fail();
        }
        catch (IllegalStateException expected)
        {
        }

        try
        {
            channel.removeListener(channelListener);
            Assert.fail();
        }
        catch (IllegalStateException expected)
        {
        }

        try
        {
            channel.setAttribute("foo", "bar");
            Assert.fail();
        }
        catch (IllegalStateException expected)
        {
        }

        try
        {
            channel.removeAttribute("foo");
            Assert.fail();
        }
        catch (IllegalStateException expected)
        {
        }

        try
        {
            channel.getAttributeNames();
            Assert.fail();
        }
        catch (IllegalStateException expected)
        {
        }

        ClientSessionChannel.MessageListener listener = new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
            }
        };
        try
        {
            channel.subscribe(listener);
            Assert.fail();
        }
        catch (IllegalStateException expected)
        {
        }

        try
        {
            channel.unsubscribe(listener);
            Assert.fail();
        }
        catch (IllegalStateException expected)
        {
        }

        try
        {
            channel.unsubscribe();
            Assert.fail();
        }
        catch (IllegalStateException expected)
        {
        }

        try
        {
            channel.publish("");
            Assert.fail();
        }
        catch (IllegalStateException expected)
        {
        }

        try
        {
            channel.getSession();
            Assert.fail();
        }
        catch (IllegalStateException expected)
        {
        }
View Full Code Here

                else if (wasConnected && !connected.get())
                    System.err.println("BayeuxClient unconnected");
            }
        });
        String channelName = "/test";
        ClientSessionChannel channel = client.getChannel(channelName);
        channel.addListener(new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
                if (!message.isSuccessful())
                    publishLatch.get().countDown();
            }
        });
        client.handshake();
        assertTrue(connectLatch.await(5, TimeUnit.SECONDS));

        // Wait for a second connect to be issued
        Thread.sleep(1000);

        // Add some margin since the session is swept every 'sweepIntervalMs'
        long networkDown = maxInterval + 3 * sweepInterval;
        client.setNetworkDown(networkDown);

        // Publish, it must succeed
        publishLatch.set(new CountDownLatch(1));
        channel.publish(new HashMap<>());
        assertTrue(publishLatch.get().await(5, TimeUnit.SECONDS));

        // Wait for the connect to return
        // We already slept a bit before, so we are sure that the connect returned
        Thread.sleep(timeout);

        // Now we are simulating the network is down
        // Be sure we are disconnected
        assertFalse(connected.get());

        // Another publish, it must fail
        publishLatch.set(new CountDownLatch(1));
        channel.publish(new HashMap<>());
        assertTrue(publishLatch.get().await(5, TimeUnit.SECONDS));

        // Sleep to allow the next connect to be issued
        Thread.sleep(networkDown);

        // Now another connect has been sent (delayed by 'networkDown' ms)
        // but the server expired the client, so we handshake again
        assertTrue(handshakeLatch.await(5, TimeUnit.SECONDS));

        // We should be able to publish now
        publishLatch.set(new CountDownLatch(1));
        channel.publish(new HashMap<>());
        assertFalse(publishLatch.get().await(1, TimeUnit.SECONDS));

        disconnectBayeuxClient(client);
    }
View Full Code Here

        List<ListenerCallback> callbacks = listeners.remove(bean);
        if (callbacks != null)
        {
            for (ListenerCallback callback : callbacks)
            {
                ClientSessionChannel channel = clientSession.getChannel(callback.subscription);
                if (channel != null)
                {
                    channel.removeListener(callback);
                    result = true;
                }
            }
        }
        return result;
View Full Code Here

            public void onMessage(ClientSessionChannel channel, Message message)
            {
                latch.countDown();
            }
        });
        final ClientSessionChannel channel = client.getChannel("/foo");
        final ClientSessionChannel.MessageListener listener = new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
            }
        };
        client.batch(new Runnable()
        {
            public void run()
            {
                channel.subscribe(listener);
                channel.unsubscribe(listener);
            }
        });
        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));

        Assert.assertEquals(0, extension.rcvs.size());
View Full Code Here

        CountingExtension extension = new CountingExtension(channelName);
        client.addExtension(extension);
        client.handshake();
        Assert.assertTrue(client.waitFor(5000, BayeuxClient.State.CONNECTED));

        final ClientSessionChannel channel = client.getChannel(channelName);
        client.batch(new Runnable()
        {
            public void run()
            {
                channel.subscribe(new ClientSessionChannel.MessageListener()
                {
                    public void onMessage(ClientSessionChannel channel, Message message)
                    {
                    }
                });
                channel.publish(new HashMap<>());
            }
        });

        // Wait for the message to arrive, along with the publish response
        Thread.sleep(1000);
View Full Code Here

                else if (wasConnected && !connected.get())
                    System.err.printf("BayeuxClient unconnected %s%n", message);
            }
        });
        String channelName = "/test";
        ClientSessionChannel channel = client.getChannel(channelName);
        channel.addListener(new ClientSessionChannel.MessageListener()
        {
            public void onMessage(ClientSessionChannel channel, Message message)
            {
                if (!message.isSuccessful())
                    publishLatch.get().countDown();
            }
        });

        client.handshake();
        assertTrue(connectLatch.await(5, TimeUnit.SECONDS));

        // Wait for a second connect to be issued
        Thread.sleep(1000);

        long networkDown = maxInterval / 2;
        client.setNetworkDown(networkDown);

        // Publish, it must succeed
        publishLatch.set(new CountDownLatch(1));
        channel.publish(new HashMap());
        assertTrue(publishLatch.get().await(5, TimeUnit.SECONDS));

        // Wait for the connect to return
        // We already slept a bit before, so we are sure that the connect returned
        Thread.sleep(timeout);

        // Now we are simulating the network is down
        // Be sure we are disconnected
        assertFalse(connected.get());

        // Another publish, it must fail
        publishLatch.set(new CountDownLatch(1));
        channel.publish(new HashMap());
        assertTrue(publishLatch.get().await(5, TimeUnit.SECONDS));

        // Sleep to allow the next connect to be issued
        Thread.sleep(networkDown);

        // Now another connect has been sent (delayed by 'networkDown' ms)
        Thread.sleep(timeout);
        assertTrue(connected.get());

        // We should be able to publish now
        publishLatch.set(new CountDownLatch(1));
        channel.publish(new HashMap());
        assertFalse(publishLatch.get().await(1, TimeUnit.SECONDS));

        disconnectBayeuxClient(client);
    }
View Full Code Here

TOP

Related Classes of org.cometd.bayeux.client.ClientSessionChannel

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.