***  This class provides Binary Compatibility only, not Source Compatibility  ***

com.sas.net.rmi
Class ActivatableExporter

com.sas.net.rmi.ActivatableExporter
All Implemented Interfaces:
RemoteObjectExporterInterface

public class ActivatableExporter
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:

*

Constructor Examples

This section presents examples that show how to construct an activatable remote object exporter.

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(java.rmi.Remote remoteObject, int portNumber, java.rmi.server.RMIClientSocketFactory rmiClientSocketFactory, java.rmi.server.RMIServerSocketFactory rmiServerSocketFactory, boolean isForcibleUnexport, java.rmi.activation.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  java.rmi.Remote exportObject(java.rmi.Remote remoteObject, int portNumber, java.rmi.server.RMIClientSocketFactory rmiClientSocketFactory, java.rmi.server.RMIServerSocketFactory rmiServerSocketFactory)
          Exports the remote object returning the remote object's stub.
protected  boolean unexportObject(java.rmi.Remote exportedRemoteObjectStub, boolean isForcibleUnexport)
          Unexports the exported remote object's stub from the RMI system.
 
Methods inherited from class com.sas.net.rmi.AbstractRemoteObjectExporter
exportObject, getExportedRemoteObjectStub, getPortNumber, getRemotableObject, getRMIClientSocketFactory, getRMIServerSocketFactory, isExported, isForcibleUnexport, setIsForcibleUnexport, unexportObject
 
Methods inherited from interface com.sas.net.rmi.RemoteObjectExporterInterface
exportObject, getExportedRemoteObjectStub, isExported, unexportObject
 

Constructor Detail

ActivatableExporter

public ActivatableExporter(java.rmi.Remote remoteObject,
                           int portNumber,
                           java.rmi.server.RMIClientSocketFactory rmiClientSocketFactory,
                           java.rmi.server.RMIServerSocketFactory rmiServerSocketFactory,
                           boolean isForcibleUnexport,
                           java.rmi.activation.ActivationID activationId)
                    throws java.lang.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 ID
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.
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:
java.lang.IllegalArgumentException - if an invalid remote object, port number, or activation ID is specified.
Method Detail

exportObject

protected final java.rmi.Remote exportObject(java.rmi.Remote remoteObject,
                                             int portNumber,
                                             java.rmi.server.RMIClientSocketFactory rmiClientSocketFactory,
                                             java.rmi.server.RMIServerSocketFactory rmiServerSocketFactory)
                                      throws java.rmi.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) .

Specified by:
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. The stub will always be non-null.
Throws:
java.rmi.RemoteException - if unable to unexport the remote object.

unexportObject

protected final boolean unexportObject(java.rmi.Remote exportedRemoteObjectStub,
                                       boolean isForcibleUnexport)
                                throws java.rmi.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).

Specified by:
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:
java.rmi.NoSuchObjectException - if unable to unexport the remote object.

***  This class provides Binary Compatibility only, not Source Compatibility  ***




Copyright © 2009 SAS Institute Inc. All Rights Reserved.