avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-apps/demo/src/java/org/apache/avalon/apps/demos/helloworldserver HelloWorldHandler.java HelloWorldServerImpl.java
Date Sat, 31 Aug 2002 06:34:51 GMT
donaldp     2002/08/30 23:34:51

  Modified:    demo     build.xml
               demo/src/java/org/apache/avalon/apps/demos/helloworldserver
                        HelloWorldHandler.java HelloWorldServerImpl.java
  Log:
  Update to demonstrate the requestShutdown() method in BlockContext.
  
  Revision  Changes    Path
  1.61      +1 -1      jakarta-avalon-apps/demo/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/demo/build.xml,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- build.xml	4 Aug 2002 06:39:48 -0000	1.60
  +++ build.xml	31 Aug 2002 06:34:51 -0000	1.61
  @@ -45,7 +45,7 @@
       <pathelement path="${java.class.path}" />
       <pathelement path="${build.classes}" />
       <fileset dir="../common/lib">
  -      <include name="*.jar" />
  +      <include name="**/*.jar" />
       </fileset>
       <fileset dir="lib">
         <include name="*.jar" />
  
  
  
  1.5       +12 -3     jakarta-avalon-apps/demo/src/java/org/apache/avalon/apps/demos/helloworldserver/HelloWorldHandler.java
  
  Index: HelloWorldHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/demo/src/java/org/apache/avalon/apps/demos/helloworldserver/HelloWorldHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- HelloWorldHandler.java	14 May 2002 11:02:54 -0000	1.4
  +++ HelloWorldHandler.java	31 Aug 2002 06:34:51 -0000	1.5
  @@ -14,6 +14,7 @@
   import java.net.SocketException;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;
  +import org.apache.avalon.phoenix.BlockContext;
   
   /**
    * This handles an individual incoming request.  It outputs a greeting as html.
  @@ -25,12 +26,15 @@
       extends AbstractLogEnabled
       implements ConnectionHandler
   {
  -    protected static int        c_counter;
  -    protected String            m_greeting;
  +    private static int        c_counter;
  +    private String            m_greeting;
  +    private BlockContext      m_context;
   
  -    protected HelloWorldHandler( final String greeting )
  +    protected HelloWorldHandler( final String greeting,
  +                                 final BlockContext context )
       {
           m_greeting = greeting;
  +        m_context = context;
       }
   
       /**
  @@ -52,6 +56,7 @@
               out.println( "<html><body><b>" + m_greeting + "!</b><br>
Requests so far = " +
                            ++c_counter + "<br>" );
               out.println( "you are " + remoteHost + " at " + remoteIP + "<br>" );
  +            out.println( "<p>The application will shutdown after 5 requests" );
               out.println( "</body></html>" );
   
               socket.close();
  @@ -83,5 +88,9 @@
           }
   
           getLogger().info( "Connection from " + remoteHost + " (" + remoteIP + ")" );
  +        if( c_counter > 4 )
  +        {
  +            m_context.requestShutdown();
  +        }
       }
   }
  
  
  
  1.11      +21 -20    jakarta-avalon-apps/demo/src/java/org/apache/avalon/apps/demos/helloworldserver/HelloWorldServerImpl.java
  
  Index: HelloWorldServerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/demo/src/java/org/apache/avalon/apps/demos/helloworldserver/HelloWorldServerImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- HelloWorldServerImpl.java	26 Aug 2002 22:13:12 -0000	1.10
  +++ HelloWorldServerImpl.java	31 Aug 2002 06:34:51 -0000	1.11
  @@ -41,8 +41,8 @@
   public class HelloWorldServerImpl
       extends AbstractLogEnabled
       implements HelloWorldServer, HelloWorldServerMBean, Contextualizable,
  -	       Serviceable, Configurable, Initializable, Disposable,
  -	       ConnectionHandlerFactory
  +    Serviceable, Configurable, Initializable, Disposable,
  +    ConnectionHandlerFactory
   {
       protected SocketManager m_socketManager;
       protected ConnectionManager m_connectionManager;
  @@ -114,23 +114,23 @@
   
       public void dispose()
       {
  -	try
  -	{
  -	    m_connectionManager.disconnect( m_connectionName );
  -	}
  -	catch ( final Exception e )
  -	{
  -	    getLogger().warn( "Error while disconnecting.", e );
  -	}
  -
  -	try
  -	{
  -	    m_serverSocket.close();
  -	}
  -	catch ( final IOException ioe )
  -	{
  -	    getLogger().warn( "Error while closing server socket.", ioe );
  -	}
  +        try
  +        {
  +            m_connectionManager.disconnect( m_connectionName );
  +        }
  +        catch( final Exception e )
  +        {
  +            getLogger().warn( "Error while disconnecting.", e );
  +        }
  +
  +        try
  +        {
  +            m_serverSocket.close();
  +        }
  +        catch( final IOException ioe )
  +        {
  +            getLogger().warn( "Error while closing server socket.", ioe );
  +        }
       }
   
       /**
  @@ -142,7 +142,8 @@
       public ConnectionHandler createConnectionHandler()
           throws Exception
       {
  -        final HelloWorldHandler handler = new HelloWorldHandler( m_greeting );
  +        final HelloWorldHandler handler =
  +            new HelloWorldHandler( m_greeting, m_context );
           setupLogger( handler );
           return handler;
       }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message