⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractbayeux.java

📁 jetty SERVER連接資料庫用的軟體
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            reply=extendSendMeta(client,reply);            if (reply!=null)            {                transport.send(reply);                if (reply instanceof MessageImpl)                    ((MessageImpl)reply).decRef();            }        }    }    /* ------------------------------------------------------------ */    /* ------------------------------------------------------------ */    protected class ConnectHandler extends Handler    {        protected String _metaChannel=META_CONNECT;        @Override        ChannelId getMetaChannelId()        {            return META_CONNECT_ID;        }        @Override        public void handle(ClientImpl client, Transport transport, Message message) throws IOException        {            if (client==null)            {                unknownClient(transport,_metaChannel);                return;            }            // is this the first connect message?            String type=client.getConnectionType();            boolean polling=true;            if (type==null)            {                type=(String)message.get(Bayeux.CONNECTION_TYPE_FIELD);                client.setConnectionType(type);                polling=false;            }            Object advice = message.get(ADVICE_FIELD);            if (advice!=null)            {                Long timeout=(Long)((Map)advice).get("timeout");                if (timeout!=null && timeout.longValue()>0)                    client.setTimeout(timeout.longValue());                else                    client.setTimeout(0);            }            else                client.setTimeout(0);            advice=null;            // Work out if multiple clients from some browser?            if (polling && _multiFrameInterval>0 && client.getBrowserId()!=null)            {                List<String> clients=clientsOnBrowser(client.getBrowserId());                int count=clients.size();                if (count>1)                {                    polling=clients.get(0).equals(client.getId());                    advice=client.getAdvice();                    if (advice==null)                        advice=_multiFrameAdvice;                    else // could probably cache this                        advice=multiFrameAdvice((JSON.Literal)advice);                }            }            synchronized(this)            {                if (advice==null)                {                    if (_adviceVersion!=client._adviseVersion)                    {                        advice=_advice;                        client._adviseVersion=_adviceVersion;                    }                }                else                    client._adviseVersion=-1; // clear so it is reset after multi state clears            }            // 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.setMetaConnnectReply(reply);            else                sendMetaReply(client,reply,transport);        }    }    /* ------------------------------------------------------------ */    /* ------------------------------------------------------------ */    protected class DisconnectHandler extends Handler    {        @Override        ChannelId getMetaChannelId()        {            return META_DISCONNECT_ID;        }        @Override        public void handle(ClientImpl client, Transport transport, Message message) throws IOException        {            if (client==null)            {                unknownClient(transport,META_DISCONNECT);                return;            }            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.getMetaConnectReply();            if (pollReply!=null)            {                transport.setMetaConnnectReply(null);                sendMetaReply(client,pollReply,transport);            }            sendMetaReply(client,reply,transport);        }    }    /* ------------------------------------------------------------ */    /* ------------------------------------------------------------ */    protected class HandshakeHandler extends Handler    {        @Override        ChannelId getMetaChannelId()        {            return META_HANDSHAKE_ID;        }        @Override        public void handle(ClientImpl client, Transport transport, Message message) throws IOException        {            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");                sendMetaReply(client,reply,transport);                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);            sendMetaReply(client,reply,transport);        }    }    /* ------------------------------------------------------------ */    /* ------------------------------------------------------------ */    protected class PublishHandler extends Handler    {        @Override        ChannelId getMetaChannelId()        {            return null;        }        @Override        public void handle(ClientImpl client, Transport transport, Message message) throws IOException        {            String channel_id=message.getChannel();            if (client==null && message.containsKey(CLIENT_FIELD))            {                unknownClient(transport,channel_id);                return;            }            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");            }            sendMetaReply(client,reply,transport);            if (message!=null)                _root.doDelivery(cid,client,message);        }    }    /* ------------------------------------------------------------ */    /* ------------------------------------------------------------ */    protected class MetaPublishHandler extends Handler    {        @Override        ChannelId getMetaChannelId()        {            return null;        }        @Override        public void handle(ClientImpl client, Transport transport, Message message) throws IOException        {            String channel_id=message.getChannel();            if (client==null && !META_HANDSHAKE.equals(channel_id))            {                // unknown client                return;            }            if(_securityPolicy.canPublish(client,channel_id,message))            {                _root.doDelivery(getChannelId(channel_id),client,message);            }        }    }    /* ------------------------------------------------------------ */    /* ------------------------------------------------------------ */    protected class SubscribeHandler extends Handler    {        @Override        ChannelId getMetaChannelId()        {            return META_SUBSCRIBE_ID;        }        @Override        public void handle(ClientImpl client, Transport transport, Message message) throws IOException        {            if (client==null)            {                unknownClient(transport,META_SUBSCRIBE);                return;            }            String subscribe_id=(String)message.get(SUBSCRIPTION_FIELD);            // select a random channel ID if none specifified            if (subscribe_id==null)            {                subscribe_id=Long.toString(getRandom(),36);                while (getChannel(subscribe_id)!=null)                    subscribe_id=Long.toString(getRandom(),36);            }            ChannelId cid=null;            boolean can_subscribe=false;            if (subscribe_id.startsWith(Bayeux.SERVICE_SLASH))            {                can_subscribe=true;            }            else if (subscribe_id.startsWith(Bayeux.META_SLASH))            {                can_subscribe=false;            }            else            {                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);            sendMetaReply(client,reply,transport);        }    }    /* ------------------------------------------------------------ */    /* ------------------------------------------------------------ */    protected class UnsubscribeHandler extends Handler    {        @Override        ChannelId getMetaChannelId()        {            return META_UNSUBSCRIBE_ID;        }        @Override        public void handle(ClientImpl client, Transport transport, Message message) throws IOException        {            if (client==null)            {                unknownClient(transport,META_UNSUBSCRIBE);                return;            }            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_id);            reply.put(SUCCESSFUL_FIELD,Boolean.TRUE);            String id=message.getId();            if (id!=null)                reply.put(ID_FIELD,id);            sendMetaReply(client,reply,transport);        }    }    /* ------------------------------------------------------------ */    /* ------------------------------------------------------------ */    protected class PingHandler extends Handler    {        @Override        ChannelId getMetaChannelId()        {            return META_PING_ID;        }        @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);            sendMetaReply(client,reply,transport);        }    }    /* ------------------------------------------------------------ */    /* ------------------------------------------------------------ */    protected class ServiceChannel extends ChannelImpl    {        ServiceChannel(String id)        {            super(id,AbstractBayeux.this);        }        /* ------------------------------------------------------------ */        /* (non-Javadoc)         * @see org.mortbay.cometd.ChannelImpl#addChild(org.mortbay.cometd.ChannelImpl)         */        @Override        public void addChild(ChannelImpl channel)        {            super.addChild(channel);            setPersistent(true);        }        /* ------------------------------------------------------------ */        @Override        public void subscribe(Client client)        {            if (client.isLocal())                super.subscribe(client);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -