package org.jenkinsci.remoting.nio;

import hudson.remoting.Channel;
import hudson.remoting.ChannelBuilder;

import java.io.IOException;
import java.net.Socket;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SocketChannel;
import java.util.concurrent.ExecutorService;

/**
 * @author Kohsuke Kawaguchi
 */
public class NioChannelBuilder extends ChannelBuilder {
    /*package*/ SelectableChannel/* & ReadableByteChannel&WritableByteChannel */ r,w;

    public NioChannelBuilder(String name, ExecutorService executors) {
        super(name, executors);
    }

    public Channel build(SocketChannel socket) throws IOException {
        this.r = socket;
        this.w = socket;
        return super.build(socket.socket());
    }

    @Override
    public Channel build(Socket s) throws IOException {
        return build(s.getChannel());
    }
}

@@ -30,16 +30,51 @@
 g.nio;%0A%0A
+import hudson.remoting.Capability;%0A
 import h
@@ -131,44 +131,143 @@
 nnel
-Builder;%0A%0Aimport java.io.IOException
+.Mode;%0Aimport hudson.remoting.ChannelBuilder;%0Aimport hudson.remoting.JarCache;%0A%0Aimport java.io.IOException;%0Aimport java.io.OutputStream
 ;%0Aim
@@ -992,10 +992,907 @@
 ;%0A    %7D%0A
+%0A%0A    @Override%0A    public NioChannelBuilder withBaseLoader(ClassLoader base) %7B%0A        return (NioChannelBuilder)super.withBaseLoader(base);%0A    %7D%0A%0A    @Override%0A    public NioChannelBuilder withMode(Mode mode) %7B%0A        return (NioChannelBuilder)super.withMode(mode);%0A    %7D%0A%0A    @Override%0A    public NioChannelBuilder withCapability(Capability capability) %7B%0A        return (NioChannelBuilder) super.withCapability(capability);%0A    %7D%0A%0A    @Override%0A    public NioChannelBuilder withHeaderStream(OutputStream header) %7B%0A        return (NioChannelBuilder) super.withHeaderStream(header);%0A    %7D%0A%0A    @Override%0A    public NioChannelBuilder withRestricted(boolean restricted) %7B%0A        return (NioChannelBuilder) super.withRestricted(restricted);%0A    %7D%0A%0A    @Override%0A    public NioChannelBuilder withJarCache(JarCache jarCache) %7B%0A        return (NioChannelBuilder) super.withJarCache(jarCache);%0A    %7D%0A
 %7D%0A

needs to return the 'self' type