サーバ側の設定
サーバ側で必要な設定は次の通りです.
- コンポーネントの実装クラスを登録する.
- S2RMIのアダプタを設定する.
- コンポーネントを起動するためのコンポーネント (
ComponentInvoker)を設定する.
SMART deployを使う場合
S2RMIはSeasar2.4で導入されたSMART deployに対応しています. SMART deployを利用すると設定を簡素化することができます.
開発時にはSMART deployの一つであるHOT deployを利用することができます. HOT deployを利用すると,RMI サーバプロセスを起動したままコンポーネントの ソースを変更してそのままテストすることができます.
以下ではS2RMIサンプルのサーバ側に含まれる設定ファイルについて説明します.
s2rmi-examples-server/src/main/resources 以下にあります.
s2container.dicon
SMART deployを利用するにはs2container.diconが必要です.
S2RMI固有の設定は必要ありません.
以下はenv.txtでHOT deploy / COOL deployを切り替えられるようにした設定の例です.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN" "http://www.seasar.org/dtd/components24.dtd"> <components xmlns:xi="http://www.w3.org/2001/XInclude"> <include condition="#ENV != 'ut'" path="cooldeploy.dicon"/> <include condition="#ENV == 'ut'" path="hotdeploy.dicon"/> </components>
app.dicon
app.diconでs2rmi.diconをインクルードします.
サンプルではトレースを出力するためにaop.diconもインクルードしています.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN" "http://www.seasar.org/dtd/components24.dtd"> <components xmlns:xi="http://www.w3.org/2001/XInclude"> <include path="aop.dicon"/> <include path="s2rmi.dicon"/> </components>
s2rmi.dicon
サーバ側の設定は配布ファイルのs2rmi/resourcesにあるs2rmi.diconを
コピーして使用してください.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
"http://www.seasar.org/dtd/components24.dtd">
<components xmlns:xi="http://www.w3.org/2001/XInclude">
<include path="s2rmi-server.dicon"/>
<include condition="#ENV == 'ut'" path="s2rmi-hotdeploy.dicon"/>
<component name="RMIAdapptor" class="org.seasar.remoting.rmi.adaptor.impl.RMIAdaptorImpl">
<property name="invokerName">"componentInvoker"</property>
</component>
<component class="org.seasar.remoting.rmi.filter.impl.RMIExternalContextFilter"/>
<component class="org.seasar.remoting.rmi.deployer.impl.RMIAdaptorDeployerImpl">
<property name="registryPort">1108</property>
<property name="servicePort">1109</property>
<initMethod name="deploy"/>
<destroyMethod name="undeploy"/>
</component>
</components>
RMIで使用するポート番号はRMIAdaptorDeployerImplの
servicePortプロパティで設定します.
convention.dicon
convention.diconにはコンポーネントのメソッドを起動する
ComponentInvokerのルートパッケージを設定します.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
"http://www.seasar.org/dtd/components24.dtd">
<components xmlns:xi="http://www.w3.org/2001/XInclude">
<component class="org.seasar.framework.convention.impl.NamingConventionImpl">
<!-- アプリケーション固有のルートパッケージ -->
<initMethod name="addRootPackageName">
<arg>"examples.rmi"</arg>
</initMethod>
<!-- ComponentInvoker のルートパッケージ -->
<initMethod name="addRootPackageName">
<arg>"org.seasar.extension.component"</arg>
</initMethod>
</component>
</components>
creator.dicon
creator.diconにはサービスのCreatorに加えて,コンポーネントのメソッドを起動する
ComponentInvokerをコンポーネントとして登録するためのCreatorを設定します.
<?xml version="1.0" encoding="Shift_JIS"?> <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN" "http://www.seasar.org/dtd/components24.dtd"> <components xmlns:xi="http://www.w3.org/2001/XInclude"> <include path="convention.dicon"/> <include path="customizer.dicon"/> <component class="org.seasar.framework.container.creator.ServiceCreator"/> <component class="org.seasar.extension.component.impl.ComponentInvokerCreator"/> </components>
通常のアプリケーションではより多くのCreatorが必要になります.
Seasar2の配布ファイルに含まれるcreator.diconには
通常のアプリケーションで必要になるCreatorが設定済みなので,そちらをベースに
ComponentInvokerCreatorを追加するのがいいでしょう.
customizer.dicon
customizer.diconにはサービスのカスタマイザを設定します.
S2RMI固有の設定は必要ありません.
以下ではログを出力するためにサービスにトレースインターセプタを適用する設定をしています.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
"http://www.seasar.org/dtd/components24.dtd">
<components xmlns:xi="http://www.w3.org/2001/XInclude">
<include path="default-customizer.dicon"/>
<component name="serviceCustomizer" class="org.seasar.framework.container.customizer.CustomizerChain">
<initMethod name="addCustomizer">
<arg>traceCustomizer</arg>
</initMethod>
</component>
</components>
SMART deployを使わない場合
サーバ側のdiconファイルに定義すべきコンポーネントは次の通りです.
- サービスの実装クラス
- org.seasar.extension.component.impl.ComponentInvokerImpl
- org.seasar.remoting.rmi.adaptor.impl.RMIAdaptorImpl
- org.seasar.remoting.rmi.deployer.impl.RMIAdaptorDeployerImpl
- org.seasar.remoting.rmi.filter.impl.RMIExternalContextFilter
リモートオブジェクトは通常サービスとしてインタフェースと実装クラスを作成します. サーバ側ではサービスの実装クラスをS2コンテナに定義します.
server.dicon
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
"http://www.seasar.org/dtd/components24.dtd">
<components xmlns:xi="http://www.w3.org/2001/XInclude">
<component name="helloService"
class="examples.rmi.service.impl.HelloServiceImpl"/>
<component name="componentInvoker"
class="org.seasar.extension.component.impl.ComponentInvokerImpl"/>
<component name="RMIAdapptor"
class="org.seasar.remoting.rmi.adaptor.impl.RMIAdaptorImpl">
<property name="invokerName">"componentInvoker"</property>
</component>
<component class="org.seasar.remoting.rmi.deployer.impl.RMIAdaptorDeployerImpl">
<property name="registryPort">1108</property>
<property name="servicePort">1109</property>
<initMethod name="deploy"/>
<destroyMethod name="undeploy"/>
</component>
<component class="org.seasar.remoting.rmi.filter.impl.RMIExternalContextFilter"/>
</components>
RMIで使用するポート番号はRMIAdaptorDeployerImplの
servicePortプロパティで設定します.
