< prev index next >

test/jdk/sun/net/www/httptest/TestHttpServer.java

Print this page




 128      * the specified port. The specified number of threads are created to
 129      * handle incoming requests, and each thread is allowed
 130      * to handle a number of simultaneous TCP connections.
 131      * @param cb the callback object which is invoked to handle
 132      *  each incoming request
 133      * @param threads the number of threads to create to handle
 134      *  requests in parallel
 135      * @param cperthread the number of simultaneous TCP connections
 136      *  to handle per thread
 137      * @param address the address to bind the server to. <code>Null</code>
 138      *  means bind to the wildcard address.
 139      * @param port the port number to bind the server to. <code>Zero</code>
 140      *  means choose any free port.
 141      */
 142 
 143     public TestHttpServer (HttpCallback cb, int threads, int cperthread,
 144                            InetAddress address, int port)
 145         throws IOException {
 146         schan = ServerSocketChannel.open ();
 147         InetSocketAddress addr = new InetSocketAddress (address, port);

 148         schan.socket().bind (addr);
 149         this.threads = threads;
 150         this.cb = cb;
 151         this.cperthread = cperthread;
 152         servers = new Server [threads];
 153         for (int i=0; i<threads; i++) {
 154             servers[i] = new Server (cb, schan, cperthread);
 155             servers[i].start();
 156         }
 157     }
 158 
 159     /**
 160      * Tell all threads in the server to exit within 5 seconds.
 161      * This is an abortive termination. Just prior to the thread exiting
 162      * all channels in that thread waiting to be closed are forceably closed.
 163      * @throws InterruptedException
 164      */
 165 
 166     public void terminate () {
 167         for (int i=0; i<threads; i++) {




 128      * the specified port. The specified number of threads are created to
 129      * handle incoming requests, and each thread is allowed
 130      * to handle a number of simultaneous TCP connections.
 131      * @param cb the callback object which is invoked to handle
 132      *  each incoming request
 133      * @param threads the number of threads to create to handle
 134      *  requests in parallel
 135      * @param cperthread the number of simultaneous TCP connections
 136      *  to handle per thread
 137      * @param address the address to bind the server to. <code>Null</code>
 138      *  means bind to the wildcard address.
 139      * @param port the port number to bind the server to. <code>Zero</code>
 140      *  means choose any free port.
 141      */
 142 
 143     public TestHttpServer (HttpCallback cb, int threads, int cperthread,
 144                            InetAddress address, int port)
 145         throws IOException {
 146         schan = ServerSocketChannel.open ();
 147         InetSocketAddress addr = new InetSocketAddress (address, port);
 148         schan.socket().setReuseAddress(true);
 149         schan.socket().bind (addr);
 150         this.threads = threads;
 151         this.cb = cb;
 152         this.cperthread = cperthread;
 153         servers = new Server [threads];
 154         for (int i=0; i<threads; i++) {
 155             servers[i] = new Server (cb, schan, cperthread);
 156             servers[i].start();
 157         }
 158     }
 159 
 160     /**
 161      * Tell all threads in the server to exit within 5 seconds.
 162      * This is an abortive termination. Just prior to the thread exiting
 163      * all channels in that thread waiting to be closed are forceably closed.
 164      * @throws InterruptedException
 165      */
 166 
 167     public void terminate () {
 168         for (int i=0; i<threads; i++) {


< prev index next >