Package org.cometd.bayeux.server

Examples of org.cometd.bayeux.server.ServerMessage


    @Test
    public void testSessionHeadersAdded() throws Exception {
        // setup
        when(endpoint.areSessionHeadersEnabled()).thenReturn(true);
        testObj.start();
        ServerMessage cometdMessage = mock(ServerMessage.class);
        Exchange exchange = mock(Exchange.class);
        when(endpoint.createExchange()).thenReturn(exchange);
        ArgumentCaptor<Message> transferredMessage = ArgumentCaptor.forClass(Message.class);

        // act
View Full Code Here


                if (!to.extendSendMeta(reply))
                    return null;
            }
            else
            {
                ServerMessage newReply = to.extendSendMessage(reply);
                if (newReply == null)
                {
                    reply = null;
                }
                else if (newReply != reply)
View Full Code Here

        if (callback != null)
            message.put(CALLBACK_KEY, callback);

        doSend(session, message);

        ServerMessage reply = message.getAssociated();
        if (reply != null && reply.isSuccessful())
        {
            message = _bayeux.newMessage();
            message.setChannel(Channel.META_CONNECT);
            message.getAdvice(true).put(Message.INTERVAL_FIELD, -1L);
            message.setClientId(session.getId());

            doSend(session, message);

            reply = message.getAssociated();
            if (reply != null && reply.isSuccessful())
            {
                _session = session;
                _sessionId = session.getId();
            }
        }
View Full Code Here

    private ServerMessage.Mutable notifySend(Extension extension, ServerMessage.Mutable message)
    {
        try
        {
            ServerMessage result = extension.send(this, message);
            if (result instanceof ServerMessage.Mutable)
                return (ServerMessage.Mutable)result;
            else
                return _bayeux.newMessage(result);
        }
View Full Code Here

                    public void deQueue(ServerSession session, Queue<ServerMessage> queue)
                    {
                        long lastTimeStamp = 0;
                        for (Iterator<ServerMessage> iterator = queue.iterator(); iterator.hasNext();)
                        {
                            ServerMessage message = iterator.next();
                            if (channelName.equals(message.getChannel()))
                            {
                                long timeStamp = Long.parseLong(message.get(Message.TIMESTAMP_FIELD).toString());
                                if (timeStamp <= lastTimeStamp + toleranceSeconds)
                                {
                                    System.err.println("removed " + message);
                                    iterator.remove();
                                }
View Full Code Here

    }

    @Override
    public boolean sendMeta(ServerSession session, Mutable message)
    {
        ServerMessage associated=message.getAssociated();
        if (associated != null)
        {
            Map<String,Object> extIn=associated.getExt();

            if (extIn != null)
            {
                Map<String,Object> sync=(Map<String,Object>)extIn.get("timesync");
                if (sync != null)
View Full Code Here

                output = beginWrite(request, response);

                // Write the messages first.
                for (int i = 0; i < messages.size(); ++i)
                {
                    ServerMessage message = messages.get(i);
                    if (i > 0)
                        output.print(",");
                    writeMessage(response, output, session, message);
                }
            }
            finally
            {
                // Start the interval timeout after writing the messages
                // since they may take time to be written, even in case
                // of exceptions to make sure the session can be swept.
                if (startInterval && session != null && session.isConnected())
                    session.startIntervalTimeout(getInterval());
            }

            // Write the replies, if any.
            boolean needsComma = !messages.isEmpty();
            for (int i = 0; i < replies.length; ++i)
            {
                ServerMessage reply = replies[i];
                if (reply == null)
                    continue;
                if (needsComma)
                    output.print(",");
                needsComma = true;
View Full Code Here

            StringBuilder builder = new StringBuilder(capacity);
            builder.append("[");
            if (batch == 1)
            {
                // Common path.
                ServerMessage serverMessage = messages.remove(0);
                builder.append(serverMessage.getJSON());
            }
            else
            {
                boolean comma = false;
                for (int b = 0; b < batch; ++b)
                {
                    ServerMessage serverMessage = messages.get(b);
                    if (comma)
                        builder.append(",");
                    comma = true;
                    builder.append(serverMessage.getJSON());
                }
                if (batch == size)
                    messages.clear();
                else
                    messages.subList(0, batch).clear();
View Full Code Here

TOP

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

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.