Package org.cometd.bayeux.server

Examples of org.cometd.bayeux.server.ServerChannel


        }

        public void process(final Exchange exchange) {
            String channelName = producer.getEndpoint().getPath();
            BayeuxServerImpl bayeux = producer.getBayeux();
            ServerChannel channel = bayeux.getChannel(channelName);
            ServerSession serverSession = getServerSession();

            try {
                if (channel != null) {
                    logDelivery(exchange, channel);
                    ServerMessage.Mutable mutable = binding.createCometdMessage(channel, serverSession,
                                                                                exchange.getIn());
                    channel.publish(serverSession, mutable);
                }
            } finally {
                if (disconnectLocalSession && serverSession.isLocalSession()) {
                    LOG.trace("Disconnection local session {}", serverSession);
                    serverSession.disconnect();
View Full Code Here


    @Override
    protected void doStop() throws Exception
    {
        oort.deobserveChannel(broadcastChannelName);
        BayeuxServer bayeuxServer = oort.getBayeuxServer();
        ServerChannel channel = bayeuxServer.getChannel(resultChannelName);
        if (channel != null)
            channel.removeListener(this);
        channel = bayeuxServer.getChannel(broadcastChannelName);
        if (channel != null)
            channel.removeListener(this);
        channel = bayeuxServer.getChannel(forwardChannelName);
        if (channel != null)
            channel.removeListener(this);
        session.disconnect();
        if (logger.isDebugEnabled())
            logger.debug("Stopped {}", this);
    }
View Full Code Here

        _clientComets.clear();

        _serverComets.clear();
        _channels.clear();

        ServerChannel channel = _bayeux.getChannel(OORT_SERVICE_CHANNEL);
        if (channel != null)
            channel.removeListener(_joinListener);

        channel = _bayeux.getChannel(OORT_CLOUD_CHANNEL);
        if (channel != null)
        {
            channel.removeListener(_cloudListener);
            channel.removeAuthorizer(GrantAuthorizer.GRANT_ALL);
        }

        Extension ackExtension = _ackExtension;
        _ackExtension = null;
        if (ackExtension != null)
View Full Code Here

        // Test publish triggered by a message sent by the client
        // There will be a response pending so the case is different
        publishLatch.set(new CountDownLatch(1));
        connectLatch.set(new CountDownLatch(1));
        String serviceChannelName = "/service/test";
        final ServerChannel serviceChannel = bayeux.createChannelIfAbsent(serviceChannelName, new Persistent()).getReference();
        serviceChannel.addListener(new ServerChannel.MessageListener()
        {
            public boolean onMessage(ServerSession from, ServerChannel channel, ServerMessage.Mutable message)
            {
                bayeux.getChannel(channelName).publish(emitter, data);
                return true;
View Full Code Here

        // There will be a response pending so the case is different
        // from the server-side publish
        publishLatch.set(new CountDownLatch(1));
        connectLatch.set(new CountDownLatch(1));
        String serviceChannelName = "/service/test";
        ServerChannel serviceChannel = bayeux.createChannelIfAbsent(serviceChannelName, new Persistent()).getReference();
        serviceChannel.addListener(new ServerChannel.MessageListener()
        {
            public boolean onMessage(ServerSession from, ServerChannel channel, ServerMessage.Mutable message)
            {
                bayeux.getChannel(channelName).publish(emitter, data);
                return true;
View Full Code Here

        // Test publish triggered by a message sent by the client
        // There will be a response pending so the case is different
        publishLatch.set(new CountDownLatch(1));
        connectLatch.set(new CountDownLatch(1));
        String serviceChannelName = "/service/test";
        final ServerChannel serviceChannel = bayeux.createChannelIfAbsent(serviceChannelName, new Persistent()).getReference();
        serviceChannel.addListener(new ServerChannel.MessageListener()
        {
            public boolean onMessage(ServerSession from, ServerChannel channel, ServerMessage.Mutable message)
            {
                bayeux.getChannel(channelName).publish(emitter, data);
                return 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());

        // Give time to the /meta/connect to tell the server what is the current ack number
        Thread.sleep(1000);

        int port = connector.getLocalPort();
        connector.stop();
        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

        final AtomicReference<ServerMessage> messageRef = new AtomicReference<>();

        ListenUnlistenService s = new ListenUnlistenService(sessionRef, messageRef);
        boolean processed = processor.process(s);
        assertTrue(processed);
        ServerChannel channel = bayeuxServer.getChannel("/foo");
        assertNotNull(channel);
        assertEquals(1, channel.getListeners().size());

        // Fake a publish
        LocalSession remote = bayeuxServer.newLocalSession("remote");
        remote.handshake();
        ServerMessage.Mutable message = bayeuxServer.newMessage();
        message.setChannel(channel.getId());
        bayeuxServer.handle((ServerSessionImpl)remote.getServerSession(), message);

        assertNotNull(sessionRef.get());
        assertSame(sessionRef.get(), remote.getServerSession());
        assertNotNull(messageRef.get());

        processed = processor.deprocessCallbacks(s);
        assertTrue(processed);

        // Fake another publish
        sessionRef.set(null);
        messageRef.set(null);
        message = bayeuxServer.newMessage();
        message.setChannel(channel.getId());
        bayeuxServer.handle((ServerSessionImpl)remote.getServerSession(), message);

        assertNull(sessionRef.get());
        assertNull(messageRef.get());

        // Be sure the channel is removed after few sweeps
        for (int i = 0; i < 3; ++i)
            bayeuxServer.sweep();
        assertNull(bayeuxServer.getChannel(channel.getId()));
    }
View Full Code Here

        if (!ServerSession.class.isAssignableFrom(candidate.getParameterTypes()[0]))
            throw new IllegalArgumentException("Service method '" + methodName + "' does not have " + ServerSession.class.getName() + " as first parameter");
        if (!ServerMessage.class.isAssignableFrom(candidate.getParameterTypes()[1]))
            throw new IllegalArgumentException("Service method '" + methodName + "' does not have " + ServerMessage.class.getName() + " as second parameter");

        ServerChannel channel = _bayeux.createChannelIfAbsent(channelName).getReference();
        Invoker invoker = new Invoker(channelName, candidate);
        channel.addListener(invoker);
        invokers.put(methodName, invoker);
    }
View Full Code Here

     * @see #addService(String, String)
     * @see #removeService(String)
     */
    protected void removeService(String channelName, String methodName)
    {
        ServerChannel channel = _bayeux.getChannel(channelName);
        if (channel != null)
        {
            Invoker invoker = invokers.remove(methodName);
            channel.removeListener(invoker);
        }
    }
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.