Package org.cometd.bayeux.server

Examples of org.cometd.bayeux.server.ServerChannel


        // Demo lazy messages
        if (Boolean.getBoolean("LAZYCHAT"))
        {
            String channelName = "/chat/demo";
            final ServerChannel chat_demo = bayeux.createChannelIfAbsent(channelName).getReference();
            chat_demo.setLazy(true);
            chat_demo.setPersistent(true);
        }
    }
View Full Code Here


        client.handshake();

        Assert.assertTrue(subscribed.await(5, TimeUnit.SECONDS));
        Assert.assertEquals(0, messages.size());

        final ServerChannel chatChannel = bayeux.getChannel(channelName);
        Assert.assertNotNull(chatChannel);

        final int count = 5;
        client.batch(new Runnable()
        {
            public void run()
            {
                for (int i = 0; i < count; ++i)
                    client.getChannel(channelName).publish("hello_" + i);
            }
        });

        for (int i = 0; i < count; ++i)
            Assert.assertEquals("hello_" + i, messages.poll(5, TimeUnit.SECONDS).getData());

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

        int port = connector.getLocalPort();
        connector.stop();

        // Wait for connections to process the remote close
        Thread.sleep(1000);

        Assert.assertTrue(connector.isStopped());
        Assert.assertTrue(client.waitFor(5000, BayeuxClient.State.UNCONNECTED));

        // Send messages while client is offline
        for (int i = count; i < 2 * count; ++i)
            chatChannel.publish(null, "hello_" + i);

        Thread.sleep(1000);
        Assert.assertEquals(0, messages.size());

        connector.setPort(port);
View Full Code Here

        Assert.assertEquals(Channel.META_CONNECT, connectReply.getChannel());

        Message.Mutable subscribeReply = messages[1];
        Assert.assertEquals(Channel.META_SUBSCRIBE, subscribeReply.getChannel());

        ServerChannel channel = bayeux.getChannel(channelName);
        // Cannot be null since it has a subscriber.
        Assert.assertNotNull(channel);
        Assert.assertEquals(1, channel.getSubscribers().size());
    }
View Full Code Here

        ServerChannelImpl fooStarStar = (ServerChannelImpl)_bayeux.createChannelIfAbsent("/foo/**").getReference();

        ServerSessionImpl session1 = newServerSession();
        fooStarStar.subscribe(session1);

        ServerChannel fooBar = _bayeux.createChannelIfAbsent("/foo/bar").getReference();

        sweep();

        Assert.assertNull(_bayeux.getChannel(fooBar.getId()));

        ServerSessionImpl session0 = newServerSession();
        ServerMessage.Mutable message = _bayeux.newMessage();
        message.setData("test");
        fooBar.publish(session0, message);

        Assert.assertEquals(1, session1.getQueue().size());
    }
View Full Code Here

    @Test
    public void testPersistentChannelIsNotSwept() throws Exception
    {
        String channelName = "/foo/bar";
        ServerChannel foobar = _bayeux.createChannelIfAbsent(channelName).getReference();
        foobar.setPersistent(true);

        sweep();
        Assert.assertNotNull(_bayeux.getChannel(channelName));
    }
View Full Code Here

    @Test
    public void testChannelWithListenersIsNotSwept() throws Exception
    {
        String channelName = "/test";
        ServerChannel channel = _bayeux.createChannelIfAbsent(channelName).getReference();
        channel.addListener(new ServerChannel.MessageListener()
        {
            public boolean onMessage(ServerSession from, ServerChannel channel, Mutable message)
            {
                return true;
            }
View Full Code Here

                channel.addAuthorizer(GrantAuthorizer.GRANT_ALL);
            }
        };

        String channelName1 = "/a/b/c";
        ServerChannel channel1 = _bayeux.createChannelIfAbsent(channelName1).getReference();
        channel1.addListener(listener);

        String wildName1 = "/a/b/*";
        _bayeux.createChannelIfAbsent(wildName1, initializer);

        String wildName2 = "/a/**";
 
View Full Code Here

    @Test
    public void testLazyTimeout() throws Exception
    {
        String channelName = "/testLazy";
        ServerChannel channel = _bayeux.createChannelIfAbsent(channelName, new ConfigurableServerChannel.Initializer.Persistent()).getReference();
        Assert.assertFalse(channel.isLazy());

        int lazyTimeout = 1000;
        channel.setLazyTimeout(lazyTimeout);
        Assert.assertTrue(channel.isLazy());

        channel.setLazy(true);
        Assert.assertEquals(lazyTimeout, channel.getLazyTimeout());

        channel.setLazy(false);
        Assert.assertFalse(channel.isLazy());
        Assert.assertEquals(-1, channel.getLazyTimeout());

        channel.setLazy(true);
        Assert.assertTrue(channel.isLazy());
        Assert.assertEquals(-1, channel.getLazyTimeout());
    }
View Full Code Here

  @Override
  public <EventType> void publish(final IPushChannel<EventType> pushChannel, final EventType event)
  {
    if (pushChannel instanceof CometdPushChannel)
    {
      final ServerChannel channel = _getBayeuxServerChannel((CometdPushChannel<?>)pushChannel);
      if (channel == null)
        LOG.warn("No cometd channel found for {}", pushChannel);
      else
      {
        final PushChannelState state = _channelStates.get(pushChannel);
        if (state == null)
          return;

        synchronized (state.queuedEventsLock)
        {
          state.queuedEvents.add(event);
        }

        channel.publish(null, "pollEvents", state.channel.getCometdChannelEventId());
      }
    }
    else
      LOG.warn("Unsupported push channel type {}", pushChannel);
  }
View Full Code Here

   * an additional Wicket AJAX request roundtrip.
   */
  public <EventType> void publishJavascript(final CometdPushChannel<EventType> pushChannel,
      final String javascript)
  {
    final ServerChannel channel = _getBayeuxServerChannel(pushChannel);
    if (channel == null)
      LOG.warn("No cometd channel found for {}", pushChannel);
    else
      channel.publish(null, "javascript:" + javascript, pushChannel.getCometdChannelEventId());
  }
View Full Code Here

TOP

Related Classes of org.cometd.bayeux.server.ServerChannel

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.