Clover coverage report -
Coverage timestamp: Do Okt 21 2004 12:21:23 CEST
file stats: LOC: 76   Methods: 5
NCLOC: 51   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BaseServer.java 0% 0% 0% 0%
coverage
 1    /*
 2    * BaseServer.java
 3    *
 4    * Created on 17. Oktober 2003, 16:29
 5    */
 6    package org.jconfig.server;
 7   
 8    import java.io.IOException;
 9    import java.net.ServerSocket;
 10    import java.net.Socket;
 11    /**
 12    * This class implements a simple server. Every request to this server
 13    * will be handled by the defined ProtocolHandler.
 14    *
 15    * @author Andreas Mecky andreasmecky@yahoo.de
 16    * @author Terry Dye terrydye@yahoo.com
 17    */
 18    public class BaseServer extends Thread {
 19   
 20    private boolean active = false;
 21    private ServerSocket socket;
 22    private ThreadPool pool;
 23    private Class clazz;
 24    private ServerContext serverContext;
 25   
 26  0 public BaseServer(int port,Class handler,ServerContext serverContext) {
 27  0 this.serverContext = serverContext;
 28  0 try {
 29  0 socket = new ServerSocket(port);
 30  0 pool = new ThreadPool();
 31  0 active = true;
 32    //setDaemon(true);
 33    //start();
 34  0 clazz = handler;
 35    }
 36    catch (IOException ie) {
 37  0 ie.printStackTrace();
 38    }
 39    }
 40   
 41  0 public void run() {
 42  0 while (active) {
 43  0 try {
 44  0 Socket clientSocket = socket.accept();
 45  0 clientSocket.setTcpNoDelay(true);
 46  0 handleConnection(clientSocket);
 47    } catch (IOException ie) {
 48  0 ie.printStackTrace();
 49    }
 50    }
 51    }
 52   
 53  0 private void handleConnection(Socket clientSocket) throws IOException {
 54    // 1. get worker thread from pool
 55  0 WorkerThread wt = pool.getWorker();
 56    // 2. call the execute
 57  0 try {
 58  0 ProtocolHandler handler = (ProtocolHandler)clazz.newInstance();
 59  0 wt.execute(clientSocket,handler,serverContext);
 60    }
 61    catch (Exception e) {
 62  0 e.printStackTrace();
 63    }
 64    // 3. return to pool
 65  0 pool.releaseWorkerThread(wt);
 66    }
 67   
 68  0 public void shutdown() {
 69  0 active = false;
 70    }
 71   
 72  0 public void setAsDaemon(boolean isDaemon) {
 73  0 super.setDaemon(isDaemon);
 74    }
 75   
 76    }