本文整理汇总了Java中org.apache.catalina.tribes.io.XByteBuffer类的典型用法代码示例。如果您正苦于以下问题:Java XByteBuffer类的具体用法?Java XByteBuffer怎么用?Java XByteBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XByteBuffer类属于org.apache.catalina.tribes.io包,在下文中一共展示了XByteBuffer类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import org.apache.catalina.tribes.io.XByteBuffer; //导入依赖的package包/类
/**
* apply a diff, or an entire object
* @param data byte[]
* @param offset int
* @param length int
* @param diff boolean
* @throws IOException
* @throws ClassNotFoundException
*/
@SuppressWarnings("unchecked")
public void apply(byte[] data, int offset, int length, boolean diff) throws IOException, ClassNotFoundException {
if (isDiffable() && diff) {
ReplicatedMapEntry rentry = (ReplicatedMapEntry) value;
rentry.lock();
try {
rentry.applyDiff(data, offset, length);
} finally {
rentry.unlock();
}
} else if (length == 0) {
value = null;
proxy = true;
} else {
value = (V) XByteBuffer.deserialize(data, offset, length);
}
}
示例2: sendMessage
import org.apache.catalina.tribes.io.XByteBuffer; //导入依赖的package包/类
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
if ( access.addAndGet(1) == 1 ) txStart = System.currentTimeMillis();
long bytes = XByteBuffer.getDataPackageLength(((ChannelData)msg).getDataPackageLength());
try {
super.sendMessage(destination, msg, payload);
}catch ( ChannelException x ) {
msgTxErr.addAndGet(1);
if ( access.get() == 1 ) access.addAndGet(-1);
throw x;
}
mbTx += (bytes*destination.length)/(1024d*1024d);
mbAppTx += bytes/(1024d*1024d);
if ( access.addAndGet(-1) == 0 ) {
long stop = System.currentTimeMillis();
timeTx += (stop - txStart) / 1000d;
if ((msgTxCnt.get() / interval) >= lastCnt) {
lastCnt++;
report(timeTx);
}
}
msgTxCnt.addAndGet(1);
}
示例3: messageReceived
import org.apache.catalina.tribes.io.XByteBuffer; //导入依赖的package包/类
@Override
public void messageReceived(ChannelMessage msg) {
if ( !okToProcess(msg.getOptions()) ) {
super.messageReceived(msg);
return;
}
int msgnr = XByteBuffer.toInt(msg.getMessage().getBytesDirect(),msg.getMessage().getLength()-4);
msg.getMessage().trim(4);
MessageOrder order = new MessageOrder(msgnr,(ChannelMessage)msg.deepclone());
try {
inLock.writeLock().lock();
if ( processIncoming(order) ) processLeftOvers(msg.getAddress(),false);
}finally {
inLock.writeLock().unlock();
}
}
示例4: receive
import org.apache.catalina.tribes.io.XByteBuffer; //导入依赖的package包/类
/**
* Receive a datagram packet, locking wait
* @throws IOException
*/
public void receive() throws IOException {
boolean checkexpired = true;
try {
socket.receive(receivePacket);
if(receivePacket.getLength() > MAX_PACKET_SIZE) {
log.error("Multicast packet received was too long, dropping package:"+receivePacket.getLength());
} else {
byte[] data = new byte[receivePacket.getLength()];
System.arraycopy(receivePacket.getData(), receivePacket.getOffset(), data, 0, data.length);
if (XByteBuffer.firstIndexOf(data,0,MemberImpl.TRIBES_MBR_BEGIN)==0) {
memberDataReceived(data);
} else {
memberBroadcastsReceived(data);
}
}
} catch (SocketTimeoutException x ) {
//do nothing, this is normal, we don't want to block forever
//since the receive thread is the same thread
//that does membership expiration
}
if (checkexpired) checkExpired();
}
示例5: broadcast
import org.apache.catalina.tribes.io.XByteBuffer; //导入依赖的package包/类
@Override
public void broadcast(ChannelMessage message) throws ChannelException {
if (impl==null || (impl.startLevel & Channel.MBR_TX_SEQ)!=Channel.MBR_TX_SEQ )
throw new ChannelException("Multicast send is not started or enabled.");
byte[] data = XByteBuffer.createDataPackage((ChannelData)message);
if (data.length>McastServiceImpl.MAX_PACKET_SIZE) {
throw new ChannelException("Packet length["+data.length+"] exceeds max packet size of "+McastServiceImpl.MAX_PACKET_SIZE+" bytes.");
}
DatagramPacket packet = new DatagramPacket(data,0,data.length);
try {
impl.send(false, packet);
} catch (Exception x) {
throw new ChannelException(x);
}
}
示例6: createRandomData
import org.apache.catalina.tribes.io.XByteBuffer; //导入依赖的package包/类
public static Data createRandomData(int size, int number) {
int i = r.nextInt();
i = ( i % 127 );
int length = Math.abs(r.nextInt() % size);
if (length<100) length += 100;
Data d = new Data();
d.length = length;
d.key = (byte)i;
d.data = new byte[length];
Arrays.fill(d.data,d.key);
if (number>0 && d.data.length>=4) {
//populate number
d.hasNr = true;
XByteBuffer.toBytes(number,d.data, 0);
}
return d;
}
示例7: apply
import org.apache.catalina.tribes.io.XByteBuffer; //导入依赖的package包/类
/**
* apply a diff, or an entire object
*
* @param data
* byte[]
* @param offset
* int
* @param length
* int
* @param diff
* boolean
* @throws IOException
* @throws ClassNotFoundException
*/
@SuppressWarnings("unchecked")
public void apply(byte[] data, int offset, int length, boolean diff)
throws IOException, ClassNotFoundException {
if (isDiffable() && diff) {
ReplicatedMapEntry rentry = (ReplicatedMapEntry) value;
rentry.lock();
try {
rentry.applyDiff(data, offset, length);
} finally {
rentry.unlock();
}
} else if (length == 0) {
value = null;
proxy = true;
} else {
value = (V) XByteBuffer.deserialize(data, offset, length);
}
}
示例8: sendMessage
import org.apache.catalina.tribes.io.XByteBuffer; //导入依赖的package包/类
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)
throws ChannelException {
if (access.addAndGet(1) == 1)
txStart = System.currentTimeMillis();
long bytes = XByteBuffer.getDataPackageLength(((ChannelData) msg).getDataPackageLength());
try {
super.sendMessage(destination, msg, payload);
} catch (ChannelException x) {
msgTxErr.addAndGet(1);
if (access.get() == 1)
access.addAndGet(-1);
throw x;
}
mbTx += (bytes * destination.length) / (1024d * 1024d);
mbAppTx += bytes / (1024d * 1024d);
if (access.addAndGet(-1) == 0) {
long stop = System.currentTimeMillis();
timeTx += (stop - txStart) / 1000d;
if ((msgTxCnt.get() / interval) >= lastCnt) {
lastCnt++;
report(timeTx);
}
}
msgTxCnt.addAndGet(1);
}
示例9: messageReceived
import org.apache.catalina.tribes.io.XByteBuffer; //导入依赖的package包/类
@Override
public void messageReceived(ChannelMessage msg) {
if (!okToProcess(msg.getOptions())) {
super.messageReceived(msg);
return;
}
int msgnr = XByteBuffer.toInt(msg.getMessage().getBytesDirect(), msg.getMessage().getLength() - 4);
msg.getMessage().trim(4);
MessageOrder order = new MessageOrder(msgnr, (ChannelMessage) msg.deepclone());
try {
inLock.writeLock().lock();
if (processIncoming(order))
processLeftOvers(msg.getAddress(), false);
} finally {
inLock.writeLock().unlock();
}
}
示例10: receive
import org.apache.catalina.tribes.io.XByteBuffer; //导入依赖的package包/类
/**
* Receive a datagram packet, locking wait
*
* @throws IOException
*/
public void receive() throws IOException {
boolean checkexpired = true;
try {
socket.receive(receivePacket);
if (receivePacket.getLength() > MAX_PACKET_SIZE) {
log.error("Multicast packet received was too long, dropping package:" + receivePacket.getLength());
} else {
byte[] data = new byte[receivePacket.getLength()];
System.arraycopy(receivePacket.getData(), receivePacket.getOffset(), data, 0, data.length);
if (XByteBuffer.firstIndexOf(data, 0, MemberImpl.TRIBES_MBR_BEGIN) == 0) {
memberDataReceived(data);
} else {
memberBroadcastsReceived(data);
}
}
} catch (SocketTimeoutException x) {
// do nothing, this is normal, we don't want to block forever
// since the receive thread is the same thread
// that does membership expiration
}
if (checkexpired)
checkExpired();
}
示例11: broadcast
import org.apache.catalina.tribes.io.XByteBuffer; //导入依赖的package包/类
@Override
public void broadcast(ChannelMessage message) throws ChannelException {
if (impl == null || (impl.startLevel & Channel.MBR_TX_SEQ) != Channel.MBR_TX_SEQ)
throw new ChannelException("Multicast send is not started or enabled.");
byte[] data = XByteBuffer.createDataPackage((ChannelData) message);
if (data.length > McastServiceImpl.MAX_PACKET_SIZE) {
throw new ChannelException("Packet length[" + data.length + "] exceeds max packet size of "
+ McastServiceImpl.MAX_PACKET_SIZE + " bytes.");
}
DatagramPacket packet = new DatagramPacket(data, 0, data.length);
try {
impl.send(false, packet);
} catch (Exception x) {
throw new ChannelException(x);
}
}
示例12: apply
import org.apache.catalina.tribes.io.XByteBuffer; //导入依赖的package包/类
/**
* apply a diff, or an entire object
* @param data byte[]
* @param offset int
* @param length int
* @param diff boolean
* @throws IOException
* @throws ClassNotFoundException
*/
public void apply(byte[] data, int offset, int length, boolean diff) throws IOException, ClassNotFoundException {
if (isDiffable() && diff) {
ReplicatedMapEntry rentry = (ReplicatedMapEntry) value;
try {
rentry.lock();
rentry.applyDiff(data, offset, length);
} finally {
rentry.unlock();
}
} else if (length == 0) {
value = null;
proxy = true;
} else {
value = XByteBuffer.deserialize(data, offset, length);
}
}