当前位置: 首页>>代码示例>>Java>>正文


Java XByteBuffer类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:27,代码来源:AbstractReplicatedMap.java

示例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);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:24,代码来源:ThroughputInterceptor.java

示例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();
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:17,代码来源:OrderInterceptor.java

示例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();
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:29,代码来源:McastServiceImpl.java

示例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);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:17,代码来源:McastService.java

示例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;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:18,代码来源:TestMulticastPackages.java

示例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);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:33,代码来源:AbstractReplicatedMap.java

示例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);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:27,代码来源:ThroughputInterceptor.java

示例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();
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:18,代码来源:OrderInterceptor.java

示例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();
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:31,代码来源:McastServiceImpl.java

示例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);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:18,代码来源:McastService.java

示例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);
    }
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:26,代码来源:AbstractReplicatedMap.java


注:本文中的org.apache.catalina.tribes.io.XByteBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。