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

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

View File

@@ -0,0 +1,70 @@
/*
* 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>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>) and methods of the
* <code>java.rmi.activation.ActivationSystem</code> interface 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 JDK1.1
* @see java.rmi.Naming
* @see java.rmi.activation.ActivationSystem
*/
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 JDK1.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 JDK1.1
*/
public AccessException(String s, Exception ex) {
super(s, ex);
}
}

View 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;
/**
* An <code>AlreadyBoundException</code> is thrown if an attempt
* is made to bind an object in the registry to a name that already
* has an associated binding.
*
* @since JDK1.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 JDK1.1
*/
public AlreadyBoundException() {
super();
}
/**
* Constructs an <code>AlreadyBoundException</code> with the specified
* detail message.
*
* @param s the detail message
* @since JDK1.1
*/
public AlreadyBoundException(String s) {
super(s);
}
}

View 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 JDK1.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 JDK1.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 JDK1.1
*/
public ConnectException(String s, Exception ex) {
super(s, ex);
}
}

View 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 JDK1.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 JDK1.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 JDK1.1
*/
public ConnectIOException(String s, Exception ex) {
super(s, ex);
}
}

View 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 JDK1.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 JDK1.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 JDK1.1
*/
public MarshalException(String s, Exception ex) {
super(s, ex);
}
}

View File

@@ -0,0 +1,352 @@
/*
* Copyright (c) 1997, 2016, 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.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamConstants;
import java.io.OutputStream;
import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.rmi.server.MarshalInputStream;
import sun.rmi.server.MarshalOutputStream;
import sun.misc.ObjectInputFilter;
/**
* 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)
* @exception 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 = ObjectInputFilter.Config.getObjectInputFilter(stream);
}
/**
* Returns a new copy of the contained marshalledobject. The internal
* representation is deserialized with the semantics used for
* unmarshaling parameters for RMI calls.
*
* @return a copy of the contained object
* @exception IOException if an <code>IOException</code> occurs while
* deserializing the object from its internal representation.
* @exception 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 != null && obj instanceof MarshalledObject) {
MarshalledObject<?> other = (MarshalledObject<?>) obj;
// 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 comparision 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) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
ObjectInputFilter.Config.setObjectInputFilter(MarshalledObjectInputStream.this, filter);
if (MarshalledObjectInputStream.this.locIn != null) {
ObjectInputFilter.Config.setObjectInputFilter(MarshalledObjectInputStream.this.locIn, filter);
}
return null;
}
});
}
}
/**
* 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());
}
}
}

View File

@@ -0,0 +1,356 @@
/*
* Copyright (c) 1996, 2005, 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;
/**
* 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 JDK1.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
* @exception NotBoundException if name is not currently bound
* @exception RemoteException if registry could not be contacted
* @exception AccessException if this operation is not permitted
* @exception MalformedURLException if the name is not an appropriately
* formatted URL
* @since JDK1.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)
* @exception AlreadyBoundException if name is already bound
* @exception MalformedURLException if the name is not an appropriately
* formatted URL
* @exception RemoteException if registry could not be contacted
* @exception AccessException if this operation is not permitted (if
* originating from a non-local host, for example)
* @since JDK1.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)
* @exception NotBoundException if name is not currently bound
* @exception MalformedURLException if the name is not an appropriately
* formatted URL
* @exception RemoteException if registry could not be contacted
* @exception AccessException if this operation is not permitted (if
* originating from a non-local host, for example)
* @since JDK1.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
* @exception MalformedURLException if the name is not an appropriately
* formatted URL
* @exception RemoteException if registry could not be contacted
* @exception AccessException if this operation is not permitted (if
* originating from a non-local host, for example)
* @since JDK1.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
* @exception MalformedURLException if the name is not an appropriately
* formatted URL
* @exception RemoteException if registry could not be contacted.
* @since JDK1.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.equals(""))
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);
}
/**
* Dissect Naming URL strings to obtain referenced host, port and
* object name.
*
* @return an object which contains each of the above
* components.
*
* @exception 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 = new MalformedURLException(
"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 new MalformedURLException(
"not a hierarchical URL: " + str);
}
if (uri.getFragment() != null) {
throw new MalformedURLException(
"invalid character, '#', in URL name: " + str);
} else if (uri.getQuery() != null) {
throw new MalformedURLException(
"invalid character, '?', in URL name: " + str);
} else if (uri.getUserInfo() != null) {
throw new MalformedURLException(
"invalid character, '@', in URL host: " + str);
}
String scheme = uri.getScheme();
if (scheme != null && !scheme.equals("rmi")) {
throw new MalformedURLException("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;
}
}
}

View 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>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> and
* <code>java.rmi.activation.Activatable</code> and
*
* @author Ann Wollrath
* @since JDK1.1
* @see java.rmi.server.RemoteObject#toStub(Remote)
* @see java.rmi.server.UnicastRemoteObject#unexportObject(Remote,boolean)
* @see java.rmi.activation.Activatable#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 JDK1.1
*/
public NoSuchObjectException(String s) {
super(s);
}
}

View 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 JDK1.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 JDK1.1
*/
public NotBoundException() {
super();
}
/**
* Constructs a <code>NotBoundException</code> with the specified
* detail message.
*
* @param s the detail message
* @since JDK1.1
*/
public NotBoundException(String s) {
super(s);
}
}

View File

@@ -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 JDK1.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 JDK1.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 JDK1.1
* @deprecated no replacement
*/
@Deprecated
public RMISecurityException(String name, String arg) {
this(name);
}
}

View File

@@ -0,0 +1,67 @@
/*
* 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;
import java.security.*;
/**
* {@code RMISecurityManager} implements a policy identical to the policy
* implemented by {@link SecurityManager}. RMI applications
* should use the {@code SecurityManager} class or another appropriate
* {@code SecurityManager} implementation instead of this class. RMI's class
* loader will download classes from remote locations only if a security
* manager has been set.
*
* @implNote
* <p>Applets typically run in a container that already has a security
* manager, so there is generally no need for applets to set a security
* manager. If you have a standalone application, you might need to set a
* {@code SecurityManager} in order to enable class downloading. This can be
* done by adding the following to your code. (It needs to be executed before
* RMI can download code from remote hosts, so it most likely needs to appear
* in the {@code main} method of your application.)
*
* <pre>{@code
* if (System.getSecurityManager() == null) {
* System.setSecurityManager(new SecurityManager());
* }
* }</pre>
*
* @author Roger Riggs
* @author Peter Jones
* @since JDK1.1
* @deprecated Use {@link SecurityManager} instead.
*/
@Deprecated
public class RMISecurityManager extends SecurityManager {
/**
* Constructs a new {@code RMISecurityManager}.
* @since JDK1.1
*/
public RMISecurityManager() {
}
}

View File

@@ -0,0 +1,50 @@
/*
* 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;
/**
* 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 some
* convenience classes that remote object implementations can extend which
* facilitate remote object creation. These classes are
* <code>java.rmi.server.UnicastRemoteObject</code> and
* <code>java.rmi.activation.Activatable</code>.
*
* <p>For complete details on RMI, see the <a
href=../../../platform/rmi/spec/rmiTOC.html>RMI Specification</a> which describes the RMI API and system.
*
* @since JDK1.1
* @author Ann Wollrath
* @see java.rmi.server.UnicastRemoteObject
* @see java.rmi.activation.Activatable
*/
public interface Remote {}

View 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</code> 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</code>, must list
* <code>RemoteException</code> 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</code> always throws {@link
* IllegalStateException}.
*
* @author Ann Wollrath
* @since JDK1.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</code>.
*/
public RemoteException() {
initCause(null); // Disallow subsequent initCause
}
/**
* Constructs a <code>RemoteException</code> 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</code> with the specified detail
* message and cause. This constructor sets the {@link #detail}
* field to the specified <code>Throwable</code>.
*
* @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 <tt>null</tt>.
* @since 1.4
*/
public Throwable getCause() {
return detail;
}
}

View 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 JDK1.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 JDK1.1
*/
public ServerError(String s, Error err) {
super(s, err);
}
}

View 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 JDK1.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 JDK1.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 JDK1.1
*/
public ServerException(String s, Exception ex) {
super(s, ex);
}
}

View File

@@ -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&nbsp;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 JDK1.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 JDK1.1
*/
@Deprecated
public ServerRuntimeException(String s, Exception ex) {
super(s, ex);
}
}

View 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>StubNotFoundException</code> is thrown if a valid stub class
* could not be found for a remote object when it is exported.
* A <code>StubNotFoundException</code> may also be
* thrown when an activatable object is registered via the
* <code>java.rmi.activation.Activatable.register</code> method.
*
* @author Roger Riggs
* @since JDK1.1
* @see java.rmi.server.UnicastRemoteObject
* @see java.rmi.activation.Activatable
*/
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 JDK1.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 JDK1.1
*/
public StubNotFoundException(String s, Exception ex) {
super(s, ex);
}
}

View 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 JDK1.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 JDK1.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 JDK1.1
*/
public UnexpectedException(String s, Exception ex) {
super(s, ex);
}
}

View 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;
/**
* 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 JDK1.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 JDK1.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 JDK1.1
*/
public UnknownHostException(String s, Exception ex) {
super(s, ex);
}
}

View 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 JDK1.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 JDK1.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 JDK1.1
*/
public UnmarshalException(String s, Exception ex) {
super(s, ex);
}
}

View File

@@ -0,0 +1,579 @@
/*
* Copyright (c) 1997, 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.activation;
import java.rmi.MarshalledObject;
import java.rmi.NoSuchObjectException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.activation.UnknownGroupException;
import java.rmi.activation.UnknownObjectException;
import java.rmi.server.RMIClientSocketFactory;
import java.rmi.server.RMIServerSocketFactory;
import java.rmi.server.RemoteServer;
import sun.rmi.server.ActivatableServerRef;
/**
* The <code>Activatable</code> class provides support for remote
* objects that require persistent access over time and that
* can be activated by the system.
*
* <p>For the constructors and static <code>exportObject</code> methods,
* the stub for a remote object being exported is obtained as described in
* {@link java.rmi.server.UnicastRemoteObject}.
*
* <p>An attempt to serialize explicitly an instance of this class will
* fail.
*
* @author Ann Wollrath
* @since 1.2
* @serial exclude
*/
public abstract class Activatable extends RemoteServer {
private ActivationID id;
/** indicate compatibility with the Java 2 SDK v1.2 version of class */
private static final long serialVersionUID = -3120617863591563455L;
/**
* Constructs an activatable remote object by registering
* an activation descriptor (with the specified location, data, and
* restart mode) for this object, and exporting the object with the
* specified port.
*
* <p><strong>Note:</strong> Using the <code>Activatable</code>
* constructors that both register and export an activatable remote
* object is strongly discouraged because the actions of registering
* and exporting the remote object are <i>not</i> guaranteed to be
* atomic. Instead, an application should register an activation
* descriptor and export a remote object separately, so that exceptions
* can be handled properly.
*
* <p>This method invokes the {@link
* #exportObject(Remote,String,MarshalledObject,boolean,int)
* exportObject} method with this object, and the specified location,
* data, restart mode, and port. Subsequent calls to {@link #getID}
* will return the activation identifier returned from the call to
* <code>exportObject</code>.
*
* @param location the location for classes for this object
* @param data the object's initialization data
* @param port the port on which the object is exported (an anonymous
* port is used if port=0)
* @param restart if true, the object is restarted (reactivated) when
* either the activator is restarted or the object's activation group
* is restarted after an unexpected crash; if false, the object is only
* activated on demand. Specifying <code>restart</code> to be
* <code>true</code> does not force an initial immediate activation of
* a newly registered object; initial activation is lazy.
* @exception ActivationException if object registration fails.
* @exception RemoteException if either of the following fails:
* a) registering the object with the activation system or b) exporting
* the object to the RMI runtime.
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation.
* @since 1.2
**/
protected Activatable(String location,
MarshalledObject<?> data,
boolean restart,
int port)
throws ActivationException, RemoteException
{
super();
id = exportObject(this, location, data, restart, port);
}
/**
* Constructs an activatable remote object by registering
* an activation descriptor (with the specified location, data, and
* restart mode) for this object, and exporting the object with the
* specified port, and specified client and server socket factories.
*
* <p><strong>Note:</strong> Using the <code>Activatable</code>
* constructors that both register and export an activatable remote
* object is strongly discouraged because the actions of registering
* and exporting the remote object are <i>not</i> guaranteed to be
* atomic. Instead, an application should register an activation
* descriptor and export a remote object separately, so that exceptions
* can be handled properly.
*
* <p>This method invokes the {@link
* #exportObject(Remote,String,MarshalledObject,boolean,int,RMIClientSocketFactory,RMIServerSocketFactory)
* exportObject} method with this object, and the specified location,
* data, restart mode, port, and client and server socket factories.
* Subsequent calls to {@link #getID} will return the activation
* identifier returned from the call to <code>exportObject</code>.
*
* @param location the location for classes for this object
* @param data the object's initialization data
* @param restart if true, the object is restarted (reactivated) when
* either the activator is restarted or the object's activation group
* is restarted after an unexpected crash; if false, the object is only
* activated on demand. Specifying <code>restart</code> to be
* <code>true</code> does not force an initial immediate activation of
* a newly registered object; initial activation is lazy.
* @param port the port on which the object is exported (an anonymous
* port is used if port=0)
* @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
* @exception ActivationException if object registration fails.
* @exception RemoteException if either of the following fails:
* a) registering the object with the activation system or b) exporting
* the object to the RMI runtime.
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation.
* @since 1.2
**/
protected Activatable(String location,
MarshalledObject<?> data,
boolean restart,
int port,
RMIClientSocketFactory csf,
RMIServerSocketFactory ssf)
throws ActivationException, RemoteException
{
super();
id = exportObject(this, location, data, restart, port, csf, ssf);
}
/**
* Constructor used to activate/export the object on a specified
* port. An "activatable" remote object must have a constructor that
* takes two arguments: <ul>
* <li>the object's activation identifier (<code>ActivationID</code>), and
* <li>the object's initialization data (a <code>MarshalledObject</code>).
* </ul><p>
*
* A concrete subclass of this class must call this constructor when it is
* <i>activated</i> via the two parameter constructor described above. As
* a side-effect of construction, the remote object is "exported"
* to the RMI runtime (on the specified <code>port</code>) and is
* available to accept incoming calls from clients.
*
* @param id activation identifier for the object
* @param port the port number on which the object is exported
* @exception RemoteException if exporting the object to the RMI
* runtime fails
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
protected Activatable(ActivationID id, int port)
throws RemoteException
{
super();
this.id = id;
exportObject(this, id, port);
}
/**
* Constructor used to activate/export the object on a specified
* port. An "activatable" remote object must have a constructor that
* takes two arguments: <ul>
* <li>the object's activation identifier (<code>ActivationID</code>), and
* <li>the object's initialization data (a <code>MarshalledObject</code>).
* </ul><p>
*
* A concrete subclass of this class must call this constructor when it is
* <i>activated</i> via the two parameter constructor described above. As
* a side-effect of construction, the remote object is "exported"
* to the RMI runtime (on the specified <code>port</code>) and is
* available to accept incoming calls from clients.
*
* @param id activation identifier for the object
* @param port the port number on which the object is exported
* @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
* @exception RemoteException if exporting the object to the RMI
* runtime fails
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
protected Activatable(ActivationID id, int port,
RMIClientSocketFactory csf,
RMIServerSocketFactory ssf)
throws RemoteException
{
super();
this.id = id;
exportObject(this, id, port, csf, ssf);
}
/**
* Returns the object's activation identifier. The method is
* protected so that only subclasses can obtain an object's
* identifier.
* @return the object's activation identifier
* @since 1.2
*/
protected ActivationID getID() {
return id;
}
/**
* Register an object descriptor for an activatable remote
* object so that is can be activated on demand.
*
* @param desc the object's descriptor
* @return the stub for the activatable remote object
* @exception UnknownGroupException if group id in <code>desc</code>
* is not registered with the activation system
* @exception ActivationException if activation system is not running
* @exception RemoteException if remote call fails
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
public static Remote register(ActivationDesc desc)
throws UnknownGroupException, ActivationException, RemoteException
{
// register object with activator.
ActivationID id =
ActivationGroup.getSystem().registerObject(desc);
return sun.rmi.server.ActivatableRef.getStub(desc, id);
}
/**
* Informs the system that the object with the corresponding activation
* <code>id</code> is currently inactive. If the object is currently
* active, the object is "unexported" from the RMI runtime (only if
* there are no pending or in-progress calls)
* so the that it can no longer receive incoming calls. This call
* informs this VM's ActivationGroup that the object is inactive,
* that, in turn, informs its ActivationMonitor. If this call
* completes successfully, a subsequent activate request to the activator
* will cause the object to reactivate. The operation may still
* succeed if the object is considered active but has already
* unexported itself.
*
* @param id the object's activation identifier
* @return true if the operation succeeds (the operation will
* succeed if the object in currently known to be active and is
* either already unexported or is currently exported and has no
* pending/executing calls); false is returned if the object has
* pending/executing calls in which case it cannot be deactivated
* @exception UnknownObjectException if object is not known (it may
* already be inactive)
* @exception ActivationException if group is not active
* @exception RemoteException if call informing monitor fails
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
public static boolean inactive(ActivationID id)
throws UnknownObjectException, ActivationException, RemoteException
{
return ActivationGroup.currentGroup().inactiveObject(id);
}
/**
* Revokes previous registration for the activation descriptor
* associated with <code>id</code>. An object can no longer be
* activated via that <code>id</code>.
*
* @param id the object's activation identifier
* @exception UnknownObjectException if object (<code>id</code>) is unknown
* @exception ActivationException if activation system is not running
* @exception RemoteException if remote call to activation system fails
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
public static void unregister(ActivationID id)
throws UnknownObjectException, ActivationException, RemoteException
{
ActivationGroup.getSystem().unregisterObject(id);
}
/**
* Registers an activation descriptor (with the specified location,
* data, and restart mode) for the specified object, and exports that
* object with the specified port.
*
* <p><strong>Note:</strong> Using this method (as well as the
* <code>Activatable</code> constructors that both register and export
* an activatable remote object) is strongly discouraged because the
* actions of registering and exporting the remote object are
* <i>not</i> guaranteed to be atomic. Instead, an application should
* register an activation descriptor and export a remote object
* separately, so that exceptions can be handled properly.
*
* <p>This method invokes the {@link
* #exportObject(Remote,String,MarshalledObject,boolean,int,RMIClientSocketFactory,RMIServerSocketFactory)
* exportObject} method with the specified object, location, data,
* restart mode, and port, and <code>null</code> for both client and
* server socket factories, and then returns the resulting activation
* identifier.
*
* @param obj the object being exported
* @param location the object's code location
* @param data the object's bootstrapping data
* @param restart if true, the object is restarted (reactivated) when
* either the activator is restarted or the object's activation group
* is restarted after an unexpected crash; if false, the object is only
* activated on demand. Specifying <code>restart</code> to be
* <code>true</code> does not force an initial immediate activation of
* a newly registered object; initial activation is lazy.
* @param port the port on which the object is exported (an anonymous
* port is used if port=0)
* @return the activation identifier obtained from registering the
* descriptor, <code>desc</code>, with the activation system
* the wrong group
* @exception ActivationException if activation group is not active
* @exception RemoteException if object registration or export fails
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
**/
public static ActivationID exportObject(Remote obj,
String location,
MarshalledObject<?> data,
boolean restart,
int port)
throws ActivationException, RemoteException
{
return exportObject(obj, location, data, restart, port, null, null);
}
/**
* Registers an activation descriptor (with the specified location,
* data, and restart mode) for the specified object, and exports that
* object with the specified port, and the specified client and server
* socket factories.
*
* <p><strong>Note:</strong> Using this method (as well as the
* <code>Activatable</code> constructors that both register and export
* an activatable remote object) is strongly discouraged because the
* actions of registering and exporting the remote object are
* <i>not</i> guaranteed to be atomic. Instead, an application should
* register an activation descriptor and export a remote object
* separately, so that exceptions can be handled properly.
*
* <p>This method first registers an activation descriptor for the
* specified object as follows. It obtains the activation system by
* invoking the method {@link ActivationGroup#getSystem
* ActivationGroup.getSystem}. This method then obtains an {@link
* ActivationID} for the object by invoking the activation system's
* {@link ActivationSystem#registerObject registerObject} method with
* an {@link ActivationDesc} constructed with the specified object's
* class name, and the specified location, data, and restart mode. If
* an exception occurs obtaining the activation system or registering
* the activation descriptor, that exception is thrown to the caller.
*
* <p>Next, this method exports the object by invoking the {@link
* #exportObject(Remote,ActivationID,int,RMIClientSocketFactory,RMIServerSocketFactory)
* exportObject} method with the specified remote object, the
* activation identifier obtained from registration, the specified
* port, and the specified client and server socket factories. If an
* exception occurs exporting the object, this method attempts to
* unregister the activation identifier (obtained from registration) by
* invoking the activation system's {@link
* ActivationSystem#unregisterObject unregisterObject} method with the
* activation identifier. If an exception occurs unregistering the
* identifier, that exception is ignored, and the original exception
* that occurred exporting the object is thrown to the caller.
*
* <p>Finally, this method invokes the {@link
* ActivationGroup#activeObject activeObject} method on the activation
* group in this VM with the activation identifier and the specified
* remote object, and returns the activation identifier to the caller.
*
* @param obj the object being exported
* @param location the object's code location
* @param data the object's bootstrapping data
* @param restart if true, the object is restarted (reactivated) when
* either the activator is restarted or the object's activation group
* is restarted after an unexpected crash; if false, the object is only
* activated on demand. Specifying <code>restart</code> to be
* <code>true</code> does not force an initial immediate activation of
* a newly registered object; initial activation is lazy.
* @param port the port on which the object is exported (an anonymous
* port is used if port=0)
* @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 the activation identifier obtained from registering the
* descriptor with the activation system
* @exception ActivationException if activation group is not active
* @exception RemoteException if object registration or export fails
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
**/
public static ActivationID exportObject(Remote obj,
String location,
MarshalledObject<?> data,
boolean restart,
int port,
RMIClientSocketFactory csf,
RMIServerSocketFactory ssf)
throws ActivationException, RemoteException
{
ActivationDesc desc = new ActivationDesc(obj.getClass().getName(),
location, data, restart);
/*
* Register descriptor.
*/
ActivationSystem system = ActivationGroup.getSystem();
ActivationID id = system.registerObject(desc);
/*
* Export object.
*/
try {
exportObject(obj, id, port, csf, ssf);
} catch (RemoteException e) {
/*
* Attempt to unregister activation descriptor because export
* failed and register/export should be atomic (see 4323621).
*/
try {
system.unregisterObject(id);
} catch (Exception ex) {
}
/*
* Report original exception.
*/
throw e;
}
/*
* This call can't fail (it is a local call, and the only possible
* exception, thrown if the group is inactive, will not be thrown
* because the group is not inactive).
*/
ActivationGroup.currentGroup().activeObject(id, obj);
return id;
}
/**
* Export the activatable remote object to the RMI runtime to make
* the object available to receive incoming calls. The object is
* exported on an anonymous port, if <code>port</code> is zero. <p>
*
* During activation, this <code>exportObject</code> method should
* be invoked explicitly by an "activatable" object, that does not
* extend the <code>Activatable</code> class. There is no need for objects
* that do extend the <code>Activatable</code> class to invoke this
* method directly because the object is exported during construction.
*
* @return the stub for the activatable remote object
* @param obj the remote object implementation
* @param id the object's activation identifier
* @param port the port on which the object is exported (an anonymous
* port is used if port=0)
* @exception RemoteException if object export fails
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
public static Remote exportObject(Remote obj,
ActivationID id,
int port)
throws RemoteException
{
return exportObject(obj, new ActivatableServerRef(id, port));
}
/**
* Export the activatable remote object to the RMI runtime to make
* the object available to receive incoming calls. The object is
* exported on an anonymous port, if <code>port</code> is zero. <p>
*
* During activation, this <code>exportObject</code> method should
* be invoked explicitly by an "activatable" object, that does not
* extend the <code>Activatable</code> class. There is no need for objects
* that do extend the <code>Activatable</code> class to invoke this
* method directly because the object is exported during construction.
*
* @return the stub for the activatable remote object
* @param obj the remote object implementation
* @param id the object's activation identifier
* @param port the port on which the object is exported (an anonymous
* port is used if port=0)
* @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
* @exception RemoteException if object export fails
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
public static Remote exportObject(Remote obj,
ActivationID id,
int port,
RMIClientSocketFactory csf,
RMIServerSocketFactory ssf)
throws RemoteException
{
return exportObject(obj, new ActivatableServerRef(id, port, csf, ssf));
}
/**
* Remove the remote object, obj, from the RMI runtime. If
* successful, the object can no longer accept incoming RMI calls.
* If the force parameter is true, the object is forcibly unexported
* even if there are pending calls to the remote object or the
* remote object still has calls in progress. If the force
* parameter is false, the object is only unexported if there are
* no pending or in progress calls to the object.
*
* @param obj the remote object to be unexported
* @param force if true, unexports the object even if there are
* pending or in-progress calls; if false, only unexports the object
* if there are no pending or in-progress calls
* @return true if operation is successful, false otherwise
* @exception NoSuchObjectException if the remote object is not
* currently exported
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
public static boolean unexportObject(Remote obj, boolean force)
throws NoSuchObjectException
{
return sun.rmi.transport.ObjectTable.unexportObject(obj, force);
}
/**
* Exports the specified object using the specified server ref.
*/
private static Remote exportObject(Remote obj, ActivatableServerRef sref)
throws RemoteException
{
// if obj extends Activatable, set its ref.
if (obj instanceof Activatable) {
((Activatable) obj).ref = sref;
}
return sref.exportObject(obj, null, false);
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 1998, 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.activation;
/**
* This exception is thrown by the RMI runtime when activation
* fails during a remote call to an activatable object.
*
* @author Ann Wollrath
* @since 1.2
*/
public class ActivateFailedException extends java.rmi.RemoteException {
/** indicate compatibility with the Java 2 SDK v1.2 version of class */
private static final long serialVersionUID = 4863550261346652506L;
/**
* Constructs an <code>ActivateFailedException</code> with the specified
* detail message.
*
* @param s the detail message
* @since 1.2
*/
public ActivateFailedException(String s) {
super(s);
}
/**
* Constructs an <code>ActivateFailedException</code> with the specified
* detail message and nested exception.
*
* @param s the detail message
* @param ex the nested exception
* @since 1.2
*/
public ActivateFailedException(String s, Exception ex) {
super(s, ex);
}
}

View File

@@ -0,0 +1,347 @@
/*
* Copyright (c) 1997, 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.activation;
import java.io.Serializable;
import java.rmi.MarshalledObject;
/**
* An activation descriptor contains the information necessary to
* activate an object: <ul>
* <li> the object's group identifier,
* <li> the object's fully-qualified class name,
* <li> the object's code location (the location of the class), a codebase URL
* path,
* <li> the object's restart "mode", and,
* <li> a "marshalled" object that can contain object specific
* initialization data. </ul>
*
* <p>A descriptor registered with the activation system can be used to
* recreate/activate the object specified by the descriptor. The
* <code>MarshalledObject</code> in the object's descriptor is passed
* as the second argument to the remote object's constructor for
* object to use during reinitialization/activation.
*
* @author Ann Wollrath
* @since 1.2
* @see java.rmi.activation.Activatable
*/
public final class ActivationDesc implements Serializable {
/**
* @serial the group's identifier
*/
private ActivationGroupID groupID;
/**
* @serial the object's class name
*/
private String className;
/**
* @serial the object's code location
*/
private String location;
/**
* @serial the object's initialization data
*/
private MarshalledObject<?> data;
/**
* @serial indicates whether the object should be restarted
*/
private boolean restart;
/** indicate compatibility with the Java 2 SDK v1.2 version of class */
private static final long serialVersionUID = 7455834104417690957L;
/**
* Constructs an object descriptor for an object whose class name
* is <code>className</code>, that can be loaded from the
* code <code>location</code> and whose initialization
* information is <code>data</code>. If this form of the constructor
* is used, the <code>groupID</code> defaults to the current id for
* <code>ActivationGroup</code> for this VM. All objects with the
* same <code>ActivationGroupID</code> are activated in the same VM.
*
* <p>Note that objects specified by a descriptor created with this
* constructor will only be activated on demand (by default, the restart
* mode is <code>false</code>). If an activatable object requires restart
* services, use one of the <code>ActivationDesc</code> constructors that
* takes a boolean parameter, <code>restart</code>.
*
* <p> This constructor will throw <code>ActivationException</code> if
* there is no current activation group for this VM. To create an
* <code>ActivationGroup</code> use the
* <code>ActivationGroup.createGroup</code> method.
*
* @param className the object's fully package qualified class name
* @param location the object's code location (from where the class is
* loaded)
* @param data the object's initialization (activation) data contained
* in marshalled form.
* @exception ActivationException if the current group is nonexistent
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
public ActivationDesc(String className,
String location,
MarshalledObject<?> data)
throws ActivationException
{
this(ActivationGroup.internalCurrentGroupID(),
className, location, data, false);
}
/**
* Constructs an object descriptor for an object whose class name
* is <code>className</code>, that can be loaded from the
* code <code>location</code> and whose initialization
* information is <code>data</code>. If this form of the constructor
* is used, the <code>groupID</code> defaults to the current id for
* <code>ActivationGroup</code> for this VM. All objects with the
* same <code>ActivationGroupID</code> are activated in the same VM.
*
* <p>This constructor will throw <code>ActivationException</code> if
* there is no current activation group for this VM. To create an
* <code>ActivationGroup</code> use the
* <code>ActivationGroup.createGroup</code> method.
*
* @param className the object's fully package qualified class name
* @param location the object's code location (from where the class is
* loaded)
* @param data the object's initialization (activation) data contained
* in marshalled form.
* @param restart if true, the object is restarted (reactivated) when
* either the activator is restarted or the object's activation group
* is restarted after an unexpected crash; if false, the object is only
* activated on demand. Specifying <code>restart</code> to be
* <code>true</code> does not force an initial immediate activation of
* a newly registered object; initial activation is lazy.
* @exception ActivationException if the current group is nonexistent
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
public ActivationDesc(String className,
String location,
MarshalledObject<?> data,
boolean restart)
throws ActivationException
{
this(ActivationGroup.internalCurrentGroupID(),
className, location, data, restart);
}
/**
* Constructs an object descriptor for an object whose class name
* is <code>className</code> that can be loaded from the
* code <code>location</code> and whose initialization
* information is <code>data</code>. All objects with the same
* <code>groupID</code> are activated in the same Java VM.
*
* <p>Note that objects specified by a descriptor created with this
* constructor will only be activated on demand (by default, the restart
* mode is <code>false</code>). If an activatable object requires restart
* services, use one of the <code>ActivationDesc</code> constructors that
* takes a boolean parameter, <code>restart</code>.
*
* @param groupID the group's identifier (obtained from registering
* <code>ActivationSystem.registerGroup</code> method). The group
* indicates the VM in which the object should be activated.
* @param className the object's fully package-qualified class name
* @param location the object's code location (from where the class is
* loaded)
* @param data the object's initialization (activation) data contained
* in marshalled form.
* @exception IllegalArgumentException if <code>groupID</code> is null
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
public ActivationDesc(ActivationGroupID groupID,
String className,
String location,
MarshalledObject<?> data)
{
this(groupID, className, location, data, false);
}
/**
* Constructs an object descriptor for an object whose class name
* is <code>className</code> that can be loaded from the
* code <code>location</code> and whose initialization
* information is <code>data</code>. All objects with the same
* <code>groupID</code> are activated in the same Java VM.
*
* @param groupID the group's identifier (obtained from registering
* <code>ActivationSystem.registerGroup</code> method). The group
* indicates the VM in which the object should be activated.
* @param className the object's fully package-qualified class name
* @param location the object's code location (from where the class is
* loaded)
* @param data the object's initialization (activation) data contained
* in marshalled form.
* @param restart if true, the object is restarted (reactivated) when
* either the activator is restarted or the object's activation group
* is restarted after an unexpected crash; if false, the object is only
* activated on demand. Specifying <code>restart</code> to be
* <code>true</code> does not force an initial immediate activation of
* a newly registered object; initial activation is lazy.
* @exception IllegalArgumentException if <code>groupID</code> is null
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
public ActivationDesc(ActivationGroupID groupID,
String className,
String location,
MarshalledObject<?> data,
boolean restart)
{
if (groupID == null)
throw new IllegalArgumentException("groupID can't be null");
this.groupID = groupID;
this.className = className;
this.location = location;
this.data = data;
this.restart = restart;
}
/**
* Returns the group identifier for the object specified by this
* descriptor. A group provides a way to aggregate objects into a
* single Java virtual machine. RMI creates/activates objects with
* the same <code>groupID</code> in the same virtual machine.
*
* @return the group identifier
* @since 1.2
*/
public ActivationGroupID getGroupID() {
return groupID;
}
/**
* Returns the class name for the object specified by this
* descriptor.
* @return the class name
* @since 1.2
*/
public String getClassName() {
return className;
}
/**
* Returns the code location for the object specified by
* this descriptor.
* @return the code location
* @since 1.2
*/
public String getLocation() {
return location;
}
/**
* Returns a "marshalled object" containing intialization/activation
* data for the object specified by this descriptor.
* @return the object specific "initialization" data
* @since 1.2
*/
public MarshalledObject<?> getData() {
return data;
}
/**
* Returns the "restart" mode of the object associated with
* this activation descriptor.
*
* @return true if the activatable object associated with this
* activation descriptor is restarted via the activation
* daemon when either the daemon comes up or the object's group
* is restarted after an unexpected crash; otherwise it returns false,
* meaning that the object is only activated on demand via a
* method call. Note that if the restart mode is <code>true</code>, the
* activator does not force an initial immediate activation of
* a newly registered object; initial activation is lazy.
* @since 1.2
*/
public boolean getRestartMode() {
return restart;
}
/**
* Compares two activation descriptors for content equality.
*
* @param obj the Object to compare with
* @return true if these Objects are equal; false otherwise.
* @see java.util.Hashtable
* @since 1.2
*/
public boolean equals(Object obj) {
if (obj instanceof ActivationDesc) {
ActivationDesc desc = (ActivationDesc) obj;
return
((groupID == null ? desc.groupID == null :
groupID.equals(desc.groupID)) &&
(className == null ? desc.className == null :
className.equals(desc.className)) &&
(location == null ? desc.location == null:
location.equals(desc.location)) &&
(data == null ? desc.data == null :
data.equals(desc.data)) &&
(restart == desc.restart));
} else {
return false;
}
}
/**
* Return the same hashCode for similar <code>ActivationDesc</code>s.
* @return an integer
* @see java.util.Hashtable
*/
public int hashCode() {
return ((location == null
? 0
: location.hashCode() << 24) ^
(groupID == null
? 0
: groupID.hashCode() << 16) ^
(className == null
? 0
: className.hashCode() << 9) ^
(data == null
? 0
: data.hashCode() << 1) ^
(restart
? 1
: 0));
}
}

View File

@@ -0,0 +1,118 @@
/*
* Copyright (c) 1997, 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.activation;
/**
* General exception used by the activation interfaces.
*
* <p>As of release 1.4, this exception has been retrofitted to conform to
* the general purpose exception-chaining mechanism. The "detail 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>ActivationException</code> always throws {@link
* IllegalStateException}.
*
* @author Ann Wollrath
* @since 1.2
*/
public class ActivationException extends Exception {
/**
* The cause of the activation 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;
/** indicate compatibility with the Java 2 SDK v1.2 version of class */
private static final long serialVersionUID = -4320118837291406071L;
/**
* Constructs an <code>ActivationException</code>.
*/
public ActivationException() {
initCause(null); // Disallow subsequent initCause
}
/**
* Constructs an <code>ActivationException</code> with the specified
* detail message.
*
* @param s the detail message
*/
public ActivationException(String s) {
super(s);
initCause(null); // Disallow subsequent initCause
}
/**
* Constructs an <code>ActivationException</code> with the specified
* detail message and cause. This constructor sets the {@link #detail}
* field to the specified <code>Throwable</code>.
*
* @param s the detail message
* @param cause the cause
*/
public ActivationException(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 <tt>null</tt>.
* @since 1.4
*/
public Throwable getCause() {
return detail;
}
}

View File

@@ -0,0 +1,538 @@
/*
* Copyright (c) 1997, 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.activation;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.rmi.MarshalledObject;
import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.activation.UnknownGroupException;
import java.rmi.activation.UnknownObjectException;
import java.rmi.server.RMIClassLoader;
import java.rmi.server.UnicastRemoteObject;
import java.security.AccessController;
import sun.security.action.GetIntegerAction;
/**
* An <code>ActivationGroup</code> is responsible for creating new
* instances of "activatable" objects in its group, informing its
* <code>ActivationMonitor</code> when either: its object's become
* active or inactive, or the group as a whole becomes inactive. <p>
*
* An <code>ActivationGroup</code> is <i>initially</i> created in one
* of several ways: <ul>
* <li>as a side-effect of creating an <code>ActivationDesc</code>
* without an explicit <code>ActivationGroupID</code> for the
* first activatable object in the group, or
* <li>via the <code>ActivationGroup.createGroup</code> method
* <li>as a side-effect of activating the first object in a group
* whose <code>ActivationGroupDesc</code> was only registered.</ul><p>
*
* Only the activator can <i>recreate</i> an
* <code>ActivationGroup</code>. The activator spawns, as needed, a
* separate VM (as a child process, for example) for each registered
* activation group and directs activation requests to the appropriate
* group. It is implementation specific how VMs are spawned. An
* activation group is created via the
* <code>ActivationGroup.createGroup</code> static method. The
* <code>createGroup</code> method has two requirements on the group
* to be created: 1) the group must be a concrete subclass of
* <code>ActivationGroup</code>, and 2) the group must have a
* constructor that takes two arguments:
*
* <ul>
* <li> the group's <code>ActivationGroupID</code>, and
* <li> the group's initialization data (in a
* <code>java.rmi.MarshalledObject</code>)</ul><p>
*
* When created, the default implementation of
* <code>ActivationGroup</code> will override the system properties
* with the properties requested when its
* <code>ActivationGroupDesc</code> was created, and will set a
* {@link SecurityManager} as the default system
* security manager. If your application requires specific properties
* to be set when objects are activated in the group, the application
* should create a special <code>Properties</code> object containing
* these properties, then create an <code>ActivationGroupDesc</code>
* with the <code>Properties</code> object, and use
* <code>ActivationGroup.createGroup</code> before creating any
* <code>ActivationDesc</code>s (before the default
* <code>ActivationGroupDesc</code> is created). If your application
* requires the use of a security manager other than
* {@link SecurityManager}, in the
* ActivativationGroupDescriptor properties list you can set
* <code>java.security.manager</code> property to the name of the security
* manager you would like to install.
*
* @author Ann Wollrath
* @see ActivationInstantiator
* @see ActivationGroupDesc
* @see ActivationGroupID
* @since 1.2
*/
public abstract class ActivationGroup
extends UnicastRemoteObject
implements ActivationInstantiator
{
/**
* @serial the group's identifier
*/
private ActivationGroupID groupID;
/**
* @serial the group's monitor
*/
private ActivationMonitor monitor;
/**
* @serial the group's incarnation number
*/
private long incarnation;
/** the current activation group for this VM */
private static ActivationGroup currGroup;
/** the current group's identifier */
private static ActivationGroupID currGroupID;
/** the current group's activation system */
private static ActivationSystem currSystem;
/** used to control a group being created only once */
private static boolean canCreate = true;
/** indicate compatibility with the Java 2 SDK v1.2 version of class */
private static final long serialVersionUID = -7696947875314805420L;
/**
* Constructs an activation group with the given activation group
* identifier. The group is exported as a
* <code>java.rmi.server.UnicastRemoteObject</code>.
*
* @param groupID the group's identifier
* @throws RemoteException if this group could not be exported
* @throws UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
protected ActivationGroup(ActivationGroupID groupID)
throws RemoteException
{
// call super constructor to export the object
super();
this.groupID = groupID;
}
/**
* The group's <code>inactiveObject</code> method is called
* indirectly via a call to the <code>Activatable.inactive</code>
* method. A remote object implementation must call
* <code>Activatable</code>'s <code>inactive</code> method when
* that object deactivates (the object deems that it is no longer
* active). If the object does not call
* <code>Activatable.inactive</code> when it deactivates, the
* object will never be garbage collected since the group keeps
* strong references to the objects it creates.
*
* <p>The group's <code>inactiveObject</code> method unexports the
* remote object from the RMI runtime so that the object can no
* longer receive incoming RMI calls. An object will only be unexported
* if the object has no pending or executing calls.
* The subclass of <code>ActivationGroup</code> must override this
* method and unexport the object.
*
* <p>After removing the object from the RMI runtime, the group
* must inform its <code>ActivationMonitor</code> (via the monitor's
* <code>inactiveObject</code> method) that the remote object is
* not currently active so that the remote object will be
* re-activated by the activator upon a subsequent activation
* request.
*
* <p>This method simply informs the group's monitor that the object
* is inactive. It is up to the concrete subclass of ActivationGroup
* to fulfill the additional requirement of unexporting the object. <p>
*
* @param id the object's activation identifier
* @return true if the object was successfully deactivated; otherwise
* returns false.
* @exception UnknownObjectException if object is unknown (may already
* be inactive)
* @exception RemoteException if call informing monitor fails
* @exception ActivationException if group is inactive
* @since 1.2
*/
public boolean inactiveObject(ActivationID id)
throws ActivationException, UnknownObjectException, RemoteException
{
getMonitor().inactiveObject(id);
return true;
}
/**
* The group's <code>activeObject</code> method is called when an
* object is exported (either by <code>Activatable</code> object
* construction or an explicit call to
* <code>Activatable.exportObject</code>. The group must inform its
* <code>ActivationMonitor</code> that the object is active (via
* the monitor's <code>activeObject</code> method) if the group
* hasn't already done so.
*
* @param id the object's identifier
* @param obj the remote object implementation
* @exception UnknownObjectException if object is not registered
* @exception RemoteException if call informing monitor fails
* @exception ActivationException if group is inactive
* @since 1.2
*/
public abstract void activeObject(ActivationID id, Remote obj)
throws ActivationException, UnknownObjectException, RemoteException;
/**
* Create and set the activation group for the current VM. The
* activation group can only be set if it is not currently set.
* An activation group is set using the <code>createGroup</code>
* method when the <code>Activator</code> initiates the
* re-creation of an activation group in order to carry out
* incoming <code>activate</code> requests. A group must first be
* registered with the <code>ActivationSystem</code> before it can
* be created via this method.
*
* <p>The group class specified by the
* <code>ActivationGroupDesc</code> must be a concrete subclass of
* <code>ActivationGroup</code> and have a public constructor that
* takes two arguments: the <code>ActivationGroupID</code> for the
* group and the <code>MarshalledObject</code> containing the
* group's initialization data (obtained from the
* <code>ActivationGroupDesc</code>.
*
* <p>If the group class name specified in the
* <code>ActivationGroupDesc</code> is <code>null</code>, then
* this method will behave as if the group descriptor contained
* the name of the default activation group implementation class.
*
* <p>Note that if your application creates its own custom
* activation group, a security manager must be set for that
* group. Otherwise objects cannot be activated in the group.
* {@link SecurityManager} is set by default.
*
* <p>If a security manager is already set in the group VM, this
* method first calls the security manager's
* <code>checkSetFactory</code> method. This could result in a
* <code>SecurityException</code>. If your application needs to
* set a different security manager, you must ensure that the
* policy file specified by the group's
* <code>ActivationGroupDesc</code> grants the group the necessary
* permissions to set a new security manager. (Note: This will be
* necessary if your group downloads and sets a security manager).
*
* <p>After the group is created, the
* <code>ActivationSystem</code> is informed that the group is
* active by calling the <code>activeGroup</code> method which
* returns the <code>ActivationMonitor</code> for the group. The
* application need not call <code>activeGroup</code>
* independently since it is taken care of by this method.
*
* <p>Once a group is created, subsequent calls to the
* <code>currentGroupID</code> method will return the identifier
* for this group until the group becomes inactive.
*
* @param id the activation group's identifier
* @param desc the activation group's descriptor
* @param incarnation the group's incarnation number (zero on group's
* initial creation)
* @return the activation group for the VM
* @exception ActivationException if group already exists or if error
* occurs during group creation
* @exception SecurityException if permission to create group is denied.
* (Note: The default implementation of the security manager
* <code>checkSetFactory</code>
* method requires the RuntimePermission "setFactory")
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @see SecurityManager#checkSetFactory
* @since 1.2
*/
public static synchronized
ActivationGroup createGroup(ActivationGroupID id,
final ActivationGroupDesc desc,
long incarnation)
throws ActivationException
{
SecurityManager security = System.getSecurityManager();
if (security != null)
security.checkSetFactory();
if (currGroup != null)
throw new ActivationException("group already exists");
if (canCreate == false)
throw new ActivationException("group deactivated and " +
"cannot be recreated");
try {
// load group's class
String groupClassName = desc.getClassName();
Class<? extends ActivationGroup> cl;
Class<? extends ActivationGroup> defaultGroupClass =
sun.rmi.server.ActivationGroupImpl.class;
if (groupClassName == null || // see 4252236
groupClassName.equals(defaultGroupClass.getName()))
{
cl = defaultGroupClass;
} else {
Class<?> cl0;
try {
cl0 = RMIClassLoader.loadClass(desc.getLocation(),
groupClassName);
} catch (Exception ex) {
throw new ActivationException(
"Could not load group implementation class", ex);
}
if (ActivationGroup.class.isAssignableFrom(cl0)) {
cl = cl0.asSubclass(ActivationGroup.class);
} else {
throw new ActivationException("group not correct class: " +
cl0.getName());
}
}
// create group
Constructor<? extends ActivationGroup> constructor =
cl.getConstructor(ActivationGroupID.class,
MarshalledObject.class);
ActivationGroup newGroup =
constructor.newInstance(id, desc.getData());
currSystem = id.getSystem();
newGroup.incarnation = incarnation;
newGroup.monitor =
currSystem.activeGroup(id, newGroup, incarnation);
currGroup = newGroup;
currGroupID = id;
canCreate = false;
} catch (InvocationTargetException e) {
e.getTargetException().printStackTrace();
throw new ActivationException("exception in group constructor",
e.getTargetException());
} catch (ActivationException e) {
throw e;
} catch (Exception e) {
throw new ActivationException("exception creating group", e);
}
return currGroup;
}
/**
* Returns the current activation group's identifier. Returns null
* if no group is currently active for this VM.
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @return the activation group's identifier
* @since 1.2
*/
public static synchronized ActivationGroupID currentGroupID() {
return currGroupID;
}
/**
* Returns the activation group identifier for the VM. If an
* activation group does not exist for this VM, a default
* activation group is created. A group can be created only once,
* so if a group has already become active and deactivated.
*
* @return the activation group identifier
* @exception ActivationException if error occurs during group
* creation, if security manager is not set, or if the group
* has already been created and deactivated.
*/
static synchronized ActivationGroupID internalCurrentGroupID()
throws ActivationException
{
if (currGroupID == null)
throw new ActivationException("nonexistent group");
return currGroupID;
}
/**
* Set the activation system for the VM. The activation system can
* only be set it if no group is currently active. If the activation
* system is not set via this call, then the <code>getSystem</code>
* method attempts to obtain a reference to the
* <code>ActivationSystem</code> by looking up the name
* "java.rmi.activation.ActivationSystem" in the Activator's
* registry. By default, the port number used to look up the
* activation system is defined by
* <code>ActivationSystem.SYSTEM_PORT</code>. This port can be overridden
* by setting the property <code>java.rmi.activation.port</code>.
*
* <p>If there is a security manager, this method first
* calls the security manager's <code>checkSetFactory</code> method.
* This could result in a SecurityException.
*
* @param system remote reference to the <code>ActivationSystem</code>
* @exception ActivationException if activation system is already set
* @exception SecurityException if permission to set the activation system is denied.
* (Note: The default implementation of the security manager
* <code>checkSetFactory</code>
* method requires the RuntimePermission "setFactory")
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @see #getSystem
* @see SecurityManager#checkSetFactory
* @since 1.2
*/
public static synchronized void setSystem(ActivationSystem system)
throws ActivationException
{
SecurityManager security = System.getSecurityManager();
if (security != null)
security.checkSetFactory();
if (currSystem != null)
throw new ActivationException("activation system already set");
currSystem = system;
}
/**
* Returns the activation system for the VM. The activation system
* may be set by the <code>setSystem</code> method. If the
* activation system is not set via the <code>setSystem</code>
* method, then the <code>getSystem</code> method attempts to
* obtain a reference to the <code>ActivationSystem</code> by
* looking up the name "java.rmi.activation.ActivationSystem" in
* the Activator's registry. By default, the port number used to
* look up the activation system is defined by
* <code>ActivationSystem.SYSTEM_PORT</code>. This port can be
* overridden by setting the property
* <code>java.rmi.activation.port</code>.
*
* @return the activation system for the VM/group
* @exception ActivationException if activation system cannot be
* obtained or is not bound
* (means that it is not running)
* @exception UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @see #setSystem
* @since 1.2
*/
public static synchronized ActivationSystem getSystem()
throws ActivationException
{
if (currSystem == null) {
try {
int port = AccessController.doPrivileged(
new GetIntegerAction("java.rmi.activation.port",
ActivationSystem.SYSTEM_PORT));
currSystem = (ActivationSystem)
Naming.lookup("//:" + port +
"/java.rmi.activation.ActivationSystem");
} catch (Exception e) {
throw new ActivationException(
"unable to obtain ActivationSystem", e);
}
}
return currSystem;
}
/**
* This protected method is necessary for subclasses to
* make the <code>activeObject</code> callback to the group's
* monitor. The call is simply forwarded to the group's
* <code>ActivationMonitor</code>.
*
* @param id the object's identifier
* @param mobj a marshalled object containing the remote object's stub
* @exception UnknownObjectException if object is not registered
* @exception RemoteException if call informing monitor fails
* @exception ActivationException if an activation error occurs
* @since 1.2
*/
protected void activeObject(ActivationID id,
MarshalledObject<? extends Remote> mobj)
throws ActivationException, UnknownObjectException, RemoteException
{
getMonitor().activeObject(id, mobj);
}
/**
* This protected method is necessary for subclasses to
* make the <code>inactiveGroup</code> callback to the group's
* monitor. The call is simply forwarded to the group's
* <code>ActivationMonitor</code>. Also, the current group
* for the VM is set to null.
*
* @exception UnknownGroupException if group is not registered
* @exception RemoteException if call informing monitor fails
* @since 1.2
*/
protected void inactiveGroup()
throws UnknownGroupException, RemoteException
{
try {
getMonitor().inactiveGroup(groupID, incarnation);
} finally {
destroyGroup();
}
}
/**
* Returns the monitor for the activation group.
*/
private ActivationMonitor getMonitor() throws RemoteException {
synchronized (ActivationGroup.class) {
if (monitor != null) {
return monitor;
}
}
throw new RemoteException("monitor not received");
}
/**
* Destroys the current group.
*/
private static synchronized void destroyGroup() {
currGroup = null;
currGroupID = null;
// NOTE: don't set currSystem to null since it may be needed
}
/**
* Returns the current group for the VM.
* @exception ActivationException if current group is null (not active)
*/
static synchronized ActivationGroup currentGroup()
throws ActivationException
{
if (currGroup == null) {
throw new ActivationException("group is not active");
}
return currGroup;
}
}

View File

@@ -0,0 +1,370 @@
/*
* Copyright (c) 1997, 2008, 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.activation;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.rmi.MarshalledObject;
import java.util.Arrays;
import java.util.Properties;
/**
* An activation group descriptor contains the information necessary to
* create/recreate an activation group in which to activate objects.
* Such a descriptor contains: <ul>
* <li> the group's class name,
* <li> the group's code location (the location of the group's class), and
* <li> a "marshalled" object that can contain group specific
* initialization data. </ul> <p>
*
* The group's class must be a concrete subclass of
* <code>ActivationGroup</code>. A subclass of
* <code>ActivationGroup</code> is created/recreated via the
* <code>ActivationGroup.createGroup</code> static method that invokes
* a special constructor that takes two arguments: <ul>
*
* <li> the group's <code>ActivationGroupID</code>, and
* <li> the group's initialization data (in a
* <code>java.rmi.MarshalledObject</code>)</ul><p>
*
* @author Ann Wollrath
* @since 1.2
* @see ActivationGroup
* @see ActivationGroupID
*/
public final class ActivationGroupDesc implements Serializable {
/**
* @serial The group's fully package qualified class name.
*/
private String className;
/**
* @serial The location from where to load the group's class.
*/
private String location;
/**
* @serial The group's initialization data.
*/
private MarshalledObject<?> data;
/**
* @serial The controlling options for executing the VM in
* another process.
*/
private CommandEnvironment env;
/**
* @serial A properties map which will override those set
* by default in the subprocess environment.
*/
private Properties props;
/** indicate compatibility with the Java 2 SDK v1.2 version of class */
private static final long serialVersionUID = -4936225423168276595L;
/**
* Constructs a group descriptor that uses the system defaults for group
* implementation and code location. Properties specify Java
* environment overrides (which will override system properties in
* the group implementation's VM). The command
* environment can control the exact command/options used in
* starting the child VM, or can be <code>null</code> to accept
* rmid's default.
*
* <p>This constructor will create an <code>ActivationGroupDesc</code>
* with a <code>null</code> group class name, which indicates the system's
* default <code>ActivationGroup</code> implementation.
*
* @param overrides the set of properties to set when the group is
* recreated.
* @param cmd the controlling options for executing the VM in
* another process (or <code>null</code>).
* @since 1.2
*/
public ActivationGroupDesc(Properties overrides,
CommandEnvironment cmd)
{
this(null, null, null, overrides, cmd);
}
/**
* Specifies an alternate group implementation and execution
* environment to be used for the group.
*
* @param className the group's package qualified class name or
* <code>null</code>. A <code>null</code> group class name indicates
* the system's default <code>ActivationGroup</code> implementation.
* @param location the location from where to load the group's
* class
* @param data the group's initialization data contained in
* marshalled form (could contain properties, for example)
* @param overrides a properties map which will override those set
* by default in the subprocess environment (will be translated
* into <code>-D</code> options), or <code>null</code>.
* @param cmd the controlling options for executing the VM in
* another process (or <code>null</code>).
* @since 1.2
*/
public ActivationGroupDesc(String className,
String location,
MarshalledObject<?> data,
Properties overrides,
CommandEnvironment cmd)
{
this.props = overrides;
this.env = cmd;
this.data = data;
this.location = location;
this.className = className;
}
/**
* Returns the group's class name (possibly <code>null</code>). A
* <code>null</code> group class name indicates the system's default
* <code>ActivationGroup</code> implementation.
* @return the group's class name
* @since 1.2
*/
public String getClassName() {
return className;
}
/**
* Returns the group's code location.
* @return the group's code location
* @since 1.2
*/
public String getLocation() {
return location;
}
/**
* Returns the group's initialization data.
* @return the group's initialization data
* @since 1.2
*/
public MarshalledObject<?> getData() {
return data;
}
/**
* Returns the group's property-override list.
* @return the property-override list, or <code>null</code>
* @since 1.2
*/
public Properties getPropertyOverrides() {
return (props != null) ? (Properties) props.clone() : null;
}
/**
* Returns the group's command-environment control object.
* @return the command-environment object, or <code>null</code>
* @since 1.2
*/
public CommandEnvironment getCommandEnvironment() {
return this.env;
}
/**
* Startup options for ActivationGroup implementations.
*
* This class allows overriding default system properties and
* specifying implementation-defined options for ActivationGroups.
* @since 1.2
*/
public static class CommandEnvironment implements Serializable {
private static final long serialVersionUID = 6165754737887770191L;
/**
* @serial
*/
private String command;
/**
* @serial
*/
private String[] options;
/**
* Create a CommandEnvironment with all the necessary
* information.
*
* @param cmdpath the name of the java executable, including
* the full path, or <code>null</code>, meaning "use rmid's default".
* The named program <em>must</em> be able to accept multiple
* <code>-Dpropname=value</code> options (as documented for the
* "java" tool)
*
* @param argv extra options which will be used in creating the
* ActivationGroup. Null has the same effect as an empty
* list.
* @since 1.2
*/
public CommandEnvironment(String cmdpath,
String[] argv)
{
this.command = cmdpath; // might be null
// Hold a safe copy of argv in this.options
if (argv == null) {
this.options = new String[0];
} else {
this.options = new String[argv.length];
System.arraycopy(argv, 0, this.options, 0, argv.length);
}
}
/**
* Fetch the configured path-qualified java command name.
*
* @return the configured name, or <code>null</code> if configured to
* accept the default
* @since 1.2
*/
public String getCommandPath() {
return (this.command);
}
/**
* Fetch the configured java command options.
*
* @return An array of the command options which will be passed
* to the new child command by rmid.
* Note that rmid may add other options before or after these
* options, or both.
* Never returns <code>null</code>.
* @since 1.2
*/
public String[] getCommandOptions() {
return options.clone();
}
/**
* Compares two command environments for content equality.
*
* @param obj the Object to compare with
* @return true if these Objects are equal; false otherwise.
* @see java.util.Hashtable
* @since 1.2
*/
public boolean equals(Object obj) {
if (obj instanceof CommandEnvironment) {
CommandEnvironment env = (CommandEnvironment) obj;
return
((command == null ? env.command == null :
command.equals(env.command)) &&
Arrays.equals(options, env.options));
} else {
return false;
}
}
/**
* Return identical values for similar
* <code>CommandEnvironment</code>s.
* @return an integer
* @see java.util.Hashtable
*/
public int hashCode()
{
// hash command and ignore possibly expensive options
return (command == null ? 0 : command.hashCode());
}
/**
* <code>readObject</code> for custom serialization.
*
* <p>This method reads this object's serialized form for this
* class as follows:
*
* <p>This method first invokes <code>defaultReadObject</code> on
* the specified object input stream, and if <code>options</code>
* is <code>null</code>, then <code>options</code> is set to a
* zero-length array of <code>String</code>.
*/
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
in.defaultReadObject();
if (options == null) {
options = new String[0];
}
}
}
/**
* Compares two activation group descriptors for content equality.
*
* @param obj the Object to compare with
* @return true if these Objects are equal; false otherwise.
* @see java.util.Hashtable
* @since 1.2
*/
public boolean equals(Object obj) {
if (obj instanceof ActivationGroupDesc) {
ActivationGroupDesc desc = (ActivationGroupDesc) obj;
return
((className == null ? desc.className == null :
className.equals(desc.className)) &&
(location == null ? desc.location == null :
location.equals(desc.location)) &&
(data == null ? desc.data == null : data.equals(desc.data)) &&
(env == null ? desc.env == null : env.equals(desc.env)) &&
(props == null ? desc.props == null :
props.equals(desc.props)));
} else {
return false;
}
}
/**
* Produce identical numbers for similar <code>ActivationGroupDesc</code>s.
* @return an integer
* @see java.util.Hashtable
*/
public int hashCode() {
// hash location, className, data, and env
// but omit props (may be expensive)
return ((location == null
? 0
: location.hashCode() << 24) ^
(env == null
? 0
: env.hashCode() << 16) ^
(className == null
? 0
: className.hashCode() << 8) ^
(data == null
? 0
: data.hashCode()));
}
}

View File

@@ -0,0 +1,117 @@
/*
* Copyright (c) 1997, 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.activation;
import java.rmi.server.UID;
/**
* The identifier for a registered activation group serves several
* purposes: <ul>
* <li>identifies the group uniquely within the activation system, and
* <li>contains a reference to the group's activation system so that the
* group can contact its activation system when necessary.</ul><p>
*
* The <code>ActivationGroupID</code> is returned from the call to
* <code>ActivationSystem.registerGroup</code> and is used to identify
* the group within the activation system. This group id is passed
* as one of the arguments to the activation group's special constructor
* when an activation group is created/recreated.
*
* @author Ann Wollrath
* @see ActivationGroup
* @see ActivationGroupDesc
* @since 1.2
*/
public class ActivationGroupID implements java.io.Serializable {
/**
* @serial The group's activation system.
*/
private ActivationSystem system;
/**
* @serial The group's unique id.
*/
private UID uid = new UID();
/** indicate compatibility with the Java 2 SDK v1.2 version of class */
private static final long serialVersionUID = -1648432278909740833L;
/**
* Constructs a unique group id.
*
* @param system the group's activation system
* @throws UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
public ActivationGroupID(ActivationSystem system) {
this.system = system;
}
/**
* Returns the group's activation system.
* @return the group's activation system
* @since 1.2
*/
public ActivationSystem getSystem() {
return system;
}
/**
* Returns a hashcode for the group's identifier. Two group
* identifiers that refer to the same remote group will have the
* same hash code.
*
* @see java.util.Hashtable
* @since 1.2
*/
public int hashCode() {
return uid.hashCode();
}
/**
* Compares two group identifiers for content equality.
* Returns true if both of the following conditions are true:
* 1) the unique identifiers are equivalent (by content), and
* 2) the activation system specified in each
* refers to the same remote object.
*
* @param obj the Object to compare with
* @return true if these Objects are equal; false otherwise.
* @see java.util.Hashtable
* @since 1.2
*/
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj instanceof ActivationGroupID) {
ActivationGroupID id = (ActivationGroupID)obj;
return (uid.equals(id.uid) && system.equals(id.system));
} else {
return false;
}
}
}

View File

@@ -0,0 +1,312 @@
/*
* Copyright (c) 1997, 2017, 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.activation;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.rmi.MarshalledObject;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.UnmarshalException;
import java.rmi.server.RemoteObject;
import java.rmi.server.RemoteObjectInvocationHandler;
import java.rmi.server.RemoteRef;
import java.rmi.server.UID;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.Permissions;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.ProtectionDomain;
/**
* Activation makes use of special identifiers to denote remote
* objects that can be activated over time. An activation identifier
* (an instance of the class <code>ActivationID</code>) contains several
* pieces of information needed for activating an object:
* <ul>
* <li> a remote reference to the object's activator (a {@link
* java.rmi.server.RemoteRef RemoteRef}
* instance), and
* <li> a unique identifier (a {@link java.rmi.server.UID UID}
* instance) for the object. </ul> <p>
*
* An activation identifier for an object can be obtained by registering
* an object with the activation system. Registration is accomplished
* in a few ways: <ul>
* <li>via the <code>Activatable.register</code> method
* <li>via the first <code>Activatable</code> constructor (that takes
* three arguments and both registers and exports the object, and
* <li>via the first <code>Activatable.exportObject</code> method
* that takes the activation descriptor, object and port as arguments;
* this method both registers and exports the object. </ul>
*
* @author Ann Wollrath
* @see Activatable
* @since 1.2
*/
public class ActivationID implements Serializable {
/**
* the object's activator
*/
private transient Activator activator;
/**
* the object's unique id
*/
private transient UID uid = new UID();
/** indicate compatibility with the Java 2 SDK v1.2 version of class */
private static final long serialVersionUID = -4608673054848209235L;
/** an AccessControlContext with no permissions */
private static final AccessControlContext NOPERMS_ACC;
static {
Permissions perms = new Permissions();
ProtectionDomain[] pd = { new ProtectionDomain(null, perms) };
NOPERMS_ACC = new AccessControlContext(pd);
}
/**
* The constructor for <code>ActivationID</code> takes a single
* argument, activator, that specifies a remote reference to the
* activator responsible for activating the object associated with
* this identifier. An instance of <code>ActivationID</code> is globally
* unique.
*
* @param activator reference to the activator responsible for
* activating the object
* @throws UnsupportedOperationException if and only if activation is
* not supported by this implementation
* @since 1.2
*/
public ActivationID(Activator activator) {
this.activator = activator;
}
/**
* Activate the object for this id.
*
* @param force if true, forces the activator to contact the group
* when activating the object (instead of returning a cached reference);
* if false, returning a cached value is acceptable.
* @return the reference to the active remote object
* @exception ActivationException if activation fails
* @exception UnknownObjectException if the object is unknown
* @exception RemoteException if remote call fails
* @since 1.2
*/
public Remote activate(boolean force)
throws ActivationException, UnknownObjectException, RemoteException
{
try {
MarshalledObject<? extends Remote> mobj =
activator.activate(this, force);
return AccessController.doPrivileged(
new PrivilegedExceptionAction<Remote>() {
public Remote run() throws IOException, ClassNotFoundException {
return mobj.get();
}
}, NOPERMS_ACC);
} catch (PrivilegedActionException pae) {
Exception ex = pae.getException();
if (ex instanceof RemoteException) {
throw (RemoteException) ex;
} else {
throw new UnmarshalException("activation failed", ex);
}
}
}
/**
* Returns a hashcode for the activation id. Two identifiers that
* refer to the same remote object will have the same hash code.
*
* @see java.util.Hashtable
* @since 1.2
*/
public int hashCode() {
return uid.hashCode();
}
/**
* Compares two activation ids for content equality.
* Returns true if both of the following conditions are true:
* 1) the unique identifiers equivalent (by content), and
* 2) the activator specified in each identifier
* refers to the same remote object.
*
* @param obj the Object to compare with
* @return true if these Objects are equal; false otherwise.
* @see java.util.Hashtable
* @since 1.2
*/
public boolean equals(Object obj) {
if (obj instanceof ActivationID) {
ActivationID id = (ActivationID) obj;
return (uid.equals(id.uid) && activator.equals(id.activator));
} else {
return false;
}
}
/**
* <code>writeObject</code> for custom serialization.
*
* <p>This method writes this object's serialized form for
* this class as follows:
*
* <p>The <code>writeObject</code> method is invoked on
* <code>out</code> passing this object's unique identifier
* (a {@link java.rmi.server.UID UID} instance) as the argument.
*
* <p>Next, the {@link
* java.rmi.server.RemoteRef#getRefClass(java.io.ObjectOutput)
* getRefClass} method is invoked on the activator's
* <code>RemoteRef</code> instance to obtain its external ref
* type name. Next, 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 the
* <code>RemoteRef</code> instance passing <code>out</code>
* as the argument.
*
* @serialData The serialized data for this class comprises a
* <code>java.rmi.server.UID</code> (written with
* <code>ObjectOutput.writeObject</code>) followed by the
* external ref type name of the activator's
* <code>RemoteRef</code> instance (a string written with
* <code>ObjectOutput.writeUTF</code>), followed by the
* external form of the <code>RemoteRef</code> instance as
* written by its <code>writeExternal</code> method.
*
* <p>The external ref type name of the
* <code>RemoteRef</Code> instance is
* determined using the definitions of external ref type
* names specified in the {@link java.rmi.server.RemoteObject
* RemoteObject} <code>writeObject</code> method
* <b>serialData</b> specification. Similarly, the data
* written by the <code>writeExternal</code> method and read
* by the <code>readExternal</code> method of
* <code>RemoteRef</code> implementation classes
* corresponding to each of the defined external ref type
* names is specified in the {@link
* java.rmi.server.RemoteObject RemoteObject}
* <code>writeObject</code> method <b>serialData</b>
* specification.
**/
private void writeObject(ObjectOutputStream out)
throws IOException, ClassNotFoundException
{
out.writeObject(uid);
RemoteRef ref;
if (activator instanceof RemoteObject) {
ref = ((RemoteObject) activator).getRef();
} else if (Proxy.isProxyClass(activator.getClass())) {
InvocationHandler handler = Proxy.getInvocationHandler(activator);
if (!(handler instanceof RemoteObjectInvocationHandler)) {
throw new InvalidObjectException(
"unexpected invocation handler");
}
ref = ((RemoteObjectInvocationHandler) handler).getRef();
} else {
throw new InvalidObjectException("unexpected activator type");
}
out.writeUTF(ref.getRefClass(out));
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>readObject</code> method is invoked on
* <code>in</code> to read this object's unique identifier
* (a {@link java.rmi.server.UID UID} instance).
*
* <p>Next, the <code>readUTF</code> method is invoked on
* <code>in</code> to read the external ref type name of the
* <code>RemoteRef</code> instance for this object's
* activator. Next, the <code>RemoteRef</code>
* instance is created of an implementation-specific class
* corresponding to the external ref type name (returned by
* <code>readUTF</code>), and the <code>readExternal</code>
* method is invoked on that <code>RemoteRef</code> instance
* to read the external form corresponding to the external
* ref type name.
*
* <p>Note: If the external ref type name is
* <code>"UnicastRef"</code>, <code>"UnicastServerRef"</code>,
* <code>"UnicastRef2"</code>, <code>"UnicastServerRef2"</code>,
* or <code>"ActivatableRef"</code>, a corresponding
* implementation-specific class must be found, and its
* <code>readExternal</code> method must read the serial data
* for that external ref type name as specified to be written
* in the <b>serialData</b> documentation for this class.
* If the external ref type name is any other string (of non-zero
* length), a <code>ClassNotFoundException</code> will be thrown,
* unless the implementation provides an implementation-specific
* class corresponding to that external ref type name, in which
* case the <code>RemoteRef</code> will be an instance of
* that implementation-specific class.
*/
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
uid = (UID)in.readObject();
try {
Class<? extends RemoteRef> refClass =
Class.forName(RemoteRef.packagePrefix + "." + in.readUTF())
.asSubclass(RemoteRef.class);
RemoteRef ref = refClass.newInstance();
ref.readExternal(in);
activator = (Activator)
Proxy.newProxyInstance(null,
new Class<?>[] { Activator.class },
new RemoteObjectInvocationHandler(ref));
} catch (InstantiationException e) {
throw (IOException)
new InvalidObjectException(
"Unable to create remote reference").initCause(e);
} catch (IllegalAccessException e) {
throw (IOException)
new InvalidObjectException(
"Unable to create remote reference").initCause(e);
}
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 1997, 2005, 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.activation;
import java.rmi.MarshalledObject;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* An <code>ActivationInstantiator</code> is responsible for creating
* instances of "activatable" objects. A concrete subclass of
* <code>ActivationGroup</code> implements the <code>newInstance</code>
* method to handle creating objects within the group.
*
* @author Ann Wollrath
* @see ActivationGroup
* @since 1.2
*/
public interface ActivationInstantiator extends Remote {
/**
* The activator calls an instantiator's <code>newInstance</code>
* method in order to recreate in that group an object with the
* activation identifier, <code>id</code>, and descriptor,
* <code>desc</code>. The instantiator is responsible for: <ul>
*
* <li> determining the class for the object using the descriptor's
* <code>getClassName</code> method,
*
* <li> loading the class from the code location obtained from the
* descriptor (using the <code>getLocation</code> method),
*
* <li> creating an instance of the class by invoking the special
* "activation" constructor of the object's class that takes two
* arguments: the object's <code>ActivationID</code>, and the
* <code>MarshalledObject</code> containing object specific
* initialization data, and
*
* <li> returning a MarshalledObject containing the stub for the
* remote object it created </ul>
*
* @param id the object's activation identifier
* @param desc the object's descriptor
* @return a marshalled object containing the serialized
* representation of remote object's stub
* @exception ActivationException if object activation fails
* @exception RemoteException if remote call fails
* @since 1.2
*/
public MarshalledObject<? extends Remote> newInstance(ActivationID id,
ActivationDesc desc)
throws ActivationException, RemoteException;
}

View File

@@ -0,0 +1,108 @@
/*
* Copyright (c) 1997, 2005, 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.activation;
import java.rmi.MarshalledObject;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.activation.UnknownGroupException;
import java.rmi.activation.UnknownObjectException;
/**
* An <code>ActivationMonitor</code> is specific to an
* <code>ActivationGroup</code> and is obtained when a group is
* reported active via a call to
* <code>ActivationSystem.activeGroup</code> (this is done
* internally). An activation group is responsible for informing its
* <code>ActivationMonitor</code> when either: its objects become active or
* inactive, or the group as a whole becomes inactive.
*
* @author Ann Wollrath
* @see Activator
* @see ActivationSystem
* @see ActivationGroup
* @since 1.2
*/
public interface ActivationMonitor extends Remote {
/**
* An activation group calls its monitor's
* <code>inactiveObject</code> method when an object in its group
* becomes inactive (deactivates). An activation group discovers
* that an object (that it participated in activating) in its VM
* is no longer active, via calls to the activation group's
* <code>inactiveObject</code> method. <p>
*
* The <code>inactiveObject</code> call informs the
* <code>ActivationMonitor</code> that the remote object reference
* it holds for the object with the activation identifier,
* <code>id</code>, is no longer valid. The monitor considers the
* reference associated with <code>id</code> as a stale reference.
* Since the reference is considered stale, a subsequent
* <code>activate</code> call for the same activation identifier
* results in re-activating the remote object.<p>
*
* @param id the object's activation identifier
* @exception UnknownObjectException if object is unknown
* @exception RemoteException if remote call fails
* @since 1.2
*/
public void inactiveObject(ActivationID id)
throws UnknownObjectException, RemoteException;
/**
* Informs that an object is now active. An <code>ActivationGroup</code>
* informs its monitor if an object in its group becomes active by
* other means than being activated directly (i.e., the object
* is registered and "activated" itself).
*
* @param id the active object's id
* @param obj the marshalled form of the object's stub
* @exception UnknownObjectException if object is unknown
* @exception RemoteException if remote call fails
* @since 1.2
*/
public void activeObject(ActivationID id,
MarshalledObject<? extends Remote> obj)
throws UnknownObjectException, RemoteException;
/**
* Informs that the group is now inactive. The group will be
* recreated upon a subsequent request to activate an object
* within the group. A group becomes inactive when all objects
* in the group report that they are inactive.
*
* @param id the group's id
* @param incarnation the group's incarnation number
* @exception UnknownGroupException if group is unknown
* @exception RemoteException if remote call fails
* @since 1.2
*/
public void inactiveGroup(ActivationGroupID id,
long incarnation)
throws UnknownGroupException, RemoteException;
}

View File

@@ -0,0 +1,229 @@
/*
* Copyright (c) 1997, 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.activation;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.activation.UnknownGroupException;
import java.rmi.activation.UnknownObjectException;
/**
* The <code>ActivationSystem</code> provides a means for registering
* groups and "activatable" objects to be activated within those groups.
* The <code>ActivationSystem</code> works closely with the
* <code>Activator</code>, which activates objects registered via the
* <code>ActivationSystem</code>, and the <code>ActivationMonitor</code>,
* which obtains information about active and inactive objects,
* and inactive groups.
*
* @author Ann Wollrath
* @see Activator
* @see ActivationMonitor
* @since 1.2
*/
public interface ActivationSystem extends Remote {
/** The port to lookup the activation system. */
public static final int SYSTEM_PORT = 1098;
/**
* The <code>registerObject</code> method is used to register an
* activation descriptor, <code>desc</code>, and obtain an
* activation identifier for a activatable remote object. The
* <code>ActivationSystem</code> creates an
* <code>ActivationID</code> (a activation identifier) for the
* object specified by the descriptor, <code>desc</code>, and
* records, in stable storage, the activation descriptor and its
* associated identifier for later use. When the <code>Activator</code>
* receives an <code>activate</code> request for a specific identifier, it
* looks up the activation descriptor (registered previously) for
* the specified identifier and uses that information to activate
* the object. <p>
*
* @param desc the object's activation descriptor
* @return the activation id that can be used to activate the object
* @exception ActivationException if registration fails (e.g., database
* update failure, etc).
* @exception UnknownGroupException if group referred to in
* <code>desc</code> is not registered with this system
* @exception RemoteException if remote call fails
* @since 1.2
*/
public ActivationID registerObject(ActivationDesc desc)
throws ActivationException, UnknownGroupException, RemoteException;
/**
* Remove the activation id and associated descriptor previously
* registered with the <code>ActivationSystem</code>; the object
* can no longer be activated via the object's activation id.
*
* @param id the object's activation id (from previous registration)
* @exception ActivationException if unregister fails (e.g., database
* update failure, etc).
* @exception UnknownObjectException if object is unknown (not registered)
* @exception RemoteException if remote call fails
* @since 1.2
*/
public void unregisterObject(ActivationID id)
throws ActivationException, UnknownObjectException, RemoteException;
/**
* Register the activation group. An activation group must be
* registered with the <code>ActivationSystem</code> before objects
* can be registered within that group.
*
* @param desc the group's descriptor
* @return an identifier for the group
* @exception ActivationException if group registration fails
* @exception RemoteException if remote call fails
* @since 1.2
*/
public ActivationGroupID registerGroup(ActivationGroupDesc desc)
throws ActivationException, RemoteException;
/**
* Callback to inform activation system that group is now
* active. This call is made internally by the
* <code>ActivationGroup.createGroup</code> method to inform
* the <code>ActivationSystem</code> that the group is now
* active.
*
* @param id the activation group's identifier
* @param group the group's instantiator
* @param incarnation the group's incarnation number
* @return monitor for activation group
* @exception UnknownGroupException if group is not registered
* @exception ActivationException if a group for the specified
* <code>id</code> is already active and that group is not equal
* to the specified <code>group</code> or that group has a different
* <code>incarnation</code> than the specified <code>group</code>
* @exception RemoteException if remote call fails
* @since 1.2
*/
public ActivationMonitor activeGroup(ActivationGroupID id,
ActivationInstantiator group,
long incarnation)
throws UnknownGroupException, ActivationException, RemoteException;
/**
* Remove the activation group. An activation group makes this call back
* to inform the activator that the group should be removed (destroyed).
* If this call completes successfully, objects can no longer be
* registered or activated within the group. All information of the
* group and its associated objects is removed from the system.
*
* @param id the activation group's identifier
* @exception ActivationException if unregister fails (e.g., database
* update failure, etc).
* @exception UnknownGroupException if group is not registered
* @exception RemoteException if remote call fails
* @since 1.2
*/
public void unregisterGroup(ActivationGroupID id)
throws ActivationException, UnknownGroupException, RemoteException;
/**
* Shutdown the activation system. Destroys all groups spawned by
* the activation daemon and exits the activation daemon.
* @exception RemoteException if failed to contact/shutdown the activation
* daemon
* @since 1.2
*/
public void shutdown() throws RemoteException;
/**
* Set the activation descriptor, <code>desc</code> for the object with
* the activation identifier, <code>id</code>. The change will take
* effect upon subsequent activation of the object.
*
* @param id the activation identifier for the activatable object
* @param desc the activation descriptor for the activatable object
* @exception UnknownGroupException the group associated with
* <code>desc</code> is not a registered group
* @exception UnknownObjectException the activation <code>id</code>
* is not registered
* @exception ActivationException for general failure (e.g., unable
* to update log)
* @exception RemoteException if remote call fails
* @return the previous value of the activation descriptor
* @see #getActivationDesc
* @since 1.2
*/
public ActivationDesc setActivationDesc(ActivationID id,
ActivationDesc desc)
throws ActivationException, UnknownObjectException,
UnknownGroupException, RemoteException;
/**
* Set the activation group descriptor, <code>desc</code> for the object
* with the activation group identifier, <code>id</code>. The change will
* take effect upon subsequent activation of the group.
*
* @param id the activation group identifier for the activation group
* @param desc the activation group descriptor for the activation group
* @exception UnknownGroupException the group associated with
* <code>id</code> is not a registered group
* @exception ActivationException for general failure (e.g., unable
* to update log)
* @exception RemoteException if remote call fails
* @return the previous value of the activation group descriptor
* @see #getActivationGroupDesc
* @since 1.2
*/
public ActivationGroupDesc setActivationGroupDesc(ActivationGroupID id,
ActivationGroupDesc desc)
throws ActivationException, UnknownGroupException, RemoteException;
/**
* Returns the activation descriptor, for the object with the activation
* identifier, <code>id</code>.
*
* @param id the activation identifier for the activatable object
* @exception UnknownObjectException if <code>id</code> is not registered
* @exception ActivationException for general failure
* @exception RemoteException if remote call fails
* @return the activation descriptor
* @see #setActivationDesc
* @since 1.2
*/
public ActivationDesc getActivationDesc(ActivationID id)
throws ActivationException, UnknownObjectException, RemoteException;
/**
* Returns the activation group descriptor, for the group
* with the activation group identifier, <code>id</code>.
*
* @param id the activation group identifier for the group
* @exception UnknownGroupException if <code>id</code> is not registered
* @exception ActivationException for general failure
* @exception RemoteException if remote call fails
* @return the activation group descriptor
* @see #setActivationGroupDesc
* @since 1.2
*/
public ActivationGroupDesc getActivationGroupDesc(ActivationGroupID id)
throws ActivationException, UnknownGroupException, RemoteException;
}

View File

@@ -0,0 +1,114 @@
/*
* Copyright (c) 1997, 2005, 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.activation;
import java.rmi.MarshalledObject;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.activation.UnknownObjectException;
/**
* The <code>Activator</code> facilitates remote object activation. A
* "faulting" remote reference calls the activator's
* <code>activate</code> method to obtain a "live" reference to a
* "activatable" remote object. Upon receiving a request for activation,
* the activator looks up the activation descriptor for the activation
* identifier, <code>id</code>, determines the group in which the
* object should be activated initiates object re-creation via the
* group's <code>ActivationInstantiator</code> (via a call to the
* <code>newInstance</code> method). The activator initiates the
* execution of activation groups as necessary. For example, if an
* activation group for a specific group identifier is not already
* executing, the activator initiates the execution of a VM for the
* group. <p>
*
* The <code>Activator</code> works closely with
* <code>ActivationSystem</code>, which provides a means for registering
* groups and objects within those groups, and <code>ActivationMonitor</code>,
* which recives information about active and inactive objects and inactive
* groups. <p>
*
* The activator is responsible for monitoring and detecting when
* activation groups fail so that it can remove stale remote references
* to groups and active object's within those groups.<p>
*
* @author Ann Wollrath
* @see ActivationInstantiator
* @see ActivationGroupDesc
* @see ActivationGroupID
* @since 1.2
*/
public interface Activator extends Remote {
/**
* Activate the object associated with the activation identifier,
* <code>id</code>. If the activator knows the object to be active
* already, and <code>force</code> is false , the stub with a
* "live" reference is returned immediately to the caller;
* otherwise, if the activator does not know that corresponding
* the remote object is active, the activator uses the activation
* descriptor information (previously registered) to determine the
* group (VM) in which the object should be activated. If an
* <code>ActivationInstantiator</code> corresponding to the
* object's group descriptor already exists, the activator invokes
* the activation group's <code>newInstance</code> method passing
* it the object's id and descriptor. <p>
*
* If the activation group for the object's group descriptor does
* not yet exist, the activator starts an
* <code>ActivationInstantiator</code> executing (by spawning a
* child process, for example). When the activator receives the
* activation group's call back (via the
* <code>ActivationSystem</code>'s <code>activeGroup</code>
* method) specifying the activation group's reference, the
* activator can then invoke that activation instantiator's
* <code>newInstance</code> method to forward each pending
* activation request to the activation group and return the
* result (a marshalled remote object reference, a stub) to the
* caller.<p>
*
* Note that the activator receives a "marshalled" object instead of a
* Remote object so that the activator does not need to load the
* code for that object, or participate in distributed garbage
* collection for that object. If the activator kept a strong
* reference to the remote object, the activator would then
* prevent the object from being garbage collected under the
* normal distributed garbage collection mechanism. <p>
*
* @param id the activation identifier for the object being activated
* @param force if true, the activator contacts the group to obtain
* the remote object's reference; if false, returning the cached value
* is allowed.
* @return the remote object (a stub) in a marshalled form
* @exception ActivationException if object activation fails
* @exception UnknownObjectException if object is unknown (not registered)
* @exception RemoteException if remote call fails
* @since 1.2
*/
public MarshalledObject<? extends Remote> activate(ActivationID id,
boolean force)
throws ActivationException, UnknownObjectException, RemoteException;
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 1997, 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.activation;
/**
* An <code>UnknownGroupException</code> is thrown by methods of classes and
* interfaces in the <code>java.rmi.activation</code> package when the
* <code>ActivationGroupID</code> parameter to the method is determined to be
* invalid, i.e., not known by the <code>ActivationSystem</code>. An
* <code>UnknownGroupException</code> is also thrown if the
* <code>ActivationGroupID</code> in an <code>ActivationDesc</code> refers to
* a group that is not registered with the <code>ActivationSystem</code>
*
* @author Ann Wollrath
* @since 1.2
* @see java.rmi.activation.Activatable
* @see java.rmi.activation.ActivationGroup
* @see java.rmi.activation.ActivationGroupID
* @see java.rmi.activation.ActivationMonitor
* @see java.rmi.activation.ActivationSystem
*/
public class UnknownGroupException extends ActivationException {
/** indicate compatibility with the Java 2 SDK v1.2 version of class */
private static final long serialVersionUID = 7056094974750002460L;
/**
* Constructs an <code>UnknownGroupException</code> with the specified
* detail message.
*
* @param s the detail message
* @since 1.2
*/
public UnknownGroupException(String s) {
super(s);
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 1997, 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.activation;
/**
* An <code>UnknownObjectException</code> is thrown by methods of classes and
* interfaces in the <code>java.rmi.activation</code> package when the
* <code>ActivationID</code> parameter to the method is determined to be
* invalid. An <code>ActivationID</code> is invalid if it is not currently
* known by the <code>ActivationSystem</code>. An <code>ActivationID</code>
* is obtained by the <code>ActivationSystem.registerObject</code> method.
* An <code>ActivationID</code> is also obtained during the
* <code>Activatable.register</code> call.
*
* @author Ann Wollrath
* @since 1.2
* @see java.rmi.activation.Activatable
* @see java.rmi.activation.ActivationGroup
* @see java.rmi.activation.ActivationID
* @see java.rmi.activation.ActivationMonitor
* @see java.rmi.activation.ActivationSystem
* @see java.rmi.activation.Activator
*/
public class UnknownObjectException extends ActivationException {
/** indicate compatibility with the Java 2 SDK v1.2 version of class */
private static final long serialVersionUID = 3425547551622251430L;
/**
* Constructs an <code>UnknownObjectException</code> with the specified
* detail message.
*
* @param s the detail message
* @since 1.2
*/
public UnknownObjectException(String s) {
super(s);
}
}

View 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;
}

View 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;
}
}

View 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() {
StringBuffer result = new StringBuffer();
if (addr != null)
for (int i = 0; i < addr.length; ++ i) {
int x = addr[i] & 0xFF;
result.append((x < 0x10 ? "0" : "") +
Integer.toString(x, 16));
}
result.append(':');
result.append(uid.toString());
return result.toString();
}
}

View File

@@ -0,0 +1,241 @@
/*
* 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.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 JDK1.1
* @see java.rmi.registry.Registry
*/
public final class LocateRegistry {
/**
* Private constructor to disable public construction.
*/
private LocateRegistry() {}
/**
* Returns a reference to the 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
* @exception RemoteException if the reference could not be created
* @since JDK1.1
*/
public static Registry getRegistry()
throws RemoteException
{
return getRegistry(null, Registry.REGISTRY_PORT);
}
/**
* Returns a reference to the 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
* @exception RemoteException if the reference could not be created
* @since JDK1.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
* @exception RemoteException if the reference could not be created
* @since JDK1.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
* @exception RemoteException if the reference could not be created
* @since JDK1.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
* @exception 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
* @exception RemoteException if the registry could not be exported
* @since JDK1.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
* @exception 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);
}
}

View 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 JDK1.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;
}

View File

@@ -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 JDK1.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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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