home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / RMISocketFactory.java < prev    next >
Text File  |  1997-05-20  |  4KB  |  111 lines

  1. /*
  2.  * @(#)RMISocketFactory.java    1.5 97/01/03
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  */
  21.  
  22. package java.rmi.server;
  23.  
  24. import java.io.*;
  25. import java.net.*;
  26.  
  27. /**
  28.  * The RMISocketFactory is used by the RMI runtime in order to obtain
  29.  * client and server sockets for RMI calls. The default implementation
  30.  * of the socket factory performs a three-tiered approach to creating
  31.  * client sockets. First, a direct socket connection to the remote VM
  32.  * is attempted.  If that fails (due to a firewall), the runtime uses
  33.  * HTTP with the explicit port number of the server.  If the firewall
  34.  * does not allow this type of communication, then HTTP to a cgi-bin
  35.  * script on the server is used to POST the RMI call.
  36.  *
  37.  * An application may set the source of sockets for RMI. In this case,
  38.  * the application is responsible for offering up sockets that will
  39.  * penetrate a firewall.
  40.  */
  41. public abstract class RMISocketFactory {
  42.  
  43.     /** Client/server socket factory used by RMI */
  44.     private static RMISocketFactory factory = null;
  45.     /** Handler for socket creation failure */
  46.     private static RMIFailureHandler handler = null;
  47.  
  48.     /**
  49.      * Create a client socket connected to the specified host and port.
  50.      */
  51.     public abstract Socket createSocket(String host, int port)
  52.     throws IOException;
  53.  
  54.     /**
  55.      * Create a server socket on the specified port (port 0 represents
  56.      * an anonymous port).
  57.      */
  58.     public abstract ServerSocket createServerSocket(int port)
  59.     throws IOException;
  60.  
  61.     /**
  62.      * Set the socket factory from which RMI gets sockets. The RMI
  63.      * socket factory can only be set once. Note: The RMISocketFactory
  64.      * may only be set if the current security manager allows setting
  65.      * a socket factory; if disallowed, a SecurityException will be
  66.      * thrown.
  67.      */
  68.     public static void setSocketFactory(RMISocketFactory fac)
  69.     throws IOException
  70.     {
  71.         if (factory != null) {
  72.         throw new SocketException("factory already defined");
  73.     }
  74.     SecurityManager security = System.getSecurityManager();
  75.     if (security != null) {
  76.         security.checkSetFactory();
  77.     }
  78.     factory = fac;
  79.     }
  80.  
  81.     /**
  82.      * Returns the socket factory used by RMI.
  83.      */
  84.     public static RMISocketFactory getSocketFactory() 
  85.     {
  86.     return factory;
  87.     }
  88.  
  89.     /**
  90.      * Set the failure handler to be called by the RMI runtime if
  91.      * socket creation fails.  The default implementation of this
  92.      * handler returns false (thus recreation of sockets is not
  93.      * attempted by the runtime).
  94.      */
  95.     public static void setFailureHandler(RMIFailureHandler fh) 
  96.     {
  97.     handler = fh;
  98.     }
  99.  
  100.     /**
  101.      * Returns the handler for socket creation failure.
  102.      */
  103.     public static RMIFailureHandler getFailureHandler()
  104.     {
  105.     return handler;
  106.     }
  107. }
  108.  
  109.     
  110.     
  111.