モジュール・デプロイメント記述子
(
web.xml ファイルおよび
ibm-web-bnd.xmi ファイル) で resource-ref を定義し
、
java:comp ネーム・スペースを使用してキャッシュをルックアップします。
Resource-ref の例:
ファイル: web.xml
<resource-ref id="ResourceRef_1">
<res-ref-name>dmap/LayoutCache</res-ref-name>
<res-type>com.ibm.websphere.cache.DistributedMap</res-type>
<res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref id="ResourceRef_2">
<res-ref-name>dmap/UserCache</res-ref-name>
<res-type>com.ibm.websphere.cache.DistributedMap</res-type>
<res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
ファイル: ibm-web-bnd.xmi
<?xml version="1.0" encoding="UTF-8"?>
<webappbnd:WebAppBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:webappbnd="webappbnd.xmi"
xmlns:webapplication="webapplication.xmi" xmlns:commonbnd="commonbnd.xmi" xmlns:common="common.xmi"
xmi:id="WebApp_ID_Bnd" virtualHostName="default_host">
<webapp href="WEB-INF/web.xml#WebApp_ID"/>
<resRefBindings xmi:id="ResourceRefBinding_1" jndiName="services/cache/instance_one">
<bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1"/>
</resRefBindings>
<resRefBindings xmi:id="ResourceRefBinding_2" jndiName="services/cache/instance_two">
<bindingResourceRef href="WEB-INF/web.xml#ResourceRef_2"/>
</resRefBindings>
</webappbnd:WebAppBinding>
以下の例は、resource-ref のルックアップ方法を示しています。
InitialContext ic = new InitialContext();
DistributedMap dm1a =(DistributedMap)ic.lookup("java:comp/env/dmap/LayoutCache");
DistributedMap dm2a =(DistributedMap)ic.lookup("java:comp/env/dmap/UserCache");// or
DistributedObjectCache dm1a =(DistributedObjectCache)ic.lookup("java:comp/env/dmap/LayoutCache");
DistributedObjectCache dm2a =(DistributedObjectCache)ic.lookup("java:comp/env/dmap/UserCache");
上記の
resource-ref の例では、
java:comp/env/dmap/LayoutCache を
/services/cache/instance_one にマップし、
java:comp/env/dmap/UserCache
を
/services/cache/instance_two にマップしています。この例では、
DistributedMap
dm1 と
dm1a が同じオブジェクトです。
DistributedMap dm2 と
dm2a が同じオブジェクトです。