Package org.cometd

Examples of org.cometd.Message


   
    /* ------------------------------------------------------------ */
    public void deliver(Client from, String toChannel, Object data, String id)
    {
        // TODO recycle maps
        Message message=_bayeux.newMessage();
        message.put(Bayeux.CHANNEL_FIELD,toChannel);
        message.put(Bayeux.DATA_FIELD,data);
        if (id!=null)  
            message.put(Bayeux.ID_FIELD,id);

        message=_bayeux.extendSendBayeux(from,message);
        if (message!=null)
            doDelivery(from,message);
       
View Full Code Here


                for (Message message : messages)
                    ((MessageImpl)message).decRef();
            }
        }

        Message pollReply=null;
        // Do we need to wait for messages
        if (transport!=null)
        {
            pollReply=transport.getPollReply();
            if (pollReply!=null)
            {
                if (_bayeux.isLogDebug())
                    _bayeux.logDebug("doPost: transport is polling");
                long timeout=client.getTimeout();
                if (timeout==0)
                    timeout=_bayeux.getTimeout();

                Continuation continuation=ContinuationSupport.getContinuation(request,client);

                // Get messages or wait
                synchronized (client)
                {
                    if (!client.hasMessages() && !continuation.isPending()&& received<=1)
                    {
                        // save state and suspend
                        ((ContinuationClient)client).setContinuation(continuation);
                        request.setAttribute(CLIENT_ATTR,client);
                        request.setAttribute(TRANSPORT_ATTR,transport);
                        continuation.suspend(timeout);
                    }

                    if (!continuation.isPending())
                        client.access();

                    continuation.reset();
                }

                ((ContinuationClient)client).setContinuation(null);
                transport.setPollReply(null);

                pollReply=_bayeux.extendSendMeta(client,pollReply);
            }
            else if (client!=null)
            {
                client.access();
            }
        }

        // Send any messages.
        if (client!=null)
        {
            synchronized(client)
            {
                client.doDeliverListeners();
                ArrayQueue<Message> messages= (ArrayQueue)client.getQueue();
                int size=messages.size();
                boolean flushed=false;
                boolean shouldSendMessages= !( pollReply == null && client.isDeliverViaMetaConnectOnly() );

                try
                {
                    if (pollReply!=null)
                    {
                        // can we bypass response generation?
                        if (_refsThreshold>0 && size==1 && transport instanceof JSONTransport)
                        {
                            MessageImpl message = (MessageImpl)messages.peek();

                            // is there a response already prepared
                            ByteBuffer buffer = message.getBuffer();
                            if (buffer!=null)
                            {
                                request.setAttribute("org.mortbay.jetty.ResponseBuffer",buffer);
                                ((MessageImpl)message).decRef();
                                pollReply=null;
                                flushed=true;
                            }
                            else if (message.getRefs()>=_refsThreshold)
                            {
                                byte[] contentBytes = ("["+message.getJSON()+",{\""+Bayeux.SUCCESSFUL_FIELD+"\":true,\""+
                                        Bayeux.CHANNEL_FIELD+"\":\""+Bayeux.META_CONNECT+"\"}]")
                                        .getBytes(StringUtil.__UTF8);
                                int contentLength = contentBytes.length;

                                String headerString = "HTTP/1.1 200 OK\r\n"+
                                "Content-Type: text/json; charset=utf-8\r\n" +
                                "Content-Length: " + contentLength + "\r\n" +
                                "\r\n";

                                byte[] headerBytes = headerString.getBytes(StringUtil.__UTF8);

                                buffer = ByteBuffer.allocateDirect(headerBytes.length+contentLength);
                                buffer.put(headerBytes);
                                buffer.put(contentBytes);
                                buffer.flip();

                                message.setBuffer(buffer);
                                request.setAttribute("org.mortbay.jetty.ResponseBuffer",buffer);
                                ((MessageImpl)message).decRef();
                                pollReply=null;
                                flushed=true;
                            }
                        }
                    }

                    if (!flushed)
                    {
                        if ( shouldSendMessages )
                        {
                            Message message = null;
                            for (int i = 0;i<size;i++)
                            {
                                message=messages.getUnsafe(i);
                                message=_bayeux.extendSendClient(null, client, message);
                                if (message!=null)
View Full Code Here

    /* (non-Javadoc)
     * @see dojox.cometd.Client#deliver(dojox.cometd.Client, java.lang.String, java.lang.Object, java.lang.String)
     */
    public void deliver(Client from, String toChannel, Object data, String id)
    {
        Message message = new MessageImpl();

        message.put(Bayeux.CHANNEL_FIELD,toChannel);
        message.put(Bayeux.DATA_FIELD,data);
        if (id!=null)
            message.put(Bayeux.ID_FIELD,id);

        synchronized (_inQ)
        {
            if (_mListeners==null)
                _inQ.add(message);
View Full Code Here

    /* (non-Javadoc)
     * @see dojox.cometd.Client#publish(java.lang.String, java.lang.Object, java.lang.String)
     */
    public void publish(String toChannel, Object data, String msgId)
    {
        Message msg=new MessageImpl();
        msg.put(Bayeux.CHANNEL_FIELD,toChannel);
        msg.put(Bayeux.DATA_FIELD,data);
        if (msgId!=null)
            msg.put(Bayeux.ID_FIELD,msgId);
        publish(msg);
    }
View Full Code Here

    /* (non-Javadoc)
     * @see dojox.cometd.Client#subscribe(java.lang.String)
     */
    public void subscribe(String toChannel)
    {
        Message msg=new MessageImpl();
        msg.put(Bayeux.CHANNEL_FIELD,Bayeux.META_SUBSCRIBE);
        msg.put(Bayeux.SUBSCRIPTION_FIELD,toChannel);
        publish(msg);
    }
View Full Code Here

    /* (non-Javadoc)
     * @see dojox.cometd.Client#unsubscribe(java.lang.String)
     */
    public void unsubscribe(String toChannel)
    {
        Message msg=new MessageImpl();
        msg.put(Bayeux.CHANNEL_FIELD,Bayeux.META_UNSUBSCRIBE);
        msg.put(Bayeux.SUBSCRIPTION_FIELD,toChannel);
        publish(msg);
    }
View Full Code Here

    /* (non-Javadoc)
     * @see dojox.cometd.Client#remove(boolean)
     */
    public void remove(boolean timeout)
    {
        Message msg=new MessageImpl();
        msg.put(Bayeux.CHANNEL_FIELD,Bayeux.META_DISCONNECT);

        synchronized (_outQ)
        {
            _outQ.add(msg);

View Full Code Here

                {
                    startBatch();

                    for (int i=0; i<_responses.length; i++)
                    {
                        Message msg=(Message)_responses[i];

                        if (Bayeux.META_CONNECT.equals(msg.get(Bayeux.CHANNEL_FIELD)))
                        {
                            Boolean successful=(Boolean)msg.get(Bayeux.SUCCESSFUL_FIELD);
                            if (successful!=null&&successful.booleanValue())
                            {
                                if (!_initialized)
                                {
                                    _initialized=true;
View Full Code Here

                if (getResponseStatus()==200&&_responses!=null&&_responses.length>0)
                {

                    for (int i=0; i<_responses.length; i++)
                    {
                        Message msg=(Message)_responses[i];
                        deliver(null,msg);
                    }
                }
                else
                {
View Full Code Here

    /* ------------------------------------------------------------ */
    public void deliver(Client from, String toChannel, Object data, String id)
    {
        // TODO recycle maps
        Message message=_bayeux.newMessage();
        message.put(Bayeux.CHANNEL_FIELD,toChannel);
        message.put(Bayeux.DATA_FIELD,data);
        if (id!=null)  
            message.put(Bayeux.ID_FIELD,id);

        for (Extension e:_bayeux._extensions)
            message=e.send(message);
        doDelivery(from,message);
       
View Full Code Here

TOP

Related Classes of org.cometd.Message

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.