jdk/src/share/classes/java/rmi/server/RMISocketFactory.java
author smarks
Thu, 24 Oct 2013 10:13:39 -0700
changeset 21359 2d32ce9ea2b4
parent 19580 8ef7bdc1bb5a
child 24865 09b1d992ca72
permissions -rw-r--r--
8023862: deprecate HTTP proxying from RMI Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19201
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
     2
 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.rmi.server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * An <code>RMISocketFactory</code> instance is used by the RMI runtime
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * in order to obtain client and server sockets for RMI calls.  An
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * application may use the <code>setSocketFactory</code> method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * request that the RMI runtime use its socket factory instance
19201
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    36
 * instead of the default implementation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
19201
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    38
 * <p>The default socket factory implementation performs a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * three-tiered approach to creating client sockets. First, a direct
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * socket connection to the remote VM is attempted.  If that fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * (due to a firewall), the runtime uses HTTP with the explicit port
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * number of the server.  If the firewall does not allow this type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * communication, then HTTP to a cgi-bin script on the server is used
21359
2d32ce9ea2b4 8023862: deprecate HTTP proxying from RMI
smarks
parents: 19580
diff changeset
    44
 * to POST the RMI call. The HTTP tunneling mechanisms are disabled by
2d32ce9ea2b4 8023862: deprecate HTTP proxying from RMI
smarks
parents: 19580
diff changeset
    45
 * default. This behavior is controlled by the {@code java.rmi.server.disableHttp}
2d32ce9ea2b4 8023862: deprecate HTTP proxying from RMI
smarks
parents: 19580
diff changeset
    46
 * property, whose default value is {@code true}. Setting this property's
2d32ce9ea2b4 8023862: deprecate HTTP proxying from RMI
smarks
parents: 19580
diff changeset
    47
 * value to {@code false} will enable the HTTP tunneling mechanisms.
2d32ce9ea2b4 8023862: deprecate HTTP proxying from RMI
smarks
parents: 19580
diff changeset
    48
 *
2d32ce9ea2b4 8023862: deprecate HTTP proxying from RMI
smarks
parents: 19580
diff changeset
    49
 * <p><strong>Deprecated: HTTP Tunneling.</strong> <em>The HTTP tunneling mechanisms
2d32ce9ea2b4 8023862: deprecate HTTP proxying from RMI
smarks
parents: 19580
diff changeset
    50
 * described above, specifically HTTP with an explicit port and HTTP to a
2d32ce9ea2b4 8023862: deprecate HTTP proxying from RMI
smarks
parents: 19580
diff changeset
    51
 * cgi-bin script, are deprecated. These HTTP tunneling mechanisms are
2d32ce9ea2b4 8023862: deprecate HTTP proxying from RMI
smarks
parents: 19580
diff changeset
    52
 * subject to removal in a future release of the platform.</em>
19201
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    53
 *
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    54
 * <p>The default socket factory implementation creates server sockets that
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    55
 * are bound to the wildcard address, which accepts requests from all network
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    56
 * interfaces.
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    57
 *
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    58
 * @implNote
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    59
 * <p>You can use the {@code RMISocketFactory} class to create a server socket that
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    60
 * is bound to a specific address, restricting the origin of requests. For example,
19580
8ef7bdc1bb5a 8022445: fix RMISocketFactory example to avoid using localhost
smarks
parents: 19201
diff changeset
    61
 * the following code implements a socket factory that binds server sockets to an IPv4
19201
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    62
 * loopback address. This restricts RMI to processing requests only from the local host.
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    63
 *
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    64
 * <pre>{@code
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    65
 *     class LoopbackSocketFactory extends RMISocketFactory {
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    66
 *         public ServerSocket createServerSocket(int port) throws IOException {
19580
8ef7bdc1bb5a 8022445: fix RMISocketFactory example to avoid using localhost
smarks
parents: 19201
diff changeset
    67
 *             return new ServerSocket(port, 5, InetAddress.getByName("127.0.0.1"));
19201
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    68
 *         }
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    69
 *
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    70
 *         public Socket createSocket(String host, int port) throws IOException {
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    71
 *             // just call the default client socket factory
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    72
 *             return RMISocketFactory.getDefaultSocketFactory()
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    73
 *                                    .createSocket(host, port);
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    74
 *         }
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    75
 *     }
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    76
 *
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    77
 *     // ...
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    78
 *
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    79
 *     RMISocketFactory.setSocketFactory(new LoopbackSocketFactory());
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    80
 * }</pre>
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    81
 *
80230405e311 8020854: change RMI javadocs to specify that remote objects are exported to the wildcard address
smarks
parents: 5506
diff changeset
    82
 * Set the {@code java.rmi.server.hostname} system property
19580
8ef7bdc1bb5a 8022445: fix RMISocketFactory example to avoid using localhost
smarks
parents: 19201
diff changeset
    83
 * to {@code 127.0.0.1} to ensure that the generated stubs connect to the right
8ef7bdc1bb5a 8022445: fix RMISocketFactory example to avoid using localhost
smarks
parents: 19201
diff changeset
    84
 * network interface.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @author  Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * @author  Peter Jones
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
public abstract class RMISocketFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        implements RMIClientSocketFactory, RMIServerSocketFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /** Client/server socket factory to be used by RMI runtime */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static RMISocketFactory factory = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /** default socket factory used by this RMI implementation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static RMISocketFactory defaultSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /** Handler for socket creation failure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static RMIFailureHandler handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Constructs an <code>RMISocketFactory</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public RMISocketFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Creates a client socket connected to the specified host and port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param  host   the host name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param  port   the port number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @return a socket connected to the specified host and port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @exception IOException if an I/O error occurs during socket creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public abstract Socket createSocket(String host, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Create a server socket on the specified port (port 0 indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * an anonymous port).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param  port the port number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @return the server socket on the specified port
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @exception IOException if an I/O error occurs during server socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public abstract ServerSocket createServerSocket(int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Set the global socket factory from which RMI gets sockets (if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * remote object is not associated with a specific client and/or server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * socket factory). The RMI socket factory can only be set once. Note: The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * RMISocketFactory may only be set if the current security manager allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * setting a socket factory; if disallowed, a SecurityException will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param fac the socket factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @exception IOException if the RMI socket factory is already set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @exception  SecurityException  if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *             <code>checkSetFactory</code> method doesn't allow the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @see #getSocketFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @see java.lang.SecurityManager#checkSetFactory()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public synchronized static void setSocketFactory(RMISocketFactory fac)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (factory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            throw new SocketException("factory already defined");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            security.checkSetFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        factory = fac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Returns the socket factory set by the <code>setSocketFactory</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * method. Returns <code>null</code> if no socket factory has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return the socket factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @see #setSocketFactory(RMISocketFactory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public synchronized static RMISocketFactory getSocketFactory()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Returns a reference to the default socket factory used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * by this RMI implementation.  This will be the factory used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * by the RMI runtime when <code>getSocketFactory</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @return the default RMI socket factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public synchronized static RMISocketFactory getDefaultSocketFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (defaultSocketFactory == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            defaultSocketFactory =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                new sun.rmi.transport.proxy.RMIMasterSocketFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return defaultSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Sets the failure handler to be called by the RMI runtime if server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * socket creation fails.  By default, if no failure handler is installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * and server socket creation fails, the RMI runtime does attempt to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * recreate the server socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * <p>If there is a security manager, this method first calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * the security manager's <code>checkSetFactory</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * to ensure the operation is allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * This could result in a <code>SecurityException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param fh the failure handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @throws  SecurityException  if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *          <code>checkSetFactory</code> method doesn't allow the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *          operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @see #getFailureHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @see java.rmi.server.RMIFailureHandler#failure(Exception)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public synchronized static void setFailureHandler(RMIFailureHandler fh)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            security.checkSetFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        handler = fh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Returns the handler for socket creation failure set by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <code>setFailureHandler</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @return the failure handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @see #setFailureHandler(RMIFailureHandler)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public synchronized static RMIFailureHandler getFailureHandler()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
}