/* * Copyright (C) 1996, 1997 By Radu Sion * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Radu Sion (radus@cs.pub.ro) * * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * (radus@cs.pub.ro, http://www.dsp.pub.ro/radu.html) * */ import java.net.*; import java.io.*; import RoundRobinServerThread; import SleepingThread; import ServerConnectAAA; import NullServerConnectAAA; import ConnectAAAServerThread; import dbg; /** * A thread that runs as server on a specified port and accepts * connect requests from clients. It then passes the accepted socket * to a new created ConnectAAAThread which does the AAA, in order * NOT to block the connection process. * Written: Radu Sion
* Version: 0.33
* Source: ConnectServerThread.java * @see RoundRobinServerThread */ class ConnectServerThread extends SleepingThread { ServerSocket ss; /* server socket */ Socket ns; /* new socket */ RoundRobinServerThread rrst; ServerConnectAAA aaa; /** * Constructs a thread object. * @param port Port on which to listen for connections * @param rrstt RoundRobinServerThread to which to pass the incoming sockets * @param sleep Internal sleep delay */ public ConnectServerThread(int port, RoundRobinServerThread rrstt, ServerConnectAAA a, long sleep) { aaa = a; rrst = rrstt; dbg.p(dbg.INFO,"CST: Initializing ..."); try { ss = new ServerSocket(port); dbg.p(dbg.INFO,"CST: ServerSocket : " + ss); } catch(IOException err) { dbg.p(dbg.ERROR,"CST: ServerSocket Creating Error : " + err.getMessage()); } setSleep(sleep); } public void run() { dbg.p(dbg.INFO,"CST: Connect-Server Thread Running ..."); try { if (aaa == null) aaa = new NullServerConnectAAA(); while (true) { /* listening & accepting connections ... */ try { dbg.p(dbg.INFO,"CST: Accepting Connections ..."); ns = ss.accept(); dbg.p(dbg.INFO,"CST: New Socket : " + ns); /** starting AAA thread and going on ... **/ new ConnectAAAServerThread(rrst, ns, aaa).start(); dbg.p(dbg.INFO,"CST: Sleeping " + getSleep() + " ms."); pause(); } catch(IOException err) { dbg.p(dbg.INFO,"CST: Accepting Error : " + err.getMessage()); } catch (Exception err) { dbg.p(dbg.INFO,"CST: Error : " + err.getMessage()); if (rrst != null) rrst.stop(); this.stop(); } } } catch (ThreadDeath err) { dbg.p(dbg.FATAL,"CST: Catched DIE Object ... shuting down."); try { ss.close(); } catch (IOException ioe) { } } } protected void finalize() { dbg.p(dbg.FATAL,"CST: Cleaning up ..."); try { ss.close(); } catch (IOException ioe) { } } } /*eoc*/