📄 clientimpl.java
字号:
{ if (_bayeux.hasClient(_id)) remove(false); } } /* ------------------------------------------------------------ */ /* (non-Javadoc) * @see dojox.cometd.Client#remove(boolean) */ public void remove(boolean timeout) { Client client=_bayeux.removeClient(_id); if (client!=null && _bayeux.isLogInfo()) _bayeux.logInfo("Remove client "+client+" timeout="+timeout); final String browser_id; final RemoveListener[] listeners; synchronized(this) { browser_id=_browserId; _browserId=null; listeners=_rListeners; } if (browser_id!=null) _bayeux.clientOffBrowser(browser_id,_id); if (listeners!=null) for (RemoveListener l:listeners) l.removed(_id, timeout); resume(); } /* ------------------------------------------------------------ */ public int responded() { synchronized(this) { return _responsesPending--; } } /* ------------------------------------------------------------ */ public int responsePending() { synchronized(this) { return ++_responsesPending; } } /* ------------------------------------------------------------ */ /** Called by deliver to resume anything waiting on this client. */ public void resume() { } /* ------------------------------------------------------------ */ /* * @return the number of messages queued */ public int getMessages() { return _queue.size(); } /* ------------------------------------------------------------ */ public List<Message> takeMessages() { synchronized(this) { ArrayList<Message> list = new ArrayList<Message>(_queue); _queue.clear(); return list; } } /* ------------------------------------------------------------ */ public void returnMessages(List<Message> messages) { synchronized(this) { _queue.addAll(0,messages); } } /* ------------------------------------------------------------ */ @Override public String toString() { return _id; } /* ------------------------------------------------------------ */ protected void addSubscription(ChannelImpl channel) { synchronized (this) { _subscriptions=(ChannelImpl[])LazyList.addToArray(_subscriptions,channel,null); } } /* ------------------------------------------------------------ */ protected void removeSubscription(ChannelImpl channel) { synchronized (this) { _subscriptions=(ChannelImpl[])LazyList.removeFromArray(_subscriptions,channel); } } /* ------------------------------------------------------------ */ protected void setConnectionType(String type) { synchronized (this) { _type=type; } } /* ------------------------------------------------------------ */ protected void setId(String id) { synchronized (this) { _id=id; } } /* ------------------------------------------------------------ */ protected void unsubscribeAll() { ChannelImpl[] subscriptions; synchronized(this) { _queue.clear(); subscriptions=_subscriptions; _subscriptions=new ChannelImpl[0]; } for (ChannelImpl channel : subscriptions) channel.unsubscribe(this); } /* ------------------------------------------------------------ */ public void setBrowserId(String id) { if (_browserId!=null && !_browserId.equals(id)) _bayeux.clientOffBrowser(_browserId,_id); _browserId=id; if (_browserId!=null) _bayeux.clientOnBrowser(_browserId,_id); } /* ------------------------------------------------------------ */ public String getBrowserId() { return _browserId; } /* ------------------------------------------------------------ */ @Override public boolean equals(Object o) { if (!(o instanceof Client)) return false; return getId().equals(((Client)o).getId()); } /* ------------------------------------------------------------ */ /** * Get the advice specific for this Client * @return advice specific for this client or null */ public JSON.Literal getAdvice() { return _advice; } /* ------------------------------------------------------------ */ /** * @param advice specific for this client */ public void setAdvice(JSON.Literal advice) { _advice=advice; } /* ------------------------------------------------------------ */ public void addListener(ClientListener listener) { synchronized(this) { if (listener instanceof MessageListener) { if (listener instanceof MessageListener.Synchronous) _syncMListeners=(MessageListener[])LazyList.addToArray(_syncMListeners,listener,MessageListener.class); else _asyncMListeners=(MessageListener[])LazyList.addToArray(_asyncMListeners,listener,MessageListener.class); } if (listener instanceof RemoveListener) _rListeners=(RemoveListener[])LazyList.addToArray(_rListeners,listener,RemoveListener.class); if (listener instanceof QueueListener) _qListeners=(QueueListener[])LazyList.addToArray(_qListeners,listener,QueueListener.class); if (listener instanceof DeliverListener) _dListeners=(DeliverListener[])LazyList.addToArray(_dListeners,listener,DeliverListener.class); } } /* ------------------------------------------------------------ */ public void removeListener(ClientListener listener) { synchronized(this) { if (listener instanceof MessageListener) { _syncMListeners=(MessageListener[])LazyList.removeFromArray(_syncMListeners,listener); _asyncMListeners=(MessageListener[])LazyList.removeFromArray(_asyncMListeners,listener); } if (listener instanceof RemoveListener) _rListeners=(RemoveListener[])LazyList.removeFromArray(_rListeners,listener); if (listener instanceof QueueListener) _qListeners=(QueueListener[])LazyList.removeFromArray(_qListeners,listener); } } /* ------------------------------------------------------------ */ public long getTimeout() { return _timeout; } /* ------------------------------------------------------------ */ public void setTimeout(long timeoutMS) { _timeout=timeoutMS; } /* ------------------------------------------------------------ */ public void setMaxQueue(int maxQueue) { _maxQueue=maxQueue; } /* ------------------------------------------------------------ */ public int getMaxQueue() { return _maxQueue; } /* ------------------------------------------------------------ */ public Queue<Message> getQueue() { return _queue; } /* ------------------------------------------------------------ */ /** * @see org.mortbay.cometd.ext.TimesyncExtension * @return The lag in ms as measured by an extension like the TimesyncExtension */ public int getLag() { return _lag; } /* ------------------------------------------------------------ */ /** * @see org.mortbay.cometd.ext.TimesyncExtension * @param lag in ms */ public void setLag(int lag) { _lag = lag; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -