Example usage for org.springframework.remoting.rmi RmiInvocationWrapper RmiInvocationWrapper

List of usage examples for org.springframework.remoting.rmi RmiInvocationWrapper RmiInvocationWrapper

Introduction

In this page you can find the example usage for org.springframework.remoting.rmi RmiInvocationWrapper RmiInvocationWrapper.

Prototype

public RmiInvocationWrapper(Object wrappedObject, RmiBasedExporter rmiExporter) 

Source Link

Document

Create a new RmiInvocationWrapper for the given object.

Usage

From source file:org.springframework.remoting.rmi.RmiServiceExporter.java

/**
 * Register the service as RMI object.//from   w w w . j a va  2 s  .  com
 * Creates an RMI registry on the specified port if none exists.
 */
public void afterPropertiesSet() throws Exception {
    super.afterPropertiesSet();

    if (this.serviceName == null) {
        throw new IllegalArgumentException("serviceName is required");
    }
    if (this.clientSocketFactory instanceof RMIServerSocketFactory) {
        this.serverSocketFactory = (RMIServerSocketFactory) this.clientSocketFactory;
    }
    if ((this.clientSocketFactory != null && this.serverSocketFactory == null)
            || (this.clientSocketFactory == null && this.serverSocketFactory != null)) {
        throw new IllegalArgumentException(
                "Both RMIClientSocketFactory and RMIServerSocketFactory or none required");
    }

    Registry registry = null;
    logger.info("Looking for RMI registry at port '" + this.registryPort + "'");
    try {
        // retrieve registry
        registry = LocateRegistry.getRegistry(this.registryPort);
        registry.list();
    } catch (RemoteException ex) {
        logger.debug("RMI registry access threw exception", ex);
        logger.warn("Could not detect RMI registry - creating new one");
        // assume no registry found -> create new one
        registry = LocateRegistry.createRegistry(this.registryPort);
    }

    // determine remote object
    if (getService() instanceof Remote) {
        // conventional RMI service
        this.exportedObject = (Remote) getService();
    } else {
        // RMI invoker
        logger.info("RMI object '" + this.serviceName + "' is an RMI invoker");
        this.exportedObject = new RmiInvocationWrapper(getProxyForService(), this);
    }

    // export remote object and bind it to registry
    logger.info(
            "Binding RMI service '" + this.serviceName + "' to registry at port '" + this.registryPort + "'");
    if (this.clientSocketFactory != null) {
        UnicastRemoteObject.exportObject(this.exportedObject, this.servicePort, this.clientSocketFactory,
                this.serverSocketFactory);
    } else {
        UnicastRemoteObject.exportObject(this.exportedObject, this.servicePort);
    }
    registry.rebind(this.serviceName, this.exportedObject);
}