Methods Summary |
---|
public static java.lang.String | bToS(byte[] data)
StringBuffer buf = new StringBuffer(4*16);
buf.append("{");
for (int i=0; data!=null && i<data.length; i++ ) buf.append(String.valueOf(data[i])).append(" ");
buf.append("}");
return buf.toString();
|
public java.lang.Object | clone()Create a shallow clone, only the data gets recreated
// byte[] d = this.getDataPackage();
// return ClusterData.getDataFromPackage(d);
ChannelData clone = new ChannelData(false);
clone.options = this.options;
clone.message = new XByteBuffer(this.message.getBytesDirect(),false);
clone.timestamp = this.timestamp;
clone.uniqueId = this.uniqueId;
clone.address = this.address;
return clone;
|
public java.lang.Object | deepclone()Complete clone
byte[] d = this.getDataPackage();
return ChannelData.getDataFromPackage(d);
|
public boolean | equals(java.lang.Object o)Compares to ChannelData objects, only compares on getUniqueId().equals(o.getUniqueId())
if ( o instanceof ChannelData ) {
return Arrays.equals(getUniqueId(),((ChannelData)o).getUniqueId());
} else return false;
|
public void | generateUUID()Generates a UUID and invokes setUniqueId
byte[] data = new byte[16];
UUIDGenerator.randomUUID(USE_SECURE_RANDOM_FOR_UUID,data,0);
setUniqueId(data);
|
public org.apache.catalina.tribes.Member | getAddress()Returns the source or reply-to address
return address;
|
public static org.apache.catalina.tribes.io.ChannelData | getDataFromPackage(XByteBuffer xbuf)Deserializes a ChannelData object from a byte array
ChannelData data = new ChannelData(false);
int offset = 0;
data.setOptions(XByteBuffer.toInt(xbuf.getBytesDirect(),offset));
offset += 4; //options
data.setTimestamp(XByteBuffer.toLong(xbuf.getBytesDirect(),offset));
offset += 8; //timestamp
data.uniqueId = new byte[XByteBuffer.toInt(xbuf.getBytesDirect(),offset)];
offset += 4; //uniqueId length
System.arraycopy(xbuf.getBytesDirect(),offset,data.uniqueId,0,data.uniqueId.length);
offset += data.uniqueId.length; //uniqueId data
//byte[] addr = new byte[XByteBuffer.toInt(xbuf.getBytesDirect(),offset)];
int addrlen = XByteBuffer.toInt(xbuf.getBytesDirect(),offset);
offset += 4; //addr length
//System.arraycopy(xbuf.getBytesDirect(),offset,addr,0,addr.length);
data.setAddress(MemberImpl.getMember(xbuf.getBytesDirect(),offset,addrlen));
//offset += addr.length; //addr data
offset += addrlen;
int xsize = XByteBuffer.toInt(xbuf.getBytesDirect(),offset);
offset += 4; //xsize length
System.arraycopy(xbuf.getBytesDirect(),offset,xbuf.getBytesDirect(),0,xsize);
xbuf.setLength(xsize);
data.message = xbuf;
return data;
|
public static org.apache.catalina.tribes.io.ChannelData | getDataFromPackage(byte[] b)
ChannelData data = new ChannelData(false);
int offset = 0;
data.setOptions(XByteBuffer.toInt(b,offset));
offset += 4; //options
data.setTimestamp(XByteBuffer.toLong(b,offset));
offset += 8; //timestamp
data.uniqueId = new byte[XByteBuffer.toInt(b,offset)];
offset += 4; //uniqueId length
System.arraycopy(b,offset,data.uniqueId,0,data.uniqueId.length);
offset += data.uniqueId.length; //uniqueId data
byte[] addr = new byte[XByteBuffer.toInt(b,offset)];
offset += 4; //addr length
System.arraycopy(b,offset,addr,0,addr.length);
data.setAddress(MemberImpl.getMember(addr));
offset += addr.length; //addr data
int xsize = XByteBuffer.toInt(b,offset);
//data.message = new XByteBuffer(new byte[xsize],false);
data.message = BufferPool.getBufferPool().getBuffer(xsize,false);
offset += 4; //message length
System.arraycopy(b,offset,data.message.getBytesDirect(),0,xsize);
data.message.append(b,offset,xsize);
offset += xsize; //message data
return data;
|
public byte[] | getDataPackage()Serializes the ChannelData object into a byte[] array
int length = getDataPackageLength();
byte[] data = new byte[length];
int offset = 0;
return getDataPackage(data,offset);
|
public byte[] | getDataPackage(byte[] data, int offset)
byte[] addr = ((MemberImpl)address).getData(false);
XByteBuffer.toBytes(options,data,offset);
offset += 4; //options
XByteBuffer.toBytes(timestamp,data,offset);
offset += 8; //timestamp
XByteBuffer.toBytes(uniqueId.length,data,offset);
offset += 4; //uniqueId.length
System.arraycopy(uniqueId,0,data,offset,uniqueId.length);
offset += uniqueId.length; //uniqueId data
XByteBuffer.toBytes(addr.length,data,offset);
offset += 4; //addr.length
System.arraycopy(addr,0,data,offset,addr.length);
offset += addr.length; //addr data
XByteBuffer.toBytes(message.getLength(),data,offset);
offset += 4; //message.length
System.arraycopy(message.getBytesDirect(),0,data,offset,message.getLength());
offset += message.getLength(); //message data
return data;
|
public int | getDataPackageLength()
int length =
4 + //options
8 + //timestamp off=4
4 + //unique id length off=12
uniqueId.length+ //id data off=12+uniqueId.length
4 + //addr length off=12+uniqueId.length+4
((MemberImpl)address).getDataLength()+ //member data off=12+uniqueId.length+4+add.length
4 + //message length off=12+uniqueId.length+4+add.length+4
message.getLength();
return length;
|
public XByteBuffer | getMessage()
return message;
|
public int | getOptions()
return options;
|
public long | getTimestamp()
return timestamp;
|
public byte[] | getUniqueId()
return uniqueId;
|
public int | hashCode()
return XByteBuffer.toInt(getUniqueId(),0);
|
public static boolean | sendAckAsync(int options)Utility method, returns true if the options flag indicates that an ack
is to be sent after the message has been received but not yet processed
return ( (Channel.SEND_OPTIONS_USE_ACK & options) == Channel.SEND_OPTIONS_USE_ACK) &&
( (Channel.SEND_OPTIONS_SYNCHRONIZED_ACK & options) != Channel.SEND_OPTIONS_SYNCHRONIZED_ACK);
|
public static boolean | sendAckSync(int options)Utility method, returns true if the options flag indicates that an ack
is to be sent after the message has been received and processed
return ( (Channel.SEND_OPTIONS_USE_ACK & options) == Channel.SEND_OPTIONS_USE_ACK) &&
( (Channel.SEND_OPTIONS_SYNCHRONIZED_ACK & options) == Channel.SEND_OPTIONS_SYNCHRONIZED_ACK);
|
public void | setAddress(org.apache.catalina.tribes.Member address)Sets the source or reply-to address
this.address = address;
|
public void | setMessage(XByteBuffer message)
this.message = message;
|
public void | setOptions(int options)
this.options = options;
|
public void | setTimestamp(long timestamp)
this.timestamp = timestamp;
|
public void | setUniqueId(byte[] uniqueId)
this.uniqueId = uniqueId;
|
public java.lang.String | toString()
StringBuffer buf = new StringBuffer();
buf.append("ClusterData[src=");
buf.append(getAddress()).append("; id=");
buf.append(bToS(getUniqueId())).append("; sent=");
buf.append(new Timestamp(this.getTimestamp()).toString()).append("]");
return buf.toString();
|