avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/transport/publishing SocketObjectStreamConnectionHandler.java SocketObjectStreamPublisher.java
Date Wed, 09 Jan 2002 22:48:45 GMT
hammant     02/01/09 14:48:45

  Modified:    src/java/org/apache/avalon/cornerstone/blocks/transport/publishing
                        SocketObjectStreamPublisher.java
  Added:       src/java/org/apache/avalon/cornerstone/blocks/transport/publishing
                        SocketObjectStreamConnectionHandler.java
  Log:
  Use cornerstone's own Connection Manager
  
  Revision  Changes    Path
  1.2       +62 -8     jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/transport/publishing/SocketObjectStreamPublisher.java
  
  Index: SocketObjectStreamPublisher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/transport/publishing/SocketObjectStreamPublisher.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SocketObjectStreamPublisher.java	9 Jan 2002 21:40:04 -0000	1.1
  +++ SocketObjectStreamPublisher.java	9 Jan 2002 22:48:45 -0000	1.2
  @@ -8,11 +8,21 @@
    */
   package org.apache.avalon.cornerstone.blocks.transport.publishing;
   
  -
  -
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.commons.altrmi.server.impl.socket.PlainSocketServer;
  +import org.apache.avalon.framework.component.Composable;
  +import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.component.ComponentException;
  +import org.apache.avalon.cornerstone.services.sockets.SocketManager;
  +import org.apache.avalon.cornerstone.services.sockets.ServerSocketFactory;
  +import org.apache.avalon.cornerstone.services.connection.ConnectionManager;
  +import org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory;
  +import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;
  +import org.apache.commons.altrmi.server.impl.socket.PartialSocketObjectStreamServer;
  +
  +import java.net.InetAddress;
  +import java.net.UnknownHostException;
  +import java.net.ServerSocket;
   
   
   /**
  @@ -20,11 +30,14 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
  -public class SocketObjectStreamPublisher extends AbstractPublisher {
  +public class SocketObjectStreamPublisher extends AbstractPublisher implements Composable,
ConnectionHandlerFactory {
   
  -    private int mPort;
  +    private SocketManager m_socketManager;
  +    private ConnectionManager m_connectionManager;
  +    private int m_port;
  +    private InetAddress m_bindTo;
   
       /**
        * Pass the <code>Configuration</code> to the <code>Configurable</code>
  @@ -36,8 +49,42 @@
       public void configure(Configuration configuration) throws ConfigurationException {
   
           super.configure(configuration);
  +        m_port = configuration.getChild("port").getValueAsInteger();
  +        try
  +        {
  +            final String bindAddress = configuration.getChild( "bind" ).getValue();
  +            m_bindTo = InetAddress.getByName( bindAddress );
  +        }
  +        catch( final UnknownHostException unhe )
  +        {
  +            throw new ConfigurationException( "Malformed bind parameter", unhe );
  +        }
   
  -        mPort = configuration.getChild("port").getValueAsInteger();
  +    }
  +
  +    public void compose(ComponentManager manager) throws ComponentException {
  +        m_socketManager = (SocketManager)manager.lookup( SocketManager.ROLE );
  +        m_connectionManager = (ConnectionManager)manager.lookup( ConnectionManager.ROLE
);
  +    }
  +
  +    /**
  +     * Construct an appropriate ConnectionHandler.
  +     *
  +     * @return the new ConnectionHandler
  +     * @exception Exception if an error occurs
  +     */
  +    public ConnectionHandler createConnectionHandler()
  +            throws Exception {
  +        final SocketObjectStreamConnectionHandler handler = new SocketObjectStreamConnectionHandler(
(PartialSocketObjectStreamServer) mAltrmiServer );
  +        setupLogger( handler );
  +        return handler;
  +    }
  +
  +    /**
  +     * Release a previously created ConnectionHandler.
  +     * e.g. for spooling.
  +     */
  +    public void releaseConnectionHandler(ConnectionHandler connectionHandler) {
       }
   
       /**
  @@ -49,8 +96,15 @@
        */
       public void initialize() throws Exception {
   
  -        mAltrmiServer = new PlainSocketServer(mPort);
  +        mAltrmiServer = new PartialSocketObjectStreamServer();
   
           super.initialize();
  +
  +        final ServerSocketFactory factory =
  +            m_socketManager.getServerSocketFactory( "plain" );
  +        final ServerSocket serverSocket = factory.createServerSocket( m_port, 5, m_bindTo
);
  +
  +        m_connectionManager.connect( "SocketObjectStreamListener", serverSocket, this );
  +
       }
   }
  
  
  
  1.1                  jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/transport/publishing/SocketObjectStreamConnectionHandler.java
  
  Index: SocketObjectStreamConnectionHandler.java
  ===================================================================
  /*
   * Created by IntelliJ IDEA.
   * User: Administrator
   * Date: Jan 9, 2002
   * Time: 10:25:12 PM
   * To change template for new class use 
   * Code Style | Class Templates options (Tools | IDE Options).
   */
  package org.apache.avalon.cornerstone.blocks.transport.publishing;
  
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;
  import org.apache.commons.altrmi.server.impl.socket.PartialSocketObjectStreamServer;
  
  import java.net.Socket;
  import java.net.ProtocolException;
  import java.io.IOException;
  
  public class SocketObjectStreamConnectionHandler extends AbstractLogEnabled
      implements Component, ConnectionHandler {
  
      private PartialSocketObjectStreamServer m_PartialSocketObjectStreamServer;
  
      public SocketObjectStreamConnectionHandler(PartialSocketObjectStreamServer partialSocketObjectStreamServer)
{
          m_PartialSocketObjectStreamServer = partialSocketObjectStreamServer;
      }
  
      /**
       * Handle a connection.
       * This handler is responsible for processing connections as they occur.
       *
       * @param connection the connection
       * @exception IOException if an error reading from socket occurs
       * @exception ProtocolException if an error handling connection occurs
       */
      public void handleConnection(Socket connection)
              throws IOException, ProtocolException {
          m_PartialSocketObjectStreamServer.handleConnection(connection);
      }
  }
  
  
  

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