Spring 管理拡張 Bean および名前空間のサポートを使用して、コンテナー・サーバーを始動できます。
まず最初に、1 つの ObjectGrid "Grid" と 1 つのマップ "Test" が含まれているだけの、単純な ObjectGrid XML ファイル を定義します。この ObjectGrid には "partitionListener" という名前の ObjectGridEventListener プラグインがあり、 マップ "Test" には "testLRUEvictor" という名前の Evictor プラグインがあります。 ObjectGridEventListener プラグインと Evictor プラグインの両方とも、 名前に "{spring}" が含まれるため、Spring を使用して構成されることに注意してください。
<?xml version="1.0" encoding="UTF-8"?>
<objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ibm.com/ws/objectgrid/config ../objectGrid.xsd"
xmlns="http://ibm.com/ws/objectgrid/config">
<objectGrids>
<objectGrid name="Grid">
<bean id="ObjectGridEventListener" className="{spring}partitionListener" />
<backingMap name="Test" pluginCollectionRef="test" />
</objectGrid>
</objectGrids>
<backingMapPluginCollections>
<backingMapPluginCollection id="test">
<bean id="Evictor" className="{spring}testLRUEvictor"/>
</backingMapPluginCollection>
</backingMapPluginCollections>
</objectGridConfig>
次に、 以下に示すように単純な ObjectGrid デプロイメント XML ファイルを作成します。これは ObjectGrid を 5 個の区画に 分けます。レプリカは必要ありません。
<?xml version="1.0" encoding="UTF-8"?>
<deploymentPolicy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ibm.com/ws/objectgrid/deploymentPolicy ../deploymentPolicy.xsd"
xmlns="http://ibm.com/ws/objectgrid/deploymentPolicy">
<objectgridDeployment objectgridName="Grid">
<mapSet name="mapSet" numInitialContainers="1" numberOfPartitions="5" minSyncReplicas="0"
maxSyncReplicas="1" maxAsyncReplicas="0">
<map ref="Test"/>
</mapSet>
</objectgridDeployment>
</deploymentPolicy>
次に、 ObjectGrid Spring 管理拡張 Bean および名前空間のサポート機能を両方とも使用 して、ObjectGrid Bean を構成します。spring xml ファイル の名前は Grid_spring.xml です。この XML ファイルには 2 つのスキーマ が含まれていることに注意してください。spring-beans-2.0.xsd は Spring 管理 Bean を使用 するためのもので、objectgrid.xsd は objectgrid 名前空間内に事前定義された Bean を使用する ためのものです。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:objectgrid="http://www.ibm.com/schema/objectgrid"
xsi:schemaLocation="
http://www.ibm.com/schema/objectgrid
http://www.ibm.com/schema/objectgrid/objectgrid.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<objectgrid:register id="ogregister" gridname="Grid"/>
<objectgrid:server id="server" isCatalog="true" name="server">
<objectgrid:catalog host="localhost" port="2809"/>
</objectgrid:server>
<objectgrid:container id="container"
objectgridxml="com/ibm/ws/objectgrid/test/springshard/objectgrid.xml"
deploymentxml="com/ibm/ws/objectgrid/test/springshard/deployment.xml"
server="server"/>
<objectgrid:LRUEvictor id="testLRUEvictor" numberOfLRUQueues="31"/>
<bean id="partitionListener"
class="com.ibm.websphere.objectgrid.springshard.ShardListener" scope="shard"/>
</beans>
この spring XML ファイルには、次の 6 個の Bean が定義されました。
以下のスニペットは、 コンテナー・サービスとカタログ・サービスの両方をホストする ObjectGrid サーバーを 開始します。これを見て分かるように、サーバーを開始するために呼び出す必要のあるメソッドは、Bean ファクトリーからの Bean "container" の get だけです。 これは、ロジックの大部分を Spring 構成に移すことになり、プログラミングの複雑さ が軽減されます。
public class ShardServer extends TestCase
{
Container container;
org.springframework.beans.factory.BeanFactory bf;
public void startServer(String cep)
{
try
{
bf = new org.springframework.context.support.ClassPathXmlApplicationContext(
"/com/ibm/ws/objectgrid/test/springshard/Grid_spring.xml", ShardServer.class);
container = (Container)bf.getBean("container");
}
catch(Exception e)
{
throw new ObjectGridRuntimeException("Cannot start OG container", e);
}
}
public void stopServer()
{
if(container != null)
container.teardown();
}
}