Package org.cometd.bayeux.server

Examples of org.cometd.bayeux.server.ServerSession


        for (String peerName : peerNames)
        {
            String peerId = membersMap.get(peerName);
            if (peerId!=null)
            {
                ServerSession peer = _bayeux.getSession(peerId);
                if (peer!=null)
                    peers.add(peer);
            }
        }

        if (peers.size() > 0)
        {
            Map<String, Object> chat = new HashMap<>();
            String text=(String)data.get("chat");
            chat.put("chat", text);
            chat.put("user", data.get("user"));
            chat.put("scope", "private");
            ServerMessage.Mutable forward = _bayeux.newMessage();
            forward.setChannel("/chat/"+room);
            forward.setId(message.getId());
            forward.setData(chat);

            // test for lazy messages
            if (text.lastIndexOf("lazy")>0)
                forward.setLazy(true);

            for (ServerSession peer : peers)
                if (peer!=client)
                    peer.deliver(_session, forward);
            client.deliver(_session, forward);
        }
    }
View Full Code Here


        return session;
    }

    private boolean processSession(Object bean, LocalSession localSession)
    {
        ServerSession serverSession = localSession.getServerSession();

        boolean result = false;
        for (Class<?> c = bean.getClass(); c != Object.class; c = c.getSuperclass())
        {
            Field[] fields = c.getDeclaredFields();
            for (Field field : fields)
            {
                if (field.getAnnotation(Session.class) != null)
                {
                    Object value = null;
                    if (field.getType().isAssignableFrom(localSession.getClass()))
                        value = localSession;
                    else if (field.getType().isAssignableFrom(serverSession.getClass()))
                        value = serverSession;

                    if (value != null)
                    {
                        setField(bean, field, value);
                        result = true;
                        if (logger.isDebugEnabled())
                            logger.debug("Injected {} to field {} on bean {}", value, field, bean);
                    }
                }
            }

            Method[] methods = c.getDeclaredMethods();
            for (Method method : methods)
            {
                if (method.getAnnotation(Session.class) != null)
                {
                    Class<?>[] parameterTypes = method.getParameterTypes();
                    if (parameterTypes.length == 1)
                    {
                        Object value = null;
                        if (parameterTypes[0].isAssignableFrom(localSession.getClass()))
                            value = localSession;
                        else if (parameterTypes[0].isAssignableFrom(serverSession.getClass()))
                            value = serverSession;

                        if (value != null)
                        {
                            invokePrivate(bean, method, value);
View Full Code Here

                "\"connectionType\": \"long-polling\"" +
                "}]");
        response = connect.send();
        Assert.assertEquals(200, response.getStatus());

        ServerSession serverSession = bayeux.getSession(clientId);
        Assert.assertNotNull(serverSession);

        Request connect2 = newBayeuxRequest("[{" +
                "\"channel\": \"/meta/connect\"," +
                "\"clientId\": \"" + clientId + "\"," +
                "\"connectionType\": \"long-polling\"" +
                "}]");

        FutureResponseListener listener = new FutureResponseListener(connect2);
        connect2.send(listener);

        // Wait for the /meta/connect to be suspended
        Thread.sleep(1000);

        final CountDownLatch latch = new CountDownLatch(1);
        serverSession.addListener(new ServerSession.RemoveListener()
        {
            @Override
            public void removed(ServerSession session, boolean timeout)
            {
                latch.countDown();
View Full Code Here

    @Test
    public void testSessionAttributes() throws Exception
    {
        LocalSession local = _bayeux.newLocalSession("s0");
        local.handshake();
        ServerSession session = local.getServerSession();

        local.setAttribute("foo","bar");
        Assert.assertEquals("bar",local.getAttribute("foo"));
        Assert.assertEquals(null,session.getAttribute("foo"));

        session.setAttribute("bar","foo");
        Assert.assertEquals(null,local.getAttribute("bar"));
        Assert.assertEquals("foo",session.getAttribute("bar"));

        Assert.assertTrue(local.getAttributeNames().contains("foo"));
        Assert.assertFalse(local.getAttributeNames().contains("bar"));
        Assert.assertFalse(session.getAttributeNames().contains("foo"));
        Assert.assertTrue(session.getAttributeNames().contains("bar"));

        Assert.assertEquals("bar",local.removeAttribute("foo"));
        Assert.assertEquals(null,local.removeAttribute("foo"));
        Assert.assertEquals("foo",session.removeAttribute("bar"));
        Assert.assertEquals(null,local.removeAttribute("bar"));
    }
View Full Code Here

        Assert.assertEquals(2,_bayeux.getChannel("/foo/bar").getSubscribers().size());

        Assert.assertTrue(session0.isConnected());
        Assert.assertTrue(session1.isConnected());
        Assert.assertTrue(session2.isConnected());
        ServerSession ss0=session0.getServerSession();
        ServerSession ss1=session1.getServerSession();
        ServerSession ss2=session2.getServerSession();
        Assert.assertTrue(ss0.isConnected());
        Assert.assertTrue(ss1.isConnected());
        Assert.assertTrue(ss2.isConnected());

        session0.disconnect();
        Assert.assertFalse(session0.isConnected());
        Assert.assertFalse(ss0.isConnected());

        session1.getServerSession().disconnect();
        Assert.assertFalse(session1.isConnected());
        Assert.assertFalse(ss1.isConnected());

        session2.getServerSession().disconnect();
        Assert.assertFalse(session2.isConnected());
        Assert.assertFalse(ss2.isConnected());
    }
View Full Code Here

        output.write(request.getBytes("UTF-8"));
        output.write(content);
        output.flush();

        final CountDownLatch removeLatch = new CountDownLatch(1);
        ServerSession session = bayeux.getSession(clientId);
        session.addListener(new ServerSession.RemoveListener()
        {
            @Override
            public void removed(ServerSession session, boolean timeout)
            {
                removeLatch.countDown();
View Full Code Here

                "\"connectionType\": \"long-polling\"" +
                "}]");
        response = connect1.send();
        Assert.assertEquals(200, response.getStatus());

        ServerSession serverSession = bayeux.getSession(clientId);
        Assert.assertNotNull(serverSession);

        Request connect2 = newBayeuxRequest("[{" +
                "\"channel\": \"/meta/connect\"," +
                "\"clientId\": \"" + clientId + "\"," +
View Full Code Here

                connectRequestLatch.countDown();
        }

        public void disconnect(String sessionId)
        {
            ServerSession session = getBayeux().getSession(sessionId);
            session.disconnect();
        }
View Full Code Here

        {
            final ServerMessage.Mutable kickMessage = getBayeux().newMessage();
            kickMessage.setChannel(channelName);
            kickMessage.setData(new HashMap());

            final ServerSession session = getBayeux().getSession(sessionId);

            // We need to batch otherwise the deliver() will wake up the long poll
            // and the disconnect may not be delivered, since the client won't issue
            // a new long poll, and the disconnect will remain in the queue
            session.batch(new Runnable()
            {
                public void run()
                {
                    session.deliver(getServerSession(), kickMessage);
                    session.disconnect();
                }
            });
        }
View Full Code Here

        evaluateScript("cometd.handshake();");
        Assert.assertTrue(subscribeLatch.await(5000));

        String sessionId = evaluateScript("cometd.getClientId();");
        ServerSession session = bayeuxServer.getSession(sessionId);
        session.deliver(null, channelName, content);

        Assert.assertTrue(messageLatch.await(5000));
    }
View Full Code Here

TOP

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

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.