1 36 37 import java.io.*; 38 import java.nio.channels.*; 39 import javax.net.ssl.*; 40 41 49 class AcceptHandler implements Handler { 50 51 private ServerSocketChannel channel; 52 private Dispatcher dsp; 53 54 private SSLContext sslContext; 55 56 AcceptHandler(ServerSocketChannel ssc, Dispatcher dsp, 57 SSLContext sslContext) { 58 channel = ssc; 59 this.dsp = dsp; 60 this.sslContext = sslContext; 61 } 62 63 public void handle(SelectionKey sk) throws IOException { 64 65 if (!sk.isAcceptable()) 66 return; 67 68 SocketChannel sc = channel.accept(); 69 if (sc == null) { 70 return; 71 } 72 73 ChannelIO cio = (sslContext != null ? 74 ChannelIOSecure.getInstance( 75 sc, false , sslContext) : 76 ChannelIO.getInstance( 77 sc, false )); 78 79 RequestHandler rh = new RequestHandler(cio); 80 dsp.register(cio.getSocketChannel(), SelectionKey.OP_READ, rh); 81 } 82 } 83 | Popular Tags |