tests/utils/monitor/org/apache/test/TestClientListener.java
/**
     *
     * Sits waiting for a client thread and when one connects we start up a new TestClientThread to handle
     * the request. This method then goes round again waiting for future requests.
     *  
     * @see Thread
     */
Sits waiting for a client thread and when one connects we start up a new TestClientThread to handle
the request. This method then goes round again waiting for future requests.

@see Thread
Sits waiting for a client thread and when one connects we start up a new TestClientThread to handle the request . This method then goes round again waiting for future requests . @see Thread
public void run( )
    {
        stayAlive=true;
        Socket clientSocket=null;
        while (stayAlive==true)
        {
            clientSocket=null;
            try
            {
                System.out
                        .println("TestClientListener#run(): Waiting for a new client request: "+listenPort);
                clientSocket=serverSocket.accept( );
                clientSocket.setKeepAlive(true);
                System.out
                        .println("TestClientListener#run():Got a client new client request");
            }
            catch (SocketTimeoutException socketTimeoutException)
            {
            }
            catch (IOException exception)
            {
                if(stayAlive)
                {
                System.err
                        .println("IOException when accepting a connection from the client: "
                                +exception);
                throw new RuntimeException(
                        "IOException when accepting a connection from the client: "
                                +exception);
                }
            }
            if (clientSocket!=null)
            {
                TestClientThread connectionToServer=null;
                try
                {
                        connectionToServer=ServerConnectionFactory.getServerConnection(clientSocket, serviceHostNme, servicePort);
                        addChild(connectionToServer);
                        Thread connectionToServerThread = new Thread(connectionToServer);
                        connectionToServerThread.start( );
                }
                catch(IllegalAccessException illegalAccessException)
                {
                    System.err.println( "Cannot connect to server");
                    illegalAccessException.printStackTrace();
                    stayAlive=false;
                }
                catch(InstantiationException instantiationException)
                {
                    System.err.println( "InstatntiationException: Cannot connect to server");
                    instantiationException.printStackTrace();
                    stayAlive=false;
                }
                catch(NoSuchMethodException noSuchMethodException)
                {
                    System.err.println( "NoSuchMethodException: Cannot connect to server");
                    noSuchMethodException.printStackTrace();
                    stayAlive=false;
                }
                catch(InvocationTargetException invocationTargetException)
                {
                    if(invocationTargetException.getCause() instanceof StopRequestException)
                    {
                        System.out
                        .println("TestClientListener got a Stop monitor message");
                    }
                    else
                    {
                        System.err.println( "InvocationTargetException: Cannot connect to server");
                        invocationTargetException.printStackTrace();
                    }
                    stayAlive=false;
                }
                catch (StopRequestException stopRequestException)
                {
                    System.out
                            .println("TestClientListener got a Stop monitor message");
                    stayAlive=false;
                }
                catch(ConnectionNotEstablishedException connectionNotEstablishedException)
                {
                    System.err.println( "ConnectionNotEstablished: Cannot connect to server");
                    stayAlive=false;
                }
                catch (ConnectException connectException)
                {
                    System.err
                            .println("Connection exception when reading in bytes from the client : "
                                    +connectException);
                }
                catch (IOException exception)
                {
                    System.err
                            .println("IOException when creating the connection to the server or getting the connection stream back to the client: "
                                    +exception);
                    throw new RuntimeException(
                            "IOException when creating the connection to the server or getting the connection stream back to the client: "
                                    +exception);
                }
            }
        }
    }
public void run ( ) { stayAlive = true ; Socket clientSocket = null ; while ( stayAlive == true ) { clientSocket = null ; try { System . out . println ( "TestClientListener#run(): Waiting for a new client request: " + listenPort ) ; clientSocket = serverSocket . accept ( ) ; clientSocket . setKeepAlive ( true ) ; System . out . println ( "TestClientListener#run():Got a client new client request" ) ; } catch ( SocketTimeoutException socketTimeoutException ) { } catch ( IOException exception ) { if ( stayAlive ) { System . err . println ( "IOException when accepting a connection from the client: " + exception ) ; throw new RuntimeException ( "IOException when accepting a connection from the client: " + exception ) ; } } if ( clientSocket != null ) { TestClientThread connectionToServer = null ; try { connectionToServer = ServerConnectionFactory . getServerConnection ( clientSocket , serviceHostNme , servicePort ) ; addChild ( connectionToServer ) ; Thread connectionToServerThread = new Thread ( connectionToServer ) ; connectionToServerThread . start ( ) ; } catch ( IllegalAccessException illegalAccessException ) { System . err . println ( "Cannot connect to server" ) ; illegalAccessException . printStackTrace ( ) ; stayAlive = false ; } catch ( InstantiationException instantiationException ) { System . err . println ( "InstatntiationException: Cannot connect to server" ) ; instantiationException . printStackTrace ( ) ; stayAlive = false ; } catch ( NoSuchMethodException noSuchMethodException ) { System . err . println ( "NoSuchMethodException: Cannot connect to server" ) ; noSuchMethodException . printStackTrace ( ) ; stayAlive = false ; } catch ( InvocationTargetException invocationTargetException ) { if ( invocationTargetException . getCause ( ) instanceof StopRequestException ) { System . out . println ( "TestClientListener got a Stop monitor message" ) ; } else { System . err . println ( "InvocationTargetException: Cannot connect to server" ) ; invocationTargetException . printStackTrace ( ) ; } stayAlive = false ; } catch ( StopRequestException stopRequestException ) { System . out . println ( "TestClientListener got a Stop monitor message" ) ; stayAlive = false ; } catch ( ConnectionNotEstablishedException connectionNotEstablishedException ) { System . err . println ( "ConnectionNotEstablished: Cannot connect to server" ) ; stayAlive = false ; } catch ( ConnectException connectException ) { System . err . println ( "Connection exception when reading in bytes from the client : " + connectException ) ; } catch ( IOException exception ) { System . err . println ( "IOException when creating the connection to the server or getting the connection stream back to the client: " + exception ) ; throw new RuntimeException ( "IOException when creating the connection to the server or getting the connection stream back to the client: " + exception ) ; } } } }
Sits waiting for a client thread and when one connects we start up a new TestClientThread to handle
 the request.
Sits waiting for a client thread and when one connects we start up a new TestClientThread to handle the request .
//        try //        { //            //serverSocket.setSoTimeout(2000); //        } //        catch(SocketException exception) //        { //            exception.printStackTrace(); //        } // ensure clientSocket is an indicator of whether we got a new connection or not // Set keep-alive option to ensure that if client crashes we do not  // hang waiting on TCP/IP response. // System.out.println( "socket timedout"); // that's fine - this is what helps us get out of this loop // Wait until we have received our first bytes from the // client before we create the connection to the service. // this is thrown when we cannot instantiate the connection to server class // this is thrown when we cannot instantiate the connection to server class // this is thrown when we cannot instantiate the connection to server class // All is well ! // 	this is bad when we cannot instantiate the connection to server class // this is thrown when we cannot connect to the server // OK, well for whatever reasons the socket is closed so go // around and try and listen again !