Package java.nio.channels

Examples of java.nio.channels.AsynchronousServerSocketChannel


    @Override
    protected Runnable doRegister() throws Exception {
        Runnable task = super.doRegister();
        if (ch == null) {
            AsynchronousServerSocketChannel channel =
                    newSocket(((AioEventLoopGroup) eventLoop().parent()).channelGroup());
            ch = channel;
            config.assign(channel);
        }
        return task;
View Full Code Here


    /**
     * Port in use.
     */
    @Override
    public int getLocalPort() {
        AsynchronousServerSocketChannel ssc = serverSock;
        if (ssc == null) {
            return -1;
        } else {
            try {
                SocketAddress sa = ssc.getLocalAddress();
                if (sa != null && sa instanceof InetSocketAddress) {
                    return ((InetSocketAddress) sa).getPort();
                } else {
                    return -1;
                }
View Full Code Here

    /**
     * Port in use.
     */
    @Override
    public int getLocalPort() {
        AsynchronousServerSocketChannel ssc = serverSock;
        if (ssc == null) {
            return -1;
        } else {
            try {
                SocketAddress sa = ssc.getLocalAddress();
                if (sa != null && sa instanceof InetSocketAddress) {
                    return ((InetSocketAddress) sa).getPort();
                } else {
                    return -1;
                }
View Full Code Here

*/
public class PlainNio2EchoServer {

    public void serve(int port) throws IOException {
        System.out.println("Listening for connections on port " + port);
        final AsynchronousServerSocketChannel serverChannel = AsynchronousServerSocketChannel.open();
        InetSocketAddress address = new InetSocketAddress(port);
        serverChannel.bind(address);
        final CountDownLatch latch = new CountDownLatch(1);
        serverChannel.accept(null, new CompletionHandler<AsynchronousSocketChannel, Object>() {
            @Override
            public void completed(final AsynchronousSocketChannel channel, Object attachment) {
                serverChannel.accept(null, this);
                ByteBuffer buffer = ByteBuffer.allocate(100);
                channel.read(buffer, buffer, new EchoCompletionHandler(channel));
            }

            @Override
            public void failed(Throwable throwable, Object attachment) {
                try {
                    serverChannel.close();
                } catch (IOException e) {
                    // ingnore on close
                } finally {
                    latch.countDown();
                }
View Full Code Here

    static int count = 0;
    static AsynchronousChannelGroup channelGroup;

    public static void main(String[] args) throws Exception {
        channelGroup = AsynchronousChannelGroup.withThreadPool(Executors.newFixedThreadPool(5));
        final AsynchronousServerSocketChannel server = AsynchronousServerSocketChannel.open(channelGroup);
        server.bind(new InetSocketAddress(5000));
        Stopwatch stopwatch = new Stopwatch().start();
        while (!channelGroup.isShutdown()) {
            AsynchronousSocketChannel socket = server.accept().get();
            processConnection(socket);
        }
        stopwatch.stop();
        System.out.println("EchoServer is done in " + stopwatch.elapsedMillis());
    }
View Full Code Here

TOP

Related Classes of java.nio.channels.AsynchronousServerSocketChannel

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.