Java 类org.apache.catalina.tribes.io.XByteBuffer 实例源码

项目:tomcat7    文件:AbstractReplicatedMap.java   
/**
 * 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);
    }
}
项目:tomcat7    文件:ThroughputInterceptor.java   
@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);
}
项目:tomcat7    文件:OrderInterceptor.java   
@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();
    }
}
项目:tomcat7    文件:McastServiceImpl.java   
/**
 * 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();
}
项目:tomcat7    文件:McastService.java   
@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);
    }
}
项目:tomcat7    文件:TestMulticastPackages.java   
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;
}
项目:tomcat7    文件:TestUdpPackages.java   
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;
}
项目:apache-tomcat-7.0.73-with-comment    文件:AbstractReplicatedMap.java   
/**
 * 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);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:ThroughputInterceptor.java   
@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);
}
项目:apache-tomcat-7.0.73-with-comment    文件:OrderInterceptor.java   
@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();
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:McastServiceImpl.java   
/**
 * 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();
}
项目:apache-tomcat-7.0.73-with-comment    文件:McastService.java   
@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);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestMulticastPackages.java   
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;
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestUdpPackages.java   
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;
}
项目:lazycat    文件:AbstractReplicatedMap.java   
/**
 * 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);
    }
}
项目:lazycat    文件:ThroughputInterceptor.java   
@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);
}
项目:lazycat    文件:OrderInterceptor.java   
@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();
    }
}
项目:lazycat    文件:McastServiceImpl.java   
/**
 * 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();
}
项目:lazycat    文件:McastService.java   
@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);
    }
}
项目:class-guard    文件:AbstractReplicatedMap.java   
/**
 * 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);
    }
}
项目:class-guard    文件:ThroughputInterceptor.java   
@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);
}
项目:class-guard    文件:OrderInterceptor.java   
@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();
    }
}
项目:class-guard    文件:McastServiceImpl.java   
/**
 * 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();
}
项目:class-guard    文件:McastService.java   
@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);
    }
}
项目:class-guard    文件:TestMulticastPackages.java   
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;
}
项目:class-guard    文件:TestUdpPackages.java   
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;
}
项目:apache-tomcat-7.0.57    文件:McastService.java   
@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);
    }
}
项目:apache-tomcat-7.0.57    文件:AbstractReplicatedMap.java   
/**
 * 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);
    }
}
项目:apache-tomcat-7.0.57    文件:ThroughputInterceptor.java   
@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);
}
项目:apache-tomcat-7.0.57    文件:OrderInterceptor.java   
@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();
    }
}
项目:apache-tomcat-7.0.57    文件:McastServiceImpl.java   
/**
 * 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();
}
项目:apache-tomcat-7.0.57    文件:McastServiceImpl.java   
/**
 * 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();
}
项目:apache-tomcat-7.0.57    文件:McastService.java   
@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);
    }
}
项目:apache-tomcat-7.0.57    文件:TestMulticastPackages.java   
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;
}
项目:apache-tomcat-7.0.57    文件:TestUdpPackages.java   
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;
}
项目:apache-tomcat-7.0.57    文件:TestMulticastPackages.java   
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;
}
项目:apache-tomcat-7.0.57    文件:TestUdpPackages.java   
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;
}
项目:apache-tomcat-7.0.57    文件:AbstractReplicatedMap.java   
/**
 * 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);
    }
}
项目:apache-tomcat-7.0.57    文件:ThroughputInterceptor.java   
@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);
}
项目:apache-tomcat-7.0.57    文件:OrderInterceptor.java   
@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();
    }
}