|
What this is
Other links
The source code
package org.mortbay.cometd;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.mortbay.util.ajax.JSON;
import dojox.cometd.Bayeux;
import dojox.cometd.Message;
public class MessageImpl extends HashMap<String, Object> implements Message, org.mortbay.util.ajax.JSON.Generator
{
MessagePool _pool;
String _clientId;
String _json;
String _channel;
String _id;
Object _data;
Message _associated;
AtomicInteger _refs=new AtomicInteger();
/* ------------------------------------------------------------ */
public MessageImpl()
{
super(8);
}
/* ------------------------------------------------------------ */
public MessageImpl(MessagePool bayeux)
{
super(8);
_pool=bayeux;
}
/* ------------------------------------------------------------ */
public void incRef()
{
_refs.getAndIncrement();
}
/* ------------------------------------------------------------ */
public void decRef()
{
int r= _refs.decrementAndGet();
if (r==0 && _pool!=null)
_pool.recycleMessage(this);
else if (r<0)
throw new IllegalStateException();
}
/* ------------------------------------------------------------ */
public String getChannel()
{
return _channel;
}
/* ------------------------------------------------------------ */
public String getClientId()
{
if (_clientId==null)
_clientId=(String)get(Bayeux.CLIENT_FIELD);
return _clientId;
}
/* ------------------------------------------------------------ */
public String getId()
{
return _id;
}
/* ------------------------------------------------------------ */
public Object getData()
{
return _data;
}
/* ------------------------------------------------------------ */
public void addJSON(StringBuffer buffer)
{
buffer.append(getJSON());
}
/* ------------------------------------------------------------ */
public String getJSON()
{
if (_json==null)
{
JSON json=_pool==null?JSON.getDefault():_pool.getMsgJSON();
StringBuffer buf = new StringBuffer(json.getStringBufferSize());
synchronized(buf)
{
json.appendMap(buf,this);
_json=buf.toString();
}
}
return _json;
}
/* ------------------------------------------------------------ */
/* (non-Javadoc)
* @see java.util.HashMap#clear()
*/
public void clear()
{
_json=null;
_id=null;
_channel=null;
_clientId=null;
setAssociated(null);
_refs.set(0);
Iterator<Map.Entry
|
Copyright 1998-2008 Alvin Alexander
All Rights Reserved.
devdaily.com is based in louisville, kentucky, and this web site is hosted by godaddy.com