undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
68
src/java.rmi/share/classes/java/rmi/AccessException.java
Normal file
68
src/java.rmi/share/classes/java/rmi/AccessException.java
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2021, 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;
|
||||
|
||||
/**
|
||||
* An <code>AccessException</code> is thrown by certain methods of the
|
||||
* <code>java.rmi.Naming</code> class (specifically <code>bind</code>,
|
||||
* <code>rebind</code>, and <code>unbind</code>) to
|
||||
* indicate that the caller does not have permission to perform the action
|
||||
* requested by the method call. If the method was invoked from a non-local
|
||||
* host, then an <code>AccessException</code> is thrown.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @author Roger Riggs
|
||||
* @since 1.1
|
||||
* @see java.rmi.Naming
|
||||
*/
|
||||
public class AccessException extends java.rmi.RemoteException {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = 6314925228044966088L;
|
||||
|
||||
/**
|
||||
* Constructs an <code>AccessException</code> with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @since 1.1
|
||||
*/
|
||||
public AccessException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an <code>AccessException</code> with the specified
|
||||
* detail message and nested exception.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @param ex the nested exception
|
||||
* @since 1.1
|
||||
*/
|
||||
public AccessException(String s, Exception ex) {
|
||||
super(s, ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* An <code>AlreadyBoundException</code> is thrown if an attempt
|
||||
* is made to bind an object to a name that already
|
||||
* has an associated binding in the registry.
|
||||
*
|
||||
* @since 1.1
|
||||
* @author Ann Wollrath
|
||||
* @author Roger Riggs
|
||||
* @see java.rmi.Naming#bind(String, java.rmi.Remote)
|
||||
* @see java.rmi.registry.Registry#bind(String, java.rmi.Remote)
|
||||
*/
|
||||
public class AlreadyBoundException extends java.lang.Exception {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = 9218657361741657110L;
|
||||
|
||||
/**
|
||||
* Constructs an <code>AlreadyBoundException</code> with no
|
||||
* specified detail message.
|
||||
* @since 1.1
|
||||
*/
|
||||
public AlreadyBoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an <code>AlreadyBoundException</code> with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @since 1.1
|
||||
*/
|
||||
public AlreadyBoundException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
62
src/java.rmi/share/classes/java/rmi/ConnectException.java
Normal file
62
src/java.rmi/share/classes/java/rmi/ConnectException.java
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* A <code>ConnectException</code> is thrown if a connection is refused
|
||||
* to the remote host for a remote method call.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @since 1.1
|
||||
*/
|
||||
public class ConnectException extends RemoteException {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = 4863550261346652506L;
|
||||
|
||||
/**
|
||||
* Constructs a <code>ConnectException</code> with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @since 1.1
|
||||
*/
|
||||
public ConnectException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>ConnectException</code> with the specified
|
||||
* detail message and nested exception.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @param ex the nested exception
|
||||
* @since 1.1
|
||||
*/
|
||||
public ConnectException(String s, Exception ex) {
|
||||
super(s, ex);
|
||||
}
|
||||
}
|
||||
64
src/java.rmi/share/classes/java/rmi/ConnectIOException.java
Normal file
64
src/java.rmi/share/classes/java/rmi/ConnectIOException.java
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* A <code>ConnectIOException</code> is thrown if an
|
||||
* <code>IOException</code> occurs while making a connection
|
||||
* to the remote host for a remote method call.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @since 1.1
|
||||
*/
|
||||
public class ConnectIOException extends RemoteException {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = -8087809532704668744L;
|
||||
|
||||
/**
|
||||
* Constructs a <code>ConnectIOException</code> with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @since 1.1
|
||||
*/
|
||||
public ConnectIOException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a <code>ConnectIOException</code> with the specified
|
||||
* detail message and nested exception.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @param ex the nested exception
|
||||
* @since 1.1
|
||||
*/
|
||||
public ConnectIOException(String s, Exception ex) {
|
||||
super(s, ex);
|
||||
}
|
||||
}
|
||||
71
src/java.rmi/share/classes/java/rmi/MarshalException.java
Normal file
71
src/java.rmi/share/classes/java/rmi/MarshalException.java
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* A <code>MarshalException</code> is thrown if a
|
||||
* <code>java.io.IOException</code> occurs while marshalling the remote call
|
||||
* header, arguments or return value for a remote method call. A
|
||||
* <code>MarshalException</code> is also thrown if the receiver does not
|
||||
* support the protocol version of the sender.
|
||||
*
|
||||
* <p>If a <code>MarshalException</code> occurs during a remote method call,
|
||||
* the call may or may not have reached the server. If the call did reach the
|
||||
* server, parameters may have been deserialized. A call may not be
|
||||
* retransmitted after a <code>MarshalException</code> and reliably preserve
|
||||
* "at most once" call semantics.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @since 1.1
|
||||
*/
|
||||
public class MarshalException extends RemoteException {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = 6223554758134037936L;
|
||||
|
||||
/**
|
||||
* Constructs a <code>MarshalException</code> with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @since 1.1
|
||||
*/
|
||||
public MarshalException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>MarshalException</code> with the specified
|
||||
* detail message and nested exception.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @param ex the nested exception
|
||||
* @since 1.1
|
||||
*/
|
||||
public MarshalException(String s, Exception ex) {
|
||||
super(s, ex);
|
||||
}
|
||||
}
|
||||
344
src/java.rmi/share/classes/java/rmi/MarshalledObject.java
Normal file
344
src/java.rmi/share/classes/java/rmi/MarshalledObject.java
Normal file
|
|
@ -0,0 +1,344 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2024, 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;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputFilter;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamConstants;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import sun.rmi.server.MarshalInputStream;
|
||||
import sun.rmi.server.MarshalOutputStream;
|
||||
|
||||
/**
|
||||
* A <code>MarshalledObject</code> contains a byte stream with the serialized
|
||||
* representation of an object given to its constructor. The <code>get</code>
|
||||
* method returns a new copy of the original object, as deserialized from
|
||||
* the contained byte stream. The contained object is serialized and
|
||||
* deserialized with the same serialization semantics used for marshaling
|
||||
* and unmarshaling parameters and return values of RMI calls: When the
|
||||
* serialized form is created:
|
||||
*
|
||||
* <ul>
|
||||
* <li> classes are annotated with a codebase URL from where the class
|
||||
* can be loaded (if available), and
|
||||
* <li> any remote object in the <code>MarshalledObject</code> is
|
||||
* represented by a serialized instance of its stub.
|
||||
* </ul>
|
||||
*
|
||||
* <p>When copy of the object is retrieved (via the <code>get</code> method),
|
||||
* if the class is not available locally, it will be loaded from the
|
||||
* appropriate location (specified the URL annotated with the class descriptor
|
||||
* when the class was serialized.
|
||||
*
|
||||
* <p><code>MarshalledObject</code> facilitates passing objects in RMI calls
|
||||
* that are not automatically deserialized immediately by the remote peer.
|
||||
*
|
||||
* @param <T> the type of the object contained in this
|
||||
* <code>MarshalledObject</code>
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @author Peter Jones
|
||||
* @since 1.2
|
||||
*/
|
||||
public final class MarshalledObject<T> implements Serializable {
|
||||
/**
|
||||
* @serial Bytes of serialized representation. If <code>objBytes</code> is
|
||||
* <code>null</code> then the object marshalled was a <code>null</code>
|
||||
* reference.
|
||||
*/
|
||||
private byte[] objBytes = null;
|
||||
|
||||
/**
|
||||
* @serial Bytes of location annotations, which are ignored by
|
||||
* <code>equals</code>. If <code>locBytes</code> is null, there were no
|
||||
* non-<code>null</code> annotations during marshalling.
|
||||
*/
|
||||
private byte[] locBytes = null;
|
||||
|
||||
/**
|
||||
* @serial Stored hash code of contained object.
|
||||
*
|
||||
* @see #hashCode
|
||||
*/
|
||||
private int hash;
|
||||
|
||||
/** Filter used when creating the instance from a stream; may be null. */
|
||||
private transient ObjectInputFilter objectInputFilter = null;
|
||||
|
||||
/** Indicate compatibility with 1.2 version of class. */
|
||||
private static final long serialVersionUID = 8988374069173025854L;
|
||||
|
||||
/**
|
||||
* Creates a new <code>MarshalledObject</code> that contains the
|
||||
* serialized representation of the current state of the supplied object.
|
||||
* The object is serialized with the semantics used for marshaling
|
||||
* parameters for RMI calls.
|
||||
*
|
||||
* @param obj the object to be serialized (must be serializable)
|
||||
* @throws IOException if an <code>IOException</code> occurs; an
|
||||
* <code>IOException</code> may occur if <code>obj</code> is not
|
||||
* serializable.
|
||||
* @since 1.2
|
||||
*/
|
||||
public MarshalledObject(T obj) throws IOException {
|
||||
if (obj == null) {
|
||||
hash = 13;
|
||||
return;
|
||||
}
|
||||
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream lout = new ByteArrayOutputStream();
|
||||
MarshalledObjectOutputStream out =
|
||||
new MarshalledObjectOutputStream(bout, lout);
|
||||
out.writeObject(obj);
|
||||
out.flush();
|
||||
objBytes = bout.toByteArray();
|
||||
// locBytes is null if no annotations
|
||||
locBytes = (out.hadAnnotations() ? lout.toByteArray() : null);
|
||||
|
||||
/*
|
||||
* Calculate hash from the marshalled representation of object
|
||||
* so the hashcode will be comparable when sent between VMs.
|
||||
*/
|
||||
int h = 0;
|
||||
for (int i = 0; i < objBytes.length; i++) {
|
||||
h = 31 * h + objBytes[i];
|
||||
}
|
||||
hash = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads in the state of the object and saves the stream's
|
||||
* serialization filter to be used when the object is deserialized.
|
||||
*
|
||||
* @param stream the stream
|
||||
* @throws IOException if an I/O error occurs
|
||||
* @throws ClassNotFoundException if a class cannot be found
|
||||
*/
|
||||
private void readObject(ObjectInputStream stream)
|
||||
throws IOException, ClassNotFoundException {
|
||||
stream.defaultReadObject(); // read in all fields
|
||||
objectInputFilter = stream.getObjectInputFilter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new copy of the contained marshalledobject. The internal
|
||||
* representation is deserialized with the semantics used for
|
||||
* unmarshaling parameters for RMI calls.
|
||||
* If the MarshalledObject was read from an ObjectInputStream,
|
||||
* the filter from that stream is used to deserialize the object.
|
||||
*
|
||||
* @return a copy of the contained object
|
||||
* @throws IOException if an <code>IOException</code> occurs while
|
||||
* deserializing the object from its internal representation.
|
||||
* @throws ClassNotFoundException if a
|
||||
* <code>ClassNotFoundException</code> occurs while deserializing
|
||||
* the object from its internal representation.
|
||||
* could not be found
|
||||
* @since 1.2
|
||||
*/
|
||||
public T get() throws IOException, ClassNotFoundException {
|
||||
if (objBytes == null) // must have been a null object
|
||||
return null;
|
||||
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream(objBytes);
|
||||
// locBytes is null if no annotations
|
||||
ByteArrayInputStream lin =
|
||||
(locBytes == null ? null : new ByteArrayInputStream(locBytes));
|
||||
MarshalledObjectInputStream in =
|
||||
new MarshalledObjectInputStream(bin, lin, objectInputFilter);
|
||||
@SuppressWarnings("unchecked")
|
||||
T obj = (T) in.readObject();
|
||||
in.close();
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a hash code for this <code>MarshalledObject</code>.
|
||||
*
|
||||
* @return a hash code
|
||||
*/
|
||||
public int hashCode() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this <code>MarshalledObject</code> to another object.
|
||||
* Returns true if and only if the argument refers to a
|
||||
* <code>MarshalledObject</code> that contains exactly the same
|
||||
* serialized representation of an object as this one does. The
|
||||
* comparison ignores any class codebase annotation, meaning that
|
||||
* two objects are equivalent if they have the same serialized
|
||||
* representation <i>except</i> for the codebase of each class
|
||||
* in the serialized representation.
|
||||
*
|
||||
* @param obj the object to compare with this <code>MarshalledObject</code>
|
||||
* @return <code>true</code> if the argument contains an equivalent
|
||||
* serialized object; <code>false</code> otherwise
|
||||
* @since 1.2
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
if (obj instanceof MarshalledObject<?> other) {
|
||||
|
||||
// if either is a ref to null, both must be
|
||||
if (objBytes == null || other.objBytes == null)
|
||||
return objBytes == other.objBytes;
|
||||
|
||||
// quick, easy test
|
||||
if (objBytes.length != other.objBytes.length)
|
||||
return false;
|
||||
|
||||
//!! There is talk about adding an array comparison method
|
||||
//!! at 1.2 -- if so, this should be rewritten. -arnold
|
||||
for (int i = 0; i < objBytes.length; ++i) {
|
||||
if (objBytes[i] != other.objBytes[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is used to marshal objects for
|
||||
* <code>MarshalledObject</code>. It places the location annotations
|
||||
* to one side so that two <code>MarshalledObject</code>s can be
|
||||
* compared for equality if they differ only in location
|
||||
* annotations. Objects written using this stream should be read back
|
||||
* from a <code>MarshalledObjectInputStream</code>.
|
||||
*
|
||||
* @see java.rmi.MarshalledObject
|
||||
* @see MarshalledObjectInputStream
|
||||
*/
|
||||
private static class MarshalledObjectOutputStream
|
||||
extends MarshalOutputStream
|
||||
{
|
||||
/** The stream on which location objects are written. */
|
||||
private ObjectOutputStream locOut;
|
||||
|
||||
/** <code>true</code> if non-<code>null</code> annotations are
|
||||
* written.
|
||||
*/
|
||||
private boolean hadAnnotations;
|
||||
|
||||
/**
|
||||
* Creates a new <code>MarshalledObjectOutputStream</code> whose
|
||||
* non-location bytes will be written to <code>objOut</code> and whose
|
||||
* location annotations (if any) will be written to
|
||||
* <code>locOut</code>.
|
||||
*/
|
||||
MarshalledObjectOutputStream(OutputStream objOut, OutputStream locOut)
|
||||
throws IOException
|
||||
{
|
||||
super(objOut);
|
||||
this.useProtocolVersion(ObjectStreamConstants.PROTOCOL_VERSION_2);
|
||||
this.locOut = new ObjectOutputStream(locOut);
|
||||
hadAnnotations = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if any non-<code>null</code> location
|
||||
* annotations have been written to this stream.
|
||||
*/
|
||||
boolean hadAnnotations() {
|
||||
return hadAnnotations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides MarshalOutputStream.writeLocation implementation to write
|
||||
* annotations to the location stream.
|
||||
*/
|
||||
protected void writeLocation(String loc) throws IOException {
|
||||
hadAnnotations |= (loc != null);
|
||||
locOut.writeObject(loc);
|
||||
}
|
||||
|
||||
|
||||
public void flush() throws IOException {
|
||||
super.flush();
|
||||
locOut.flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The counterpart to <code>MarshalledObjectOutputStream</code>.
|
||||
*
|
||||
* @see MarshalledObjectOutputStream
|
||||
*/
|
||||
private static class MarshalledObjectInputStream
|
||||
extends MarshalInputStream
|
||||
{
|
||||
/**
|
||||
* The stream from which annotations will be read. If this is
|
||||
* <code>null</code>, then all annotations were <code>null</code>.
|
||||
*/
|
||||
private ObjectInputStream locIn;
|
||||
|
||||
/**
|
||||
* Creates a new <code>MarshalledObjectInputStream</code> that
|
||||
* reads its objects from <code>objIn</code> and annotations
|
||||
* from <code>locIn</code>. If <code>locIn</code> is
|
||||
* <code>null</code>, then all annotations will be
|
||||
* <code>null</code>.
|
||||
*/
|
||||
MarshalledObjectInputStream(InputStream objIn, InputStream locIn,
|
||||
ObjectInputFilter filter)
|
||||
throws IOException
|
||||
{
|
||||
super(objIn);
|
||||
this.locIn = (locIn == null ? null : new ObjectInputStream(locIn));
|
||||
if (filter != null) {
|
||||
MarshalledObjectInputStream.this.setObjectInputFilter(filter);
|
||||
if (MarshalledObjectInputStream.this.locIn != null) {
|
||||
MarshalledObjectInputStream.this.locIn.setObjectInputFilter(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides MarshalInputStream.readLocation to return locations from
|
||||
* the stream we were given, or <code>null</code> if we were given a
|
||||
* <code>null</code> location stream.
|
||||
*/
|
||||
protected Object readLocation()
|
||||
throws IOException, ClassNotFoundException
|
||||
{
|
||||
return (locIn == null ? null : locIn.readObject());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
363
src/java.rmi/share/classes/java/rmi/Naming.java
Normal file
363
src/java.rmi/share/classes/java/rmi/Naming.java
Normal file
|
|
@ -0,0 +1,363 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2020, 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;
|
||||
|
||||
import java.rmi.registry.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import static jdk.internal.util.Exceptions.filterNonSocketInfo;
|
||||
import static jdk.internal.util.Exceptions.formatMsg;
|
||||
|
||||
/**
|
||||
* The <code>Naming</code> class provides methods for storing and obtaining
|
||||
* references to remote objects in a remote object registry. Each method of
|
||||
* the <code>Naming</code> class takes as one of its arguments a name that
|
||||
* is a <code>java.lang.String</code> in URL format (without the
|
||||
* scheme component) of the form:
|
||||
*
|
||||
* <PRE>
|
||||
* //host:port/name
|
||||
* </PRE>
|
||||
*
|
||||
* <P>where <code>host</code> is the host (remote or local) where the registry
|
||||
* is located, <code>port</code> is the port number on which the registry
|
||||
* accepts calls, and where <code>name</code> is a simple string uninterpreted
|
||||
* by the registry. Both <code>host</code> and <code>port</code> are optional.
|
||||
* If <code>host</code> is omitted, the host defaults to the local host. If
|
||||
* <code>port</code> is omitted, then the port defaults to 1099, the
|
||||
* "well-known" port that RMI's registry, <code>rmiregistry</code>, uses.
|
||||
*
|
||||
* <P><em>Binding</em> a name for a remote object is associating or
|
||||
* registering a name for a remote object that can be used at a later time to
|
||||
* look up that remote object. A remote object can be associated with a name
|
||||
* using the <code>Naming</code> class's <code>bind</code> or
|
||||
* <code>rebind</code> methods.
|
||||
*
|
||||
* <P>Once a remote object is registered (bound) with the RMI registry on the
|
||||
* local host, callers on a remote (or local) host can lookup the remote
|
||||
* object by name, obtain its reference, and then invoke remote methods on the
|
||||
* object. A registry may be shared by all servers running on a host or an
|
||||
* individual server process may create and use its own registry if desired
|
||||
* (see <code>java.rmi.registry.LocateRegistry.createRegistry</code> method
|
||||
* for details).
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @author Roger Riggs
|
||||
* @since 1.1
|
||||
* @see java.rmi.registry.Registry
|
||||
* @see java.rmi.registry.LocateRegistry
|
||||
* @see java.rmi.registry.LocateRegistry#createRegistry(int)
|
||||
*/
|
||||
public final class Naming {
|
||||
/**
|
||||
* Disallow anyone from creating one of these
|
||||
*/
|
||||
private Naming() {}
|
||||
|
||||
/**
|
||||
* Returns a reference, a stub, for the remote object associated
|
||||
* with the specified <code>name</code>.
|
||||
*
|
||||
* @param name a name in URL format (without the scheme component)
|
||||
* @return a reference for a remote object
|
||||
* @throws NotBoundException if name is not currently bound
|
||||
* @throws RemoteException if registry could not be contacted
|
||||
* @throws AccessException if this operation is not permitted
|
||||
* @throws MalformedURLException if the name is not an appropriately
|
||||
* formatted URL
|
||||
* @since 1.1
|
||||
*/
|
||||
public static Remote lookup(String name)
|
||||
throws NotBoundException,
|
||||
java.net.MalformedURLException,
|
||||
RemoteException
|
||||
{
|
||||
ParsedNamingURL parsed = parseURL(name);
|
||||
Registry registry = getRegistry(parsed);
|
||||
|
||||
if (parsed.name == null)
|
||||
return registry;
|
||||
return registry.lookup(parsed.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds the specified <code>name</code> to a remote object.
|
||||
*
|
||||
* @param name a name in URL format (without the scheme component)
|
||||
* @param obj a reference for the remote object (usually a stub)
|
||||
* @throws AlreadyBoundException if name is already bound
|
||||
* @throws MalformedURLException if the name is not an appropriately
|
||||
* formatted URL
|
||||
* @throws RemoteException if registry could not be contacted
|
||||
* @throws AccessException if this operation is not permitted (if
|
||||
* originating from a non-local host, for example)
|
||||
* @since 1.1
|
||||
*/
|
||||
public static void bind(String name, Remote obj)
|
||||
throws AlreadyBoundException,
|
||||
java.net.MalformedURLException,
|
||||
RemoteException
|
||||
{
|
||||
ParsedNamingURL parsed = parseURL(name);
|
||||
Registry registry = getRegistry(parsed);
|
||||
|
||||
if (obj == null)
|
||||
throw new NullPointerException("cannot bind to null");
|
||||
|
||||
registry.bind(parsed.name, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the binding for the specified name that is associated
|
||||
* with a remote object.
|
||||
*
|
||||
* @param name a name in URL format (without the scheme component)
|
||||
* @throws NotBoundException if name is not currently bound
|
||||
* @throws MalformedURLException if the name is not an appropriately
|
||||
* formatted URL
|
||||
* @throws RemoteException if registry could not be contacted
|
||||
* @throws AccessException if this operation is not permitted (if
|
||||
* originating from a non-local host, for example)
|
||||
* @since 1.1
|
||||
*/
|
||||
public static void unbind(String name)
|
||||
throws RemoteException,
|
||||
NotBoundException,
|
||||
java.net.MalformedURLException
|
||||
{
|
||||
ParsedNamingURL parsed = parseURL(name);
|
||||
Registry registry = getRegistry(parsed);
|
||||
|
||||
registry.unbind(parsed.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebinds the specified name to a new remote object. Any existing
|
||||
* binding for the name is replaced.
|
||||
*
|
||||
* @param name a name in URL format (without the scheme component)
|
||||
* @param obj new remote object to associate with the name
|
||||
* @throws MalformedURLException if the name is not an appropriately
|
||||
* formatted URL
|
||||
* @throws RemoteException if registry could not be contacted
|
||||
* @throws AccessException if this operation is not permitted (if
|
||||
* originating from a non-local host, for example)
|
||||
* @since 1.1
|
||||
*/
|
||||
public static void rebind(String name, Remote obj)
|
||||
throws RemoteException, java.net.MalformedURLException
|
||||
{
|
||||
ParsedNamingURL parsed = parseURL(name);
|
||||
Registry registry = getRegistry(parsed);
|
||||
|
||||
if (obj == null)
|
||||
throw new NullPointerException("cannot bind to null");
|
||||
|
||||
registry.rebind(parsed.name, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the names bound in the registry. The names are
|
||||
* URL-formatted (without the scheme component) strings. The array contains
|
||||
* a snapshot of the names present in the registry at the time of the
|
||||
* call.
|
||||
*
|
||||
* @param name a registry name in URL format (without the scheme
|
||||
* component)
|
||||
* @return an array of names (in the appropriate format) bound
|
||||
* in the registry
|
||||
* @throws MalformedURLException if the name is not an appropriately
|
||||
* formatted URL
|
||||
* @throws RemoteException if registry could not be contacted.
|
||||
* @since 1.1
|
||||
*/
|
||||
public static String[] list(String name)
|
||||
throws RemoteException, java.net.MalformedURLException
|
||||
{
|
||||
ParsedNamingURL parsed = parseURL(name);
|
||||
Registry registry = getRegistry(parsed);
|
||||
|
||||
String prefix = "";
|
||||
if (parsed.port > 0 || !parsed.host.isEmpty())
|
||||
prefix += "//" + parsed.host;
|
||||
if (parsed.port > 0)
|
||||
prefix += ":" + parsed.port;
|
||||
prefix += "/";
|
||||
|
||||
String[] names = registry.list();
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
names[i] = prefix + names[i];
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a registry reference obtained from information in the URL.
|
||||
*/
|
||||
private static Registry getRegistry(ParsedNamingURL parsed)
|
||||
throws RemoteException
|
||||
{
|
||||
return LocateRegistry.getRegistry(parsed.host, parsed.port);
|
||||
}
|
||||
|
||||
private static MalformedURLException newMalformedURLException(String prefix, String msg) {
|
||||
return new MalformedURLException(
|
||||
prefix + formatMsg(filterNonSocketInfo(msg).prefixWith(": ")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Dissect Naming URL strings to obtain referenced host, port and
|
||||
* object name.
|
||||
*
|
||||
* @return an object which contains each of the above
|
||||
* components.
|
||||
*
|
||||
* @throws MalformedURLException if given url string is malformed
|
||||
*/
|
||||
private static ParsedNamingURL parseURL(String str)
|
||||
throws MalformedURLException
|
||||
{
|
||||
try {
|
||||
return intParseURL(str);
|
||||
} catch (URISyntaxException ex) {
|
||||
/* With RFC 3986 URI handling, 'rmi://:<port>' and
|
||||
* '//:<port>' forms will result in a URI syntax exception
|
||||
* Convert the authority to a localhost:<port> form
|
||||
*/
|
||||
MalformedURLException mue = newMalformedURLException(
|
||||
"invalid URL String", str);
|
||||
mue.initCause(ex);
|
||||
int indexSchemeEnd = str.indexOf(':');
|
||||
int indexAuthorityBegin = str.indexOf("//:");
|
||||
if (indexAuthorityBegin < 0) {
|
||||
throw mue;
|
||||
}
|
||||
if ((indexAuthorityBegin == 0) ||
|
||||
((indexSchemeEnd > 0) &&
|
||||
(indexAuthorityBegin == indexSchemeEnd + 1))) {
|
||||
int indexHostBegin = indexAuthorityBegin + 2;
|
||||
String newStr = str.substring(0, indexHostBegin) +
|
||||
"localhost" +
|
||||
str.substring(indexHostBegin);
|
||||
try {
|
||||
return intParseURL(newStr);
|
||||
} catch (URISyntaxException inte) {
|
||||
throw mue;
|
||||
} catch (MalformedURLException inte) {
|
||||
throw inte;
|
||||
}
|
||||
}
|
||||
throw mue;
|
||||
}
|
||||
}
|
||||
|
||||
private static ParsedNamingURL intParseURL(String str)
|
||||
throws MalformedURLException, URISyntaxException
|
||||
{
|
||||
URI uri = new URI(str);
|
||||
if (uri.isOpaque()) {
|
||||
throw newMalformedURLException(
|
||||
"not a hierarchical URL", str);
|
||||
}
|
||||
if (uri.getFragment() != null) {
|
||||
throw newMalformedURLException(
|
||||
"invalid character, '#', in URL name", str);
|
||||
} else if (uri.getQuery() != null) {
|
||||
throw newMalformedURLException(
|
||||
"invalid character, '?', in URL name", str);
|
||||
} else if (uri.getUserInfo() != null) {
|
||||
throw newMalformedURLException(
|
||||
"invalid character, '@', in URL host", str);
|
||||
}
|
||||
String scheme = uri.getScheme();
|
||||
if (scheme != null && !scheme.equals("rmi")) {
|
||||
throw newMalformedURLException("invalid URL scheme", str);
|
||||
}
|
||||
|
||||
String name = uri.getPath();
|
||||
if (name != null) {
|
||||
if (name.startsWith("/")) {
|
||||
name = name.substring(1);
|
||||
}
|
||||
if (name.length() == 0) {
|
||||
name = null;
|
||||
}
|
||||
}
|
||||
|
||||
String host = uri.getHost();
|
||||
if (host == null) {
|
||||
host = "";
|
||||
try {
|
||||
/*
|
||||
* With 2396 URI handling, forms such as 'rmi://host:bar'
|
||||
* or 'rmi://:<port>' are parsed into a registry based
|
||||
* authority. We only want to allow server based naming
|
||||
* authorities.
|
||||
*/
|
||||
uri.parseServerAuthority();
|
||||
} catch (URISyntaxException use) {
|
||||
// Check if the authority is of form ':<port>'
|
||||
String authority = uri.getAuthority();
|
||||
if (authority != null && authority.startsWith(":")) {
|
||||
// Convert the authority to 'localhost:<port>' form
|
||||
authority = "localhost" + authority;
|
||||
try {
|
||||
uri = new URI(null, authority, null, null, null);
|
||||
// Make sure it now parses to a valid server based
|
||||
// naming authority
|
||||
uri.parseServerAuthority();
|
||||
} catch (URISyntaxException use2) {
|
||||
throw new
|
||||
MalformedURLException("invalid authority: " + str);
|
||||
}
|
||||
} else {
|
||||
throw new
|
||||
MalformedURLException("invalid authority: " + str);
|
||||
}
|
||||
}
|
||||
}
|
||||
int port = uri.getPort();
|
||||
if (port == -1) {
|
||||
port = Registry.REGISTRY_PORT;
|
||||
}
|
||||
return new ParsedNamingURL(host, port, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple class to enable multiple URL return values.
|
||||
*/
|
||||
private static class ParsedNamingURL {
|
||||
String host;
|
||||
int port;
|
||||
String name;
|
||||
|
||||
ParsedNamingURL(String host, int port, String name) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2021, 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;
|
||||
|
||||
/**
|
||||
* A <code>NoSuchObjectException</code> is thrown if an attempt is made to
|
||||
* invoke a method on an object that no longer exists in the remote virtual
|
||||
* machine. If a <code>NoSuchObjectException</code> occurs attempting to
|
||||
* invoke a method on a remote object, the call may be retransmitted and still
|
||||
* preserve RMI's "at most once" call semantics.
|
||||
*
|
||||
* A <code>NoSuchObjectException</code> is also thrown by the method
|
||||
* <code>java.rmi.server.RemoteObject.toStub</code> and by the
|
||||
* <code>unexportObject</code> methods of
|
||||
* <code>java.rmi.server.UnicastRemoteObject</code>.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @since 1.1
|
||||
* @see java.rmi.server.RemoteObject#toStub(Remote)
|
||||
* @see java.rmi.server.UnicastRemoteObject#unexportObject(Remote,boolean)
|
||||
*/
|
||||
public class NoSuchObjectException extends RemoteException {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = 6619395951570472985L;
|
||||
|
||||
/**
|
||||
* Constructs a <code>NoSuchObjectException</code> with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @since 1.1
|
||||
*/
|
||||
public NoSuchObjectException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
64
src/java.rmi/share/classes/java/rmi/NotBoundException.java
Normal file
64
src/java.rmi/share/classes/java/rmi/NotBoundException.java
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* A <code>NotBoundException</code> is thrown if an attempt
|
||||
* is made to lookup or unbind in the registry a name that has
|
||||
* no associated binding.
|
||||
*
|
||||
* @since 1.1
|
||||
* @author Ann Wollrath
|
||||
* @author Roger Riggs
|
||||
* @see java.rmi.Naming#lookup(String)
|
||||
* @see java.rmi.Naming#unbind(String)
|
||||
* @see java.rmi.registry.Registry#lookup(String)
|
||||
* @see java.rmi.registry.Registry#unbind(String)
|
||||
*/
|
||||
public class NotBoundException extends java.lang.Exception {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = -1857741824849069317L;
|
||||
|
||||
/**
|
||||
* Constructs a <code>NotBoundException</code> with no
|
||||
* specified detail message.
|
||||
* @since 1.1
|
||||
*/
|
||||
public NotBoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>NotBoundException</code> with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @since 1.1
|
||||
*/
|
||||
public NotBoundException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* An <code>RMISecurityException</code> signals that a security exception
|
||||
* has occurred during the execution of one of
|
||||
* <code>java.rmi.RMISecurityManager</code>'s methods.
|
||||
*
|
||||
* @author Roger Riggs
|
||||
* @since 1.1
|
||||
* @deprecated Use {@link java.lang.SecurityException} instead.
|
||||
* Application code should never directly reference this class, and
|
||||
* <code>RMISecurityManager</code> no longer throws this subclass of
|
||||
* <code>java.lang.SecurityException</code>.
|
||||
*/
|
||||
@Deprecated
|
||||
public class RMISecurityException extends java.lang.SecurityException {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = -8433406075740433514L;
|
||||
|
||||
/**
|
||||
* Construct an <code>RMISecurityException</code> with a detail message.
|
||||
* @param name the detail message
|
||||
* @since 1.1
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
public RMISecurityException(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an <code>RMISecurityException</code> with a detail message.
|
||||
* @param name the detail message
|
||||
* @param arg ignored
|
||||
* @since 1.1
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
public RMISecurityException(String name, String arg) {
|
||||
this(name);
|
||||
}
|
||||
}
|
||||
49
src/java.rmi/share/classes/java/rmi/RMISecurityManager.java
Normal file
49
src/java.rmi/share/classes/java/rmi/RMISecurityManager.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2024, 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;
|
||||
|
||||
/**
|
||||
* RMISecurityManager was originally specified to allow an application implement
|
||||
* a security policy identical to the policy implemented by {@link SecurityManager}.
|
||||
* This feature no longer exists.
|
||||
*
|
||||
* @author Roger Riggs
|
||||
* @author Peter Jones
|
||||
* @since 1.1
|
||||
* @deprecated There is no replacement for the Security Manager.
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
@Deprecated(since="1.8", forRemoval = true)
|
||||
public class RMISecurityManager extends SecurityManager {
|
||||
|
||||
/**
|
||||
* Constructs a new {@code RMISecurityManager}.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public RMISecurityManager() {
|
||||
}
|
||||
}
|
||||
48
src/java.rmi/share/classes/java/rmi/Remote.java
Normal file
48
src/java.rmi/share/classes/java/rmi/Remote.java
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2021, 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;
|
||||
|
||||
/**
|
||||
* The <code>Remote</code> interface serves to identify interfaces whose
|
||||
* methods may be invoked from a non-local virtual machine. Any object that
|
||||
* is a remote object must directly or indirectly implement this interface.
|
||||
* Only those methods specified in a "remote interface", an interface that
|
||||
* extends <code>java.rmi.Remote</code> are available remotely.
|
||||
*
|
||||
* <p>Implementation classes can implement any number of remote interfaces and
|
||||
* can extend other remote implementation classes. RMI provides a convenience
|
||||
* class {@link java.rmi.server.UnicastRemoteObject UnicastRemoteObject}
|
||||
* that remote object implementations can extend and that facilitates remote
|
||||
* object creation.
|
||||
*
|
||||
* <p>For complete details on RMI, see the <a
|
||||
* href="{@docRoot}/../specs/rmi/index.html">RMI Specification</a> which
|
||||
* describes the RMI API and system.
|
||||
*
|
||||
* @since 1.1
|
||||
* @author Ann Wollrath
|
||||
*/
|
||||
public interface Remote {}
|
||||
122
src/java.rmi/share/classes/java/rmi/RemoteException.java
Normal file
122
src/java.rmi/share/classes/java/rmi/RemoteException.java
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* A {@code RemoteException} is the common superclass for a number of
|
||||
* communication-related exceptions that may occur during the execution of a
|
||||
* remote method call. Each method of a remote interface, an interface that
|
||||
* extends {@code java.rmi.Remote}, must list
|
||||
* {@code RemoteException} in its throws clause.
|
||||
*
|
||||
* <p>As of release 1.4, this exception has been retrofitted to conform to
|
||||
* the general purpose exception-chaining mechanism. The "wrapped remote
|
||||
* 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 RemoteException} always throws {@link
|
||||
* IllegalStateException}.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @since 1.1
|
||||
*/
|
||||
public class RemoteException extends java.io.IOException {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = -5148567311918794206L;
|
||||
|
||||
/**
|
||||
* The cause of the remote 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 Throwable detail;
|
||||
|
||||
/**
|
||||
* Constructs a {@code RemoteException}.
|
||||
*/
|
||||
public RemoteException() {
|
||||
initCause(null); // Disallow subsequent initCause
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@code RemoteException} with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param s the detail message
|
||||
*/
|
||||
public RemoteException(String s) {
|
||||
super(s);
|
||||
initCause(null); // Disallow subsequent initCause
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@code RemoteException} with the specified detail
|
||||
* message and cause. This constructor sets the {@link #detail}
|
||||
* field to the specified {@code Throwable}.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @param cause the cause
|
||||
*/
|
||||
public RemoteException(String s, Throwable 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 {@code null}.
|
||||
* @since 1.4
|
||||
*/
|
||||
public Throwable getCause() {
|
||||
return detail;
|
||||
}
|
||||
}
|
||||
56
src/java.rmi/share/classes/java/rmi/ServerError.java
Normal file
56
src/java.rmi/share/classes/java/rmi/ServerError.java
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 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;
|
||||
|
||||
/**
|
||||
* A <code>ServerError</code> is thrown as a result of a remote method
|
||||
* invocation when an <code>Error</code> is thrown while processing
|
||||
* the invocation on the server, either while unmarshalling the arguments,
|
||||
* executing the remote method itself, or marshalling the return value.
|
||||
*
|
||||
* A <code>ServerError</code> instance contains the original
|
||||
* <code>Error</code> that occurred as its cause.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @since 1.1
|
||||
*/
|
||||
public class ServerError extends RemoteException {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = 8455284893909696482L;
|
||||
|
||||
/**
|
||||
* Constructs a <code>ServerError</code> with the specified
|
||||
* detail message and nested error.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @param err the nested error
|
||||
* @since 1.1
|
||||
*/
|
||||
public ServerError(String s, Error err) {
|
||||
super(s, err);
|
||||
}
|
||||
}
|
||||
67
src/java.rmi/share/classes/java/rmi/ServerException.java
Normal file
67
src/java.rmi/share/classes/java/rmi/ServerException.java
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* A <code>ServerException</code> is thrown as a result of a remote method
|
||||
* invocation when a <code>RemoteException</code> is thrown while processing
|
||||
* the invocation on the server, either while unmarshalling the arguments or
|
||||
* executing the remote method itself.
|
||||
*
|
||||
* A <code>ServerException</code> instance contains the original
|
||||
* <code>RemoteException</code> that occurred as its cause.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @since 1.1
|
||||
*/
|
||||
public class ServerException extends RemoteException {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = -4775845313121906682L;
|
||||
|
||||
/**
|
||||
* Constructs a <code>ServerException</code> with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @since 1.1
|
||||
*/
|
||||
public ServerException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>ServerException</code> with the specified
|
||||
* detail message and nested exception.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @param ex the nested exception
|
||||
* @since 1.1
|
||||
*/
|
||||
public ServerException(String s, Exception ex) {
|
||||
super(s, ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* From a server executing on JDK 1.1, a
|
||||
* <code>ServerRuntimeException</code> is thrown as a result of a
|
||||
* remote method invocation when a <code>RuntimeException</code> is
|
||||
* thrown while processing the invocation on the server, either while
|
||||
* unmarshalling the arguments, executing the remote method itself, or
|
||||
* marshalling the return value.
|
||||
*
|
||||
* A <code>ServerRuntimeException</code> instance contains the original
|
||||
* <code>RuntimeException</code> that occurred as its cause.
|
||||
*
|
||||
* <p>A <code>ServerRuntimeException</code> is not thrown from servers
|
||||
* executing on the Java 2 platform v1.2 or later versions.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @since 1.1
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
public class ServerRuntimeException extends RemoteException {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = 7054464920481467219L;
|
||||
|
||||
/**
|
||||
* Constructs a <code>ServerRuntimeException</code> with the specified
|
||||
* detail message and nested exception.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @param ex the nested exception
|
||||
* @deprecated no replacement
|
||||
* @since 1.1
|
||||
*/
|
||||
@Deprecated
|
||||
public ServerRuntimeException(String s, Exception ex) {
|
||||
super(s, ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2021, 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;
|
||||
|
||||
/**
|
||||
* A <code>StubNotFoundException</code> is thrown if a valid stub class
|
||||
* could not be found for a remote object when it is exported.
|
||||
*
|
||||
* @author Roger Riggs
|
||||
* @since 1.1
|
||||
* @see java.rmi.server.UnicastRemoteObject
|
||||
*/
|
||||
public class StubNotFoundException extends RemoteException {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = -7088199405468872373L;
|
||||
|
||||
/**
|
||||
* Constructs a <code>StubNotFoundException</code> with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @since 1.1
|
||||
*/
|
||||
public StubNotFoundException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>StubNotFoundException</code> with the specified
|
||||
* detail message and nested exception.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @param ex the nested exception
|
||||
* @since 1.1
|
||||
*/
|
||||
public StubNotFoundException(String s, Exception ex) {
|
||||
super(s, ex);
|
||||
}
|
||||
}
|
||||
64
src/java.rmi/share/classes/java/rmi/UnexpectedException.java
Normal file
64
src/java.rmi/share/classes/java/rmi/UnexpectedException.java
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* An <code>UnexpectedException</code> is thrown if the client of a
|
||||
* remote method call receives, as a result of the call, a checked
|
||||
* exception that is not among the checked exception types declared in the
|
||||
* <code>throws</code> clause of the method in the remote interface.
|
||||
*
|
||||
* @author Roger Riggs
|
||||
* @since 1.1
|
||||
*/
|
||||
public class UnexpectedException extends RemoteException {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = 1800467484195073863L;
|
||||
|
||||
/**
|
||||
* Constructs an <code>UnexpectedException</code> with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @since 1.1
|
||||
*/
|
||||
public UnexpectedException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>UnexpectedException</code> with the specified
|
||||
* detail message and nested exception.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @param ex the nested exception
|
||||
* @since 1.1
|
||||
*/
|
||||
public UnexpectedException(String s, Exception ex) {
|
||||
super(s, ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* An <code>UnknownHostException</code> is thrown if a
|
||||
* <code>java.net.UnknownHostException</code> occurs while creating
|
||||
* a connection to the remote host for a remote method call.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public class UnknownHostException extends RemoteException {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = -8152710247442114228L;
|
||||
|
||||
/**
|
||||
* Constructs an <code>UnknownHostException</code> with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @since 1.1
|
||||
*/
|
||||
public UnknownHostException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an <code>UnknownHostException</code> with the specified
|
||||
* detail message and nested exception.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @param ex the nested exception
|
||||
* @since 1.1
|
||||
*/
|
||||
public UnknownHostException(String s, Exception ex) {
|
||||
super(s, ex);
|
||||
}
|
||||
}
|
||||
76
src/java.rmi/share/classes/java/rmi/UnmarshalException.java
Normal file
76
src/java.rmi/share/classes/java/rmi/UnmarshalException.java
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* An <code>UnmarshalException</code> can be thrown while unmarshalling the
|
||||
* parameters or results of a remote method call if any of the following
|
||||
* conditions occur:
|
||||
* <ul>
|
||||
* <li> if an exception occurs while unmarshalling the call header
|
||||
* <li> if the protocol for the return value is invalid
|
||||
* <li> if a <code>java.io.IOException</code> occurs unmarshalling
|
||||
* parameters (on the server side) or the return value (on the client side).
|
||||
* <li> if a <code>java.lang.ClassNotFoundException</code> occurs during
|
||||
* unmarshalling parameters or return values
|
||||
* <li> if no skeleton can be loaded on the server-side; note that skeletons
|
||||
* are required in the 1.1 stub protocol, but not in the 1.2 stub protocol.
|
||||
* <li> if the method hash is invalid (i.e., missing method).
|
||||
* <li> if there is a failure to create a remote reference object for
|
||||
* a remote object's stub when it is unmarshalled.
|
||||
* </ul>
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @since 1.1
|
||||
*/
|
||||
public class UnmarshalException extends RemoteException {
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = 594380845140740218L;
|
||||
|
||||
/**
|
||||
* Constructs an <code>UnmarshalException</code> with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @since 1.1
|
||||
*/
|
||||
public UnmarshalException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an <code>UnmarshalException</code> with the specified
|
||||
* detail message and nested exception.
|
||||
*
|
||||
* @param s the detail message
|
||||
* @param ex the nested exception
|
||||
* @since 1.1
|
||||
*/
|
||||
public UnmarshalException(String s, Exception ex) {
|
||||
super(s, ex);
|
||||
}
|
||||
}
|
||||
115
src/java.rmi/share/classes/java/rmi/dgc/DGC.java
Normal file
115
src/java.rmi/share/classes/java/rmi/dgc/DGC.java
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 1999, 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.dgc;
|
||||
|
||||
import java.rmi.*;
|
||||
import java.rmi.server.ObjID;
|
||||
|
||||
/**
|
||||
* The DGC abstraction is used for the server side of the distributed
|
||||
* garbage collection algorithm. This interface contains the two
|
||||
* methods: dirty and clean. A dirty call is made when a remote
|
||||
* reference is unmarshaled in a client (the client is indicated by
|
||||
* its VMID). A corresponding clean call is made when no more
|
||||
* references to the remote reference exist in the client. A failed
|
||||
* dirty call must schedule a strong clean call so that the call's
|
||||
* sequence number can be retained in order to detect future calls
|
||||
* received out of order by the distributed garbage collector.
|
||||
*
|
||||
* A reference to a remote object is leased for a period of time by
|
||||
* the client holding the reference. The lease period starts when the
|
||||
* dirty call is received. It is the client's responsibility to renew
|
||||
* the leases, by making additional dirty calls, on the remote
|
||||
* references it holds before such leases expire. If the client does
|
||||
* not renew the lease before it expires, the distributed garbage
|
||||
* collector assumes that the remote object is no longer referenced by
|
||||
* that client.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
*/
|
||||
public interface DGC extends Remote {
|
||||
|
||||
/**
|
||||
* The dirty call requests leases for the remote object references
|
||||
* associated with the object identifiers contained in the array
|
||||
* 'ids'. The 'lease' contains a client's unique VM identifier (VMID)
|
||||
* and a requested lease period. For each remote object exported
|
||||
* in the local VM, the garbage collector maintains a reference
|
||||
* list-a list of clients that hold references to it. If the lease
|
||||
* is granted, the garbage collector adds the client's VMID to the
|
||||
* reference list for each remote object indicated in 'ids'. The
|
||||
* 'sequenceNum' parameter is a sequence number that is used to
|
||||
* detect and discard late calls to the garbage collector. The
|
||||
* sequence number should always increase for each subsequent call
|
||||
* to the garbage collector.
|
||||
*
|
||||
* Some clients are unable to generate a VMID, since a VMID is a
|
||||
* universally unique identifier that contains a host address
|
||||
* which some clients are unable to obtain due to security
|
||||
* restrictions. In this case, a client can use a VMID of null,
|
||||
* and the distributed garbage collector will assign a VMID for
|
||||
* the client.
|
||||
*
|
||||
* The dirty call returns a Lease object that contains the VMID
|
||||
* used and the lease period granted for the remote references (a
|
||||
* server may decide to grant a smaller lease period than the
|
||||
* client requests). A client must use the VMID the garbage
|
||||
* collector uses in order to make corresponding clean calls when
|
||||
* the client drops remote object references.
|
||||
*
|
||||
* A client VM need only make one initial dirty call for each
|
||||
* remote reference referenced in the VM (even if it has multiple
|
||||
* references to the same remote object). The client must also
|
||||
* make a dirty call to renew leases on remote references before
|
||||
* such leases expire. When the client no longer has any
|
||||
* references to a specific remote object, it must schedule a
|
||||
* clean call for the object ID associated with the reference.
|
||||
*
|
||||
* @param ids IDs of objects to mark as referenced by calling client
|
||||
* @param sequenceNum sequence number
|
||||
* @param lease requested lease
|
||||
* @return granted lease
|
||||
* @throws RemoteException if dirty call fails
|
||||
*/
|
||||
Lease dirty(ObjID[] ids, long sequenceNum, Lease lease)
|
||||
throws RemoteException;
|
||||
|
||||
/**
|
||||
* The clean call removes the 'vmid' from the reference list of
|
||||
* each remote object indicated in 'id's. The sequence number is
|
||||
* used to detect late clean calls. If the argument 'strong' is
|
||||
* true, then the clean call is a result of a failed dirty call,
|
||||
* thus the sequence number for the client 'vmid' needs to be
|
||||
* remembered.
|
||||
*
|
||||
* @param ids IDs of objects to mark as unreferenced by calling client
|
||||
* @param sequenceNum sequence number
|
||||
* @param vmid client VMID
|
||||
* @param strong make 'strong' clean call
|
||||
* @throws RemoteException if clean call fails
|
||||
*/
|
||||
void clean(ObjID[] ids, long sequenceNum, VMID vmid, boolean strong)
|
||||
throws RemoteException;
|
||||
}
|
||||
77
src/java.rmi/share/classes/java/rmi/dgc/Lease.java
Normal file
77
src/java.rmi/share/classes/java/rmi/dgc/Lease.java
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* 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.dgc;
|
||||
|
||||
/**
|
||||
* A lease contains a unique VM identifier and a lease duration. A
|
||||
* Lease object is used to request and grant leases to remote object
|
||||
* references.
|
||||
*/
|
||||
public final class Lease implements java.io.Serializable {
|
||||
|
||||
/**
|
||||
* @serial Virtual Machine ID with which this Lease is associated.
|
||||
* @see #getVMID
|
||||
*/
|
||||
private VMID vmid;
|
||||
|
||||
/**
|
||||
* @serial Duration of this lease.
|
||||
* @see #getValue
|
||||
*/
|
||||
private long value;
|
||||
/** indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = -5713411624328831948L;
|
||||
|
||||
/**
|
||||
* Constructs a lease with a specific VMID and lease duration. The
|
||||
* vmid may be null.
|
||||
* @param id VMID associated with this lease
|
||||
* @param duration lease duration
|
||||
*/
|
||||
public Lease(VMID id, long duration)
|
||||
{
|
||||
vmid = id;
|
||||
value = duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the client VMID associated with the lease.
|
||||
* @return client VMID
|
||||
*/
|
||||
public VMID getVMID()
|
||||
{
|
||||
return vmid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the lease duration.
|
||||
* @return lease duration
|
||||
*/
|
||||
public long getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
134
src/java.rmi/share/classes/java/rmi/dgc/VMID.java
Normal file
134
src/java.rmi/share/classes/java/rmi/dgc/VMID.java
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* 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.dgc;
|
||||
|
||||
import java.rmi.server.UID;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
/**
|
||||
* A VMID is a identifier that is unique across all Java virtual
|
||||
* machines. VMIDs are used by the distributed garbage collector
|
||||
* to identify client VMs.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @author Peter Jones
|
||||
*/
|
||||
public final class VMID implements java.io.Serializable {
|
||||
/** Array of bytes uniquely identifying this host */
|
||||
private static final byte[] randomBytes;
|
||||
|
||||
/**
|
||||
* @serial array of bytes uniquely identifying host created on
|
||||
*/
|
||||
private byte[] addr;
|
||||
|
||||
/**
|
||||
* @serial unique identifier with respect to host created on
|
||||
*/
|
||||
private UID uid;
|
||||
|
||||
/** indicate compatibility with JDK 1.1.x version of class */
|
||||
private static final long serialVersionUID = -538642295484486218L;
|
||||
|
||||
static {
|
||||
// Generate 8 bytes of random data.
|
||||
SecureRandom secureRandom = new SecureRandom();
|
||||
byte bytes[] = new byte[8];
|
||||
secureRandom.nextBytes(bytes);
|
||||
randomBytes = bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new VMID. Each new VMID returned from this constructor
|
||||
* is unique for all Java virtual machines under the following
|
||||
* conditions: a) the conditions for uniqueness for objects of
|
||||
* the class <code>java.rmi.server.UID</code> are satisfied, and b) an
|
||||
* address can be obtained for this host that is unique and constant
|
||||
* for the lifetime of this object.
|
||||
*/
|
||||
public VMID() {
|
||||
addr = randomBytes;
|
||||
uid = new UID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if an accurate address can be determined for this
|
||||
* host. If false, reliable VMID cannot be generated from this host
|
||||
* @return true if host address can be determined, false otherwise
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isUnique() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute hash code for this VMID.
|
||||
*/
|
||||
public int hashCode() {
|
||||
return uid.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare this VMID to another, and return true if they are the
|
||||
* same identifier.
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof VMID) {
|
||||
VMID vmid = (VMID) obj;
|
||||
if (!uid.equals(vmid.uid))
|
||||
return false;
|
||||
if ((addr == null) ^ (vmid.addr == null))
|
||||
return false;
|
||||
if (addr != null) {
|
||||
if (addr.length != vmid.addr.length)
|
||||
return false;
|
||||
for (int i = 0; i < addr.length; ++ i)
|
||||
if (addr[i] != vmid.addr[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return string representation of this VMID.
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (addr != null)
|
||||
for (int i = 0; i < addr.length; ++ i) {
|
||||
int x = addr[i] & 0xFF;
|
||||
sb.append((x < 0x10 ? "0" : "") +
|
||||
Integer.toString(x, 16));
|
||||
}
|
||||
sb.append(':');
|
||||
sb.append(uid.toString());
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
37
src/java.rmi/share/classes/java/rmi/dgc/package-info.java
Normal file
37
src/java.rmi/share/classes/java/rmi/dgc/package-info.java
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2018, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides classes and interface for RMI distributed
|
||||
* garbage-collection (DGC). When the RMI server returns an object to
|
||||
* its client (caller of the remote method), it tracks the remote
|
||||
* object's usage in the client. When there are no more references to the
|
||||
* remote object on the client, or if the reference's ``lease'' expires and
|
||||
* not renewed, the server garbage-collects the remote object.
|
||||
*
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
package java.rmi.dgc;
|
||||
40
src/java.rmi/share/classes/java/rmi/package-info.java
Normal file
40
src/java.rmi/share/classes/java/rmi/package-info.java
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2018, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides the RMI package. RMI is Remote Method Invocation. It is a
|
||||
* mechanism that enables an object on one Java virtual machine to invoke
|
||||
* methods on an object in another Java virtual machine. Any object that
|
||||
* can be invoked this way must implement the Remote interface. When such
|
||||
* an object is invoked, its arguments are ``marshalled'' and sent from the
|
||||
* local virtual machine to the remote one, where the arguments are
|
||||
* ``unmarshalled.'' When the method terminates, the results are
|
||||
* marshalled from the remote machine and sent to the caller's virtual
|
||||
* machine. If the method invocation results in an exception being
|
||||
* thrown, the exception is indicated to caller.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
package java.rmi;
|
||||
241
src/java.rmi/share/classes/java/rmi/registry/LocateRegistry.java
Normal file
241
src/java.rmi/share/classes/java/rmi/registry/LocateRegistry.java
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2020, 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.registry;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.server.ObjID;
|
||||
import java.rmi.server.RMIClientSocketFactory;
|
||||
import java.rmi.server.RMIServerSocketFactory;
|
||||
import java.rmi.server.RemoteRef;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
import sun.rmi.registry.RegistryImpl;
|
||||
import sun.rmi.server.UnicastRef2;
|
||||
import sun.rmi.server.UnicastRef;
|
||||
import sun.rmi.server.Util;
|
||||
import sun.rmi.transport.LiveRef;
|
||||
import sun.rmi.transport.tcp.TCPEndpoint;
|
||||
|
||||
/**
|
||||
* <code>LocateRegistry</code> is used to obtain a reference to a bootstrap
|
||||
* remote object registry on a particular host (including the local host), or
|
||||
* to create a remote object registry that accepts calls on a specific port.
|
||||
*
|
||||
* <p> Note that a <code>getRegistry</code> call does not actually make a
|
||||
* connection to the remote host. It simply creates a local reference to
|
||||
* the remote registry and will succeed even if no registry is running on
|
||||
* the remote host. Therefore, a subsequent method invocation to a remote
|
||||
* registry returned as a result of this method may fail.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @author Peter Jones
|
||||
* @since 1.1
|
||||
* @see java.rmi.registry.Registry
|
||||
*/
|
||||
public final class LocateRegistry {
|
||||
|
||||
/**
|
||||
* Private constructor to disable public construction.
|
||||
*/
|
||||
private LocateRegistry() {}
|
||||
|
||||
/**
|
||||
* Returns a reference to the remote object <code>Registry</code> for
|
||||
* the local host on the default registry port of 1099.
|
||||
*
|
||||
* @return reference (a stub) to the remote object registry
|
||||
* @throws RemoteException if the reference could not be created
|
||||
* @since 1.1
|
||||
*/
|
||||
public static Registry getRegistry()
|
||||
throws RemoteException
|
||||
{
|
||||
return getRegistry(null, Registry.REGISTRY_PORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the remote object <code>Registry</code> for
|
||||
* the local host on the specified <code>port</code>.
|
||||
*
|
||||
* @param port port on which the registry accepts requests
|
||||
* @return reference (a stub) to the remote object registry
|
||||
* @throws RemoteException if the reference could not be created
|
||||
* @since 1.1
|
||||
*/
|
||||
public static Registry getRegistry(int port)
|
||||
throws RemoteException
|
||||
{
|
||||
return getRegistry(null, port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the remote object <code>Registry</code> on the
|
||||
* specified <code>host</code> on the default registry port of 1099. If
|
||||
* <code>host</code> is <code>null</code>, the local host is used.
|
||||
*
|
||||
* @param host host for the remote registry
|
||||
* @return reference (a stub) to the remote object registry
|
||||
* @throws RemoteException if the reference could not be created
|
||||
* @since 1.1
|
||||
*/
|
||||
public static Registry getRegistry(String host)
|
||||
throws RemoteException
|
||||
{
|
||||
return getRegistry(host, Registry.REGISTRY_PORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the remote object <code>Registry</code> on the
|
||||
* specified <code>host</code> and <code>port</code>. If <code>host</code>
|
||||
* is <code>null</code>, the local host is used.
|
||||
*
|
||||
* @param host host for the remote registry
|
||||
* @param port port on which the registry accepts requests
|
||||
* @return reference (a stub) to the remote object registry
|
||||
* @throws RemoteException if the reference could not be created
|
||||
* @since 1.1
|
||||
*/
|
||||
public static Registry getRegistry(String host, int port)
|
||||
throws RemoteException
|
||||
{
|
||||
return getRegistry(host, port, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a locally created remote reference to the remote object
|
||||
* <code>Registry</code> on the specified <code>host</code> and
|
||||
* <code>port</code>. Communication with this remote registry will
|
||||
* use the supplied <code>RMIClientSocketFactory</code> <code>csf</code>
|
||||
* to create <code>Socket</code> connections to the registry on the
|
||||
* remote <code>host</code> and <code>port</code>.
|
||||
*
|
||||
* @param host host for the remote registry
|
||||
* @param port port on which the registry accepts requests
|
||||
* @param csf client-side <code>Socket</code> factory used to
|
||||
* make connections to the registry. If <code>csf</code>
|
||||
* is null, then the default client-side <code>Socket</code>
|
||||
* factory will be used in the registry stub.
|
||||
* @return reference (a stub) to the remote registry
|
||||
* @throws RemoteException if the reference could not be created
|
||||
* @since 1.2
|
||||
*/
|
||||
public static Registry getRegistry(String host, int port,
|
||||
RMIClientSocketFactory csf)
|
||||
throws RemoteException
|
||||
{
|
||||
Registry registry = null;
|
||||
|
||||
if (port <= 0)
|
||||
port = Registry.REGISTRY_PORT;
|
||||
|
||||
if (host == null || host.length() == 0) {
|
||||
// If host is blank (as returned by "file:" URL in 1.0.2 used in
|
||||
// java.rmi.Naming), try to convert to real local host name so
|
||||
// that the RegistryImpl's checkAccess will not fail.
|
||||
try {
|
||||
host = java.net.InetAddress.getLocalHost().getHostAddress();
|
||||
} catch (Exception e) {
|
||||
// If that failed, at least try "" (localhost) anyway...
|
||||
host = "";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a proxy for the registry with the given host, port, and
|
||||
* client socket factory. If the supplied client socket factory is
|
||||
* null, then the ref type is a UnicastRef, otherwise the ref type
|
||||
* is a UnicastRef2. If the property
|
||||
* java.rmi.server.ignoreStubClasses is true, then the proxy
|
||||
* returned is an instance of a dynamic proxy class that implements
|
||||
* the Registry interface; otherwise the proxy returned is an
|
||||
* instance of the pregenerated stub class for RegistryImpl.
|
||||
**/
|
||||
LiveRef liveRef =
|
||||
new LiveRef(new ObjID(ObjID.REGISTRY_ID),
|
||||
new TCPEndpoint(host, port, csf, null),
|
||||
false);
|
||||
RemoteRef ref =
|
||||
(csf == null) ? new UnicastRef(liveRef) : new UnicastRef2(liveRef);
|
||||
|
||||
return (Registry) Util.createProxy(RegistryImpl.class, ref, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and exports a <code>Registry</code> instance on the local
|
||||
* host that accepts requests on the specified <code>port</code>.
|
||||
*
|
||||
* <p>The <code>Registry</code> instance is exported as if the static
|
||||
* {@link UnicastRemoteObject#exportObject(Remote,int)
|
||||
* UnicastRemoteObject.exportObject} method is invoked, passing the
|
||||
* <code>Registry</code> instance and the specified <code>port</code> as
|
||||
* arguments, except that the <code>Registry</code> instance is
|
||||
* exported with a well-known object identifier, an {@link ObjID}
|
||||
* instance constructed with the value {@link ObjID#REGISTRY_ID}.
|
||||
*
|
||||
* @param port the port on which the registry accepts requests
|
||||
* @return the registry
|
||||
* @throws RemoteException if the registry could not be exported
|
||||
* @since 1.1
|
||||
**/
|
||||
public static Registry createRegistry(int port) throws RemoteException {
|
||||
return new RegistryImpl(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and exports a <code>Registry</code> instance on the local
|
||||
* host that uses custom socket factories for communication with that
|
||||
* instance. The registry that is created listens for incoming
|
||||
* requests on the given <code>port</code> using a
|
||||
* <code>ServerSocket</code> created from the supplied
|
||||
* <code>RMIServerSocketFactory</code>.
|
||||
*
|
||||
* <p>The <code>Registry</code> instance is exported as if
|
||||
* the static {@link
|
||||
* UnicastRemoteObject#exportObject(Remote,int,RMIClientSocketFactory,RMIServerSocketFactory)
|
||||
* UnicastRemoteObject.exportObject} method is invoked, passing the
|
||||
* <code>Registry</code> instance, the specified <code>port</code>, the
|
||||
* specified <code>RMIClientSocketFactory</code>, and the specified
|
||||
* <code>RMIServerSocketFactory</code> as arguments, except that the
|
||||
* <code>Registry</code> instance is exported with a well-known object
|
||||
* identifier, an {@link ObjID} instance constructed with the value
|
||||
* {@link ObjID#REGISTRY_ID}.
|
||||
*
|
||||
* @param port port on which the registry accepts requests
|
||||
* @param csf client-side <code>Socket</code> factory used to
|
||||
* make connections to the registry
|
||||
* @param ssf server-side <code>ServerSocket</code> factory
|
||||
* used to accept connections to the registry
|
||||
* @return the registry
|
||||
* @throws RemoteException if the registry could not be exported
|
||||
* @since 1.2
|
||||
**/
|
||||
public static Registry createRegistry(int port,
|
||||
RMIClientSocketFactory csf,
|
||||
RMIServerSocketFactory ssf)
|
||||
throws RemoteException
|
||||
{
|
||||
return new RegistryImpl(port, csf, ssf);
|
||||
}
|
||||
}
|
||||
192
src/java.rmi/share/classes/java/rmi/registry/Registry.java
Normal file
192
src/java.rmi/share/classes/java/rmi/registry/Registry.java
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 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.registry;
|
||||
|
||||
import java.rmi.AccessException;
|
||||
import java.rmi.AlreadyBoundException;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
/**
|
||||
* <code>Registry</code> is a remote interface to a simple remote
|
||||
* object registry that provides methods for storing and retrieving
|
||||
* remote object references bound with arbitrary string names. The
|
||||
* <code>bind</code>, <code>unbind</code>, and <code>rebind</code>
|
||||
* methods are used to alter the name bindings in the registry, and
|
||||
* the <code>lookup</code> and <code>list</code> methods are used to
|
||||
* query the current name bindings.
|
||||
*
|
||||
* <p>In its typical usage, a <code>Registry</code> enables RMI client
|
||||
* bootstrapping: it provides a simple means for a client to obtain an
|
||||
* initial reference to a remote object. Therefore, a registry's
|
||||
* remote object implementation is typically exported with a
|
||||
* well-known address, such as with a well-known {@link
|
||||
* java.rmi.server.ObjID#REGISTRY_ID ObjID} and TCP port number
|
||||
* (default is {@link #REGISTRY_PORT 1099}).
|
||||
*
|
||||
* <p>The {@link LocateRegistry} class provides a programmatic API for
|
||||
* constructing a bootstrap reference to a <code>Registry</code> at a
|
||||
* remote address (see the static <code>getRegistry</code> methods)
|
||||
* and for creating and exporting a <code>Registry</code> in the
|
||||
* current VM on a particular local address (see the static
|
||||
* <code>createRegistry</code> methods).
|
||||
*
|
||||
* <p>A <code>Registry</code> implementation may choose to restrict
|
||||
* access to some or all of its methods (for example, methods that
|
||||
* mutate the registry's bindings may be restricted to calls
|
||||
* originating from the local host). If a <code>Registry</code>
|
||||
* method chooses to deny access for a given invocation, its
|
||||
* implementation may throw {@link java.rmi.AccessException}, which
|
||||
* (because it extends {@link java.rmi.RemoteException}) will be
|
||||
* wrapped in a {@link java.rmi.ServerException} when caught by a
|
||||
* remote client.
|
||||
*
|
||||
* <p>The names used for bindings in a <code>Registry</code> are pure
|
||||
* strings, not parsed. A service which stores its remote reference
|
||||
* in a <code>Registry</code> may wish to use a package name as a
|
||||
* prefix in the name binding to reduce the likelihood of name
|
||||
* collisions in the registry.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @author Peter Jones
|
||||
* @since 1.1
|
||||
* @see LocateRegistry
|
||||
*/
|
||||
public interface Registry extends Remote {
|
||||
|
||||
/** Well known port for registry. */
|
||||
public static final int REGISTRY_PORT = 1099;
|
||||
|
||||
/**
|
||||
* Returns the remote reference bound to the specified
|
||||
* <code>name</code> in this registry.
|
||||
*
|
||||
* @param name the name for the remote reference to look up
|
||||
*
|
||||
* @return a reference to a remote object
|
||||
*
|
||||
* @throws NotBoundException if <code>name</code> is not currently bound
|
||||
*
|
||||
* @throws RemoteException if remote communication with the
|
||||
* registry failed; if exception is a <code>ServerException</code>
|
||||
* containing an <code>AccessException</code>, then the registry
|
||||
* denies the caller access to perform this operation
|
||||
*
|
||||
* @throws AccessException if this registry is local and it denies
|
||||
* the caller access to perform this operation
|
||||
*
|
||||
* @throws NullPointerException if <code>name</code> is <code>null</code>
|
||||
*/
|
||||
public Remote lookup(String name)
|
||||
throws RemoteException, NotBoundException, AccessException;
|
||||
|
||||
/**
|
||||
* Binds a remote reference to the specified <code>name</code> in
|
||||
* this registry.
|
||||
*
|
||||
* @param name the name to associate with the remote reference
|
||||
* @param obj a reference to a remote object (usually a stub)
|
||||
*
|
||||
* @throws AlreadyBoundException if <code>name</code> is already bound
|
||||
*
|
||||
* @throws RemoteException if remote communication with the
|
||||
* registry failed; if exception is a <code>ServerException</code>
|
||||
* containing an <code>AccessException</code>, then the registry
|
||||
* denies the caller access to perform this operation (if
|
||||
* originating from a non-local host, for example)
|
||||
*
|
||||
* @throws AccessException if this registry is local and it denies
|
||||
* the caller access to perform this operation
|
||||
*
|
||||
* @throws NullPointerException if <code>name</code> is
|
||||
* <code>null</code>, or if <code>obj</code> is <code>null</code>
|
||||
*/
|
||||
public void bind(String name, Remote obj)
|
||||
throws RemoteException, AlreadyBoundException, AccessException;
|
||||
|
||||
/**
|
||||
* Removes the binding for the specified <code>name</code> in
|
||||
* this registry.
|
||||
*
|
||||
* @param name the name of the binding to remove
|
||||
*
|
||||
* @throws NotBoundException if <code>name</code> is not currently bound
|
||||
*
|
||||
* @throws RemoteException if remote communication with the
|
||||
* registry failed; if exception is a <code>ServerException</code>
|
||||
* containing an <code>AccessException</code>, then the registry
|
||||
* denies the caller access to perform this operation (if
|
||||
* originating from a non-local host, for example)
|
||||
*
|
||||
* @throws AccessException if this registry is local and it denies
|
||||
* the caller access to perform this operation
|
||||
*
|
||||
* @throws NullPointerException if <code>name</code> is <code>null</code>
|
||||
*/
|
||||
public void unbind(String name)
|
||||
throws RemoteException, NotBoundException, AccessException;
|
||||
|
||||
/**
|
||||
* Replaces the binding for the specified <code>name</code> in
|
||||
* this registry with the supplied remote reference. If there is
|
||||
* an existing binding for the specified <code>name</code>, it is
|
||||
* discarded.
|
||||
*
|
||||
* @param name the name to associate with the remote reference
|
||||
* @param obj a reference to a remote object (usually a stub)
|
||||
*
|
||||
* @throws RemoteException if remote communication with the
|
||||
* registry failed; if exception is a <code>ServerException</code>
|
||||
* containing an <code>AccessException</code>, then the registry
|
||||
* denies the caller access to perform this operation (if
|
||||
* originating from a non-local host, for example)
|
||||
*
|
||||
* @throws AccessException if this registry is local and it denies
|
||||
* the caller access to perform this operation
|
||||
*
|
||||
* @throws NullPointerException if <code>name</code> is
|
||||
* <code>null</code>, or if <code>obj</code> is <code>null</code>
|
||||
*/
|
||||
public void rebind(String name, Remote obj)
|
||||
throws RemoteException, AccessException;
|
||||
|
||||
/**
|
||||
* Returns an array of the names bound in this registry. The
|
||||
* array will contain a snapshot of the names bound in this
|
||||
* registry at the time of the given invocation of this method.
|
||||
*
|
||||
* @return an array of the names bound in this registry
|
||||
*
|
||||
* @throws RemoteException if remote communication with the
|
||||
* registry failed; if exception is a <code>ServerException</code>
|
||||
* containing an <code>AccessException</code>, then the registry
|
||||
* denies the caller access to perform this operation
|
||||
*
|
||||
* @throws AccessException if this registry is local and it denies
|
||||
* the caller access to perform this operation
|
||||
*/
|
||||
public String[] list() throws RemoteException, AccessException;
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 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.registry;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.UnknownHostException;
|
||||
|
||||
/**
|
||||
* <code>RegistryHandler</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 1.1
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
public interface RegistryHandler {
|
||||
|
||||
/**
|
||||
* Returns a "stub" for contacting a remote registry
|
||||
* on the specified host and port.
|
||||
*
|
||||
* @deprecated no replacement. As of the Java 2 platform v1.2, RMI no
|
||||
* longer uses the <code>RegistryHandler</code> to obtain the registry's
|
||||
* stub.
|
||||
* @param host name of remote registry host
|
||||
* @param port remote registry port
|
||||
* @return remote registry stub
|
||||
* @throws RemoteException if a remote error occurs
|
||||
* @throws UnknownHostException if unable to resolve given hostname
|
||||
*/
|
||||
@Deprecated
|
||||
Registry registryStub(String host, int port)
|
||||
throws RemoteException, UnknownHostException;
|
||||
|
||||
/**
|
||||
* Constructs and exports a Registry on the specified port.
|
||||
* The port must be non-zero.
|
||||
*
|
||||
* @deprecated no replacement. As of the Java 2 platform v1.2, RMI no
|
||||
* longer uses the <code>RegistryHandler</code> to obtain the registry's
|
||||
* implementation.
|
||||
* @param port port to export registry on
|
||||
* @return registry stub
|
||||
* @throws RemoteException if a remote error occurs
|
||||
*/
|
||||
@Deprecated
|
||||
Registry registryImpl(int port) throws RemoteException;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2018, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides a class and two interfaces for the RMI registry.
|
||||
* A registry is a remote object that maps names to remote objects. A
|
||||
* server registers its remote objects with the registry so that they can
|
||||
* be looked up. When an object wants to invoke a method on a remote
|
||||
* object, it must first lookup the remote object using its name. The
|
||||
* registry returns to the calling object a reference to the remote
|
||||
* object, using which a remote method can be invoked.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
package java.rmi.registry;
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2021, 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>.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @since 1.1
|
||||
* @see java.rmi.server.UnicastRemoteObject
|
||||
*/
|
||||
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 1.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 1.1
|
||||
*/
|
||||
public ExportException(String s, Exception ex) {
|
||||
super(s, ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2022, 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 1.1
|
||||
*
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
public interface LoaderHandler {
|
||||
|
||||
/** package of system <code>LoaderHandler</code> implementation. */
|
||||
static final 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
|
||||
* @throws MalformedURLException
|
||||
* if the system property <b>java.rmi.server.codebase</b>
|
||||
* contains an invalid URL
|
||||
* @throws ClassNotFoundException
|
||||
* if a definition for the class could not
|
||||
* be found at the codebase location.
|
||||
* @since 1.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
|
||||
* @throws MalformedURLException
|
||||
* if the <code>codebase</code> parameter
|
||||
* contains an invalid URL
|
||||
* @throws ClassNotFoundException
|
||||
* if a definition for the class could not
|
||||
* be found at the specified URL
|
||||
* @since 1.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 1.1
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
Object getSecurityContext(ClassLoader loader);
|
||||
}
|
||||
265
src/java.rmi/share/classes/java/rmi/server/LogStream.java
Normal file
265
src/java.rmi/share/classes/java/rmi/server/LogStream.java
Normal file
|
|
@ -0,0 +1,265 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2024, 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 1.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 1.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 1.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 1.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 1.1
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
public static synchronized void setDefaultStream(PrintStream newDefault) {
|
||||
defaultStream = newDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current stream to which output from this log is sent.
|
||||
* @return output stream for this log
|
||||
* @see #setOutputStream
|
||||
* @since 1.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 1.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 1.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 1.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 1.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 1.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;
|
||||
}
|
||||
}
|
||||
246
src/java.rmi/share/classes/java/rmi/server/ObjID.java
Normal file
246
src/java.rmi/share/classes/java/rmi/server/ObjID.java
Normal file
|
|
@ -0,0 +1,246 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2024, 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.SecureRandom;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* 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 {@systemProperty java.rmi.server.randomIDs}
|
||||
* 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 1.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();
|
||||
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
|
||||
*/
|
||||
@Override
|
||||
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 = System.getProperty("java.rmi.server.randomIDs");
|
||||
return value == null ? true : Boolean.parseBoolean(value);
|
||||
}
|
||||
}
|
||||
72
src/java.rmi/share/classes/java/rmi/server/Operation.java
Normal file
72
src/java.rmi/share/classes/java/rmi/server/Operation.java
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2020, 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; hence, this class is deprecated.
|
||||
*
|
||||
* @since 1.1
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
public class Operation {
|
||||
private String operation;
|
||||
|
||||
/**
|
||||
* Creates a new Operation object.
|
||||
* @param op method name
|
||||
* @deprecated no replacement
|
||||
* @since 1.1
|
||||
*/
|
||||
@Deprecated
|
||||
public Operation(String op) {
|
||||
operation = op;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the method.
|
||||
* @return method name
|
||||
* @deprecated no replacement
|
||||
* @since 1.1
|
||||
*/
|
||||
@Deprecated
|
||||
public String getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string representation of the operation.
|
||||
* @deprecated no replacement
|
||||
* @since 1.1
|
||||
*/
|
||||
@Deprecated
|
||||
public String toString() {
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
645
src/java.rmi/share/classes/java/rmi/server/RMIClassLoader.java
Normal file
645
src/java.rmi/share/classes/java/rmi/server/RMIClassLoader.java
Normal file
|
|
@ -0,0 +1,645 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2024, 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.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.
|
||||
*
|
||||
* <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
|
||||
* {@systemProperty java.rmi.server.RMIClassLoaderSpi} 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 1.1
|
||||
*/
|
||||
public class RMIClassLoader {
|
||||
|
||||
/** "default" provider instance */
|
||||
private static final RMIClassLoaderSpi defaultProvider =
|
||||
newDefaultProviderInstance();
|
||||
|
||||
/** provider instance */
|
||||
private static final RMIClassLoaderSpi provider = 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.
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @since 1.3
|
||||
*/
|
||||
public static ClassLoader getClassLoader(String codebase)
|
||||
throws MalformedURLException
|
||||
{
|
||||
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>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
|
||||
* {@systemProperty java.rmi.server.codebase} 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.
|
||||
*
|
||||
* <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,
|
||||
* the <code>codebase</code> argument is ignored. Class loading
|
||||
* proceeds using the the current thread's context class loader
|
||||
* (see {@link Thread#getContextClassLoader()}), which is also
|
||||
* considered to be the codebase loader, irrespective of any
|
||||
* value passed as the <code>codebase</code> argument.
|
||||
*
|
||||
* <p>The <b>{@link RMIClassLoaderSpi#getClassLoader(String)
|
||||
* getClassLoader}</b> method returns the current thread's
|
||||
* context class loader.
|
||||
*
|
||||
* <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>, as if 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 current
|
||||
* thread's context class 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
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public static RMIClassLoaderSpi getDefaultProviderInstance() {
|
||||
return defaultProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns null.
|
||||
*
|
||||
* @param loader a class loader from which to get the security context
|
||||
*
|
||||
* @return null
|
||||
*
|
||||
* @deprecated no replacement. This method has no purpose in the absence
|
||||
* of a Security Manager.
|
||||
*/
|
||||
@Deprecated
|
||||
public static Object getSecurityContext(ClassLoader loader)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
@SuppressWarnings("deprecation")
|
||||
RMIClassLoaderSpi result = providerClass.newInstance();
|
||||
return result;
|
||||
|
||||
} 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) {
|
||||
throw new LinkageError(
|
||||
"provider class not assignable to RMIClassLoaderSpi", e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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) {
|
||||
throw new LinkageError(
|
||||
"provider class not assignable to RMIClassLoaderSpi", e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Finally, return the canonical instance of the default provider.
|
||||
*/
|
||||
return defaultProvider;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2024, 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 {
|
||||
|
||||
/**
|
||||
* Constructor for subclasses to call.
|
||||
*/
|
||||
public 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.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2021, 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>.
|
||||
*
|
||||
* <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.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.
|
||||
* @throws IOException if an I/O error occurs during socket creation
|
||||
* @since 1.2
|
||||
*/
|
||||
public Socket createSocket(String host, int port)
|
||||
throws IOException;
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 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;
|
||||
|
||||
/**
|
||||
* An {@code RMIFailureHandler} can be registered via the
|
||||
* {@code RMISocketFactory.setFailureHandler} call. The
|
||||
* {@code failure} method of the handler is invoked when the RMI
|
||||
* runtime is unable to create a {@code ServerSocket} to listen
|
||||
* for incoming calls. The {@code failure} method returns a boolean
|
||||
* indicating whether the runtime should attempt to re-create the
|
||||
* {@code ServerSocket}.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @since 1.1
|
||||
*/
|
||||
public interface RMIFailureHandler {
|
||||
|
||||
/**
|
||||
* The {@code failure} callback is invoked when the RMI
|
||||
* runtime is unable to create a {@code ServerSocket} via the
|
||||
* {@code RMISocketFactory}. An {@code RMIFailureHandler}
|
||||
* is registered via a call to
|
||||
* {@code RMISocketFactory.setFailureHandler}. 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}
|
||||
* creation
|
||||
* @return if true, the RMI runtime attempts to retry
|
||||
* {@code ServerSocket} creation
|
||||
* @see java.rmi.server.RMISocketFactory#setFailureHandler(RMIFailureHandler)
|
||||
* @since 1.1
|
||||
*/
|
||||
public boolean failure(Exception ex);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2021, 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>.
|
||||
*
|
||||
* <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.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
|
||||
* @throws IOException if an I/O error occurs during server socket
|
||||
* creation
|
||||
* @since 1.2
|
||||
*/
|
||||
public ServerSocket createServerSocket(int port)
|
||||
throws IOException;
|
||||
}
|
||||
193
src/java.rmi/share/classes/java/rmi/server/RMISocketFactory.java
Normal file
193
src/java.rmi/share/classes/java/rmi/server/RMISocketFactory.java
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2024, 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 creates a direct
|
||||
* socket connection to the remote host.
|
||||
*
|
||||
* <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 {@systemProperty 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 1.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 1.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.
|
||||
* @throws IOException if an I/O error occurs during socket creation
|
||||
* @since 1.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
|
||||
* @throws IOException if an I/O error occurs during server socket
|
||||
* creation
|
||||
* @since 1.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.
|
||||
* @param fac the socket factory
|
||||
* @throws IOException if the RMI socket factory is already set
|
||||
* @see #getSocketFactory
|
||||
* @since 1.1
|
||||
*/
|
||||
public static synchronized void setSocketFactory(RMISocketFactory fac)
|
||||
throws IOException
|
||||
{
|
||||
if (factory != null) {
|
||||
throw new SocketException("factory already defined");
|
||||
}
|
||||
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 1.1
|
||||
*/
|
||||
public static synchronized 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 1.1
|
||||
*/
|
||||
public static synchronized RMISocketFactory getDefaultSocketFactory() {
|
||||
if (defaultSocketFactory == null) {
|
||||
defaultSocketFactory =
|
||||
new sun.rmi.transport.tcp.TCPDirectSocketFactory();
|
||||
}
|
||||
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.
|
||||
*
|
||||
* @param fh the failure handler.
|
||||
* @see #getFailureHandler
|
||||
* @see java.rmi.server.RMIFailureHandler#failure(Exception)
|
||||
* @since 1.1
|
||||
*/
|
||||
public static synchronized void setFailureHandler(RMIFailureHandler fh)
|
||||
{
|
||||
handler = fh;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the handler for socket creation failure set by the
|
||||
* <code>setFailureHandler</code> method.
|
||||
* @return the failure handler
|
||||
* @see #setFailureHandler(RMIFailureHandler)
|
||||
* @since 1.1
|
||||
*/
|
||||
public static synchronized RMIFailureHandler getFailureHandler()
|
||||
{
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
132
src/java.rmi/share/classes/java/rmi/server/RemoteCall.java
Normal file
132
src/java.rmi/share/classes/java/rmi/server/RemoteCall.java
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2020, 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 1.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
|
||||
* @throws java.io.IOException if an I/O error occurs.
|
||||
* @since 1.1
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
ObjectOutput getOutputStream() throws IOException;
|
||||
|
||||
/**
|
||||
* Release the output stream; in some transports this would release
|
||||
* the stream.
|
||||
*
|
||||
* @throws java.io.IOException if an I/O error occurs.
|
||||
* @since 1.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
|
||||
* @throws java.io.IOException if an I/O error occurs.
|
||||
* @since 1.1
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
ObjectInput getInputStream() throws IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Release the input stream. This would allow some transports to release
|
||||
* the channel early.
|
||||
*
|
||||
* @throws java.io.IOException if an I/O error occurs.
|
||||
* @since 1.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
|
||||
* @throws java.io.IOException if an I/O error occurs.
|
||||
* @throws java.io.StreamCorruptedException If already been called.
|
||||
* @since 1.1
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
ObjectOutput getResultStream(boolean success) throws IOException,
|
||||
StreamCorruptedException;
|
||||
|
||||
/**
|
||||
* Do whatever it takes to execute the call.
|
||||
*
|
||||
* @throws java.lang.Exception if a general exception occurs.
|
||||
* @since 1.1
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
void executeCall() throws Exception;
|
||||
|
||||
/**
|
||||
* Allow cleanup after the remote call has completed.
|
||||
*
|
||||
* @throws java.io.IOException if an I/O error occurs.
|
||||
* @since 1.1
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
void done() throws IOException;
|
||||
}
|
||||
425
src/java.rmi/share/classes/java/rmi/server/RemoteObject.java
Normal file
425
src/java.rmi/share/classes/java/rmi/server/RemoteObject.java
Normal file
|
|
@ -0,0 +1,425 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2021, 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.IOException;
|
||||
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 1.1
|
||||
*/
|
||||
public abstract class RemoteObject implements Remote, java.io.Serializable {
|
||||
|
||||
/** The object's remote reference. */
|
||||
protected transient RemoteRef ref;
|
||||
|
||||
/** indicate compatibility with JDK 1.1.x version of class */
|
||||
@java.io.Serial
|
||||
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>.
|
||||
* @throws NoSuchObjectException if the stub for the
|
||||
* remote object could not be found.
|
||||
* @since 1.2
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
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
|
||||
* 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>"UnicastServerRef"</code> and
|
||||
* <code>"UnicastServerRef2"</code>, no data is written by the
|
||||
* <code>writeExternal</code> method or read by the
|
||||
* <code>readExternal</code> method.
|
||||
*
|
||||
* @param out the {@code ObjectOutputStream} to which data is written
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
@java.io.Serial
|
||||
private void writeObject(java.io.ObjectOutputStream out)
|
||||
throws java.io.IOException
|
||||
{
|
||||
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>, or <code>"UnicastServerRef2"</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.
|
||||
*
|
||||
* @param in the {@code ObjectInputStream} from which data is read
|
||||
* @throws IOException if an I/O error occurs
|
||||
* @throws ClassNotFoundException if a serialized class cannot be loaded
|
||||
*/
|
||||
@java.io.Serial
|
||||
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 {
|
||||
@SuppressWarnings("deprecation")
|
||||
Object tmp = refClass.newInstance();
|
||||
ref = (RemoteRef) tmp;
|
||||
|
||||
/*
|
||||
* If this step fails, assume we found an internal
|
||||
* class that is not meant to be a serializable ref
|
||||
* type.
|
||||
*/
|
||||
} catch (InstantiationException | IllegalAccessException | ClassCastException e) {
|
||||
throw new ClassNotFoundException(internalRefClassName, e);
|
||||
}
|
||||
ref.readExternal(in);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,303 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2021, 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.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}
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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>If <code>method</code> overrides {@link Object#finalize Object.finalize},
|
||||
* it is ignored.
|
||||
*
|
||||
* <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) {
|
||||
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 new IllegalArgumentException(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;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
200
src/java.rmi/share/classes/java/rmi/server/RemoteRef.java
Normal file
200
src/java.rmi/share/classes/java/rmi/server/RemoteRef.java
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2025, 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 1.1
|
||||
* @see java.rmi.server.RemoteStub
|
||||
*/
|
||||
public interface RemoteRef extends java.io.Externalizable {
|
||||
|
||||
/** indicate compatibility with JDK 1.1.x version of class.
|
||||
*
|
||||
* @deprecated A {@code serialVersionUID} field in an interface is
|
||||
* ineffectual. Do not use; no replacement.
|
||||
*/
|
||||
@Deprecated
|
||||
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.
|
||||
*/
|
||||
static final 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
|
||||
* @throws 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 1.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 1.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 1.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 1.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 1.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 1.1
|
||||
*/
|
||||
boolean remoteEquals(RemoteRef obj);
|
||||
|
||||
/**
|
||||
* Returns a String that represents the reference of this remote
|
||||
* object.
|
||||
* @return string representing remote object reference
|
||||
* @since 1.1
|
||||
*/
|
||||
String remoteToString();
|
||||
|
||||
}
|
||||
107
src/java.rmi/share/classes/java/rmi/server/RemoteServer.java
Normal file
107
src/java.rmi/share/classes/java/rmi/server/RemoteServer.java
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2024, 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 1.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 1.1
|
||||
*/
|
||||
protected RemoteServer() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>RemoteServer</code> with the given reference type.
|
||||
*
|
||||
* @param ref the remote reference
|
||||
* @since 1.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 1.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.
|
||||
*
|
||||
* @param out the output stream to which RMI calls should be logged
|
||||
* @see #getLog
|
||||
* @since 1.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 1.1
|
||||
*/
|
||||
public static java.io.PrintStream getLog()
|
||||
{
|
||||
return (logNull ? null : UnicastServerRef.callLog.getPrintStream());
|
||||
}
|
||||
|
||||
// initialize log status
|
||||
private static boolean logNull = !UnicastServerRef.logCalls;
|
||||
}
|
||||
83
src/java.rmi/share/classes/java/rmi/server/RemoteStub.java
Normal file
83
src/java.rmi/share/classes/java/rmi/server/RemoteStub.java
Normal 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 1.1
|
||||
*
|
||||
* @deprecated Statically generated stubs are deprecated, since
|
||||
* stubs are generated dynamically. See {@link UnicastRemoteObject}
|
||||
* for information about dynamic stub generation.
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract 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 1.1
|
||||
*/
|
||||
protected RemoteStub(RemoteRef ref) {
|
||||
super(ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws {@link UnsupportedOperationException}.
|
||||
*
|
||||
* @param stub the remote stub
|
||||
* @param ref the remote reference
|
||||
* @throws UnsupportedOperationException always
|
||||
* @since 1.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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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} is thrown if a remote exception occurs
|
||||
* during the cloning of a {@code UnicastRemoteObject}.
|
||||
*
|
||||
* <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} always throws {@link
|
||||
* IllegalStateException}.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @since 1.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} 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} 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 {@code null}.
|
||||
* @since 1.4
|
||||
*/
|
||||
public Throwable getCause() {
|
||||
return detail;
|
||||
}
|
||||
}
|
||||
|
|
@ -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 1.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 1.1
|
||||
*/
|
||||
public ServerNotActiveException() {}
|
||||
|
||||
/**
|
||||
* Constructs an <code>ServerNotActiveException</code> with the specified
|
||||
* detail message.
|
||||
*
|
||||
* @param s the detail message.
|
||||
* @since 1.1
|
||||
*/
|
||||
public ServerNotActiveException(String s)
|
||||
{
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
73
src/java.rmi/share/classes/java/rmi/server/ServerRef.java
Normal file
73
src/java.rmi/share/classes/java/rmi/server/ServerRef.java
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2025, 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 1.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.
|
||||
*
|
||||
* @deprecated A {@code serialVersionUID} field in an interface is
|
||||
* ineffectual. Do not use; no replacement.
|
||||
*/
|
||||
@Deprecated
|
||||
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
|
||||
* @throws RemoteException if an exception occurs attempting
|
||||
* to export the object (e.g., stub class could not be found)
|
||||
* @since 1.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
|
||||
* @throws ServerNotActiveException if called outside of servicing
|
||||
* a remote method invocation
|
||||
* @since 1.1
|
||||
*/
|
||||
String getClientHost() throws ServerNotActiveException;
|
||||
}
|
||||
68
src/java.rmi/share/classes/java/rmi/server/Skeleton.java
Normal file
68
src/java.rmi/share/classes/java/rmi/server/Skeleton.java
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2020, 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 compatible skeleton 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 1.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
|
||||
* @throws java.lang.Exception if a general exception occurs.
|
||||
* @since 1.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 1.1
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
Operation[] getOperations();
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2020, 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 protocol.
|
||||
*
|
||||
* @author Roger Riggs
|
||||
* @since 1.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 1.1
|
||||
* @deprecated no replacement
|
||||
*/
|
||||
@Deprecated
|
||||
public SkeletonMismatchException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 1.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 1.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 1.1
|
||||
*/
|
||||
public SkeletonNotFoundException(String s, Exception ex) {
|
||||
super(s, ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -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 1.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 1.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 1.1
|
||||
*/
|
||||
public SocketSecurityException(String s, Exception ex) {
|
||||
super(s, ex);
|
||||
}
|
||||
|
||||
}
|
||||
269
src/java.rmi/share/classes/java/rmi/server/UID.java
Normal file
269
src/java.rmi/share/classes/java/rmi/server/UID.java
Normal 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 1.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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,475 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2023, 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.IOException;
|
||||
import java.io.ObjectInputFilter;
|
||||
import java.rmi.*;
|
||||
import sun.rmi.server.UnicastServerRef;
|
||||
import sun.rmi.server.UnicastServerRef2;
|
||||
import sun.rmi.transport.LiveRef;
|
||||
|
||||
/**
|
||||
* Used for exporting a remote object with JRMP and obtaining a stub
|
||||
* that communicates to the remote object. Stubs are generated
|
||||
* at runtime using dynamic proxy objects.
|
||||
*
|
||||
* <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 non-deprecated ways of exporting objects as listed below. </em>
|
||||
*
|
||||
* <p>There are eight 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.
|
||||
*
|
||||
* <li>Calling the
|
||||
* {@link #exportObject(Remote, int, ObjectInputFilter) exportObject(Remote, port, filter)} method.
|
||||
*
|
||||
* <li>Calling the
|
||||
* {@link #exportObject(Remote, int, RMIClientSocketFactory, RMIServerSocketFactory, ObjectInputFilter)
|
||||
* exportObject(Remote, port, csf, ssf, filter)} method.
|
||||
*
|
||||
* </ol>
|
||||
*
|
||||
* <p>The fourth technique, {@link #exportObject(Remote)},
|
||||
* always uses statically generated stubs and is deprecated.
|
||||
*
|
||||
* <p>The other 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.
|
||||
* 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 be public, it must extend {@link RemoteStub}, it must
|
||||
* reside in a package that is exported to at least the {@code java.rmi} module, and it
|
||||
* 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 according to the specifications for the
|
||||
* {@link java.lang.reflect.Proxy##membership Proxy}
|
||||
* class, using 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>Each remote interface must either be public and reside in a package that is
|
||||
* {@linkplain Module#isExported(String,Module) exported}
|
||||
* to at least the {@code java.rmi} module, or it must reside in a package that is
|
||||
* {@linkplain Module#isOpen(String,Module) open}
|
||||
* to at least the {@code java.rmi} module.
|
||||
*
|
||||
* <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>
|
||||
*
|
||||
* <p>
|
||||
* Exported remote objects receive method invocations from the stubs
|
||||
* as described in the RMI specification. Each invocation's operation and
|
||||
* parameters are unmarshaled using a custom {@link java.io.ObjectInputStream}.
|
||||
* If an {@link ObjectInputFilter} is provided and is not {@code null} when the object
|
||||
* is exported, it is used to filter the parameters as they are unmarshaled from the stream.
|
||||
* The filter is used for all invocations and all parameters regardless of
|
||||
* the method being invoked or the parameter values.
|
||||
* If no filter is provided or is {@code null} for the exported object then the
|
||||
* {@code ObjectInputStream} default filter, if any, is used. The default filter is
|
||||
* configured with {@link ObjectInputFilter.Config#setSerialFilter(ObjectInputFilter)
|
||||
* ObjectInputFilter.Config.setSerialFilter}.
|
||||
* If the filter rejects any of the parameters, the {@code InvalidClassException}
|
||||
* thrown by {@code ObjectInputStream} is reported as the cause of an
|
||||
* {@link UnmarshalException}.
|
||||
*
|
||||
* @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}/../specs/rmi/server.html#rmi-socket-factories">RMI Socket Factories</a>
|
||||
* in the
|
||||
* <a href="{@docRoot}/../specs/rmi/index.html">Java RMI Specification</a>.
|
||||
*
|
||||
* @author Ann Wollrath
|
||||
* @author Peter Jones
|
||||
* @since 1.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)
|
||||
*/
|
||||
@SuppressWarnings("serial") // Not statically typed as Serializable
|
||||
private RMIClientSocketFactory csf = null;
|
||||
|
||||
/**
|
||||
* @serial server-side socket factory (if any) to use when
|
||||
* exporting object
|
||||
*/
|
||||
@SuppressWarnings("serial") // Not statically typed as Serializable
|
||||
private RMIServerSocketFactory ssf = null;
|
||||
|
||||
/* indicate compatibility with JDK 1.1.x version of class */
|
||||
@java.io.Serial
|
||||
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 1.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.
|
||||
*
|
||||
* @param in the {@code ObjectInputStream} from which data is read
|
||||
* @throws IOException if an I/O error occurs
|
||||
* @throws ClassNotFoundException if a serialized class cannot be loaded
|
||||
*
|
||||
*/
|
||||
@java.io.Serial
|
||||
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.
|
||||
*
|
||||
* @throws CloneNotSupportedException if clone failed due to
|
||||
* a RemoteException.
|
||||
* @return the new remote object
|
||||
* @since 1.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
|
||||
* @throws RemoteException if export fails
|
||||
* @since 1.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
|
||||
* @throws 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
|
||||
* @throws 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports the remote object to make it available to receive incoming
|
||||
* calls, using the particular supplied port
|
||||
* and {@linkplain ObjectInputFilter filter}.
|
||||
*
|
||||
* <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
|
||||
* @param filter an ObjectInputFilter applied when deserializing invocation arguments;
|
||||
* may be {@code null}
|
||||
* @return remote object stub
|
||||
* @throws RemoteException if export fails
|
||||
* @since 9
|
||||
*/
|
||||
public static Remote exportObject(Remote obj, int port,
|
||||
ObjectInputFilter filter)
|
||||
throws RemoteException
|
||||
{
|
||||
return exportObject(obj, new UnicastServerRef(new LiveRef(port), filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports the remote object to make it available to receive incoming
|
||||
* calls, using a transport specified by the given socket factory
|
||||
* and {@linkplain ObjectInputFilter filter}.
|
||||
*
|
||||
* <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
|
||||
* @param filter an ObjectInputFilter applied when deserializing invocation arguments;
|
||||
* may be {@code null}
|
||||
* @return remote object stub
|
||||
* @throws RemoteException if export fails
|
||||
* @since 9
|
||||
*/
|
||||
public static Remote exportObject(Remote obj, int port,
|
||||
RMIClientSocketFactory csf,
|
||||
RMIServerSocketFactory ssf,
|
||||
ObjectInputFilter filter)
|
||||
throws RemoteException
|
||||
{
|
||||
return exportObject(obj, new UnicastServerRef2(port, csf, ssf, filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @throws 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);
|
||||
}
|
||||
}
|
||||
45
src/java.rmi/share/classes/java/rmi/server/Unreferenced.java
Normal file
45
src/java.rmi/share/classes/java/rmi/server/Unreferenced.java
Normal 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 1.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 1.1
|
||||
*/
|
||||
public void unreferenced();
|
||||
}
|
||||
46
src/java.rmi/share/classes/java/rmi/server/package-info.java
Normal file
46
src/java.rmi/share/classes/java/rmi/server/package-info.java
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides classes and interfaces for supporting the server side of RMI.
|
||||
* One group of classes are used by the static stubs and skeletons.
|
||||
* Another group of classes implements the RMI Transport protocol.
|
||||
*
|
||||
* <p><strong>Deprecated: Skeletons and Static Stubs.</strong>
|
||||
*
|
||||
* <em>Skeletons and statically generated stubs are deprecated. This
|
||||
* includes the APIs in this package that require the use of skeletons
|
||||
* or static stubs and the runtime support for them. Support for skeletons
|
||||
* and static stubs may be removed in a future release of the
|
||||
* platform. Skeletons are unnecessary, as server-side method dispatching
|
||||
* is handled directly by the RMI runtime. Statically generated stubs are
|
||||
* unnecessary, as stubs are generated dynamically using {@link
|
||||
* java.lang.reflect.Proxy Proxy} objects. See {@link
|
||||
* java.rmi.server.UnicastRemoteObject UnicastRemoteObject} for
|
||||
* information about dynamic stub generation.</em>
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
package java.rmi.server;
|
||||
Loading…
Add table
Add a link
Reference in a new issue