Package org.cometd

Examples of org.cometd.Message


     * @param data
     * @param msgId
     */
    protected void doPublish(ChannelId to, Client from, Object data, String msgId)
    {
        Message message = newMessage();
        message.put(CHANNEL_FIELD,to.toString());

        if (msgId==null)
        {
            long id=message.hashCode()
            ^(to==null?0:to.hashCode())
            ^(from==null?0:from.hashCode());
            id=id<0?-id:id;
            message.put(ID_FIELD,Long.toString(id,36));
        }
        else
            message.put(ID_FIELD,msgId);
        message.put(DATA_FIELD,data);

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


            }

            // reply to connect message
            String id=message.getId();

            Message reply=newMessage(message);

            reply.put(CHANNEL_FIELD,META_CONNECT);
            reply.put(SUCCESSFUL_FIELD,Boolean.TRUE);
            if (advice!=null)
                reply.put(ADVICE_FIELD,advice);
            if (id!=null)
                reply.put(ID_FIELD,id);

            if (polling)
                transport.setPollReply(reply);
            else
            {
View Full Code Here

            if (isLogInfo())
                logInfo("Disconnect "+client.getId());

            client.remove(false);

            Message reply=newMessage(message);
            reply.put(CHANNEL_FIELD,META_DISCONNECT);
            reply.put(SUCCESSFUL_FIELD,Boolean.TRUE);
            String id=message.getId();
            if (id!=null)
                reply.put(ID_FIELD,id);

            reply=extendSendMeta(client,reply);

            Message pollReply = transport.getPollReply();
            if (pollReply!=null)
            {
                pollReply=extendSendMeta(client,pollReply);
                if (pollReply!=null)
                    transport.send(pollReply);
View Full Code Here

            if (client!=null)
                throw new IllegalStateException();

            if (_securityPolicy!=null && !_securityPolicy.canHandshake(message))
            {
                Message reply=newMessage(message);
                reply.put(CHANNEL_FIELD,META_HANDSHAKE);
                reply.put(SUCCESSFUL_FIELD,Boolean.FALSE);
                reply.put(ERROR_FIELD,"403::Handshake denied");

                reply=extendSendBayeux(client,reply);
                if (reply!=null)
                    transport.send(reply);
                return;
            }

            client=newRemoteClient();

            Message reply=newMessage(message);
            reply.put(CHANNEL_FIELD, META_HANDSHAKE);
            reply.put(VERSION_FIELD, "1.0");
            reply.put(MIN_VERSION_FIELD, "0.9");

            if (client!=null)
            {
                reply.put(SUPP_CONNECTION_TYPE_FIELD, _transports);
                reply.put(SUCCESSFUL_FIELD, Boolean.TRUE);
                reply.put(CLIENT_FIELD, client.getId());
                if (_advice!=null)
                    reply.put(ADVICE_FIELD,_advice);
            }
            else
            {
                reply.put(Bayeux.SUCCESSFUL_FIELD,Boolean.FALSE);
                if (_advice!=null)
                    reply.put(ADVICE_FIELD,_advice);
            }

            if (isLogDebug())
                logDebug("handshake.handle: reply="+reply);

            String id=message.getId();
            if (id!=null)
                reply.put(ID_FIELD,id);

            reply=extendSendMeta(client,reply);
            if (reply!=null)
                transport.send(reply);
        }
View Full Code Here

            String id=message.getId();

            ChannelId cid=getChannelId(channel_id);
            Object data=message.get(Bayeux.DATA_FIELD);

            Message reply=newMessage(message);
            reply.put(CHANNEL_FIELD,channel_id);
            if (id!=null)
                reply.put(ID_FIELD,id);

            if (data!=null&&_securityPolicy.canPublish(client,channel_id,message))
            {
                message.remove(CLIENT_FIELD);
                message=extendSendBayeux(client,message);
               
                if (message!=null)
                {
                    reply.put(SUCCESSFUL_FIELD,Boolean.TRUE);
                }
                else
                {
                    reply.put(SUCCESSFUL_FIELD,Boolean.FALSE);
                    reply.put(ERROR_FIELD,"404::Message deleted");
                }
            }
            else
            {
                message=null;
                reply.put(SUCCESSFUL_FIELD,Boolean.FALSE);
                reply.put(ERROR_FIELD,"403::Publish denied");
            }

            reply=extendSendBayeux(client,reply);
            if (reply!=null)
                transport.send(reply);
View Full Code Here

            {
                cid=getChannelId(subscribe_id);
                can_subscribe=_securityPolicy.canSubscribe(client,subscribe_id,message);
            }

            Message reply=newMessage(message);
            reply.put(CHANNEL_FIELD,META_SUBSCRIBE);
            reply.put(SUBSCRIPTION_FIELD,subscribe_id);

            if (can_subscribe)
            {
                if (cid!=null)
                {
                    ChannelImpl channel=getChannel(cid);
                    if (channel==null&&_securityPolicy.canCreate(client,subscribe_id,message))
                        channel=(ChannelImpl)getChannel(subscribe_id, true);

                    if (channel!=null)
                        channel.subscribe(client);
                    else
                        can_subscribe=false;
                }

                if (can_subscribe)
                {
                    reply.put(SUCCESSFUL_FIELD,Boolean.TRUE);
                }
                else
                {
                    reply.put(SUCCESSFUL_FIELD,Boolean.FALSE);
                    reply.put(ERROR_FIELD,"403::cannot create");
                }
            }
            else
            {
                reply.put(SUCCESSFUL_FIELD,Boolean.FALSE);
                reply.put(ERROR_FIELD,"403::cannot subscribe");

            }

            String id=message.getId();
            if (id!=null)
                reply.put(ID_FIELD,id);

            reply=extendSendMeta(client,reply);
            if (reply!=null)
                transport.send(reply);
        }
View Full Code Here

            String channel_id=(String)message.get(SUBSCRIPTION_FIELD);
            ChannelImpl channel=getChannel(channel_id);
            if (channel!=null)
                channel.unsubscribe(client);

            Message reply=newMessage(message);
            reply.put(CHANNEL_FIELD,META_UNSUBSCRIBE);
            reply.put(SUBSCRIPTION_FIELD,channel.getId());
            reply.put(SUCCESSFUL_FIELD,Boolean.TRUE);

            String id=message.getId();
            if (id!=null)
                reply.put(ID_FIELD,id);
            reply=extendSendMeta(client,reply);
            if (reply!=null)
                transport.send(reply);
        }
View Full Code Here

        }

        @Override
        public void handle(ClientImpl client, Transport transport, Message message) throws IOException
        {
            Message reply=newMessage(message);
            reply.put(CHANNEL_FIELD,META_PING);
            reply.put(SUCCESSFUL_FIELD,Boolean.TRUE);

            String id=message.getId();
            if (id!=null)
                reply.put(ID_FIELD,id);

            reply=extendSendMeta(client,reply);
            if (reply!=null)
                transport.send(reply);
        }
View Full Code Here

    public Message sendMeta(Client from, Message message)
    {
        if (message.getChannel().equals(Bayeux.META_HANDSHAKE) && Boolean.TRUE.equals(message.get(Bayeux.SUCCESSFUL_FIELD)))
        {
            Message rcv = message.getAssociated();
           
            Map<String, Object> ext = rcv.getExt(false);
            boolean clientRequestedAcks = ext != null && ext.get("ack") != null;

            if (clientRequestedAcks && from!=null) {
                Log.info("Enabled message acknowledgement for client " + from);
                from.addExtension(new AcknowledgedMessagesClientExtension());
View Full Code Here

        return message;
    }

    public Message sendMeta(Client from, Message message)
    {
        Message associated = message.getAssociated();
        if (associated!=null)
        {
            Map<String,Object> extIn=associated.getExt(false);
           
            if (extIn!=null)
            {
                Map<String,Object> sync=(Map<String,Object>)extIn.get("timesync");
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.