avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-avalon-apps/demo/src/java/org/apache/avalon/apps/demos/helloworldserver HelloWorldServerImpl.java
Date Mon, 29 Jul 2002 07:55:31 GMT
colus       2002/07/29 00:55:31

  Modified:    demo/src/java/org/apache/avalon/apps/demos/helloworldserver
                        HelloWorldServerImpl.java
  Log:
  Release server socket and connection.
  
  Revision  Changes    Path
  1.9       +30 -3     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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- HelloWorldServerImpl.java	2 Jun 2002 05:37:50 -0000	1.8
  +++ HelloWorldServerImpl.java	29 Jul 2002 07:55:31 -0000	1.9
  @@ -7,6 +7,7 @@
    */
   package org.apache.avalon.apps.demos.helloworldserver;
   
  +import java.io.IOException;
   import java.net.InetAddress;
   import java.net.ServerSocket;
   import java.net.UnknownHostException;
  @@ -15,6 +16,7 @@
   import org.apache.avalon.cornerstone.services.connection.ConnectionManager;
   import org.apache.avalon.cornerstone.services.sockets.ServerSocketFactory;
   import org.apache.avalon.cornerstone.services.sockets.SocketManager;
  +import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
  @@ -38,7 +40,9 @@
    */
   public class HelloWorldServerImpl
       extends AbstractLogEnabled
  -    implements HelloWorldServer, HelloWorldServerMBean, Contextualizable, Serviceable,
Configurable, Initializable, ConnectionHandlerFactory
  +    implements HelloWorldServer, HelloWorldServerMBean, Contextualizable,
  +	       Serviceable, Configurable, Initializable, Disposable,
  +	       ConnectionHandlerFactory
   {
       protected SocketManager m_socketManager;
       protected ConnectionManager m_connectionManager;
  @@ -46,6 +50,8 @@
       protected String m_greeting = "Hello World";
       protected InetAddress m_bindTo;
       protected int m_port;
  +    protected String m_connectionName = "HelloWorldListener";
  +    protected ServerSocket m_serverSocket;
   
       public void setGreeting( final String greeting )
       {
  @@ -93,12 +99,33 @@
       {
           final ServerSocketFactory factory =
               m_socketManager.getServerSocketFactory( "plain" );
  -        final ServerSocket serverSocket = factory.createServerSocket( m_port, 5, m_bindTo
);
  +        m_serverSocket = factory.createServerSocket( m_port, 5, m_bindTo );
   
  -        m_connectionManager.connect( "HelloWorldListener", serverSocket, this );
  +        m_connectionManager.connect( m_connectionName, m_serverSocket, this );
   
           // This is only to help newbies.....
           System.out.println( "HelloWorld server running with a greeting of '" + m_greeting
+ "'.  Point your browser to http://localhost:" + m_port + " to see its page" );
  +    }
  +
  +    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 );
  +	}
       }
   
       /**
  
  
  

--
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