Logo Search packages:      
Sourcecode: nailgun version File versions  Download package

void com::martiansoftware::nailgun::NGServer::run (  )  [inline]

Listens for new connections and launches NGSession threads to process them.

Definition at line 352 of file NGServer.java.

References addr, err, in, originalSecurityManager, out, port, com::martiansoftware::nailgun::NGSession::run(), running, serversocket, sessionPool, com::martiansoftware::nailgun::NGSession::shutdown(), shutdown, and com::martiansoftware::nailgun::NGSessionPool::take().

                        {
            running = true;
            NGSession sessionOnDeck = null;
            
            originalSecurityManager = System.getSecurityManager();
        System.setSecurityManager(
                new NGSecurityManager(
                        originalSecurityManager));
  

            synchronized(System.in) {
                  if (!(System.in instanceof ThreadLocalInputStream)) {
                        System.setIn(new ThreadLocalInputStream(in));
                        System.setOut(new ThreadLocalPrintStream(out));
                        System.setErr(new ThreadLocalPrintStream(err));                   
                  }
            }
            
            try {
                  if (addr == null) {
                        serversocket = new ServerSocket(port);
                  } else {
                        serversocket = new ServerSocket(port, 0, addr);
                  }
                  
                  while (!shutdown) {
                        sessionOnDeck = sessionPool.take();
                        Socket socket = serversocket.accept();
                        sessionOnDeck.run(socket);
                  }

            } catch (Throwable t) {
                  // if shutdown is called while the accept() method is blocking,
                  // an exception will be thrown that we don't care about.  filter
                  // those out.
                  if (!shutdown) {
                        t.printStackTrace();
                  }
            }
            if (sessionOnDeck != null) {
                  sessionOnDeck.shutdown();
            }
            running = false;
      }


Generated by  Doxygen 1.6.0   Back to index