About

Documentation

Project Documentation

Built by Maven

Basic Usage

Files used in these examples are located under the src/example directory. S2RMI makes components registered in the S2Container into remote objects. service.Hello interface is a normal interface. Furthermore, service.impl.HelloImpl class is an implementation class (POJO) of Hello interface. Remote objects are released by S2RMI using Hello interface and its implementation class.

Service

service.Hello.java

public interface Hello {
    public String say();
}

service.impl.HelloImpl.java

public class HelloImpl implements Hello {
    public String say() {
        return "Hello";
    }
}

Server Settings

Following 3 components must be defined in a dicon file on a server.

  • org.seasar.remoting.rmi.adaptor.RMIAdaptorImpl
  • org.seasar.remoting.rmi.deployer.RMIAdaptorDeployer
  • service.impl.HelloImpl (implementation class of interface of remote object to be released)

RMIAdaptorImpl class is an adapter that uses ComponentInvokerImpl class to call component registered in the S2Container. RMIAdaptorDeployer registers RMIAdaptorImpl class into RMI registry.

server.dicon

<components>
  <component name="rmiAdapptor" class="org.seasar.remoting.rmi.adaptor.RMIAdaptorImpl">
    <property name="invoker">
      <component class="org.seasar.extension.component.impl.ComponentInvokerImpl"/>
    </property>
  </component>

  <component class="org.seasar.remoting.rmi.deployer.RMIAdaptorDeployer">
    <property name="adaptor">rmiAdapptor</property>
    <property name="registryPort">1108</property>
    <property name="servicePort">1109</property>
    <initMethod name="deploy"/>
  </component>

  <component name="hello" class="service.impl.HelloImpl"/>
</components>

RMIAdaptorDeployer property

<property name="registryPort">
Port number of rmiregistry. When omitted, default port (1099) is used.
<property name="servicePort">
Port number to be used by RMIAdaptorImpl. When omitted, port is set to the default port (0) and anonymous port is used.

Starting RMIAdaptorDeployer

A component in S2Container can be called remotely by initializing the S2Container. S2Container is initialized by defining <initMethod name="deploy"/> in the dicon file.

server.ServerMain.java

package server;

import org.seasar.framework.container.S2Container;
import org.seasar.framework.container.factory.S2ContainerFactory;
import org.seasar.remoting.common.deployer.Deployer;

public class ServerMain {
    public static void main(String[] args) {
        S2ContainerFactory.create("server/server.dicon").init();
    }
}

To execute ServerMain, right click on ServerMain.java in the package explorer and select [Execute]-[Java Application].

Client Settings

Following 3 components must be defined in a dicon file on a client.

  • org.seasar.remoting.rmi.connector.RMIConnector
  • org.seasar.remoting.common.interceptor.RemotingInterceptor
  • service.Hello (interface to call on a remote object)

RMIConnector call retrieves RMIAdaptorImpl class from RMI registry and calls a component on the server. RemotingInterceptor class uses RMIConnector to set by AOP an interface (Hello) to call on remote object. Name of remote object to call and name of component to be called (hello) must be the same.

S2RMI is an implementation of S2Remoting. Therefore, it is possible to switch so remote object are called using S2Axis just be changing connector setting in RemotingInterceptor from RMIConnector to org.seasar.remoting.axis.connector.AxisConnector. Refer to Setting S2Axis Server for information on using S2Axis.

clinet.dicon

<components>
  <component name="rmiConnector" class="org.seasar.remoting.rmi.connector.RMIConnector">
    <property name="baseURLAsString">"rmi://localhost:1108/"</propert>
    <initMethod name="lookup"/>
  </component>

  <component name="remoting"
    class="org.seasar.remoting.common.interceptor.RemotingInterceptor">
    <property name="connector">rmiConnector</property>
  </component>

  <component name="hello" class="service.Hello">
    <aspect>remoting</aspect>
  </component>
</components>

Calling Remote Object

When a method in interface which is defined as AOP to RemoteingInterceptor on the client is called, following tasks are executed:

Hello.say() -> RMIConnector -> RMIAdaptor -> ComponentInvoker -> HelloImpl.say()

Following ClientMain is an example of executable class on a client.

client.ClientMain.java

package client;

import org.seasar.framework.container.S2Container;
import org.seasar.framework.container.factory.S2ContainerFactory;
import service.Hello;

public class ClientMain {
    public static void main(String[] args) {
        S2Container container = S2ContainerFactory
                .create("client/client.dicon");
        container.init();
        Hello hello = (Hello) container
                .getComponent(service.Hello.class);

        System.out.println(hello.say());
    }
}

To execute ClientMain, right click on ClientMain.java in the package explorer and select [Execute]-[Java Application].