Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 
 package org.jboss.remoting.transport.rmi;
 
 import  org.jboss.logging.Logger;
 
RemotingRMIServerSocketFactory provides two services to RMIServerInvoker.
  1. It can be parameterized by a host name, allowing RMIServerInvoker to supply RMI with a factory which creates server sockets bound to a specified host name as well as port.

  2. It can be parameterized by a ServerSocketFactory allowing RMIServerInvoker to supply RMI with a factory facility which creates specialized server sockets.

If the ServerSocketFactory parameter is specified, then the RemotingRMIServerSocketFactory should be used with a matching instance of RemotingRMIClientSocketFactory with a compatible SocketFactory.

If the ServerSocketFactory parameter is not specified, an instance of java.net.ServerSocket will be created by default.

Author(s):
Ron Sigal
Version:
$Revision: 1216 $

Copyright (c) 2005

 
 
 {
    protected static final Logger log = Logger.getLogger(RemotingRMIServerSocketFactory.class);
 
    private int backlog;
    private InetAddress bindAddress;
    private int timeout;
    private static final long serialVersionUID = -5851426317709480542L;
 
    // The commented code below is from an attempt to incorporate a <code>java.lang.reflect.Constructor</code>
    // parameter to provide a very general way to create server sockets.  The problem is that
    // <code>Constructor</code> does not implement <code>Serializable</code>, which is necessary to
    // allow the <code>RemotingRMIServerSocketFactory</code> to be transmitted to the RMI Registry.  The
    // code is left in place because it could be resurrected by passing in a class name and parameter
    // types to specify a constructor.  Fortunately, <code>java.lang.Class</code> does implement
    // <code>Serializable</code>.
 
 //   private Constructor constructor;
 //   private Object[] args;
 //   private int portPosition;
 

   

Parameters:
bindHost name of host to which all generated server sockets should be bound
 
    {
       this(null, -1, bindHost);
    }


   

Parameters:
backlog to be passed to all generated server sockets
bindHost name of host to which all generated server sockets should be bound
Throws:
UnknownHostException if an IP address for bindHost cannot be found
 
    public RemotingRMIServerSocketFactory(int backlogString bindHostthrows UnknownHostException
    {
      this(nullbacklogbindHost);
   }


   

Parameters:
serverSocketFactory ServerSocketFactory for generating server sockets
backlog to be passed to all generated server sockets
bindHost name of host to which all generated server sockets should be bound
Throws:
UnknownHostException if an IP address for bindHost cannot be found
   public RemotingRMIServerSocketFactory(ServerSocketFactory serverSocketFactoryint backlogString bindHost)
         throws UnknownHostException
   {
      this(serverSocketFactorybacklogbindHost, 60000); // TODO: -TME This needs to be fixed so only comes from parent class
   }
   public RemotingRMIServerSocketFactory(ServerSocketFactory serverSocketFactoryint backlogString bindHostint timeout)
         throws UnknownHostException
   {
      .info("bind host: " + bindHost);
      this. = serverSocketFactory;
      this. = backlog;
      this. = InetAddress.getByName(bindHost);
      this. = timeout;
   }
   public RemotingRMIServerSocketFactory(String bindHostint timeoutthrows UnknownHostException
   {
      this(null, -1, bindHosttimeout);
   }
//   public RemotingRMIServerSocketFactory(Constructor constructor, Object[] args, int portPosition)
//   {
//      this.constructor = constructor;
//      this.args = args;
//      this.portPosition = portPosition;
//   }


   
Creates a server socket bound to the host name passed to the constructor. If a ServerSocketFactory was passed to the constructor, it will be used to create the server socket. Otherwise, an instance of java.net.ServerSocket will be created.

Parameters:
port the port to which the generated server socket should be bound
Returns:
a new ServerSocket
Throws:
IOException if there is a problem creating a server socket
   public ServerSocket createServerSocket(int portthrows IOException
   {
      ServerSocket svrSocket = null;
      if( != null)
      {
         svrSocket = .createServerSocket(port);
      }
//      if (constructor != null)
//      {
//         try
//         {
//            if (portPosition != -1)
//               args[portPosition] = new Integer(port);
//
//            return (ServerSocket) constructor.newInstance(args);
//         }
//         catch (Exception e)
//         {
//            throw new IOException(e.getMessage());
//         }
//      }
      else
      {
         svrSocket = new ServerSocket(port);
      }
      svrSocket.setSoTimeout();
      return svrSocket;
   }


   
Overrides the equals() method provided by the Object class. It looks for equality of binding host name and server socket factory parameters passed to constructor.

Parameters:
o Object to which code is to be compared.
Returns:
true if and only if o equals this
   public boolean equals(Object o)
   {
      if(! (o instanceof RemotingRMIServerSocketFactory))
      {
         return false;
      }
      // This is for the version that uses a ServerSocketFactory
      if( != null)
      {
         if(ssf.serverSocketFactory == null ||
            !.equals(ssf.serverSocketFactory) ||
             != ssf.backlog ||
            !.equals(ssf.bindAddress))
         {
            return false;
         }
         return true;
      }
//      // This is for the version that uses a constructor
//      if (constructor != null)
//      {
//         if (ssf.constructor == null ||
//               ! constructor.equals(ssf.constructor) ||
//               portPosition != ssf.portPosition)
//            return false;
//
//         for (int i = 0; i < args.length; i++)
//         {
//            if (! args[i].equals(ssf.args[i]))
//               return false;
//         }
//
//         return true;
//      }
      // This is for the plain vanilla version
      if(ssf.serverSocketFactory != null ||  != ssf.backlog || !.equals(ssf.bindAddress))
      {
         return false;
      }
      return true;
   }


   
Overrides hashCode() method provided by the Object class.

Returns:
a hashcode for this
   public int hashCode()
   {
      if( != null)
      {
         return .hashCode() *  * .hashCode();
      }
//      if (constructor != null)
//      {
//         int hash = portPosition;
//         
//         for (int i = 0; i < args.length; i++)
//            hash *= args[i].hashCode();
//         
//         return hash;
//      }
      return  * .hashCode();
   }
New to GrepCode? Check out our FAQ X