feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 1996, 1998, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
/**
* An <code>ExportException</code> is a <code>RemoteException</code>
* thrown if an attempt to export a remote object fails. A remote object is
* exported via the constructors and <code>exportObject</code> methods of
* <code>java.rmi.server.UnicastRemoteObject</code> and
* <code>java.rmi.activation.Activatable</code>.
*
* @author Ann Wollrath
* @since JDK1.1
* @see java.rmi.server.UnicastRemoteObject
* @see java.rmi.activation.Activatable
*/
public class ExportException extends java.rmi.RemoteException {
/* indicate compatibility with JDK 1.1.x version of class */
private static final long serialVersionUID = -9155485338494060170L;
/**
* Constructs an <code>ExportException</code> with the specified
* detail message.
*
* @param s the detail message
* @since JDK1.1
*/
public ExportException(String s) {
super(s);
}
/**
* Constructs an <code>ExportException</code> with the specified
* detail message and nested exception.
*
* @param s the detail message
* @param ex the nested exception
* @since JDK1.1
*/
public ExportException(String s, Exception ex) {
super(s, ex);
}
}

View File

@@ -0,0 +1,95 @@
/*
* Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.net.MalformedURLException;
import java.net.URL;
/**
* <code>LoaderHandler</code> is an interface used internally by the RMI
* runtime in previous implementation versions. It should never be accessed
* by application code.
*
* @author Ann Wollrath
* @since JDK1.1
*
* @deprecated no replacement
*/
@Deprecated
public interface LoaderHandler {
/** package of system <code>LoaderHandler</code> implementation. */
final static String packagePrefix = "sun.rmi.server";
/**
* Loads a class from the location specified by the
* <code>java.rmi.server.codebase</code> property.
*
* @param name the name of the class to load
* @return the <code>Class</code> object representing the loaded class
* @exception MalformedURLException
* if the system property <b>java.rmi.server.codebase</b>
* contains an invalid URL
* @exception ClassNotFoundException
* if a definition for the class could not
* be found at the codebase location.
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
Class<?> loadClass(String name)
throws MalformedURLException, ClassNotFoundException;
/**
* Loads a class from a URL.
*
* @param codebase the URL from which to load the class
* @param name the name of the class to load
* @return the <code>Class</code> object representing the loaded class
* @exception MalformedURLException
* if the <code>codebase</code> paramater
* contains an invalid URL
* @exception ClassNotFoundException
* if a definition for the class could not
* be found at the specified URL
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
Class<?> loadClass(URL codebase, String name)
throws MalformedURLException, ClassNotFoundException;
/**
* Returns the security context of the given class loader.
*
* @param loader a class loader from which to get the security context
* @return the security context
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
Object getSecurityContext(ClassLoader loader);
}

View File

@@ -0,0 +1,272 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.io.*;
import java.util.*;
/**
* <code>LogStream</code> provides a mechanism for logging errors that are
* of possible interest to those monitoring a system.
*
* @author Ann Wollrath (lots of code stolen from Ken Arnold)
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
public class LogStream extends PrintStream {
/** table mapping known log names to log stream objects */
private static Map<String,LogStream> known = new HashMap<>(5);
/** default output stream for new logs */
private static PrintStream defaultStream = System.err;
/** log name for this log */
private String name;
/** stream where output of this log is sent to */
private OutputStream logOut;
/** string writer for writing message prefixes to log stream */
private OutputStreamWriter logWriter;
/** string buffer used for constructing log message prefixes */
private StringBuffer buffer = new StringBuffer();
/** stream used for buffering lines */
private ByteArrayOutputStream bufOut;
/**
* Create a new LogStream object. Since this only constructor is
* private, users must have a LogStream created through the "log"
* method.
* @param name string identifying messages from this log
* @out output stream that log messages will be sent to
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
private LogStream(String name, OutputStream out)
{
super(new ByteArrayOutputStream());
bufOut = (ByteArrayOutputStream) super.out;
this.name = name;
setOutputStream(out);
}
/**
* Return the LogStream identified by the given name. If
* a log corresponding to "name" does not exist, a log using
* the default stream is created.
* @param name name identifying the desired LogStream
* @return log associated with given name
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
public static LogStream log(String name) {
LogStream stream;
synchronized (known) {
stream = known.get(name);
if (stream == null) {
stream = new LogStream(name, defaultStream);
}
known.put(name, stream);
}
return stream;
}
/**
* Return the current default stream for new logs.
* @return default log stream
* @see #setDefaultStream
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
public static synchronized PrintStream getDefaultStream() {
return defaultStream;
}
/**
* Set the default stream for new logs.
* @param newDefault new default log stream
* @see #getDefaultStream
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
public static synchronized void setDefaultStream(PrintStream newDefault) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(
new java.util.logging.LoggingPermission("control", null));
}
defaultStream = newDefault;
}
/**
* Return the current stream to which output from this log is sent.
* @return output stream for this log
* @see #setOutputStream
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
public synchronized OutputStream getOutputStream()
{
return logOut;
}
/**
* Set the stream to which output from this log is sent.
* @param out new output stream for this log
* @see #getOutputStream
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
public synchronized void setOutputStream(OutputStream out)
{
logOut = out;
// Maintain an OutputStreamWriter with default CharToByteConvertor
// (just like new PrintStream) for writing log message prefixes.
logWriter = new OutputStreamWriter(logOut);
}
/**
* Write a byte of data to the stream. If it is not a newline, then
* the byte is appended to the internal buffer. If it is a newline,
* then the currently buffered line is sent to the log's output
* stream, prefixed with the appropriate logging information.
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
public void write(int b)
{
if (b == '\n') {
// synchronize on "this" first to avoid potential deadlock
synchronized (this) {
synchronized (logOut) {
// construct prefix for log messages:
buffer.setLength(0);;
buffer.append( // date/time stamp...
(new Date()).toString());
buffer.append(':');
buffer.append(name); // ...log name...
buffer.append(':');
buffer.append(Thread.currentThread().getName());
buffer.append(':'); // ...and thread name
try {
// write prefix through to underlying byte stream
logWriter.write(buffer.toString());
logWriter.flush();
// finally, write the already converted bytes of
// the log message
bufOut.writeTo(logOut);
logOut.write(b);
logOut.flush();
} catch (IOException e) {
setError();
} finally {
bufOut.reset();
}
}
}
}
else
super.write(b);
}
/**
* Write a subarray of bytes. Pass each through write byte method.
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
public void write(byte b[], int off, int len)
{
if (len < 0)
throw new ArrayIndexOutOfBoundsException(len);
for (int i = 0; i < len; ++ i)
write(b[off + i]);
}
/**
* Return log name as string representation.
* @return log name
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
public String toString()
{
return name;
}
/** log level constant (no logging). */
public static final int SILENT = 0;
/** log level constant (brief logging). */
public static final int BRIEF = 10;
/** log level constant (verbose logging). */
public static final int VERBOSE = 20;
/**
* Convert a string name of a logging level to its internal
* integer representation.
* @param s name of logging level (e.g., 'SILENT', 'BRIEF', 'VERBOSE')
* @return corresponding integer log level
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
public static int parseLevel(String s)
{
if ((s == null) || (s.length() < 1))
return -1;
try {
return Integer.parseInt(s);
} catch (NumberFormatException e) {
}
if (s.length() < 1)
return -1;
if ("SILENT".startsWith(s.toUpperCase()))
return SILENT;
else if ("BRIEF".startsWith(s.toUpperCase()))
return BRIEF;
else if ("VERBOSE".startsWith(s.toUpperCase()))
return VERBOSE;
return -1;
}
}

View File

@@ -0,0 +1,248 @@
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import java.security.AccessController;
import java.security.SecureRandom;
import java.util.concurrent.atomic.AtomicLong;
import sun.security.action.GetPropertyAction;
/**
* An <code>ObjID</code> is used to identify a remote object exported
* to an RMI runtime. When a remote object is exported, it is assigned
* an object identifier either implicitly or explicitly, depending on
* the API used to export.
*
* <p>The {@link #ObjID()} constructor can be used to generate a unique
* object identifier. Such an <code>ObjID</code> is unique over time
* with respect to the host it is generated on.
*
* The {@link #ObjID(int)} constructor can be used to create a
* "well-known" object identifier. The scope of a well-known
* <code>ObjID</code> depends on the RMI runtime it is exported to.
*
* <p>An <code>ObjID</code> instance contains an object number (of type
* <code>long</code>) and an address space identifier (of type
* {@link UID}). In a unique <code>ObjID</code>, the address space
* identifier is unique with respect to a given host over time. In a
* well-known <code>ObjID</code>, the address space identifier is
* equivalent to one returned by invoking the {@link UID#UID(short)}
* constructor with the value zero.
*
* <p>If the system property <code>java.rmi.server.randomIDs</code>
* is defined to equal the string <code>"true"</code> (case insensitive),
* then the {@link #ObjID()} constructor will use a cryptographically
* strong random number generator to choose the object number of the
* returned <code>ObjID</code>.
*
* @author Ann Wollrath
* @author Peter Jones
* @since JDK1.1
*/
public final class ObjID implements Serializable {
/** Object number for well-known <code>ObjID</code> of the registry. */
public static final int REGISTRY_ID = 0;
/** Object number for well-known <code>ObjID</code> of the activator. */
public static final int ACTIVATOR_ID = 1;
/**
* Object number for well-known <code>ObjID</code> of
* the distributed garbage collector.
*/
public static final int DGC_ID = 2;
/** indicate compatibility with JDK 1.1.x version of class */
private static final long serialVersionUID = -6386392263968365220L;
private static final AtomicLong nextObjNum = new AtomicLong(0);
private static final UID mySpace = new UID();
private static final SecureRandom secureRandom = new SecureRandom();
/**
* @serial object number
* @see #hashCode
*/
private final long objNum;
/**
* @serial address space identifier (unique to host over time)
*/
private final UID space;
/**
* Generates a unique object identifier.
*
* <p>If the system property <code>java.rmi.server.randomIDs</code>
* is defined to equal the string <code>"true"</code> (case insensitive),
* then this constructor will use a cryptographically
* strong random number generator to choose the object number of the
* returned <code>ObjID</code>.
*/
public ObjID() {
/*
* If generating random object numbers, create a new UID to
* ensure uniqueness; otherwise, use a shared UID because
* sequential object numbers already ensure uniqueness.
*/
if (useRandomIDs()) {
space = new UID();
objNum = secureRandom.nextLong();
} else {
space = mySpace;
objNum = nextObjNum.getAndIncrement();
}
}
/**
* Creates a "well-known" object identifier.
*
* <p>An <code>ObjID</code> created via this constructor will not
* clash with any <code>ObjID</code>s generated via the no-arg
* constructor.
*
* @param objNum object number for well-known object identifier
*/
public ObjID(int objNum) {
space = new UID((short) 0);
this.objNum = objNum;
}
/**
* Constructs an object identifier given data read from a stream.
*/
private ObjID(long objNum, UID space) {
this.objNum = objNum;
this.space = space;
}
/**
* Marshals a binary representation of this <code>ObjID</code> to
* an <code>ObjectOutput</code> instance.
*
* <p>Specifically, this method first invokes the given stream's
* {@link ObjectOutput#writeLong(long)} method with this object
* identifier's object number, and then it writes its address
* space identifier by invoking its {@link UID#write(DataOutput)}
* method with the stream.
*
* @param out the <code>ObjectOutput</code> instance to write
* this <code>ObjID</code> to
*
* @throws IOException if an I/O error occurs while performing
* this operation
*/
public void write(ObjectOutput out) throws IOException {
out.writeLong(objNum);
space.write(out);
}
/**
* Constructs and returns a new <code>ObjID</code> instance by
* unmarshalling a binary representation from an
* <code>ObjectInput</code> instance.
*
* <p>Specifically, this method first invokes the given stream's
* {@link ObjectInput#readLong()} method to read an object number,
* then it invokes {@link UID#read(DataInput)} with the
* stream to read an address space identifier, and then it
* creates and returns a new <code>ObjID</code> instance that
* contains the object number and address space identifier that
* were read from the stream.
*
* @param in the <code>ObjectInput</code> instance to read
* <code>ObjID</code> from
*
* @return unmarshalled <code>ObjID</code> instance
*
* @throws IOException if an I/O error occurs while performing
* this operation
*/
public static ObjID read(ObjectInput in) throws IOException {
long num = in.readLong();
UID space = UID.read(in);
return new ObjID(num, space);
}
/**
* Returns the hash code value for this object identifier, the
* object number.
*
* @return the hash code value for this object identifier
*/
public int hashCode() {
return (int) objNum;
}
/**
* Compares the specified object with this <code>ObjID</code> for
* equality.
*
* This method returns <code>true</code> if and only if the
* specified object is an <code>ObjID</code> instance with the same
* object number and address space identifier as this one.
*
* @param obj the object to compare this <code>ObjID</code> to
*
* @return <code>true</code> if the given object is equivalent to
* this one, and <code>false</code> otherwise
*/
public boolean equals(Object obj) {
if (obj instanceof ObjID) {
ObjID id = (ObjID) obj;
return objNum == id.objNum && space.equals(id.space);
} else {
return false;
}
}
/**
* Returns a string representation of this object identifier.
*
* @return a string representation of this object identifier
*/
/*
* The address space identifier is only included in the string
* representation if it does not denote the local address space
* (or if the randomIDs property was set).
*/
public String toString() {
return "[" + (space.equals(mySpace) ? "" : space + ", ") +
objNum + "]";
}
private static boolean useRandomIDs() {
String value = AccessController.doPrivileged(
new GetPropertyAction("java.rmi.server.randomIDs"));
return value == null ? true : Boolean.parseBoolean(value);
}
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
/**
* An <code>Operation</code> contains a description of a Java method.
* <code>Operation</code> objects were used in JDK1.1 version stubs and
* skeletons. The <code>Operation</code> class is not needed for 1.2 style
* stubs (stubs generated with <code>rmic -v1.2</code>); hence, this class
* is deprecated.
*
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
public class Operation {
private String operation;
/**
* Creates a new Operation object.
* @param op method name
* @deprecated no replacement
* @since JDK1.1
*/
@Deprecated
public Operation(String op) {
operation = op;
}
/**
* Returns the name of the method.
* @return method name
* @deprecated no replacement
* @since JDK1.1
*/
@Deprecated
public String getOperation() {
return operation;
}
/**
* Returns the string representation of the operation.
* @deprecated no replacement
* @since JDK1.1
*/
@Deprecated
public String toString() {
return operation;
}
}

View File

@@ -0,0 +1,722 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Iterator;
import java.util.ServiceLoader;
/**
* <code>RMIClassLoader</code> comprises static methods to support
* dynamic class loading with RMI. Included are methods for loading
* classes from a network location (one or more URLs) and obtaining
* the location from which an existing class should be loaded by
* remote parties. These methods are used by the RMI runtime when
* marshalling and unmarshalling classes contained in the arguments
* and return values of remote method calls, and they also may be
* invoked directly by applications in order to mimic RMI's dynamic
* class loading behavior.
*
* <p>The implementation of the following static methods
*
* <ul>
*
* <li>{@link #loadClass(URL,String)}
* <li>{@link #loadClass(String,String)}
* <li>{@link #loadClass(String,String,ClassLoader)}
* <li>{@link #loadProxyClass(String,String[],ClassLoader)}
* <li>{@link #getClassLoader(String)}
* <li>{@link #getClassAnnotation(Class)}
*
* </ul>
*
* is provided by an instance of {@link RMIClassLoaderSpi}, the
* service provider interface for those methods. When one of the
* methods is invoked, its behavior is to delegate to a corresponding
* method on the service provider instance. The details of how each
* method delegates to the provider instance is described in the
* documentation for each particular method.
*
* <p>The service provider instance is chosen as follows:
*
* <ul>
*
* <li>If the system property
* <code>java.rmi.server.RMIClassLoaderSpi</code> is defined, then if
* its value equals the string <code>"default"</code>, the provider
* instance will be the value returned by an invocation of the {@link
* #getDefaultProviderInstance()} method, and for any other value, if
* a class named with the value of the property can be loaded by the
* system class loader (see {@link ClassLoader#getSystemClassLoader})
* and that class is assignable to {@link RMIClassLoaderSpi} and has a
* public no-argument constructor, then that constructor will be
* invoked to create the provider instance. If the property is
* defined but any other of those conditions are not true, then an
* unspecified <code>Error</code> will be thrown to code that attempts
* to use <code>RMIClassLoader</code>, indicating the failure to
* obtain a provider instance.
*
* <li>If a resource named
* <code>META-INF/services/java.rmi.server.RMIClassLoaderSpi</code> is
* visible to the system class loader, then the contents of that
* resource are interpreted as a provider-configuration file, and the
* first class name specified in that file is used as the provider
* class name. If a class with that name can be loaded by the system
* class loader and that class is assignable to {@link
* RMIClassLoaderSpi} and has a public no-argument constructor, then
* that constructor will be invoked to create the provider instance.
* If the resource is found but a provider cannot be instantiated as
* described, then an unspecified <code>Error</code> will be thrown to
* code that attempts to use <code>RMIClassLoader</code>, indicating
* the failure to obtain a provider instance.
*
* <li>Otherwise, the provider instance will be the value returned by
* an invocation of the {@link #getDefaultProviderInstance()} method.
*
* </ul>
*
* @author Ann Wollrath
* @author Peter Jones
* @author Laird Dornin
* @see RMIClassLoaderSpi
* @since JDK1.1
*/
public class RMIClassLoader {
/** "default" provider instance */
private static final RMIClassLoaderSpi defaultProvider =
newDefaultProviderInstance();
/** provider instance */
private static final RMIClassLoaderSpi provider =
AccessController.doPrivileged(
new PrivilegedAction<RMIClassLoaderSpi>() {
public RMIClassLoaderSpi run() { return initializeProvider(); }
});
/*
* Disallow anyone from creating one of these.
*/
private RMIClassLoader() {}
/**
* Loads the class with the specified <code>name</code>.
*
* <p>This method delegates to {@link #loadClass(String,String)},
* passing <code>null</code> as the first argument and
* <code>name</code> as the second argument.
*
* @param name the name of the class to load
*
* @return the <code>Class</code> object representing the loaded class
*
* @throws MalformedURLException if a provider-specific URL used
* to load classes is invalid
*
* @throws ClassNotFoundException if a definition for the class
* could not be found at the codebase location
*
* @deprecated replaced by <code>loadClass(String,String)</code> method
* @see #loadClass(String,String)
*/
@Deprecated
public static Class<?> loadClass(String name)
throws MalformedURLException, ClassNotFoundException
{
return loadClass((String) null, name);
}
/**
* Loads a class from a codebase URL.
*
* If <code>codebase</code> is <code>null</code>, then this method
* will behave the same as {@link #loadClass(String,String)} with a
* <code>null</code> <code>codebase</code> and the given class name.
*
* <p>This method delegates to the
* {@link RMIClassLoaderSpi#loadClass(String,String,ClassLoader)}
* method of the provider instance, passing the result of invoking
* {@link URL#toString} on the given URL (or <code>null</code> if
* <code>codebase</code> is null) as the first argument,
* <code>name</code> as the second argument,
* and <code>null</code> as the third argument.
*
* @param codebase the URL to load the class from, or <code>null</code>
*
* @param name the name of the class to load
*
* @return the <code>Class</code> object representing the loaded class
*
* @throws MalformedURLException if <code>codebase</code> is
* <code>null</code> and a provider-specific URL used
* to load classes is invalid
*
* @throws ClassNotFoundException if a definition for the class
* could not be found at the specified URL
*/
public static Class<?> loadClass(URL codebase, String name)
throws MalformedURLException, ClassNotFoundException
{
return provider.loadClass(
codebase != null ? codebase.toString() : null, name, null);
}
/**
* Loads a class from a codebase URL path.
*
* <p>This method delegates to the
* {@link RMIClassLoaderSpi#loadClass(String,String,ClassLoader)}
* method of the provider instance, passing <code>codebase</code>
* as the first argument, <code>name</code> as the second argument,
* and <code>null</code> as the third argument.
*
* @param codebase the list of URLs (separated by spaces) to load
* the class from, or <code>null</code>
*
* @param name the name of the class to load
*
* @return the <code>Class</code> object representing the loaded class
*
* @throws MalformedURLException if <code>codebase</code> is
* non-<code>null</code> and contains an invalid URL, or if
* <code>codebase</code> is <code>null</code> and a provider-specific
* URL used to load classes is invalid
*
* @throws ClassNotFoundException if a definition for the class
* could not be found at the specified location
*
* @since 1.2
*/
public static Class<?> loadClass(String codebase, String name)
throws MalformedURLException, ClassNotFoundException
{
return provider.loadClass(codebase, name, null);
}
/**
* Loads a class from a codebase URL path, optionally using the
* supplied loader.
*
* This method should be used when the caller would like to make
* available to the provider implementation an additional contextual
* class loader to consider, such as the loader of a caller on the
* stack. Typically, a provider implementation will attempt to
* resolve the named class using the given <code>defaultLoader</code>,
* if specified, before attempting to resolve the class from the
* codebase URL path.
*
* <p>This method delegates to the
* {@link RMIClassLoaderSpi#loadClass(String,String,ClassLoader)}
* method of the provider instance, passing <code>codebase</code>
* as the first argument, <code>name</code> as the second argument,
* and <code>defaultLoader</code> as the third argument.
*
* @param codebase the list of URLs (separated by spaces) to load
* the class from, or <code>null</code>
*
* @param name the name of the class to load
*
* @param defaultLoader additional contextual class loader
* to use, or <code>null</code>
*
* @return the <code>Class</code> object representing the loaded class
*
* @throws MalformedURLException if <code>codebase</code> is
* non-<code>null</code> and contains an invalid URL, or if
* <code>codebase</code> is <code>null</code> and a provider-specific
* URL used to load classes is invalid
*
* @throws ClassNotFoundException if a definition for the class
* could not be found at the specified location
*
* @since 1.4
*/
public static Class<?> loadClass(String codebase, String name,
ClassLoader defaultLoader)
throws MalformedURLException, ClassNotFoundException
{
return provider.loadClass(codebase, name, defaultLoader);
}
/**
* Loads a dynamic proxy class (see {@link java.lang.reflect.Proxy})
* that implements a set of interfaces with the given names
* from a codebase URL path.
*
* <p>The interfaces will be resolved similar to classes loaded via
* the {@link #loadClass(String,String)} method using the given
* <code>codebase</code>.
*
* <p>This method delegates to the
* {@link RMIClassLoaderSpi#loadProxyClass(String,String[],ClassLoader)}
* method of the provider instance, passing <code>codebase</code>
* as the first argument, <code>interfaces</code> as the second argument,
* and <code>defaultLoader</code> as the third argument.
*
* @param codebase the list of URLs (space-separated) to load
* classes from, or <code>null</code>
*
* @param interfaces the names of the interfaces for the proxy class
* to implement
*
* @param defaultLoader additional contextual class loader
* to use, or <code>null</code>
*
* @return a dynamic proxy class that implements the named interfaces
*
* @throws MalformedURLException if <code>codebase</code> is
* non-<code>null</code> and contains an invalid URL, or
* if <code>codebase</code> is <code>null</code> and a provider-specific
* URL used to load classes is invalid
*
* @throws ClassNotFoundException if a definition for one of
* the named interfaces could not be found at the specified location,
* or if creation of the dynamic proxy class failed (such as if
* {@link java.lang.reflect.Proxy#getProxyClass(ClassLoader,Class[])}
* would throw an <code>IllegalArgumentException</code> for the given
* interface list)
*
* @since 1.4
*/
public static Class<?> loadProxyClass(String codebase, String[] interfaces,
ClassLoader defaultLoader)
throws ClassNotFoundException, MalformedURLException
{
return provider.loadProxyClass(codebase, interfaces, defaultLoader);
}
/**
* Returns a class loader that loads classes from the given codebase
* URL path.
*
* <p>The class loader returned is the class loader that the
* {@link #loadClass(String,String)} method would use to load classes
* for the same <code>codebase</code> argument.
*
* <p>This method delegates to the
* {@link RMIClassLoaderSpi#getClassLoader(String)} method
* of the provider instance, passing <code>codebase</code> as the argument.
*
* <p>If there is a security manger, its <code>checkPermission</code>
* method will be invoked with a
* <code>RuntimePermission("getClassLoader")</code> permission;
* this could result in a <code>SecurityException</code>.
* The provider implementation of this method may also perform further
* security checks to verify that the calling context has permission to
* connect to all of the URLs in the codebase URL path.
*
* @param codebase the list of URLs (space-separated) from which
* the returned class loader will load classes from, or <code>null</code>
*
* @return a class loader that loads classes from the given codebase URL
* path
*
* @throws MalformedURLException if <code>codebase</code> is
* non-<code>null</code> and contains an invalid URL, or
* if <code>codebase</code> is <code>null</code> and a provider-specific
* URL used to identify the class loader is invalid
*
* @throws SecurityException if there is a security manager and the
* invocation of its <code>checkPermission</code> method fails, or
* if the caller does not have permission to connect to all of the
* URLs in the codebase URL path
*
* @since 1.3
*/
public static ClassLoader getClassLoader(String codebase)
throws MalformedURLException, SecurityException
{
return provider.getClassLoader(codebase);
}
/**
* Returns the annotation string (representing a location for
* the class definition) that RMI will use to annotate the class
* descriptor when marshalling objects of the given class.
*
* <p>This method delegates to the
* {@link RMIClassLoaderSpi#getClassAnnotation(Class)} method
* of the provider instance, passing <code>cl</code> as the argument.
*
* @param cl the class to obtain the annotation for
*
* @return a string to be used to annotate the given class when
* it gets marshalled, or <code>null</code>
*
* @throws NullPointerException if <code>cl</code> is <code>null</code>
*
* @since 1.2
*/
/*
* REMIND: Should we say that the returned class annotation will or
* should be a (space-separated) list of URLs?
*/
public static String getClassAnnotation(Class<?> cl) {
return provider.getClassAnnotation(cl);
}
/**
* Returns the canonical instance of the default provider
* for the service provider interface {@link RMIClassLoaderSpi}.
* If the system property <code>java.rmi.server.RMIClassLoaderSpi</code>
* is not defined, then the <code>RMIClassLoader</code> static
* methods
*
* <ul>
*
* <li>{@link #loadClass(URL,String)}
* <li>{@link #loadClass(String,String)}
* <li>{@link #loadClass(String,String,ClassLoader)}
* <li>{@link #loadProxyClass(String,String[],ClassLoader)}
* <li>{@link #getClassLoader(String)}
* <li>{@link #getClassAnnotation(Class)}
*
* </ul>
*
* will use the canonical instance of the default provider
* as the service provider instance.
*
* <p>If there is a security manager, its
* <code>checkPermission</code> method will be invoked with a
* <code>RuntimePermission("setFactory")</code> permission; this
* could result in a <code>SecurityException</code>.
*
* <p>The default service provider instance implements
* {@link RMIClassLoaderSpi} as follows:
*
* <blockquote>
*
* <p>The <b>{@link RMIClassLoaderSpi#getClassAnnotation(Class)
* getClassAnnotation}</b> method returns a <code>String</code>
* representing the codebase URL path that a remote party should
* use to download the definition for the specified class. The
* format of the returned string is a path of URLs separated by
* spaces.
*
* The codebase string returned depends on the defining class
* loader of the specified class:
*
* <ul>
*
* <li><p>If the class loader is the system class loader (see
* {@link ClassLoader#getSystemClassLoader}), a parent of the
* system class loader such as the loader used for installed
* extensions, or the bootstrap class loader (which may be
* represented by <code>null</code>), then the value of the
* <code>java.rmi.server.codebase</code> property (or possibly an
* earlier cached value) is returned, or
* <code>null</code> is returned if that property is not set.
*
* <li><p>Otherwise, if the class loader is an instance of
* <code>URLClassLoader</code>, then the returned string is a
* space-separated list of the external forms of the URLs returned
* by invoking the <code>getURLs</code> methods of the loader. If
* the <code>URLClassLoader</code> was created by this provider to
* service an invocation of its <code>loadClass</code> or
* <code>loadProxyClass</code> methods, then no permissions are
* required to get the associated codebase string. If it is an
* arbitrary other <code>URLClassLoader</code> instance, then if
* there is a security manager, its <code>checkPermission</code>
* method will be invoked once for each URL returned by the
* <code>getURLs</code> method, with the permission returned by
* invoking <code>openConnection().getPermission()</code> on each
* URL; if any of those invocations throws a
* <code>SecurityException</code> or an <code>IOException</code>,
* then the value of the <code>java.rmi.server.codebase</code>
* property (or possibly an earlier cached value) is returned, or
* <code>null</code> is returned if that property is not set.
*
* <li><p>Finally, if the class loader is not an instance of
* <code>URLClassLoader</code>, then the value of the
* <code>java.rmi.server.codebase</code> property (or possibly an
* earlier cached value) is returned, or
* <code>null</code> is returned if that property is not set.
*
* </ul>
*
* <p>For the implementations of the methods described below,
* which all take a <code>String</code> parameter named
* <code>codebase</code> that is a space-separated list of URLs,
* each invocation has an associated <i>codebase loader</i> that
* is identified using the <code>codebase</code> argument in
* conjunction with the current thread's context class loader (see
* {@link Thread#getContextClassLoader()}). When there is a
* security manager, this provider maintains an internal table of
* class loader instances (which are at least instances of {@link
* java.net.URLClassLoader}) keyed by the pair of their parent
* class loader and their codebase URL path (an ordered list of
* URLs). If the <code>codebase</code> argument is <code>null</code>,
* the codebase URL path is the value of the system property
* <code>java.rmi.server.codebase</code> or possibly an
* earlier cached value. For a given codebase URL path passed as the
* <code>codebase</code> argument to an invocation of one of the
* below methods in a given context, the codebase loader is the
* loader in the table with the specified codebase URL path and
* the current thread's context class loader as its parent. If no
* such loader exists, then one is created and added to the table.
* The table does not maintain strong references to its contained
* loaders, in order to allow them and their defined classes to be
* garbage collected when not otherwise reachable. In order to
* prevent arbitrary untrusted code from being implicitly loaded
* into a virtual machine with no security manager, if there is no
* security manager set, the codebase loader is just the current
* thread's context class loader (the supplied codebase URL path
* is ignored, so remote class loading is disabled).
*
* <p>The <b>{@link RMIClassLoaderSpi#getClassLoader(String)
* getClassLoader}</b> method returns the codebase loader for the
* specified codebase URL path. If there is a security manager,
* then if the calling context does not have permission to connect
* to all of the URLs in the codebase URL path, a
* <code>SecurityException</code> will be thrown.
*
* <p>The <b>{@link
* RMIClassLoaderSpi#loadClass(String,String,ClassLoader)
* loadClass}</b> method attempts to load the class with the
* specified name as follows:
*
* <blockquote>
*
* If the <code>defaultLoader</code> argument is
* non-<code>null</code>, it first attempts to load the class with the
* specified <code>name</code> using the
* <code>defaultLoader</code>, such as by evaluating
*
* <pre>
* Class.forName(name, false, defaultLoader)
* </pre>
*
* If the class is successfully loaded from the
* <code>defaultLoader</code>, that class is returned. If an
* exception other than <code>ClassNotFoundException</code> is
* thrown, that exception is thrown to the caller.
*
* <p>Next, the <code>loadClass</code> method attempts to load the
* class with the specified <code>name</code> using the codebase
* loader for the specified codebase URL path.
* If there is a security manager, then the calling context
* must have permission to connect to all of the URLs in the
* codebase URL path; otherwise, the current thread's context
* class loader will be used instead of the codebase loader.
*
* </blockquote>
*
* <p>The <b>{@link
* RMIClassLoaderSpi#loadProxyClass(String,String[],ClassLoader)
* loadProxyClass}</b> method attempts to return a dynamic proxy
* class with the named interface as follows:
*
* <blockquote>
*
* <p>If the <code>defaultLoader</code> argument is
* non-<code>null</code> and all of the named interfaces can be
* resolved through that loader, then,
*
* <ul>
*
* <li>if all of the resolved interfaces are <code>public</code>,
* then it first attempts to obtain a dynamic proxy class (using
* {@link
* java.lang.reflect.Proxy#getProxyClass(ClassLoader,Class[])
* Proxy.getProxyClass}) for the resolved interfaces defined in
* the codebase loader; if that attempt throws an
* <code>IllegalArgumentException</code>, it then attempts to
* obtain a dynamic proxy class for the resolved interfaces
* defined in the <code>defaultLoader</code>. If both attempts
* throw <code>IllegalArgumentException</code>, then this method
* throws a <code>ClassNotFoundException</code>. If any other
* exception is thrown, that exception is thrown to the caller.
*
* <li>if all of the non-<code>public</code> resolved interfaces
* are defined in the same class loader, then it attempts to
* obtain a dynamic proxy class for the resolved interfaces
* defined in that loader.
*
* <li>otherwise, a <code>LinkageError</code> is thrown (because a
* class that implements all of the specified interfaces cannot be
* defined in any loader).
*
* </ul>
*
* <p>Otherwise, if all of the named interfaces can be resolved
* through the codebase loader, then,
*
* <ul>
*
* <li>if all of the resolved interfaces are <code>public</code>,
* then it attempts to obtain a dynamic proxy class for the
* resolved interfaces in the codebase loader. If the attempt
* throws an <code>IllegalArgumentException</code>, then this
* method throws a <code>ClassNotFoundException</code>.
*
* <li>if all of the non-<code>public</code> resolved interfaces
* are defined in the same class loader, then it attempts to
* obtain a dynamic proxy class for the resolved interfaces
* defined in that loader.
*
* <li>otherwise, a <code>LinkageError</code> is thrown (because a
* class that implements all of the specified interfaces cannot be
* defined in any loader).
*
* </ul>
*
* <p>Otherwise, a <code>ClassNotFoundException</code> is thrown
* for one of the named interfaces that could not be resolved.
*
* </blockquote>
*
* </blockquote>
*
* @return the canonical instance of the default service provider
*
* @throws SecurityException if there is a security manager and the
* invocation of its <code>checkPermission</code> method fails
*
* @since 1.4
*/
public static RMIClassLoaderSpi getDefaultProviderInstance() {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission("setFactory"));
}
return defaultProvider;
}
/**
* Returns the security context of the given class loader.
*
* @param loader a class loader from which to get the security context
*
* @return the security context
*
* @deprecated no replacement. As of the Java 2 platform v1.2, RMI no
* longer uses this method to obtain a class loader's security context.
* @see java.lang.SecurityManager#getSecurityContext()
*/
@Deprecated
public static Object getSecurityContext(ClassLoader loader)
{
return sun.rmi.server.LoaderHandler.getSecurityContext(loader);
}
/**
* Creates an instance of the default provider class.
*/
private static RMIClassLoaderSpi newDefaultProviderInstance() {
return new RMIClassLoaderSpi() {
public Class<?> loadClass(String codebase, String name,
ClassLoader defaultLoader)
throws MalformedURLException, ClassNotFoundException
{
return sun.rmi.server.LoaderHandler.loadClass(
codebase, name, defaultLoader);
}
public Class<?> loadProxyClass(String codebase,
String[] interfaces,
ClassLoader defaultLoader)
throws MalformedURLException, ClassNotFoundException
{
return sun.rmi.server.LoaderHandler.loadProxyClass(
codebase, interfaces, defaultLoader);
}
public ClassLoader getClassLoader(String codebase)
throws MalformedURLException
{
return sun.rmi.server.LoaderHandler.getClassLoader(codebase);
}
public String getClassAnnotation(Class<?> cl) {
return sun.rmi.server.LoaderHandler.getClassAnnotation(cl);
}
};
}
/**
* Chooses provider instance, following above documentation.
*
* This method assumes that it has been invoked in a privileged block.
*/
private static RMIClassLoaderSpi initializeProvider() {
/*
* First check for the system property being set:
*/
String providerClassName =
System.getProperty("java.rmi.server.RMIClassLoaderSpi");
if (providerClassName != null) {
if (providerClassName.equals("default")) {
return defaultProvider;
}
try {
Class<? extends RMIClassLoaderSpi> providerClass =
Class.forName(providerClassName, false,
ClassLoader.getSystemClassLoader())
.asSubclass(RMIClassLoaderSpi.class);
return providerClass.newInstance();
} catch (ClassNotFoundException e) {
throw new NoClassDefFoundError(e.getMessage());
} catch (IllegalAccessException e) {
throw new IllegalAccessError(e.getMessage());
} catch (InstantiationException e) {
throw new InstantiationError(e.getMessage());
} catch (ClassCastException e) {
Error error = new LinkageError(
"provider class not assignable to RMIClassLoaderSpi");
error.initCause(e);
throw error;
}
}
/*
* Next look for a provider configuration file installed:
*/
Iterator<RMIClassLoaderSpi> iter =
ServiceLoader.load(RMIClassLoaderSpi.class,
ClassLoader.getSystemClassLoader()).iterator();
if (iter.hasNext()) {
try {
return iter.next();
} catch (ClassCastException e) {
Error error = new LinkageError(
"provider class not assignable to RMIClassLoaderSpi");
error.initCause(e);
throw error;
}
}
/*
* Finally, return the canonical instance of the default provider.
*/
return defaultProvider;
}
}

View File

@@ -0,0 +1,192 @@
/*
* Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.net.MalformedURLException;
import java.net.URL;
/**
* <code>RMIClassLoaderSpi</code> is the service provider interface for
* <code>RMIClassLoader</code>.
*
* In particular, an <code>RMIClassLoaderSpi</code> instance provides an
* implementation of the following static methods of
* <code>RMIClassLoader</code>:
*
* <ul>
*
* <li>{@link RMIClassLoader#loadClass(URL,String)}
* <li>{@link RMIClassLoader#loadClass(String,String)}
* <li>{@link RMIClassLoader#loadClass(String,String,ClassLoader)}
* <li>{@link RMIClassLoader#loadProxyClass(String,String[],ClassLoader)}
* <li>{@link RMIClassLoader#getClassLoader(String)}
* <li>{@link RMIClassLoader#getClassAnnotation(Class)}
*
* </ul>
*
* When one of those methods is invoked, its behavior is to delegate
* to a corresponding method on an instance of this class.
* The details of how each method delegates to the provider instance is
* described in the documentation for each particular method.
* See the documentation for {@link RMIClassLoader} for a description
* of how a provider instance is chosen.
*
* @author Peter Jones
* @author Laird Dornin
* @see RMIClassLoader
* @since 1.4
*/
public abstract class RMIClassLoaderSpi {
/**
* Provides the implementation for
* {@link RMIClassLoader#loadClass(URL,String)},
* {@link RMIClassLoader#loadClass(String,String)}, and
* {@link RMIClassLoader#loadClass(String,String,ClassLoader)}.
*
* Loads a class from a codebase URL path, optionally using the
* supplied loader.
*
* Typically, a provider implementation will attempt to
* resolve the named class using the given <code>defaultLoader</code>,
* if specified, before attempting to resolve the class from the
* codebase URL path.
*
* <p>An implementation of this method must either return a class
* with the given name or throw an exception.
*
* @param codebase the list of URLs (separated by spaces) to load
* the class from, or <code>null</code>
*
* @param name the name of the class to load
*
* @param defaultLoader additional contextual class loader
* to use, or <code>null</code>
*
* @return the <code>Class</code> object representing the loaded class
*
* @throws MalformedURLException if <code>codebase</code> is
* non-<code>null</code> and contains an invalid URL, or
* if <code>codebase</code> is <code>null</code> and a provider-specific
* URL used to load classes is invalid
*
* @throws ClassNotFoundException if a definition for the class
* could not be found at the specified location
*/
public abstract Class<?> loadClass(String codebase, String name,
ClassLoader defaultLoader)
throws MalformedURLException, ClassNotFoundException;
/**
* Provides the implementation for
* {@link RMIClassLoader#loadProxyClass(String,String[],ClassLoader)}.
*
* Loads a dynamic proxy class (see {@link java.lang.reflect.Proxy}
* that implements a set of interfaces with the given names
* from a codebase URL path, optionally using the supplied loader.
*
* <p>An implementation of this method must either return a proxy
* class that implements the named interfaces or throw an exception.
*
* @param codebase the list of URLs (space-separated) to load
* classes from, or <code>null</code>
*
* @param interfaces the names of the interfaces for the proxy class
* to implement
*
* @return a dynamic proxy class that implements the named interfaces
*
* @param defaultLoader additional contextual class loader
* to use, or <code>null</code>
*
* @throws MalformedURLException if <code>codebase</code> is
* non-<code>null</code> and contains an invalid URL, or
* if <code>codebase</code> is <code>null</code> and a provider-specific
* URL used to load classes is invalid
*
* @throws ClassNotFoundException if a definition for one of
* the named interfaces could not be found at the specified location,
* or if creation of the dynamic proxy class failed (such as if
* {@link java.lang.reflect.Proxy#getProxyClass(ClassLoader,Class[])}
* would throw an <code>IllegalArgumentException</code> for the given
* interface list)
*/
public abstract Class<?> loadProxyClass(String codebase,
String[] interfaces,
ClassLoader defaultLoader)
throws MalformedURLException, ClassNotFoundException;
/**
* Provides the implementation for
* {@link RMIClassLoader#getClassLoader(String)}.
*
* Returns a class loader that loads classes from the given codebase
* URL path.
*
* <p>If there is a security manger, its <code>checkPermission</code>
* method will be invoked with a
* <code>RuntimePermission("getClassLoader")</code> permission;
* this could result in a <code>SecurityException</code>.
* The implementation of this method may also perform further security
* checks to verify that the calling context has permission to connect
* to all of the URLs in the codebase URL path.
*
* @param codebase the list of URLs (space-separated) from which
* the returned class loader will load classes from, or <code>null</code>
*
* @return a class loader that loads classes from the given codebase URL
* path
*
* @throws MalformedURLException if <code>codebase</code> is
* non-<code>null</code> and contains an invalid URL, or
* if <code>codebase</code> is <code>null</code> and a provider-specific
* URL used to identify the class loader is invalid
*
* @throws SecurityException if there is a security manager and the
* invocation of its <code>checkPermission</code> method fails, or
* if the caller does not have permission to connect to all of the
* URLs in the codebase URL path
*/
public abstract ClassLoader getClassLoader(String codebase)
throws MalformedURLException; // SecurityException
/**
* Provides the implementation for
* {@link RMIClassLoader#getClassAnnotation(Class)}.
*
* Returns the annotation string (representing a location for
* the class definition) that RMI will use to annotate the class
* descriptor when marshalling objects of the given class.
*
* @param cl the class to obtain the annotation for
*
* @return a string to be used to annotate the given class when
* it gets marshalled, or <code>null</code>
*
* @throws NullPointerException if <code>cl</code> is <code>null</code>
*/
public abstract String getClassAnnotation(Class<?> cl);
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.io.*;
import java.net.*;
/**
* An <code>RMIClientSocketFactory</code> instance is used by the RMI runtime
* in order to obtain client sockets for RMI calls. A remote object can be
* associated with an <code>RMIClientSocketFactory</code> when it is
* created/exported via the constructors or <code>exportObject</code> methods
* of <code>java.rmi.server.UnicastRemoteObject</code> and
* <code>java.rmi.activation.Activatable</code> .
*
* <p>An <code>RMIClientSocketFactory</code> instance associated with a remote
* object will be downloaded to clients when the remote object's reference is
* transmitted in an RMI call. This <code>RMIClientSocketFactory</code> will
* be used to create connections to the remote object for remote method calls.
*
* <p>An <code>RMIClientSocketFactory</code> instance can also be associated
* with a remote object registry so that clients can use custom socket
* communication with a remote object registry.
*
* <p>An implementation of this interface should be serializable and
* should implement {@link Object#equals} to return <code>true</code> when
* passed an instance that represents the same (functionally equivalent)
* client socket factory, and <code>false</code> otherwise (and it should also
* implement {@link Object#hashCode} consistently with its
* <code>Object.equals</code> implementation).
*
* @author Ann Wollrath
* @author Peter Jones
* @since 1.2
* @see java.rmi.server.UnicastRemoteObject
* @see java.rmi.activation.Activatable
* @see java.rmi.registry.LocateRegistry
*/
public interface RMIClientSocketFactory {
/**
* Create a client socket connected to the specified host and port.
* @param host the host name
* @param port the port number
* @return a socket connected to the specified host and port.
* @exception IOException if an I/O error occurs during socket creation
* @since 1.2
*/
public Socket createSocket(String host, int port)
throws IOException;
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 1996, 1998, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
/**
* An <code>RMIFailureHandler</code> can be registered via the
* <code>RMISocketFactory.setFailureHandler</code> call. The
* <code>failure</code> method of the handler is invoked when the RMI
* runtime is unable to create a <code>ServerSocket</code> to listen
* for incoming calls. The <code>failure</code> method returns a boolean
* indicating whether the runtime should attempt to re-create the
* <code>ServerSocket</code>.
*
* @author Ann Wollrath
* @since JDK1.1
*/
public interface RMIFailureHandler {
/**
* The <code>failure</code> callback is invoked when the RMI
* runtime is unable to create a <code>ServerSocket</code> via the
* <code>RMISocketFactory</code>. An <code>RMIFailureHandler</code>
* is registered via a call to
* <code>RMISocketFacotry.setFailureHandler</code>. If no failure
* handler is installed, the default behavior is to attempt to
* re-create the ServerSocket.
*
* @param ex the exception that occurred during <code>ServerSocket</code>
* creation
* @return if true, the RMI runtime attempts to retry
* <code>ServerSocket</code> creation
* @see java.rmi.server.RMISocketFactory#setFailureHandler(RMIFailureHandler)
* @since JDK1.1
*/
public boolean failure(Exception ex);
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.io.*;
import java.net.*;
/**
* An <code>RMIServerSocketFactory</code> instance is used by the RMI runtime
* in order to obtain server sockets for RMI calls. A remote object can be
* associated with an <code>RMIServerSocketFactory</code> when it is
* created/exported via the constructors or <code>exportObject</code> methods
* of <code>java.rmi.server.UnicastRemoteObject</code> and
* <code>java.rmi.activation.Activatable</code> .
*
* <p>An <code>RMIServerSocketFactory</code> instance associated with a remote
* object is used to obtain the <code>ServerSocket</code> used to accept
* incoming calls from clients.
*
* <p>An <code>RMIServerSocketFactory</code> instance can also be associated
* with a remote object registry so that clients can use custom socket
* communication with a remote object registry.
*
* <p>An implementation of this interface
* should implement {@link Object#equals} to return <code>true</code> when
* passed an instance that represents the same (functionally equivalent)
* server socket factory, and <code>false</code> otherwise (and it should also
* implement {@link Object#hashCode} consistently with its
* <code>Object.equals</code> implementation).
*
* @author Ann Wollrath
* @author Peter Jones
* @since 1.2
* @see java.rmi.server.UnicastRemoteObject
* @see java.rmi.activation.Activatable
* @see java.rmi.registry.LocateRegistry
*/
public interface RMIServerSocketFactory {
/**
* Create a server socket on the specified port (port 0 indicates
* an anonymous port).
* @param port the port number
* @return the server socket on the specified port
* @exception IOException if an I/O error occurs during server socket
* creation
* @since 1.2
*/
public ServerSocket createServerSocket(int port)
throws IOException;
}

View File

@@ -0,0 +1,228 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.io.*;
import java.net.*;
/**
* An <code>RMISocketFactory</code> instance is used by the RMI runtime
* in order to obtain client and server sockets for RMI calls. An
* application may use the <code>setSocketFactory</code> method to
* request that the RMI runtime use its socket factory instance
* instead of the default implementation.
*
* <p>The default socket factory implementation performs a
* three-tiered approach to creating client sockets. First, a direct
* socket connection to the remote VM is attempted. If that fails
* (due to a firewall), the runtime uses HTTP with the explicit port
* number of the server. If the firewall does not allow this type of
* communication, then HTTP to a cgi-bin script on the server is used
* to POST the RMI call. The HTTP tunneling mechanisms are disabled by
* default. This behavior is controlled by the {@code java.rmi.server.disableHttp}
* property, whose default value is {@code true}. Setting this property's
* value to {@code false} will enable the HTTP tunneling mechanisms.
*
* <p><strong>Deprecated: HTTP Tunneling.</strong> <em>The HTTP tunneling mechanisms
* described above, specifically HTTP with an explicit port and HTTP to a
* cgi-bin script, are deprecated. These HTTP tunneling mechanisms are
* subject to removal in a future release of the platform.</em>
*
* <p>The default socket factory implementation creates server sockets that
* are bound to the wildcard address, which accepts requests from all network
* interfaces.
*
* @implNote
* <p>You can use the {@code RMISocketFactory} class to create a server socket that
* is bound to a specific address, restricting the origin of requests. For example,
* the following code implements a socket factory that binds server sockets to an IPv4
* loopback address. This restricts RMI to processing requests only from the local host.
*
* <pre>{@code
* class LoopbackSocketFactory extends RMISocketFactory {
* public ServerSocket createServerSocket(int port) throws IOException {
* return new ServerSocket(port, 5, InetAddress.getByName("127.0.0.1"));
* }
*
* public Socket createSocket(String host, int port) throws IOException {
* // just call the default client socket factory
* return RMISocketFactory.getDefaultSocketFactory()
* .createSocket(host, port);
* }
* }
*
* // ...
*
* RMISocketFactory.setSocketFactory(new LoopbackSocketFactory());
* }</pre>
*
* Set the {@code java.rmi.server.hostname} system property
* to {@code 127.0.0.1} to ensure that the generated stubs connect to the right
* network interface.
*
* @author Ann Wollrath
* @author Peter Jones
* @since JDK1.1
*/
public abstract class RMISocketFactory
implements RMIClientSocketFactory, RMIServerSocketFactory
{
/** Client/server socket factory to be used by RMI runtime */
private static RMISocketFactory factory = null;
/** default socket factory used by this RMI implementation */
private static RMISocketFactory defaultSocketFactory;
/** Handler for socket creation failure */
private static RMIFailureHandler handler = null;
/**
* Constructs an <code>RMISocketFactory</code>.
* @since JDK1.1
*/
public RMISocketFactory() {
super();
}
/**
* Creates a client socket connected to the specified host and port.
* @param host the host name
* @param port the port number
* @return a socket connected to the specified host and port.
* @exception IOException if an I/O error occurs during socket creation
* @since JDK1.1
*/
public abstract Socket createSocket(String host, int port)
throws IOException;
/**
* Create a server socket on the specified port (port 0 indicates
* an anonymous port).
* @param port the port number
* @return the server socket on the specified port
* @exception IOException if an I/O error occurs during server socket
* creation
* @since JDK1.1
*/
public abstract ServerSocket createServerSocket(int port)
throws IOException;
/**
* Set the global socket factory from which RMI gets sockets (if the
* remote object is not associated with a specific client and/or server
* socket factory). The RMI socket factory can only be set once. Note: The
* RMISocketFactory may only be set if the current security manager allows
* setting a socket factory; if disallowed, a SecurityException will be
* thrown.
* @param fac the socket factory
* @exception IOException if the RMI socket factory is already set
* @exception SecurityException if a security manager exists and its
* <code>checkSetFactory</code> method doesn't allow the operation.
* @see #getSocketFactory
* @see java.lang.SecurityManager#checkSetFactory()
* @since JDK1.1
*/
public synchronized static void setSocketFactory(RMISocketFactory fac)
throws IOException
{
if (factory != null) {
throw new SocketException("factory already defined");
}
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkSetFactory();
}
factory = fac;
}
/**
* Returns the socket factory set by the <code>setSocketFactory</code>
* method. Returns <code>null</code> if no socket factory has been
* set.
* @return the socket factory
* @see #setSocketFactory(RMISocketFactory)
* @since JDK1.1
*/
public synchronized static RMISocketFactory getSocketFactory()
{
return factory;
}
/**
* Returns a reference to the default socket factory used
* by this RMI implementation. This will be the factory used
* by the RMI runtime when <code>getSocketFactory</code>
* returns <code>null</code>.
* @return the default RMI socket factory
* @since JDK1.1
*/
public synchronized static RMISocketFactory getDefaultSocketFactory() {
if (defaultSocketFactory == null) {
defaultSocketFactory =
new sun.rmi.transport.proxy.RMIMasterSocketFactory();
}
return defaultSocketFactory;
}
/**
* Sets the failure handler to be called by the RMI runtime if server
* socket creation fails. By default, if no failure handler is installed
* and server socket creation fails, the RMI runtime does attempt to
* recreate the server socket.
*
* <p>If there is a security manager, this method first calls
* the security manager's <code>checkSetFactory</code> method
* to ensure the operation is allowed.
* This could result in a <code>SecurityException</code>.
*
* @param fh the failure handler
* @throws SecurityException if a security manager exists and its
* <code>checkSetFactory</code> method doesn't allow the
* operation.
* @see #getFailureHandler
* @see java.rmi.server.RMIFailureHandler#failure(Exception)
* @since JDK1.1
*/
public synchronized static void setFailureHandler(RMIFailureHandler fh)
{
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkSetFactory();
}
handler = fh;
}
/**
* Returns the handler for socket creation failure set by the
* <code>setFailureHandler</code> method.
* @return the failure handler
* @see #setFailureHandler(RMIFailureHandler)
* @since JDK1.1
*/
public synchronized static RMIFailureHandler getFailureHandler()
{
return handler;
}
}

View File

@@ -0,0 +1,132 @@
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.rmi.*;
import java.io.ObjectOutput;
import java.io.ObjectInput;
import java.io.StreamCorruptedException;
import java.io.IOException;
/**
* <code>RemoteCall</code> is an abstraction used solely by the RMI runtime
* (in conjunction with stubs and skeletons of remote objects) to carry out a
* call to a remote object. The <code>RemoteCall</code> interface is
* deprecated because it is only used by deprecated methods of
* <code>java.rmi.server.RemoteRef</code>.
*
* @since JDK1.1
* @author Ann Wollrath
* @author Roger Riggs
* @see java.rmi.server.RemoteRef
* @deprecated no replacement.
*/
@Deprecated
public interface RemoteCall {
/**
* Return the output stream the stub/skeleton should put arguments/results
* into.
*
* @return output stream for arguments/results
* @exception java.io.IOException if an I/O error occurs.
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
ObjectOutput getOutputStream() throws IOException;
/**
* Release the output stream; in some transports this would release
* the stream.
*
* @exception java.io.IOException if an I/O error occurs.
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
void releaseOutputStream() throws IOException;
/**
* Get the InputStream that the stub/skeleton should get
* results/arguments from.
*
* @return input stream for reading arguments/results
* @exception java.io.IOException if an I/O error occurs.
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
ObjectInput getInputStream() throws IOException;
/**
* Release the input stream. This would allow some transports to release
* the channel early.
*
* @exception java.io.IOException if an I/O error occurs.
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
void releaseInputStream() throws IOException;
/**
* Returns an output stream (may put out header information
* relating to the success of the call). Should only succeed
* once per remote call.
*
* @param success If true, indicates normal return, else indicates
* exceptional return.
* @return output stream for writing call result
* @exception java.io.IOException if an I/O error occurs.
* @exception java.io.StreamCorruptedException If already been called.
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
ObjectOutput getResultStream(boolean success) throws IOException,
StreamCorruptedException;
/**
* Do whatever it takes to execute the call.
*
* @exception java.lang.Exception if a general exception occurs.
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
void executeCall() throws Exception;
/**
* Allow cleanup after the remote call has completed.
*
* @exception java.io.IOException if an I/O error occurs.
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
void done() throws IOException;
}

View File

@@ -0,0 +1,458 @@
/*
* Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.rmi.Remote;
import java.rmi.NoSuchObjectException;
import java.lang.reflect.Proxy;
import sun.rmi.server.Util;
/**
* The <code>RemoteObject</code> class implements the
* <code>java.lang.Object</code> behavior for remote objects.
* <code>RemoteObject</code> provides the remote semantics of Object by
* implementing methods for hashCode, equals, and toString.
*
* @author Ann Wollrath
* @author Laird Dornin
* @author Peter Jones
* @since JDK1.1
*/
public abstract class RemoteObject implements Remote, java.io.Serializable {
/** The object's remote reference. */
transient protected RemoteRef ref;
/** indicate compatibility with JDK 1.1.x version of class */
private static final long serialVersionUID = -3215090123894869218L;
/**
* Creates a remote object.
*/
protected RemoteObject() {
ref = null;
}
/**
* Creates a remote object, initialized with the specified remote
* reference.
* @param newref remote reference
*/
protected RemoteObject(RemoteRef newref) {
ref = newref;
}
/**
* Returns the remote reference for the remote object.
*
* <p>Note: The object returned from this method may be an instance of
* an implementation-specific class. The <code>RemoteObject</code>
* class ensures serialization portability of its instances' remote
* references through the behavior of its custom
* <code>writeObject</code> and <code>readObject</code> methods. An
* instance of <code>RemoteRef</code> should not be serialized outside
* of its <code>RemoteObject</code> wrapper instance or the result may
* be unportable.
*
* @return remote reference for the remote object
* @since 1.2
*/
public RemoteRef getRef() {
return ref;
}
/**
* Returns the stub for the remote object <code>obj</code> passed
* as a parameter. This operation is only valid <i>after</i>
* the object has been exported.
* @param obj the remote object whose stub is needed
* @return the stub for the remote object, <code>obj</code>.
* @exception NoSuchObjectException if the stub for the
* remote object could not be found.
* @since 1.2
*/
public static Remote toStub(Remote obj) throws NoSuchObjectException {
if (obj instanceof RemoteStub ||
(obj != null &&
Proxy.isProxyClass(obj.getClass()) &&
Proxy.getInvocationHandler(obj) instanceof
RemoteObjectInvocationHandler))
{
return obj;
} else {
return sun.rmi.transport.ObjectTable.getStub(obj);
}
}
/**
* Returns a hashcode for a remote object. Two remote object stubs
* that refer to the same remote object will have the same hash code
* (in order to support remote objects as keys in hash tables).
*
* @see java.util.Hashtable
*/
public int hashCode() {
return (ref == null) ? super.hashCode() : ref.remoteHashCode();
}
/**
* Compares two remote objects for equality.
* Returns a boolean that indicates whether this remote object is
* equivalent to the specified Object. This method is used when a
* remote object is stored in a hashtable.
* If the specified Object is not itself an instance of RemoteObject,
* then this method delegates by returning the result of invoking the
* <code>equals</code> method of its parameter with this remote object
* as the argument.
* @param obj the Object to compare with
* @return true if these Objects are equal; false otherwise.
* @see java.util.Hashtable
*/
public boolean equals(Object obj) {
if (obj instanceof RemoteObject) {
if (ref == null) {
return obj == this;
} else {
return ref.remoteEquals(((RemoteObject)obj).ref);
}
} else if (obj != null) {
/*
* Fix for 4099660: if object is not an instance of RemoteObject,
* use the result of its equals method, to support symmetry is a
* remote object implementation class that does not extend
* RemoteObject wishes to support equality with its stub objects.
*/
return obj.equals(this);
} else {
return false;
}
}
/**
* Returns a String that represents the value of this remote object.
*/
public String toString() {
String classname = Util.getUnqualifiedName(getClass());
return (ref == null) ? classname :
classname + "[" + ref.remoteToString() + "]";
}
/**
* <code>writeObject</code> for custom serialization.
*
* <p>This method writes this object's serialized form for this class
* as follows:
*
* <p>The {@link RemoteRef#getRefClass(java.io.ObjectOutput) getRefClass}
* method is invoked on this object's <code>ref</code> field
* to obtain its external ref type name.
* If the value returned by <code>getRefClass</code> was
* a non-<code>null</code> string of length greater than zero,
* the <code>writeUTF</code> method is invoked on <code>out</code>
* with the value returned by <code>getRefClass</code>, and then
* the <code>writeExternal</code> method is invoked on
* this object's <code>ref</code> field passing <code>out</code>
* as the argument; otherwise,
* the <code>writeUTF</code> method is invoked on <code>out</code>
* with a zero-length string (<code>""</code>), and then
* the <code>writeObject</code> method is invoked on <code>out</code>
* passing this object's <code>ref</code> field as the argument.
*
* @serialData
*
* The serialized data for this class comprises a string (written with
* <code>ObjectOutput.writeUTF</code>) that is either the external
* ref type name of the contained <code>RemoteRef</code> instance
* (the <code>ref</code> field) or a zero-length string, followed by
* either the external form of the <code>ref</code> field as written by
* its <code>writeExternal</code> method if the string was of non-zero
* length, or the serialized form of the <code>ref</code> field as
* written by passing it to the serialization stream's
* <code>writeObject</code> if the string was of zero length.
*
* <p>If this object is an instance of
* {@link RemoteStub} or {@link RemoteObjectInvocationHandler}
* that was returned from any of
* the <code>UnicastRemoteObject.exportObject</code> methods
* and custom socket factories are not used,
* the external ref type name is <code>"UnicastRef"</code>.
*
* If this object is an instance of
* <code>RemoteStub</code> or <code>RemoteObjectInvocationHandler</code>
* that was returned from any of
* the <code>UnicastRemoteObject.exportObject</code> methods
* and custom socket factories are used,
* the external ref type name is <code>"UnicastRef2"</code>.
*
* If this object is an instance of
* <code>RemoteStub</code> or <code>RemoteObjectInvocationHandler</code>
* that was returned from any of
* the <code>java.rmi.activation.Activatable.exportObject</code> methods,
* the external ref type name is <code>"ActivatableRef"</code>.
*
* If this object is an instance of
* <code>RemoteStub</code> or <code>RemoteObjectInvocationHandler</code>
* that was returned from
* the <code>RemoteObject.toStub</code> method (and the argument passed
* to <code>toStub</code> was not itself a <code>RemoteStub</code>),
* the external ref type name is a function of how the remote object
* passed to <code>toStub</code> was exported, as described above.
*
* If this object is an instance of
* <code>RemoteStub</code> or <code>RemoteObjectInvocationHandler</code>
* that was originally created via deserialization,
* the external ref type name is the same as that which was read
* when this object was deserialized.
*
* <p>If this object is an instance of
* <code>java.rmi.server.UnicastRemoteObject</code> that does not
* use custom socket factories,
* the external ref type name is <code>"UnicastServerRef"</code>.
*
* If this object is an instance of
* <code>UnicastRemoteObject</code> that does
* use custom socket factories,
* the external ref type name is <code>"UnicastServerRef2"</code>.
*
* <p>Following is the data that must be written by the
* <code>writeExternal</code> method and read by the
* <code>readExternal</code> method of <code>RemoteRef</code>
* implementation classes that correspond to the each of the
* defined external ref type names:
*
* <p>For <code>"UnicastRef"</code>:
*
* <ul>
*
* <li>the hostname of the referenced remote object,
* written by {@link java.io.ObjectOutput#writeUTF(String)}
*
* <li>the port of the referenced remote object,
* written by {@link java.io.ObjectOutput#writeInt(int)}
*
* <li>the data written as a result of calling
* {link java.rmi.server.ObjID#write(java.io.ObjectOutput)}
* on the <code>ObjID</code> instance contained in the reference
*
* <li>the boolean value <code>false</code>,
* written by {@link java.io.ObjectOutput#writeBoolean(boolean)}
*
* </ul>
*
* <p>For <code>"UnicastRef2"</code> with a
* <code>null</code> client socket factory:
*
* <ul>
*
* <li>the byte value <code>0x00</code>
* (indicating <code>null</code> client socket factory),
* written by {@link java.io.ObjectOutput#writeByte(int)}
*
* <li>the hostname of the referenced remote object,
* written by {@link java.io.ObjectOutput#writeUTF(String)}
*
* <li>the port of the referenced remote object,
* written by {@link java.io.ObjectOutput#writeInt(int)}
*
* <li>the data written as a result of calling
* {link java.rmi.server.ObjID#write(java.io.ObjectOutput)}
* on the <code>ObjID</code> instance contained in the reference
*
* <li>the boolean value <code>false</code>,
* written by {@link java.io.ObjectOutput#writeBoolean(boolean)}
*
* </ul>
*
* <p>For <code>"UnicastRef2"</code> with a
* non-<code>null</code> client socket factory:
*
* <ul>
*
* <li>the byte value <code>0x01</code>
* (indicating non-<code>null</code> client socket factory),
* written by {@link java.io.ObjectOutput#writeByte(int)}
*
* <li>the hostname of the referenced remote object,
* written by {@link java.io.ObjectOutput#writeUTF(String)}
*
* <li>the port of the referenced remote object,
* written by {@link java.io.ObjectOutput#writeInt(int)}
*
* <li>a client socket factory (object of type
* <code>java.rmi.server.RMIClientSocketFactory</code>),
* written by passing it to an invocation of
* <code>writeObject</code> on the stream instance
*
* <li>the data written as a result of calling
* {link java.rmi.server.ObjID#write(java.io.ObjectOutput)}
* on the <code>ObjID</code> instance contained in the reference
*
* <li>the boolean value <code>false</code>,
* written by {@link java.io.ObjectOutput#writeBoolean(boolean)}
*
* </ul>
*
* <p>For <code>"ActivatableRef"</code> with a
* <code>null</code> nested remote reference:
*
* <ul>
*
* <li>an instance of
* <code>java.rmi.activation.ActivationID</code>,
* written by passing it to an invocation of
* <code>writeObject</code> on the stream instance
*
* <li>a zero-length string (<code>""</code>),
* written by {@link java.io.ObjectOutput#writeUTF(String)}
*
* </ul>
*
* <p>For <code>"ActivatableRef"</code> with a
* non-<code>null</code> nested remote reference:
*
* <ul>
*
* <li>an instance of
* <code>java.rmi.activation.ActivationID</code>,
* written by passing it to an invocation of
* <code>writeObject</code> on the stream instance
*
* <li>the external ref type name of the nested remote reference,
* which must be <code>"UnicastRef2"</code>,
* written by {@link java.io.ObjectOutput#writeUTF(String)}
*
* <li>the external form of the nested remote reference,
* written by invoking its <code>writeExternal</code> method
* with the stream instance
* (see the description of the external form for
* <code>"UnicastRef2"</code> above)
*
* </ul>
*
* <p>For <code>"UnicastServerRef"</code> and
* <code>"UnicastServerRef2"</code>, no data is written by the
* <code>writeExternal</code> method or read by the
* <code>readExternal</code> method.
*/
private void writeObject(java.io.ObjectOutputStream out)
throws java.io.IOException, java.lang.ClassNotFoundException
{
if (ref == null) {
throw new java.rmi.MarshalException("Invalid remote object");
} else {
String refClassName = ref.getRefClass(out);
if (refClassName == null || refClassName.length() == 0) {
/*
* No reference class name specified, so serialize
* remote reference.
*/
out.writeUTF("");
out.writeObject(ref);
} else {
/*
* Built-in reference class specified, so delegate
* to reference to write out its external form.
*/
out.writeUTF(refClassName);
ref.writeExternal(out);
}
}
}
/**
* <code>readObject</code> for custom serialization.
*
* <p>This method reads this object's serialized form for this class
* as follows:
*
* <p>The <code>readUTF</code> method is invoked on <code>in</code>
* to read the external ref type name for the <code>RemoteRef</code>
* instance to be filled in to this object's <code>ref</code> field.
* If the string returned by <code>readUTF</code> has length zero,
* the <code>readObject</code> method is invoked on <code>in</code>,
* and than the value returned by <code>readObject</code> is cast to
* <code>RemoteRef</code> and this object's <code>ref</code> field is
* set to that value.
* Otherwise, this object's <code>ref</code> field is set to a
* <code>RemoteRef</code> instance that is created of an
* implementation-specific class corresponding to the external ref
* type name returned by <code>readUTF</code>, and then
* the <code>readExternal</code> method is invoked on
* this object's <code>ref</code> field.
*
* <p>If the external ref type name is
* <code>"UnicastRef"</code>, <code>"UnicastServerRef"</code>,
* <code>"UnicastRef2"</code>, <code>"UnicastServerRef2"</code>,
* or <code>"ActivatableRef"</code>, a corresponding
* implementation-specific class must be found, and its
* <code>readExternal</code> method must read the serial data
* for that external ref type name as specified to be written
* in the <b>serialData</b> documentation for this class.
* If the external ref type name is any other string (of non-zero
* length), a <code>ClassNotFoundException</code> will be thrown,
* unless the implementation provides an implementation-specific
* class corresponding to that external ref type name, in which
* case this object's <code>ref</code> field will be set to an
* instance of that implementation-specific class.
*/
private void readObject(java.io.ObjectInputStream in)
throws java.io.IOException, java.lang.ClassNotFoundException
{
String refClassName = in.readUTF();
if (refClassName == null || refClassName.length() == 0) {
/*
* No reference class name specified, so construct
* remote reference from its serialized form.
*/
ref = (RemoteRef) in.readObject();
} else {
/*
* Built-in reference class specified, so delegate to
* internal reference class to initialize its fields from
* its external form.
*/
String internalRefClassName =
RemoteRef.packagePrefix + "." + refClassName;
Class<?> refClass = Class.forName(internalRefClassName);
try {
ref = (RemoteRef) refClass.newInstance();
/*
* If this step fails, assume we found an internal
* class that is not meant to be a serializable ref
* type.
*/
} catch (InstantiationException e) {
throw new ClassNotFoundException(internalRefClassName, e);
} catch (IllegalAccessException e) {
throw new ClassNotFoundException(internalRefClassName, e);
} catch (ClassCastException e) {
throw new ClassNotFoundException(internalRefClassName, e);
}
ref.readExternal(in);
}
}
}

View File

@@ -0,0 +1,324 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.io.InvalidObjectException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.UnexpectedException;
import java.rmi.activation.Activatable;
import java.security.PrivilegedAction;
import java.util.Map;
import java.util.WeakHashMap;
import sun.rmi.server.Util;
import sun.rmi.server.WeakClassHashMap;
/**
* An implementation of the <code>InvocationHandler</code> interface for
* use with Java Remote Method Invocation (Java RMI). This invocation
* handler can be used in conjunction with a dynamic proxy instance as a
* replacement for a pregenerated stub class.
*
* <p>Applications are not expected to use this class directly. A remote
* object exported to use a dynamic proxy with {@link UnicastRemoteObject}
* or {@link Activatable} has an instance of this class as that proxy's
* invocation handler.
*
* @author Ann Wollrath
* @since 1.5
**/
public class RemoteObjectInvocationHandler
extends RemoteObject
implements InvocationHandler
{
private static final long serialVersionUID = 2L;
// set to true if invocation handler allows finalize method (legacy behavior)
private static final boolean allowFinalizeInvocation;
static {
String propName = "sun.rmi.server.invocationhandler.allowFinalizeInvocation";
String allowProp = java.security.AccessController.doPrivileged(
new PrivilegedAction<String>() {
@Override
public String run() {
return System.getProperty(propName);
}
});
if ("".equals(allowProp)) {
allowFinalizeInvocation = true;
} else {
allowFinalizeInvocation = Boolean.parseBoolean(allowProp);
}
}
/**
* A weak hash map, mapping classes to weak hash maps that map
* method objects to method hashes.
**/
private static final MethodToHash_Maps methodToHash_Maps =
new MethodToHash_Maps();
/**
* Creates a new <code>RemoteObjectInvocationHandler</code> constructed
* with the specified <code>RemoteRef</code>.
*
* @param ref the remote ref
*
* @throws NullPointerException if <code>ref</code> is <code>null</code>
**/
public RemoteObjectInvocationHandler(RemoteRef ref) {
super(ref);
if (ref == null) {
throw new NullPointerException();
}
}
/**
* Processes a method invocation made on the encapsulating
* proxy instance, <code>proxy</code>, and returns the result.
*
* <p><code>RemoteObjectInvocationHandler</code> implements this method
* as follows:
*
* <p>If <code>method</code> is one of the following methods, it
* is processed as described below:
*
* <ul>
*
* <li>{@link Object#hashCode Object.hashCode}: Returns the hash
* code value for the proxy.
*
* <li>{@link Object#equals Object.equals}: Returns <code>true</code>
* if the argument (<code>args[0]</code>) is an instance of a dynamic
* proxy class and this invocation handler is equal to the invocation
* handler of that argument, and returns <code>false</code> otherwise.
*
* <li>{@link Object#toString Object.toString}: Returns a string
* representation of the proxy.
* </ul>
*
* <p>Otherwise, a remote call is made as follows:
*
* <ul>
* <li>If <code>proxy</code> is not an instance of the interface
* {@link Remote}, then an {@link IllegalArgumentException} is thrown.
*
* <li>Otherwise, the {@link RemoteRef#invoke invoke} method is invoked
* on this invocation handler's <code>RemoteRef</code>, passing
* <code>proxy</code>, <code>method</code>, <code>args</code>, and the
* method hash (defined in section 8.3 of the "Java Remote Method
* Invocation (RMI) Specification") for <code>method</code>, and the
* result is returned.
*
* <li>If an exception is thrown by <code>RemoteRef.invoke</code> and
* that exception is a checked exception that is not assignable to any
* exception in the <code>throws</code> clause of the method
* implemented by the <code>proxy</code>'s class, then that exception
* is wrapped in an {@link UnexpectedException} and the wrapped
* exception is thrown. Otherwise, the exception thrown by
* <code>invoke</code> is thrown by this method.
* </ul>
*
* <p>The semantics of this method are unspecified if the
* arguments could not have been produced by an instance of some
* valid dynamic proxy class containing this invocation handler.
*
* @param proxy the proxy instance that the method was invoked on
* @param method the <code>Method</code> instance corresponding to the
* interface method invoked on the proxy instance
* @param args an array of objects containing the values of the
* arguments passed in the method invocation on the proxy instance, or
* <code>null</code> if the method takes no arguments
* @return the value to return from the method invocation on the proxy
* instance
* @throws Throwable the exception to throw from the method invocation
* on the proxy instance
**/
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
if (! Proxy.isProxyClass(proxy.getClass())) {
throw new IllegalArgumentException("not a proxy");
}
if (Proxy.getInvocationHandler(proxy) != this) {
throw new IllegalArgumentException("handler mismatch");
}
if (method.getDeclaringClass() == Object.class) {
return invokeObjectMethod(proxy, method, args);
} else if ("finalize".equals(method.getName()) && method.getParameterCount() == 0 &&
!allowFinalizeInvocation) {
return null; // ignore
} else {
return invokeRemoteMethod(proxy, method, args);
}
}
/**
* Handles java.lang.Object methods.
**/
private Object invokeObjectMethod(Object proxy,
Method method,
Object[] args)
{
String name = method.getName();
if (name.equals("hashCode")) {
return hashCode();
} else if (name.equals("equals")) {
Object obj = args[0];
InvocationHandler hdlr;
return
proxy == obj ||
(obj != null &&
Proxy.isProxyClass(obj.getClass()) &&
(hdlr = Proxy.getInvocationHandler(obj)) instanceof RemoteObjectInvocationHandler &&
this.equals(hdlr));
} else if (name.equals("toString")) {
return proxyToString(proxy);
} else {
throw new IllegalArgumentException(
"unexpected Object method: " + method);
}
}
/**
* Handles remote methods.
**/
private Object invokeRemoteMethod(Object proxy,
Method method,
Object[] args)
throws Exception
{
try {
if (!(proxy instanceof Remote)) {
throw new IllegalArgumentException(
"proxy not Remote instance");
}
// Verify that the method is declared on an interface that extends Remote
Class<?> decl = method.getDeclaringClass();
if (!Remote.class.isAssignableFrom(decl)) {
throw new RemoteException("Method is not Remote: " + decl + "::" + method);
}
return ref.invoke((Remote) proxy, method, args,
getMethodHash(method));
} catch (Exception e) {
if (!(e instanceof RuntimeException)) {
Class<?> cl = proxy.getClass();
try {
method = cl.getMethod(method.getName(),
method.getParameterTypes());
} catch (NoSuchMethodException nsme) {
throw (IllegalArgumentException)
new IllegalArgumentException().initCause(nsme);
}
Class<?> thrownType = e.getClass();
for (Class<?> declaredType : method.getExceptionTypes()) {
if (declaredType.isAssignableFrom(thrownType)) {
throw e;
}
}
e = new UnexpectedException("unexpected exception", e);
}
throw e;
}
}
/**
* Returns a string representation for a proxy that uses this invocation
* handler.
**/
private String proxyToString(Object proxy) {
Class<?>[] interfaces = proxy.getClass().getInterfaces();
if (interfaces.length == 0) {
return "Proxy[" + this + "]";
}
String iface = interfaces[0].getName();
if (iface.equals("java.rmi.Remote") && interfaces.length > 1) {
iface = interfaces[1].getName();
}
int dot = iface.lastIndexOf('.');
if (dot >= 0) {
iface = iface.substring(dot + 1);
}
return "Proxy[" + iface + "," + this + "]";
}
/**
* @throws InvalidObjectException unconditionally
**/
private void readObjectNoData() throws InvalidObjectException {
throw new InvalidObjectException("no data in stream; class: " +
this.getClass().getName());
}
/**
* Returns the method hash for the specified method. Subsequent calls
* to "getMethodHash" passing the same method argument should be faster
* since this method caches internally the result of the method to
* method hash mapping. The method hash is calculated using the
* "computeMethodHash" method.
*
* @param method the remote method
* @return the method hash for the specified method
*/
private static long getMethodHash(Method method) {
return methodToHash_Maps.get(method.getDeclaringClass()).get(method);
}
/**
* A weak hash map, mapping classes to weak hash maps that map
* method objects to method hashes.
**/
private static class MethodToHash_Maps
extends WeakClassHashMap<Map<Method,Long>>
{
MethodToHash_Maps() {}
protected Map<Method,Long> computeValue(Class<?> remoteClass) {
return new WeakHashMap<Method,Long>() {
public synchronized Long get(Object key) {
Long hash = super.get(key);
if (hash == null) {
Method method = (Method) key;
hash = Util.computeMethodHash(method);
put(method, hash);
}
return hash;
}
};
}
}
}

View File

@@ -0,0 +1,195 @@
/*
* Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.rmi.*;
/**
* <code>RemoteRef</code> represents the handle for a remote object. A
* <code>RemoteStub</code> uses a remote reference to carry out a
* remote method invocation to a remote object.
*
* @author Ann Wollrath
* @since JDK1.1
* @see java.rmi.server.RemoteStub
*/
public interface RemoteRef extends java.io.Externalizable {
/** indicate compatibility with JDK 1.1.x version of class. */
static final long serialVersionUID = 3632638527362204081L;
/**
* Initialize the server package prefix: assumes that the
* implementation of server ref classes (e.g., UnicastRef,
* UnicastServerRef) are located in the package defined by the
* prefix.
*/
final static String packagePrefix = "sun.rmi.server";
/**
* Invoke a method. This form of delegating method invocation
* to the reference allows the reference to take care of
* setting up the connection to the remote host, marshaling
* some representation for the method and parameters, then
* communicating the method invocation to the remote host.
* This method either returns the result of a method invocation
* on the remote object which resides on the remote host or
* throws a RemoteException if the call failed or an
* application-level exception if the remote invocation throws
* an exception.
*
* @param obj the object that contains the RemoteRef (e.g., the
* RemoteStub for the object.
* @param method the method to be invoked
* @param params the parameter list
* @param opnum a hash that may be used to represent the method
* @return result of remote method invocation
* @exception Exception if any exception occurs during remote method
* invocation
* @since 1.2
*/
Object invoke(Remote obj,
java.lang.reflect.Method method,
Object[] params,
long opnum)
throws Exception;
/**
* Creates an appropriate call object for a new remote method
* invocation on this object. Passing operation array and index,
* allows the stubs generator to assign the operation indexes and
* interpret them. The remote reference may need the operation to
* encode in the call.
*
* @since JDK1.1
* @deprecated 1.2 style stubs no longer use this method. Instead of
* using a sequence of method calls on the stub's the remote reference
* (<code>newCall</code>, <code>invoke</code>, and <code>done</code>), a
* stub uses a single method, <code>invoke(Remote, Method, Object[],
* int)</code>, on the remote reference to carry out parameter
* marshalling, remote method executing and unmarshalling of the return
* value.
*
* @param obj remote stub through which to make call
* @param op array of stub operations
* @param opnum operation number
* @param hash stub/skeleton interface hash
* @return call object representing remote call
* @throws RemoteException if failed to initiate new remote call
* @see #invoke(Remote,java.lang.reflect.Method,Object[],long)
*/
@Deprecated
RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum, long hash)
throws RemoteException;
/**
* Executes the remote call.
*
* Invoke will raise any "user" exceptions which
* should pass through and not be caught by the stub. If any
* exception is raised during the remote invocation, invoke should
* take care of cleaning up the connection before raising the
* "user" or remote exception.
*
* @since JDK1.1
* @deprecated 1.2 style stubs no longer use this method. Instead of
* using a sequence of method calls to the remote reference
* (<code>newCall</code>, <code>invoke</code>, and <code>done</code>), a
* stub uses a single method, <code>invoke(Remote, Method, Object[],
* int)</code>, on the remote reference to carry out parameter
* marshalling, remote method executing and unmarshalling of the return
* value.
*
* @param call object representing remote call
* @throws Exception if any exception occurs during remote method
* @see #invoke(Remote,java.lang.reflect.Method,Object[],long)
*/
@Deprecated
void invoke(RemoteCall call) throws Exception;
/**
* Allows the remote reference to clean up (or reuse) the connection.
* Done should only be called if the invoke returns successfully
* (non-exceptionally) to the stub.
*
* @since JDK1.1
* @deprecated 1.2 style stubs no longer use this method. Instead of
* using a sequence of method calls to the remote reference
* (<code>newCall</code>, <code>invoke</code>, and <code>done</code>), a
* stub uses a single method, <code>invoke(Remote, Method, Object[],
* int)</code>, on the remote reference to carry out parameter
* marshalling, remote method executing and unmarshalling of the return
* value.
*
* @param call object representing remote call
* @throws RemoteException if remote error occurs during call cleanup
* @see #invoke(Remote,java.lang.reflect.Method,Object[],long)
*/
@Deprecated
void done(RemoteCall call) throws RemoteException;
/**
* Returns the class name of the ref type to be serialized onto
* the stream 'out'.
* @param out the output stream to which the reference will be serialized
* @return the class name (without package qualification) of the reference
* type
* @since JDK1.1
*/
String getRefClass(java.io.ObjectOutput out);
/**
* Returns a hashcode for a remote object. Two remote object stubs
* that refer to the same remote object will have the same hash code
* (in order to support remote objects as keys in hash tables).
*
* @return remote object hashcode
* @see java.util.Hashtable
* @since JDK1.1
*/
int remoteHashCode();
/**
* Compares two remote objects for equality.
* Returns a boolean that indicates whether this remote object is
* equivalent to the specified Object. This method is used when a
* remote object is stored in a hashtable.
* @param obj the Object to compare with
* @return true if these Objects are equal; false otherwise.
* @see java.util.Hashtable
* @since JDK1.1
*/
boolean remoteEquals(RemoteRef obj);
/**
* Returns a String that represents the reference of this remote
* object.
* @return string representing remote object reference
* @since JDK1.1
*/
String remoteToString();
}

View File

@@ -0,0 +1,115 @@
/*
* Copyright (c) 1996, 2002, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.rmi.*;
import sun.rmi.server.UnicastServerRef;
import sun.rmi.runtime.Log;
/**
* The <code>RemoteServer</code> class is the common superclass to server
* implementations and provides the framework to support a wide range
* of remote reference semantics. Specifically, the functions needed
* to create and export remote objects (i.e. to make them remotely
* available) are provided abstractly by <code>RemoteServer</code> and
* concretely by its subclass(es).
*
* @author Ann Wollrath
* @since JDK1.1
*/
public abstract class RemoteServer extends RemoteObject
{
/* indicate compatibility with JDK 1.1.x version of class */
private static final long serialVersionUID = -4100238210092549637L;
/**
* Constructs a <code>RemoteServer</code>.
* @since JDK1.1
*/
protected RemoteServer() {
super();
}
/**
* Constructs a <code>RemoteServer</code> with the given reference type.
*
* @param ref the remote reference
* @since JDK1.1
*/
protected RemoteServer(RemoteRef ref) {
super(ref);
}
/**
* Returns a string representation of the client host for the
* remote method invocation being processed in the current thread.
*
* @return a string representation of the client host
*
* @throws ServerNotActiveException if no remote method invocation
* is being processed in the current thread
*
* @since JDK1.1
*/
public static String getClientHost() throws ServerNotActiveException {
return sun.rmi.transport.tcp.TCPTransport.getClientHost();
}
/**
* Log RMI calls to the output stream <code>out</code>. If
* <code>out</code> is <code>null</code>, call logging is turned off.
*
* <p>If there is a security manager, its
* <code>checkPermission</code> method will be invoked with a
* <code>java.util.logging.LoggingPermission("control")</code>
* permission; this could result in a <code>SecurityException</code>.
*
* @param out the output stream to which RMI calls should be logged
* @throws SecurityException if there is a security manager and
* the invocation of its <code>checkPermission</code> method
* fails
* @see #getLog
* @since JDK1.1
*/
public static void setLog(java.io.OutputStream out)
{
logNull = (out == null);
UnicastServerRef.callLog.setOutputStream(out);
}
/**
* Returns stream for the RMI call log.
* @return the call log
* @see #setLog
* @since JDK1.1
*/
public static java.io.PrintStream getLog()
{
return (logNull ? null : UnicastServerRef.callLog.getPrintStream());
}
// initialize log status
private static boolean logNull = !UnicastServerRef.logCalls;
}

View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
/**
* The {@code RemoteStub} class is the common superclass of
* statically generated client
* stubs and provides the framework to support a wide range of remote
* reference semantics. Stub objects are surrogates that support
* exactly the same set of remote interfaces defined by the actual
* implementation of the remote object.
*
* @author Ann Wollrath
* @since JDK1.1
*
* @deprecated Statically generated stubs are deprecated, since
* stubs are generated dynamically. See {@link UnicastRemoteObject}
* for information about dynamic stub generation.
*/
@Deprecated
abstract public class RemoteStub extends RemoteObject {
/** indicate compatibility with JDK 1.1.x version of class */
private static final long serialVersionUID = -1585587260594494182L;
/**
* Constructs a {@code RemoteStub}.
*/
protected RemoteStub() {
super();
}
/**
* Constructs a {@code RemoteStub} with the specified remote
* reference.
*
* @param ref the remote reference
* @since JDK1.1
*/
protected RemoteStub(RemoteRef ref) {
super(ref);
}
/**
* Throws {@link UnsupportedOperationException}.
*
* @param stub the remote stub
* @param ref the remote reference
* @throws UnsupportedOperationException always
* @since JDK1.1
* @deprecated No replacement. The {@code setRef} method
* was intended for setting the remote reference of a remote
* stub. This is unnecessary, since {@code RemoteStub}s can be created
* and initialized with a remote reference through use of
* the {@link #RemoteStub(RemoteRef)} constructor.
*/
@Deprecated
protected static void setRef(RemoteStub stub, RemoteRef ref) {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright (c) 1996, 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
/**
* A <code>ServerCloneException</code> is thrown if a remote exception occurs
* during the cloning of a <code>UnicastRemoteObject</code>.
*
* <p>As of release 1.4, this exception has been retrofitted to conform to
* the general purpose exception-chaining mechanism. The "nested exception"
* that may be provided at construction time and accessed via the public
* {@link #detail} field is now known as the <i>cause</i>, and may be
* accessed via the {@link Throwable#getCause()} method, as well as
* the aforementioned "legacy field."
*
* <p>Invoking the method {@link Throwable#initCause(Throwable)} on an
* instance of <code>ServerCloneException</code> always throws {@link
* IllegalStateException}.
*
* @author Ann Wollrath
* @since JDK1.1
* @see java.rmi.server.UnicastRemoteObject#clone()
*/
public class ServerCloneException extends CloneNotSupportedException {
/**
* The cause of the exception.
*
* <p>This field predates the general-purpose exception chaining facility.
* The {@link Throwable#getCause()} method is now the preferred means of
* obtaining this information.
*
* @serial
*/
public Exception detail;
/* indicate compatibility with JDK 1.1.x version of class */
private static final long serialVersionUID = 6617456357664815945L;
/**
* Constructs a <code>ServerCloneException</code> with the specified
* detail message.
*
* @param s the detail message.
*/
public ServerCloneException(String s) {
super(s);
initCause(null); // Disallow subsequent initCause
}
/**
* Constructs a <code>ServerCloneException</code> with the specified
* detail message and cause.
*
* @param s the detail message.
* @param cause the cause
*/
public ServerCloneException(String s, Exception cause) {
super(s);
initCause(null); // Disallow subsequent initCause
detail = cause;
}
/**
* Returns the detail message, including the message from the cause, if
* any, of this exception.
*
* @return the detail message
*/
public String getMessage() {
if (detail == null)
return super.getMessage();
else
return super.getMessage() +
"; nested exception is: \n\t" +
detail.toString();
}
/**
* Returns the cause of this exception. This method returns the value
* of the {@link #detail} field.
*
* @return the cause, which may be <tt>null</tt>.
* @since 1.4
*/
public Throwable getCause() {
return detail;
}
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 1996, 1998, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
/**
* An <code>ServerNotActiveException</code> is an <code>Exception</code>
* thrown during a call to <code>RemoteServer.getClientHost</code> if
* the getClientHost method is called outside of servicing a remote
* method call.
*
* @author Roger Riggs
* @since JDK1.1
* @see java.rmi.server.RemoteServer#getClientHost()
*/
public class ServerNotActiveException extends java.lang.Exception {
/* indicate compatibility with JDK 1.1.x version of class */
private static final long serialVersionUID = 4687940720827538231L;
/**
* Constructs an <code>ServerNotActiveException</code> with no specified
* detail message.
* @since JDK1.1
*/
public ServerNotActiveException() {}
/**
* Constructs an <code>ServerNotActiveException</code> with the specified
* detail message.
*
* @param s the detail message.
* @since JDK1.1
*/
public ServerNotActiveException(String s)
{
super(s);
}
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.rmi.*;
/**
* A ServerRef represents the server-side handle for a remote object
* implementation.
*
* @author Ann Wollrath
* @since JDK1.1
* @deprecated No replacement. This interface is unused and is obsolete.
*/
@Deprecated
public interface ServerRef extends RemoteRef {
/** indicate compatibility with JDK 1.1.x version of class. */
static final long serialVersionUID = -4557750989390278438L;
/**
* Creates a client stub object for the supplied Remote object.
* If the call completes successfully, the remote object should
* be able to accept incoming calls from clients.
* @param obj the remote object implementation
* @param data information necessary to export the object
* @return the stub for the remote object
* @exception RemoteException if an exception occurs attempting
* to export the object (e.g., stub class could not be found)
* @since JDK1.1
*/
RemoteStub exportObject(Remote obj, Object data)
throws RemoteException;
/**
* Returns the hostname of the current client. When called from a
* thread actively handling a remote method invocation the
* hostname of the client is returned.
* @return the client's host name
* @exception ServerNotActiveException if called outside of servicing
* a remote method invocation
* @since JDK1.1
*/
String getClientHost() throws ServerNotActiveException;
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.rmi.Remote;
/**
* The <code>Skeleton</code> interface is used solely by the RMI
* implementation.
*
* <p> Every version 1.1 (and version 1.1 compatible skeletons generated in
* 1.2 using <code>rmic -vcompat</code>) skeleton class generated by the rmic
* stub compiler implements this interface. A skeleton for a remote object is
* a server-side entity that dispatches calls to the actual remote object
* implementation.
*
* @author Ann Wollrath
* @since JDK1.1
* @deprecated no replacement. Skeletons are no longer required for remote
* method calls in the Java 2 platform v1.2 and greater.
*/
@Deprecated
public interface Skeleton {
/**
* Unmarshals arguments, calls the actual remote object implementation,
* and marshals the return value or any exception.
*
* @param obj remote implementation to dispatch call to
* @param theCall object representing remote call
* @param opnum operation number
* @param hash stub/skeleton interface hash
* @exception java.lang.Exception if a general exception occurs.
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
void dispatch(Remote obj, RemoteCall theCall, int opnum, long hash)
throws Exception;
/**
* Returns the operations supported by the skeleton.
* @return operations supported by skeleton
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
Operation[] getOperations();
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.rmi.RemoteException;
/**
* This exception is thrown when a call is received that does not
* match the available skeleton. It indicates either that the
* remote method names or signatures in this interface have changed or
* that the stub class used to make the call and the skeleton
* receiving the call were not generated by the same version of
* the stub compiler (<code>rmic</code>).
*
* @author Roger Riggs
* @since JDK1.1
* @deprecated no replacement. Skeletons are no longer required for remote
* method calls in the Java 2 platform v1.2 and greater.
*/
@Deprecated
public class SkeletonMismatchException extends RemoteException {
/* indicate compatibility with JDK 1.1.x version of class */
private static final long serialVersionUID = -7780460454818859281L;
/**
* Constructs a new <code>SkeletonMismatchException</code> with
* a specified detail message.
*
* @param s the detail message
* @since JDK1.1
* @deprecated no replacement
*/
@Deprecated
public SkeletonMismatchException(String s) {
super(s);
}
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.rmi.RemoteException;
/**
* A <code>SkeletonNotFoundException</code> is thrown if the
* <code>Skeleton</code> corresponding to the remote object being
* exported is not found. Skeletons are no longer required, so this
* exception is never thrown.
*
* @since JDK1.1
* @deprecated no replacement. Skeletons are no longer required for remote
* method calls in the Java 2 platform v1.2 and greater.
*/
@Deprecated
public class SkeletonNotFoundException extends RemoteException {
/* indicate compatibility with JDK 1.1.x version of class */
private static final long serialVersionUID = -7860299673822761231L;
/**
* Constructs a <code>SkeletonNotFoundException</code> with the specified
* detail message.
*
* @param s the detail message.
* @since JDK1.1
*/
public SkeletonNotFoundException(String s) {
super(s);
}
/**
* Constructs a <code>SkeletonNotFoundException</code> with the specified
* detail message and nested exception.
*
* @param s the detail message.
* @param ex the nested exception
* @since JDK1.1
*/
public SkeletonNotFoundException(String s, Exception ex) {
super(s, ex);
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
/**
* An obsolete subclass of {@link ExportException}.
*
* @author Ann Wollrath
* @since JDK1.1
* @deprecated This class is obsolete. Use {@link ExportException} instead.
*/
@Deprecated
public class SocketSecurityException extends ExportException {
/* indicate compatibility with JDK 1.1.x version of class */
private static final long serialVersionUID = -7622072999407781979L;
/**
* Constructs an <code>SocketSecurityException</code> with the specified
* detail message.
*
* @param s the detail message.
* @since JDK1.1
*/
public SocketSecurityException(String s) {
super(s);
}
/**
* Constructs an <code>SocketSecurityException</code> with the specified
* detail message and nested exception.
*
* @param s the detail message.
* @param ex the nested exception
* @since JDK1.1
*/
public SocketSecurityException(String s, Exception ex) {
super(s, ex);
}
}

View File

@@ -0,0 +1,269 @@
/*
* Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.Serializable;
import java.security.SecureRandom;
/**
* A <code>UID</code> represents an identifier that is unique over time
* with respect to the host it is generated on, or one of 2<sup>16</sup>
* "well-known" identifiers.
*
* <p>The {@link #UID()} constructor can be used to generate an
* identifier that is unique over time with respect to the host it is
* generated on. The {@link #UID(short)} constructor can be used to
* create one of 2<sup>16</sup> well-known identifiers.
*
* <p>A <code>UID</code> instance contains three primitive values:
* <ul>
* <li><code>unique</code>, an <code>int</code> that uniquely identifies
* the VM that this <code>UID</code> was generated in, with respect to its
* host and at the time represented by the <code>time</code> value (an
* example implementation of the <code>unique</code> value would be a
* process identifier),
* or zero for a well-known <code>UID</code>
* <li><code>time</code>, a <code>long</code> equal to a time (as returned
* by {@link System#currentTimeMillis()}) at which the VM that this
* <code>UID</code> was generated in was alive,
* or zero for a well-known <code>UID</code>
* <li><code>count</code>, a <code>short</code> to distinguish
* <code>UID</code>s generated in the same VM with the same
* <code>time</code> value
* </ul>
*
* <p>An independently generated <code>UID</code> instance is unique
* over time with respect to the host it is generated on as long as
* the host requires more than one millisecond to reboot and its system
* clock is never set backward. A globally unique identifier can be
* constructed by pairing a <code>UID</code> instance with a unique host
* identifier, such as an IP address.
*
* @author Ann Wollrath
* @author Peter Jones
* @since JDK1.1
*/
public final class UID implements Serializable {
private static int hostUnique;
private static boolean hostUniqueSet = false;
private static final Object lock = new Object();
private static long lastTime = System.currentTimeMillis();
private static short lastCount = Short.MIN_VALUE;
/** indicate compatibility with JDK 1.1.x version of class */
private static final long serialVersionUID = 1086053664494604050L;
/**
* number that uniquely identifies the VM that this <code>UID</code>
* was generated in with respect to its host and at the given time
* @serial
*/
private final int unique;
/**
* a time (as returned by {@link System#currentTimeMillis()}) at which
* the VM that this <code>UID</code> was generated in was alive
* @serial
*/
private final long time;
/**
* 16-bit number to distinguish <code>UID</code> instances created
* in the same VM with the same time value
* @serial
*/
private final short count;
/**
* Generates a <code>UID</code> that is unique over time with
* respect to the host that it was generated on.
*/
public UID() {
synchronized (lock) {
if (!hostUniqueSet) {
hostUnique = (new SecureRandom()).nextInt();
hostUniqueSet = true;
}
unique = hostUnique;
if (lastCount == Short.MAX_VALUE) {
boolean interrupted = Thread.interrupted();
boolean done = false;
while (!done) {
long now = System.currentTimeMillis();
if (now == lastTime) {
// wait for time to change
try {
Thread.sleep(1);
} catch (InterruptedException e) {
interrupted = true;
}
} else {
// If system time has gone backwards increase
// original by 1ms to maintain uniqueness
lastTime = (now < lastTime) ? lastTime+1 : now;
lastCount = Short.MIN_VALUE;
done = true;
}
}
if (interrupted) {
Thread.currentThread().interrupt();
}
}
time = lastTime;
count = lastCount++;
}
}
/**
* Creates a "well-known" <code>UID</code>.
*
* There are 2<sup>16</sup> possible such well-known ids.
*
* <p>A <code>UID</code> created via this constructor will not
* clash with any <code>UID</code>s generated via the no-arg
* constructor.
*
* @param num number for well-known <code>UID</code>
*/
public UID(short num) {
unique = 0;
time = 0;
count = num;
}
/**
* Constructs a <code>UID</code> given data read from a stream.
*/
private UID(int unique, long time, short count) {
this.unique = unique;
this.time = time;
this.count = count;
}
/**
* Returns the hash code value for this <code>UID</code>.
*
* @return the hash code value for this <code>UID</code>
*/
public int hashCode() {
return (int) time + (int) count;
}
/**
* Compares the specified object with this <code>UID</code> for
* equality.
*
* This method returns <code>true</code> if and only if the
* specified object is a <code>UID</code> instance with the same
* <code>unique</code>, <code>time</code>, and <code>count</code>
* values as this one.
*
* @param obj the object to compare this <code>UID</code> to
*
* @return <code>true</code> if the given object is equivalent to
* this one, and <code>false</code> otherwise
*/
public boolean equals(Object obj) {
if (obj instanceof UID) {
UID uid = (UID) obj;
return (unique == uid.unique &&
count == uid.count &&
time == uid.time);
} else {
return false;
}
}
/**
* Returns a string representation of this <code>UID</code>.
*
* @return a string representation of this <code>UID</code>
*/
public String toString() {
return Integer.toString(unique,16) + ":" +
Long.toString(time,16) + ":" +
Integer.toString(count,16);
}
/**
* Marshals a binary representation of this <code>UID</code> to
* a <code>DataOutput</code> instance.
*
* <p>Specifically, this method first invokes the given stream's
* {@link DataOutput#writeInt(int)} method with this <code>UID</code>'s
* <code>unique</code> value, then it invokes the stream's
* {@link DataOutput#writeLong(long)} method with this <code>UID</code>'s
* <code>time</code> value, and then it invokes the stream's
* {@link DataOutput#writeShort(int)} method with this <code>UID</code>'s
* <code>count</code> value.
*
* @param out the <code>DataOutput</code> instance to write
* this <code>UID</code> to
*
* @throws IOException if an I/O error occurs while performing
* this operation
*/
public void write(DataOutput out) throws IOException {
out.writeInt(unique);
out.writeLong(time);
out.writeShort(count);
}
/**
* Constructs and returns a new <code>UID</code> instance by
* unmarshalling a binary representation from an
* <code>DataInput</code> instance.
*
* <p>Specifically, this method first invokes the given stream's
* {@link DataInput#readInt()} method to read a <code>unique</code> value,
* then it invoke's the stream's
* {@link DataInput#readLong()} method to read a <code>time</code> value,
* then it invoke's the stream's
* {@link DataInput#readShort()} method to read a <code>count</code> value,
* and then it creates and returns a new <code>UID</code> instance
* that contains the <code>unique</code>, <code>time</code>, and
* <code>count</code> values that were read from the stream.
*
* @param in the <code>DataInput</code> instance to read
* <code>UID</code> from
*
* @return unmarshalled <code>UID</code> instance
*
* @throws IOException if an I/O error occurs while performing
* this operation
*/
public static UID read(DataInput in) throws IOException {
int unique = in.readInt();
long time = in.readLong();
short count = in.readShort();
return new UID(unique, time, count);
}
}

View File

@@ -0,0 +1,385 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
import java.rmi.*;
import sun.rmi.server.UnicastServerRef;
import sun.rmi.server.UnicastServerRef2;
/**
* Used for exporting a remote object with JRMP and obtaining a stub
* that communicates to the remote object. Stubs are either generated
* at runtime using dynamic proxy objects, or they are generated statically
* at build time, typically using the {@code rmic} tool.
*
* <p><strong>Deprecated: Static Stubs.</strong> <em>Support for statically
* generated stubs is deprecated. This includes the API in this class that
* requires the use of static stubs, as well as the runtime support for
* loading static stubs. Generating stubs dynamically is preferred, using one
* of the five non-deprecated ways of exporting objects as listed below. Do
* not run {@code rmic} to generate static stub classes. It is unnecessary, and
* it is also deprecated.</em>
*
* <p>There are six ways to export remote objects:
*
* <ol>
*
* <li>Subclassing {@code UnicastRemoteObject} and calling the
* {@link #UnicastRemoteObject()} constructor.
*
* <li>Subclassing {@code UnicastRemoteObject} and calling the
* {@link #UnicastRemoteObject(int) UnicastRemoteObject(port)} constructor.
*
* <li>Subclassing {@code UnicastRemoteObject} and calling the
* {@link #UnicastRemoteObject(int, RMIClientSocketFactory, RMIServerSocketFactory)
* UnicastRemoteObject(port, csf, ssf)} constructor.
*
* <li>Calling the
* {@link #exportObject(Remote) exportObject(Remote)} method.
* <strong>Deprecated.</strong>
*
* <li>Calling the
* {@link #exportObject(Remote, int) exportObject(Remote, port)} method.
*
* <li>Calling the
* {@link #exportObject(Remote, int, RMIClientSocketFactory, RMIServerSocketFactory)
* exportObject(Remote, port, csf, ssf)} method.
*
* </ol>
*
* <p>The fourth technique, {@link #exportObject(Remote)},
* always uses statically generated stubs and is deprecated.
*
* <p>The other five techniques all use the following approach: if the
* {@code java.rmi.server.ignoreStubClasses} property is {@code true}
* (case insensitive) or if a static stub cannot be found, stubs are generated
* dynamically using {@link java.lang.reflect.Proxy Proxy} objects. Otherwise,
* static stubs are used.
*
* <p>The default value of the
* {@code java.rmi.server.ignoreStubClasses} property is {@code false}.
*
* <p>Statically generated stubs are typically pregenerated from the
* remote object's class using the {@code rmic} tool. A static stub is
* loaded and an instance of that stub class is constructed as described
* below.
*
* <ul>
*
* <li>A "root class" is determined as follows: if the remote object's
* class directly implements an interface that extends {@link Remote}, then
* the remote object's class is the root class; otherwise, the root class is
* the most derived superclass of the remote object's class that directly
* implements an interface that extends {@code Remote}.
*
* <li>The name of the stub class to load is determined by concatenating
* the binary name of the root class with the suffix {@code _Stub}.
*
* <li>The stub class is loaded by name using the class loader of the root
* class. The stub class must extend {@link RemoteStub} and must have a
* public constructor that has one parameter of type {@link RemoteRef}.
*
* <li>Finally, an instance of the stub class is constructed with a
* {@link RemoteRef}.
*
* <li>If the appropriate stub class could not be found, or if the stub class
* could not be loaded, or if a problem occurs creating the stub instance, a
* {@link StubNotFoundException} is thrown.
*
* </ul>
*
* <p>Stubs are dynamically generated by constructing an instance of
* a {@link java.lang.reflect.Proxy Proxy} with the following characteristics:
*
* <ul>
*
* <li>The proxy's class is defined by the class loader of the remote
* object's class.
*
* <li>The proxy implements all the remote interfaces implemented by the
* remote object's class.
*
* <li>The proxy's invocation handler is a {@link
* RemoteObjectInvocationHandler} instance constructed with a
* {@link RemoteRef}.
*
* <li>If the proxy could not be created, a {@link StubNotFoundException}
* will be thrown.
*
* </ul>
*
* @implNote
* Depending upon which constructor or static method is used for exporting an
* object, {@link RMISocketFactory} may be used for creating sockets.
* By default, server sockets created by {@link RMISocketFactory}
* listen on all network interfaces. See the
* {@link RMISocketFactory} class and the section
* <a href="{@docRoot}/../platform/rmi/spec/rmi-server29.html">RMI Socket Factories</a>
* in the
* <a href="{@docRoot}/../platform/rmi/spec/rmiTOC.html">Java RMI Specification</a>.
*
* @author Ann Wollrath
* @author Peter Jones
* @since JDK1.1
**/
public class UnicastRemoteObject extends RemoteServer {
/**
* @serial port number on which to export object
*/
private int port = 0;
/**
* @serial client-side socket factory (if any)
*/
private RMIClientSocketFactory csf = null;
/**
* @serial server-side socket factory (if any) to use when
* exporting object
*/
private RMIServerSocketFactory ssf = null;
/* indicate compatibility with JDK 1.1.x version of class */
private static final long serialVersionUID = 4974527148936298033L;
/**
* Creates and exports a new UnicastRemoteObject object using an
* anonymous port.
*
* <p>The object is exported with a server socket
* created using the {@link RMISocketFactory} class.
*
* @throws RemoteException if failed to export object
* @since JDK1.1
*/
protected UnicastRemoteObject() throws RemoteException
{
this(0);
}
/**
* Creates and exports a new UnicastRemoteObject object using the
* particular supplied port.
*
* <p>The object is exported with a server socket
* created using the {@link RMISocketFactory} class.
*
* @param port the port number on which the remote object receives calls
* (if <code>port</code> is zero, an anonymous port is chosen)
* @throws RemoteException if failed to export object
* @since 1.2
*/
protected UnicastRemoteObject(int port) throws RemoteException
{
this.port = port;
exportObject((Remote) this, port);
}
/**
* Creates and exports a new UnicastRemoteObject object using the
* particular supplied port and socket factories.
*
* <p>Either socket factory may be {@code null}, in which case
* the corresponding client or server socket creation method of
* {@link RMISocketFactory} is used instead.
*
* @param port the port number on which the remote object receives calls
* (if <code>port</code> is zero, an anonymous port is chosen)
* @param csf the client-side socket factory for making calls to the
* remote object
* @param ssf the server-side socket factory for receiving remote calls
* @throws RemoteException if failed to export object
* @since 1.2
*/
protected UnicastRemoteObject(int port,
RMIClientSocketFactory csf,
RMIServerSocketFactory ssf)
throws RemoteException
{
this.port = port;
this.csf = csf;
this.ssf = ssf;
exportObject((Remote) this, port, csf, ssf);
}
/**
* Re-export the remote object when it is deserialized.
*/
private void readObject(java.io.ObjectInputStream in)
throws java.io.IOException, java.lang.ClassNotFoundException
{
in.defaultReadObject();
reexport();
}
/**
* Returns a clone of the remote object that is distinct from
* the original.
*
* @exception CloneNotSupportedException if clone failed due to
* a RemoteException.
* @return the new remote object
* @since JDK1.1
*/
public Object clone() throws CloneNotSupportedException
{
try {
UnicastRemoteObject cloned = (UnicastRemoteObject) super.clone();
cloned.reexport();
return cloned;
} catch (RemoteException e) {
throw new ServerCloneException("Clone failed", e);
}
}
/*
* Exports this UnicastRemoteObject using its initialized fields because
* its creation bypassed running its constructors (via deserialization
* or cloning, for example).
*/
private void reexport() throws RemoteException
{
if (csf == null && ssf == null) {
exportObject((Remote) this, port);
} else {
exportObject((Remote) this, port, csf, ssf);
}
}
/**
* Exports the remote object to make it available to receive incoming
* calls using an anonymous port. This method will always return a
* statically generated stub.
*
* <p>The object is exported with a server socket
* created using the {@link RMISocketFactory} class.
*
* @param obj the remote object to be exported
* @return remote object stub
* @exception RemoteException if export fails
* @since JDK1.1
* @deprecated This method is deprecated because it supports only static stubs.
* Use {@link #exportObject(Remote, int) exportObject(Remote, port)} or
* {@link #exportObject(Remote, int, RMIClientSocketFactory, RMIServerSocketFactory)
* exportObject(Remote, port, csf, ssf)}
* instead.
*/
@Deprecated
public static RemoteStub exportObject(Remote obj)
throws RemoteException
{
/*
* Use UnicastServerRef constructor passing the boolean value true
* to indicate that only a generated stub class should be used. A
* generated stub class must be used instead of a dynamic proxy
* because the return value of this method is RemoteStub which a
* dynamic proxy class cannot extend.
*/
return (RemoteStub) exportObject(obj, new UnicastServerRef(true));
}
/**
* Exports the remote object to make it available to receive incoming
* calls, using the particular supplied port.
*
* <p>The object is exported with a server socket
* created using the {@link RMISocketFactory} class.
*
* @param obj the remote object to be exported
* @param port the port to export the object on
* @return remote object stub
* @exception RemoteException if export fails
* @since 1.2
*/
public static Remote exportObject(Remote obj, int port)
throws RemoteException
{
return exportObject(obj, new UnicastServerRef(port));
}
/**
* Exports the remote object to make it available to receive incoming
* calls, using a transport specified by the given socket factory.
*
* <p>Either socket factory may be {@code null}, in which case
* the corresponding client or server socket creation method of
* {@link RMISocketFactory} is used instead.
*
* @param obj the remote object to be exported
* @param port the port to export the object on
* @param csf the client-side socket factory for making calls to the
* remote object
* @param ssf the server-side socket factory for receiving remote calls
* @return remote object stub
* @exception RemoteException if export fails
* @since 1.2
*/
public static Remote exportObject(Remote obj, int port,
RMIClientSocketFactory csf,
RMIServerSocketFactory ssf)
throws RemoteException
{
return exportObject(obj, new UnicastServerRef2(port, csf, ssf));
}
/**
* Removes the remote object, obj, from the RMI runtime. If
* successful, the object can no longer accept incoming RMI calls.
* If the force parameter is true, the object is forcibly unexported
* even if there are pending calls to the remote object or the
* remote object still has calls in progress. If the force
* parameter is false, the object is only unexported if there are
* no pending or in progress calls to the object.
*
* @param obj the remote object to be unexported
* @param force if true, unexports the object even if there are
* pending or in-progress calls; if false, only unexports the object
* if there are no pending or in-progress calls
* @return true if operation is successful, false otherwise
* @exception NoSuchObjectException if the remote object is not
* currently exported
* @since 1.2
*/
public static boolean unexportObject(Remote obj, boolean force)
throws java.rmi.NoSuchObjectException
{
return sun.rmi.transport.ObjectTable.unexportObject(obj, force);
}
/**
* Exports the specified object using the specified server ref.
*/
private static Remote exportObject(Remote obj, UnicastServerRef sref)
throws RemoteException
{
// if obj extends UnicastRemoteObject, set its ref.
if (obj instanceof UnicastRemoteObject) {
((UnicastRemoteObject) obj).ref = sref;
}
return sref.exportObject(obj, null, false);
}
}

View File

@@ -0,0 +1,45 @@
/*
* Copyright (c) 1996, 1998, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.rmi.server;
/**
* A remote object implementation should implement the
* <code>Unreferenced</code> interface to receive notification when there are
* no more clients that reference that remote object.
*
* @author Ann Wollrath
* @author Roger Riggs
* @since JDK1.1
*/
public interface Unreferenced {
/**
* Called by the RMI runtime sometime after the runtime determines that
* the reference list, the list of clients referencing the remote object,
* becomes empty.
* @since JDK1.1
*/
public void unreferenced();
}