Search in sources :

Example 16 with XByteBuffer

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

the class SocketTribesReceive method main.

public static void main(String[] args) throws Exception {
    int size = 43800;
    if (args.length > 0)
        try {
            size = Integer.parseInt(args[0]);
        } catch (Exception x) {
        /* Ignore */
        }
    XByteBuffer xbuf = new XByteBuffer(43800, true);
    ServerSocket srvSocket = new ServerSocket(9999);
    System.out.println("Listening on 9999");
    Socket socket = srvSocket.accept();
    socket.setReceiveBufferSize(size);
    InputStream in = socket.getInputStream();
    Thread t = new Thread() {

        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(1000);
                    printStats(start, mb, count, df, total);
                } catch (Exception x) {
                /* Ignore */
                }
            }
        }
    };
    t.setDaemon(true);
    t.start();
    while (true) {
        if (first) {
            first = false;
            start = System.currentTimeMillis();
        }
        int len = in.read(buf);
        if (len == -1) {
            printStats(start, mb, count, df, total);
            System.exit(1);
        }
        xbuf.append(buf, 0, len);
        if (bytes.intValue() != len)
            bytes = new BigDecimal((double) len);
        total = total.add(bytes);
        while (xbuf.countPackages(true) > 0) {
            xbuf.extractPackage(true);
            count++;
        }
        mb += ((double) len) / 1024 / 1024;
        if (((count) % 10000) == 0) {
            printStats(start, mb, count, df, total);
        }
    }
}
Also used : XByteBuffer(org.apache.catalina.tribes.io.XByteBuffer) InputStream(java.io.InputStream) ServerSocket(java.net.ServerSocket) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) BigDecimal(java.math.BigDecimal)

Example 17 with XByteBuffer

use of org.apache.catalina.tribes.io.XByteBuffer in project tomcat70 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 {
            synchronized (mutex) {
                mutex.wait(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)

Example 18 with XByteBuffer

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

the class SocketSend method main.

public static void main(String[] args) throws Exception {
    Member mbr = new MemberImpl("localhost", 9999, 0);
    ChannelData data = new ChannelData();
    data.setOptions(Channel.SEND_OPTIONS_BYTE_MESSAGE);
    data.setAddress(mbr);
    byte[] buf = new byte[8192 * 4];
    data.setMessage(new XByteBuffer(buf, false));
    buf = XByteBuffer.createDataPackage(data);
    int len = buf.length;
    System.out.println("Message size:" + len + " bytes");
    BigDecimal total = new BigDecimal((double) 0);
    BigDecimal bytes = new BigDecimal((double) len);
    Socket socket = new Socket("localhost", 9999);
    System.out.println("Writing to 9999");
    OutputStream out = socket.getOutputStream();
    long start = 0;
    double mb = 0;
    boolean first = true;
    int count = 0;
    DecimalFormat df = new DecimalFormat("##.00");
    while (count < 1000000) {
        if (first) {
            first = false;
            start = System.currentTimeMillis();
        }
        out.write(buf, 0, buf.length);
        mb += ((double) buf.length) / 1024 / 1024;
        total = total.add(bytes);
        if (((++count) % 10000) == 0) {
            long time = System.currentTimeMillis();
            double seconds = ((double) (time - start)) / 1000;
            System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds messages " + count + ", total " + mb + " MB, total " + total + " bytes.");
        }
    }
    out.flush();
    System.out.println("Complete, sleeping 5 seconds");
    Thread.sleep(5000);
    socket.close();
}
Also used : XByteBuffer(org.apache.catalina.tribes.io.XByteBuffer) MemberImpl(org.apache.catalina.tribes.membership.MemberImpl) OutputStream(java.io.OutputStream) DecimalFormat(java.text.DecimalFormat) BigDecimal(java.math.BigDecimal) ChannelData(org.apache.catalina.tribes.io.ChannelData) Member(org.apache.catalina.tribes.Member) Socket(java.net.Socket)

Example 19 with XByteBuffer

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

the class TestEncryptInterceptor method roundTrip.

/**
 * Actually go through the interceptor's send/receive message methods.
 */
private static byte[] roundTrip(byte[] input, EncryptInterceptor src, EncryptInterceptor dest) throws Exception {
    ChannelData msg = new ChannelData(false);
    msg.setMessage(new XByteBuffer(input, false));
    src.sendMessage(null, msg, null);
    return ((ValueCaptureInterceptor) dest.getPrevious()).getValue();
}
Also used : XByteBuffer(org.apache.catalina.tribes.io.XByteBuffer) ChannelData(org.apache.catalina.tribes.io.ChannelData)

Example 20 with XByteBuffer

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

the class TestEncryptInterceptor method testPickup.

@Test
public void testPickup() throws Exception {
    File file = new File(MESSAGE_FILE);
    if (!file.exists()) {
        System.err.println("File message.bin does not exist. Skipping test.");
        return;
    }
    dest.start(Channel.SND_TX_SEQ);
    byte[] bytes = new byte[8192];
    int read;
    try (FileInputStream in = new FileInputStream(file)) {
        read = in.read(bytes);
    }
    ChannelData msg = new ChannelData(false);
    XByteBuffer xbb = new XByteBuffer(read, false);
    xbb.append(bytes, 0, read);
    msg.setMessage(xbb);
    dest.messageReceived(msg);
}
Also used : XByteBuffer(org.apache.catalina.tribes.io.XByteBuffer) ChannelData(org.apache.catalina.tribes.io.ChannelData) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

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