com.sas.net.rmi
Class ActivatableExporter
java.lang.Object
|
+--com.sas.net.rmi.AbstractRemoteObjectExporter
|
+--com.sas.net.rmi.ActivatableExporter
- All Implemented Interfaces:
- RemoteObjectExporterInterface
- public class ActivatableExporter
- extends AbstractRemoteObjectExporter
- implements RemoteObjectExporterInterface
Utility class used to export/unexport an activatable remote object
to/from the RMI system using Activatable.
This utility may be used if either of the following conditions apply:
- a remote object implemenation cannot subclass a standard remote object
implementation such as
UnicastRemoteObject because
it is required to extend a different superclass.
- one desires to be able to selectively control whether or not a
remote object implementation needs to service remote callers or if it
is just being used to service local calls.
* Constructor Examples
This section presents examples that show how to construct an activatable
remote object exporter.
- Example 1 :
Default socket factories and an anonymous port
- Example 2 :
Specified socket factories and an anonymous port
- Example 3 :
Specified socket factories and port
- Example 4 :
Specified socket factories, port and forcible unexport preference
Example 1:
Construct an Exporter Using Default Socket Factories and an Anonymous Port
The following code example shows how construct an exporter using
default RMI socket factories and an anonymous port.
import java.rmi.Remote;
import java.rmi.RemoteException;
import com.sas.net.rmi.RemoteObjectExporterInterface;
import com.sas.net.rmi.ActivatableObjectExporter;
...
public SomeActivatableObjectImplementation ()
implements SomeActivatableInterface {
private RemoteObjectExporterInterface _rmiExporter;
public SomeActivatableObjectImplementation ()
throws RemoteException {
super();
...
// construct an activatable object exporter using:
// - anonymous port
// - default RMI socket factories
// - preference to forcibly unexport the remote object
// - activation ID
boolean isForcibleUnexport = false;
_rmiExporter = new ActivatableObjectExporter(
this, // the remote object to be exported
Constants.PORT_ANONYMOUS, // export remote object on an anonymous port
null, // default RMI client socket factory
null, // use default RMI server socket factory
isForcibleUnexport, // do not forcibly unexport the remote object
activationID); // activation ID obtained from a previous export
// export the remote object to the RMI system.
// a RemoteException will be thrown if the export fails.
Remote exportedRemoteObject = _rmiExporter.export();
}
}
|
Example 2:
Construct an Exporter Using Specified Socket Factories and an Anonymous Port
The following code example shows how construct an exporter by specifying
desired RMI socket factories and an anonymous port.
import java.rmi.Remote;
import java.rmi.RemoteException;
import com.sas.net.rmi.RemoteObjectExporterInterface;
import com.sas.net.rmi.ActivatableObjectExporter;
import com.sas.net.ssl.SSLRMISocketFactories;
...
public SomeActivatableObjectImplementation ()
implements SomeActivatableInterface {
private RemoteObjectExporterInterface _rmiExporter;
public SomeRemoteObjectImplementation ()
throws RemoteException {
super();
...
// construct a unicast remote object exporter using:
// - anonymous port
// - specified RMI socket factories
// - preference to forcibly unexport the remote object
// - activation ID
SSLRMISocketFactories sslRMISocketFactories =
SSLRMISocketFactories.getInstance();
Class theClass = getClass();
RMIClientSocketFactory rmiClientSocketFactory =
sslRMISocketFactories.getRMIClientSocketFactoryForClass(theClass);
RMIServerSocketFactory rmiServerSocketFactory =
sslRMISocketFactories.getRMIServerSocketFactoryForClass(theClass);
boolean isForcibleUnexport = false;
_rmiExporter = new ActivatableObjectExporter(
this, // the remote object to be exported
Constants.PORT_ANONYMOUS, // export remote object on an anonymous port
rmiClientSocketFactory, // RMI client socket factory
rmiServerSocketFactory, // RMI server socket factory
isForcibleUnexport, // do not forcibly unexport the remote object
activationID); // activation ID obtained from a previous export
// export this remote object to the RMI system.
// RemoteException will be thrown if the export fails.
Remote exportedRemoteObject = _rmiExporter.export();
}
}
|
Example 3:
Construct an Exporter Using Specified Socket Factories and Port
The following code example shows how construct an exporter by specifying
desired RMI socket factories and port.
import java.rmi.Remote;
import java.rmi.RemoteException;
import com.sas.net.rmi.RemoteObjectExporterInterface;
import com.sas.net.rmi.ActivatableObjectExporter;
import com.sas.net.ssl.SSLRMISocketFactories;
...
public SomeActivatableObjectImplementation ()
implements SomeActivatableInterface {
private RemoteObjectExporterInterface _rmiExporter;
public SomeRemoteObjectImplementation ()
throws RemoteException {
super();
// construct a unicast remote object exporter using:
// - specified port
// - specified RMI socket factories
// - preference to forcibly unexport the remote object
// - activation ID
SSLRMISocketFactories sslRMISocketFactories =
SSLRMISocketFactories.getInstance();
Class theClass = getClass();
RMIClientSocketFactory rmiClientSocketFactory =
sslRMISocketFactories.getRMIClientSocketFactoryForClass(theClass);
RMIServerSocketFactory rmiServerSocketFactory =
sslRMISocketFactories.getRMIServerSocketFactoryForClass(theClass);
int portNumber = 8216;
boolean isForcibleUnexport = false;
_rmiExporter = new ActivatableObjectExporter(
this, // the remote object to be exported
portNumber, // port on which to export the remote object
rmiClientSocketFactory, // RMI client socket factory
rmiServerSocketFactory, // RMI server socket factory
isForcibleUnexport, // do not forcibly unexport the remote object
activationID); // activation ID obtained from a previous export
// export this remote object to the RMI system.
// RemoteException will be thrown if the export fails.
Remote exportedRemoteObject = _rmiExporter.export();
}
}
|
Example 4:
Construct an Exporter Using Specified Socket Factories, Port and Forcible Unexport Preference
The following code example shows how construct an exporter by specifying
desired RMI socket factories, port, and forcible unexport preference.
import java.rmi.Remote;
import java.rmi.RemoteException;
import com.sas.net.rmi.RemoteObjectExporterInterface;
import com.sas.net.rmi.ActivatableObjectExporter;
import com.sas.net.ssl.SSLRMISocketFactories;
...
public SomeActivatableObjectImplementation ()
implements SomeActivatableInterface {
private RemoteObjectExporterInterface _rmiExporter;
public SomeRemoteObjectImplementation ()
throws RemoteException {
super();
// construct a unicast remote object exporter using:
// - specified port
// - specified RMI socket factories
// - preference to forcibly unexport the remote object
// - activation ID
SSLRMISocketFactories sslRMISocketFactories =
SSLRMISocketFactories.getInstance();
Class theClass = getClass();
RMIClientSocketFactory rmiClientSocketFactory =
sslRMISocketFactories.getRMIClientSocketFactoryForClass(theClass);
RMIServerSocketFactory rmiServerSocketFactory =
sslRMISocketFactories.getRMIServerSocketFactoryForClass(theClass);
int portNumber = 8216;
boolean isForcibleUnexport = true;
_rmiExporter = new ActivatableObjectExporter(
this, // the remote object to be exported
portNumber, // port on which to export the remote object
rmiClientSocketFactory, // RMI client socket factory
rmiServerSocketFactory, // RMI server socket factory
isForcibleUnexport, // do not forcibly unexport the remote object
activationID); // activation ID obtained from a previous export
// export this remote object to the RMI system.
// RemoteException will be thrown if the export fails.
Remote exportedRemoteObject = _rmiExporter.export();
}
}
|
Export/Unexport Examples
This section presents code examples detailing how to export
and unexport a remote object.
Example 5:
Export Remote Object
The following code example shows how to export a remote object.
import java.rmi.Remote;
import java.rmi.RemoteException;
import com.sas.net.rmi.RemoteObjectExporterInterface;
import com.sas.net.rmi.ActivatableObjectExporter;
import com.sas.net.ssl.SSLRMISocketFactories;
...
public SomeActivatableObjectImplementation ()
implements SomeActivatableInterface {
private RemoteObjectExporterInterface _rmiExporter;
public SomeRemoteObjectImplementation ()
throws RemoteException {
super();
// construct a unicast remote object exporter
// using specified socket factories and an
// anonymous port
SSLRMISocketFactories sslRMISocketFactories =
SSLRMISocketFactories.getInstance();
Class theClass = getClass();
RMIClientSocketFactory rmiClientSocketFactory =
sslRMISocketFactories.getRMIClientSocketFactoryForClass(theClass);
RMIServerSocketFactory rmiServerSocketFactory =
sslRMISocketFactories.getRMIServerSocketFactoryForClass(theClass);
int portNumber = 1099;
boolean isForcibleUnexport = true;
_rmiExporter = new ActivatableObjectExporter(
this, // the remote object to be exported
portNumber, // port on which to export the remote object
rmiClientSocketFactory, // RMI client socket factory
rmiServerSocketFactory, // RMI server socket factory
isForcibleUnexport, // do not forcibly unexport the remote object
activationID); // activation ID obtained from a previous export
// export the remote object to the RMI system
// throws a RemoteException if unable to export the remote object.
Remote exportedRemoteObject = _rmiExporter.export();
}
}
|
Example 6:
Unexport Remote Object
The following code example shows how to unexport a remote object.
import java.rmi.NoSuchObjectException;
import com.sas.net.rmi.RemoteObjectExporterInterface;
...
public SomeActivatableObjectImplementation ()
implements SomeActivatableInterface {
private RemoteObjectExporterInterface _rmiExporter;
...
public destroy () {
...
if (_rmiExporter.isExported()) {
try {
// unexport the remote object from the RMI system
// note that the remote object will be unexported
// forcibly (terminating active and refusing pending calls) if the
// preference is to forcibly unexport
boolean wasUnexported = _rmiExporter.unexport();
if (!wasUnexported) {
// if a non-forcible unexport was specified, then
// the remote object may still be servicing calls.
// forcibly unexport or try again later
}
}
catch (NoSuchObjectException) {
// log an error
}
}
}
}
|
- Since:
- 9.1.3
- See Also:
Activatable
|
Constructor Summary |
ActivatableExporter(Remote remoteObject,
int portNumber,
RMIClientSocketFactory rmiClientSocketFactory,
RMIServerSocketFactory rmiServerSocketFactory,
boolean isForcibleUnexport,
ActivationID activationId)
Constructs an instance of an activatable exporter for the
specified remote object, activation ID, and port number using
specified socket factories. |
|
Method Summary |
protected Remote |
exportObject(Remote remoteObject,
int portNumber,
RMIClientSocketFactory rmiClientSocketFactory,
RMIServerSocketFactory rmiServerSocketFactory)
Exports the remote object returning the remote object's stub.
|
protected boolean |
unexportObject(Remote exportedRemoteObjectStub,
boolean isForcibleUnexport)
Unexports the exported remote object's stub from the RMI system.
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ActivatableExporter
public ActivatableExporter(Remote remoteObject,
int portNumber,
RMIClientSocketFactory rmiClientSocketFactory,
RMIServerSocketFactory rmiServerSocketFactory,
boolean isForcibleUnexport,
ActivationID activationId)
throws IllegalArgumentException
- Constructs an instance of an activatable exporter for the
specified remote object, activation ID, and port number using
specified socket factories.
- Parameters:
remoteObject - The remote object that may be exported to the RMI system
to create a remote object stub.activationId - Activation IDportNumber - Port on which the object should be exported.
Specify Constants.PORT_ANONYMOUS to designate an anonymous port
or a value greater than 0 to designate a well-known port.rmiClientSocketFactory - The client-side RMI socket factory is used to create sockets
to make calls to the remote object or null if using the default.rmiServerSocketFactory - The server-side RMI socket factory is used to create sockets to
receive remote calls or null if using the default.isForcibleUnexport - Specify true if the remote object should be unexported
without regard to whether or not there are any active or pending
remote calls or false if the remote object should not
be unexported if there are active or pending calls.- Throws:
IllegalArgumentException - if an invalid remote object,
port number, or activation ID is specified.
exportObject
protected final Remote exportObject(Remote remoteObject,
int portNumber,
RMIClientSocketFactory rmiClientSocketFactory,
RMIServerSocketFactory rmiServerSocketFactory)
throws RemoteException
- Exports the remote object returning the remote object's stub.
This method is called by
AbstractRemoteObjectExporter.exportObject() to export
a unicast remote object stub. This method provides the
concrete implementation of a template method used to unexport
a remote object stub using
Activatable.exportObject(Remote, ActivationID, int, RMIClientSocketFactory, RMIServerSocketFactory).
- Overrides:
exportObject in class AbstractRemoteObjectExporter
- Parameters:
remoteObject - The remote object that may be exported to the RMI system
to create a remote object stub.
Ensure that the remote object implementation
correctly implements
hashCode, equals, and toString
methods to ensure correct behavior by the remote object.portNumber - Port on which the object should be exported.
Specify Constants.PORT_ANONYMOUS to designate an anonymous port
or a value greater than 0 to designate a well-known port.rmiClientSocketFactory - The client-side RMI socket factory is used to create sockets
to make calls to the remote object or null if using the default.rmiServerSocketFactory - The server-side RMI socket factory is used to create sockets to
receive remote calls or null if using the default.- Returns:
- Exported remote object's stub.
- Throws:
RemoteException - if unable to unexport the remote object.
unexportObject
protected final boolean unexportObject(Remote exportedRemoteObjectStub,
boolean isForcibleUnexport)
throws NoSuchObjectException
- Unexports the exported remote object's stub from the RMI system.
This method is called by
AbstractRemoteObjectExporter.unexportObject() to unexport
a unicast remote object stub previously exported using
AbstractRemoteObjectExporter.exportObject(). This method provides the
concrete implementation of a template method used to unexport
a remote object stub using
Activatable.unexportObject(Remote, boolean).
- Overrides:
unexportObject in class AbstractRemoteObjectExporter
- Parameters:
exportedRemoteObjectStub - The remote object's stub which is to be removed from the RMI system.
This is the stub which was obtained from the AbstractRemoteObjectExporter.exportObject()
call.isForcibleUnexport - true if the remote object's stub should be forcibly
removed from the RMI system without regard to whether or not there
are any active or pending calls. Specify false if the
stub should not be unexported if there are active or pending calls.- Returns:
true if the exported remote object's stub was
successfully unexported from the RMI system.- Throws:
NoSuchObjectException - if unable to unexport the remote object.
Copyright © 2005 SAS Institute Inc. All Rights Reserved.
javadoc generated Thu, 16 Feb 2006 02:04:20