jdk/src/java.rmi/share/classes/java/rmi/server/UnicastRemoteObject.java
changeset 41232 5da543633b3b
parent 25859 3317bb8137f4
child 43690 e8cdf30d90c4
equal deleted inserted replaced
41231:3f8807f6fec3 41232:5da543633b3b
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 package java.rmi.server;
    25 package java.rmi.server;
    26 
    26 
       
    27 import java.io.ObjectInputFilter;
    27 import java.rmi.*;
    28 import java.rmi.*;
    28 import sun.rmi.server.UnicastServerRef;
    29 import sun.rmi.server.UnicastServerRef;
    29 import sun.rmi.server.UnicastServerRef2;
    30 import sun.rmi.server.UnicastServerRef2;
       
    31 import sun.rmi.transport.LiveRef;
    30 
    32 
    31 /**
    33 /**
    32  * Used for exporting a remote object with JRMP and obtaining a stub
    34  * Used for exporting a remote object with JRMP and obtaining a stub
    33  * that communicates to the remote object. Stubs are either generated
    35  * that communicates to the remote object. Stubs are either generated
    34  * at runtime using dynamic proxy objects, or they are generated statically
    36  * at runtime using dynamic proxy objects, or they are generated statically
    36  *
    38  *
    37  * <p><strong>Deprecated: Static Stubs.</strong> <em>Support for statically
    39  * <p><strong>Deprecated: Static Stubs.</strong> <em>Support for statically
    38  * generated stubs is deprecated. This includes the API in this class that
    40  * generated stubs is deprecated. This includes the API in this class that
    39  * requires the use of static stubs, as well as the runtime support for
    41  * requires the use of static stubs, as well as the runtime support for
    40  * loading static stubs.  Generating stubs dynamically is preferred, using one
    42  * loading static stubs.  Generating stubs dynamically is preferred, using one
    41  * of the five non-deprecated ways of exporting objects as listed below. Do
    43  * of the non-deprecated ways of exporting objects as listed below. Do
    42  * not run {@code rmic} to generate static stub classes. It is unnecessary, and
    44  * not run {@code rmic} to generate static stub classes. It is unnecessary, and
    43  * it is also deprecated.</em>
    45  * it is also deprecated.</em>
    44  *
    46  *
    45  * <p>There are six ways to export remote objects:
    47  * <p>There are eight ways to export remote objects:
    46  *
    48  *
    47  * <ol>
    49  * <ol>
    48  *
    50  *
    49  * <li>Subclassing {@code UnicastRemoteObject} and calling the
    51  * <li>Subclassing {@code UnicastRemoteObject} and calling the
    50  * {@link #UnicastRemoteObject()} constructor.
    52  * {@link #UnicastRemoteObject()} constructor.
    65  *
    67  *
    66  * <li>Calling the
    68  * <li>Calling the
    67  * {@link #exportObject(Remote, int, RMIClientSocketFactory, RMIServerSocketFactory)
    69  * {@link #exportObject(Remote, int, RMIClientSocketFactory, RMIServerSocketFactory)
    68  * exportObject(Remote, port, csf, ssf)} method.
    70  * exportObject(Remote, port, csf, ssf)} method.
    69  *
    71  *
       
    72  * <li>Calling the
       
    73  * {@link #exportObject(Remote, int, ObjectInputFilter) exportObject(Remote, port, filter)} method.
       
    74  *
       
    75  * <li>Calling the
       
    76  * {@link #exportObject(Remote, int, RMIClientSocketFactory, RMIServerSocketFactory, ObjectInputFilter)
       
    77  * exportObject(Remote, port, csf, ssf, filter)} method.
       
    78  *
    70  * </ol>
    79  * </ol>
    71  *
    80  *
    72  * <p>The fourth technique, {@link #exportObject(Remote)},
    81  * <p>The fourth technique, {@link #exportObject(Remote)},
    73  * always uses statically generated stubs and is deprecated.
    82  * always uses statically generated stubs and is deprecated.
    74  *
    83  *
    75  * <p>The other five techniques all use the following approach: if the
    84  * <p>The other techniques all use the following approach: if the
    76  * {@code java.rmi.server.ignoreStubClasses} property is {@code true}
    85  * {@code java.rmi.server.ignoreStubClasses} property is {@code true}
    77  * (case insensitive) or if a static stub cannot be found, stubs are generated
    86  * (case insensitive) or if a static stub cannot be found, stubs are generated
    78  * dynamically using {@link java.lang.reflect.Proxy Proxy} objects. Otherwise,
    87  * dynamically using {@link java.lang.reflect.Proxy Proxy} objects. Otherwise,
    79  * static stubs are used.
    88  * static stubs are used.
    80  *
    89  *
   127  *
   136  *
   128  * <li>If the proxy could not be created, a {@link StubNotFoundException}
   137  * <li>If the proxy could not be created, a {@link StubNotFoundException}
   129  * will be thrown.
   138  * will be thrown.
   130  *
   139  *
   131  * </ul>
   140  * </ul>
       
   141  *
       
   142  * <p>
       
   143  * Exported remote objects receive method invocations from the stubs
       
   144  * as described in the RMI specification. Each invocation's operation and
       
   145  * parameters are unmarshaled using a custom {@link java.io.ObjectInputStream}.
       
   146  * If an {@link ObjectInputFilter} is provided and is not {@code null} when the object
       
   147  * is exported, it is used to filter the parameters as they are unmarshaled from the stream.
       
   148  * The filter is used for all invocations and all parameters regardless of
       
   149  * the method being invoked or the parameter values.
       
   150  * If no filter is provided or is {@code null} for the exported object then the
       
   151  * {@code ObjectInputStream} default filter, if any, is used. The default filter is
       
   152  * configured with {@link ObjectInputFilter.Config#setSerialFilter(ObjectInputFilter)
       
   153  * ObjectInputFilter.Config.setSerialFilter}.
       
   154  * If the filter rejects any of the parameters, the {@code InvalidClassException}
       
   155  * thrown by {@code ObjectInputStream} is reported as the cause of an
       
   156  * {@link UnmarshalException}.
   132  *
   157  *
   133  * @implNote
   158  * @implNote
   134  * Depending upon which constructor or static method is used for exporting an
   159  * Depending upon which constructor or static method is used for exporting an
   135  * object, {@link RMISocketFactory} may be used for creating sockets.
   160  * object, {@link RMISocketFactory} may be used for creating sockets.
   136  * By default, server sockets created by {@link RMISocketFactory}
   161  * By default, server sockets created by {@link RMISocketFactory}
   345 
   370 
   346         return exportObject(obj, new UnicastServerRef2(port, csf, ssf));
   371         return exportObject(obj, new UnicastServerRef2(port, csf, ssf));
   347     }
   372     }
   348 
   373 
   349     /**
   374     /**
       
   375      * Exports the remote object to make it available to receive incoming
       
   376      * calls, using the particular supplied port
       
   377      * and {@linkplain ObjectInputFilter filter}.
       
   378      *
       
   379      * <p>The object is exported with a server socket
       
   380      * created using the {@link RMISocketFactory} class.
       
   381      *
       
   382      * @param obj the remote object to be exported
       
   383      * @param port the port to export the object on
       
   384      * @param filter an ObjectInputFilter applied when deserializing invocation arguments;
       
   385      *               may be {@code null}
       
   386      * @return remote object stub
       
   387      * @exception RemoteException if export fails
       
   388      * @since 9
       
   389      */
       
   390     public static Remote exportObject(Remote obj, int port,
       
   391                                       ObjectInputFilter filter)
       
   392             throws RemoteException
       
   393     {
       
   394         return exportObject(obj, new UnicastServerRef(new LiveRef(port), filter));
       
   395     }
       
   396 
       
   397     /**
       
   398      * Exports the remote object to make it available to receive incoming
       
   399      * calls, using a transport specified by the given socket factory
       
   400      * and {@linkplain ObjectInputFilter filter}.
       
   401      *
       
   402      * <p>Either socket factory may be {@code null}, in which case
       
   403      * the corresponding client or server socket creation method of
       
   404      * {@link RMISocketFactory} is used instead.
       
   405      *
       
   406      * @param obj the remote object to be exported
       
   407      * @param port the port to export the object on
       
   408      * @param csf the client-side socket factory for making calls to the
       
   409      * remote object
       
   410      * @param ssf the server-side socket factory for receiving remote calls
       
   411      * @param filter an ObjectInputFilter applied when deserializing invocation arguments;
       
   412      *               may be {@code null}
       
   413      * @return remote object stub
       
   414      * @exception RemoteException if export fails
       
   415      * @since 9
       
   416      */
       
   417     public static Remote exportObject(Remote obj, int port,
       
   418                                       RMIClientSocketFactory csf,
       
   419                                       RMIServerSocketFactory ssf,
       
   420                                       ObjectInputFilter filter)
       
   421         throws RemoteException
       
   422     {
       
   423         return exportObject(obj, new UnicastServerRef2(port, csf, ssf, filter));
       
   424     }
       
   425 
       
   426     /**
   350      * Removes the remote object, obj, from the RMI runtime. If
   427      * Removes the remote object, obj, from the RMI runtime. If
   351      * successful, the object can no longer accept incoming RMI calls.
   428      * successful, the object can no longer accept incoming RMI calls.
   352      * If the force parameter is true, the object is forcibly unexported
   429      * If the force parameter is true, the object is forcibly unexported
   353      * even if there are pending calls to the remote object or the
   430      * even if there are pending calls to the remote object or the
   354      * remote object still has calls in progress.  If the force
   431      * remote object still has calls in progress.  If the force