Search in sources :

Example 26 with XByteBuffer

use of org.apache.catalina.tribes.io.XByteBuffer in project tomcat by apache.

the class McastServiceImpl method memberBroadcastsReceived.

private void memberBroadcastsReceived(final byte[] b) {
    if (log.isTraceEnabled()) {
        log.trace("Mcast received broadcasts.");
    }
    XByteBuffer buffer = new XByteBuffer(b, true);
    if (buffer.countPackages(true) > 0) {
        int count = buffer.countPackages();
        final ChannelData[] data = new ChannelData[count];
        for (int i = 0; i < count; i++) {
            try {
                data[i] = buffer.extractPackage(true);
            } catch (IllegalStateException ise) {
                log.debug("Unable to decode message.", ise);
            }
        }
        Runnable t = () -> {
            String name = Thread.currentThread().getName();
            try {
                Thread.currentThread().setName("Membership-MemberAdded");
                for (ChannelData datum : data) {
                    try {
                        if (datum != null && !member.equals(datum.getAddress())) {
                            msgservice.messageReceived(datum);
                        }
                    } catch (Throwable t1) {
                        if (t1 instanceof ThreadDeath) {
                            throw (ThreadDeath) t1;
                        }
                        if (t1 instanceof VirtualMachineError) {
                            throw (VirtualMachineError) t1;
                        }
                        log.error(sm.getString("mcastServiceImpl.unableReceive.broadcastMessage"), t1);
                    }
                }
            } finally {
                Thread.currentThread().setName(name);
            }
        };
        executor.execute(t);
    }
}
Also used : XByteBuffer(org.apache.catalina.tribes.io.XByteBuffer) ChannelData(org.apache.catalina.tribes.io.ChannelData)

Example 27 with XByteBuffer

use of org.apache.catalina.tribes.io.XByteBuffer in project tomcat by apache.

the class SocketNioReceive method main.

public static void main(String[] args) throws Exception {
    Member mbr = new MemberImpl("localhost", 9999, 0);
    ChannelData data = new ChannelData();
    data.setAddress(mbr);
    byte[] buf = new byte[8192 * 4];
    data.setMessage(new XByteBuffer(buf, false));
    buf = XByteBuffer.createDataPackage(data);
    len = buf.length;
    NioReceiver receiver = new NioReceiver();
    receiver.setPort(9999);
    receiver.setHost("localhost");
    MyList list = new MyList();
    receiver.setMessageListener(list);
    receiver.start();
    System.out.println("Listening on 9999");
    while (true) {
        try {
            Thread.sleep(5000);
            if (start != 0) {
                System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds, messages " + count + " accepts " + accept + ", total " + mb + " MB.");
            }
        } catch (Throwable x) {
            x.printStackTrace();
        }
    }
}
Also used : XByteBuffer(org.apache.catalina.tribes.io.XByteBuffer) NioReceiver(org.apache.catalina.tribes.transport.nio.NioReceiver) ChannelData(org.apache.catalina.tribes.io.ChannelData) MemberImpl(org.apache.catalina.tribes.membership.MemberImpl) Member(org.apache.catalina.tribes.Member)

Aggregations

XByteBuffer (org.apache.catalina.tribes.io.XByteBuffer)27 ChannelData (org.apache.catalina.tribes.io.ChannelData)23 ChannelException (org.apache.catalina.tribes.ChannelException)8 BigDecimal (java.math.BigDecimal)6 Socket (java.net.Socket)6 Member (org.apache.catalina.tribes.Member)6 MemberImpl (org.apache.catalina.tribes.membership.MemberImpl)6 DecimalFormat (java.text.DecimalFormat)4 Test (org.junit.Test)4 RemoteProcessException (org.apache.catalina.tribes.RemoteProcessException)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ConnectException (java.net.ConnectException)2 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2 ServerSocket (java.net.ServerSocket)2 SocketTimeoutException (java.net.SocketTimeoutException)2 SelectionKey (java.nio.channels.SelectionKey)2