Package com.sun.sgs.nio.channels

Examples of com.sun.sgs.nio.channels.AsynchronousChannelGroup


        executor.prestartAllCoreThreads();

        AsynchronousChannelProvider provider =
            AsynchronousChannelProvider.provider();

        AsynchronousChannelGroup group =
            provider.openAsynchronousChannelGroup(executor);

        log.log(Level.INFO, "ChannelGroup is a {0}", group.getClass());

        startSignal = new CountDownLatch(NUM_CLIENTS);
        doneSignal = new CountDownLatch(NUM_CLIENTS);

        System.out.format("Connecting %d clients\n", NUM_CLIENTS);

        Set<EchoClient> clients = new HashSet<EchoClient>(NUM_CLIENTS);

        for (int i = 0; i < NUM_CLIENTS; ++i) {
            EchoClient client = new EchoClient(group);
            clients.add(client);
            client.connect();
        }

        startSignal.await();

        System.out.println("Starting test");
        startTime = System.nanoTime();

        for (EchoClient client : clients)
            client.start();

        doneSignal.await();

        long ops = NUM_CLIENTS * NUM_MSGS * 2;
        long elapsed = System.nanoTime() - startTime;
        log.log(Level.INFO, "Bytes read: {0}  written:{1}",
            new Object[] {
                totalBytesRead.get(),
                totalBytesWritten.get()
            });
        System.out.format("%d ops in %d seconds = %d ops/sec\n",
                ops,
                TimeUnit.NANOSECONDS.toSeconds(elapsed),
                TimeUnit.SECONDS.toNanos(ops) / elapsed
            );

        group.shutdown();
        log.info("Awaiting group termination");       
        if (! group.awaitTermination(5, TimeUnit.SECONDS)) {
            log.warning("Forcing group termination");
            group.shutdownNow();
            if (! group.awaitTermination(5, TimeUnit.SECONDS)) {
                log.warning("Group could not be forcibly terminated");
            }
        }
        if (group.isTerminated())
            log.info("Group terminated");

        log.info("Terminating executor");
        executor.shutdown();
        log.info("Awaiting executor termination");       
View Full Code Here


        executor.prestartAllCoreThreads();

        AsynchronousChannelProvider provider =
            AsynchronousChannelProvider.provider();

        AsynchronousChannelGroup group =
            provider.openAsynchronousChannelGroup(executor);

        log.log(Level.INFO, "ChannelGroup is a {0}", group.getClass());

        log.info("Starting the server");

        EchoServer server = new EchoServer(group);
        server.start();

        log.info("Awaiting group termination");       
        if (! group.awaitTermination(3600, TimeUnit.SECONDS)) {
            log.warning("Forcing group termination");
            group.shutdownNow();
            if (! group.awaitTermination(5, TimeUnit.SECONDS)) {
                log.warning("Group could not be forcibly terminated");
            }
        }
        if (group.isTerminated())
            log.info("Group terminated");

        log.info("Terminating executor");
        executor.shutdown();
        log.info("Awaiting executor termination");       
View Full Code Here

TOP

Related Classes of com.sun.sgs.nio.channels.AsynchronousChannelGroup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.