Portlet MBean および PortletApplication MBean
タイプが Portlet および PortletApplication の MBean は、所定のポートレット・アプリケーションおよびそのポートレットの情報を提供します。 タイプが PortletApplication の MBean を使用すると、ポートレット・アプリケーションに属するすべてのポートレットの名前のリストを取得できます。 タイプが Portlet の MBean を所定のポートレット名で照会すると、タイプが Portlet の MBean からポートレット固有の情報を取得できます。
ポートレットまたはポートレット・アプリケーションに対応する各 MBean は、その名前によって一意的に識別可能です。
ポートレット・アプリケーションでは、portlet.xml 内に名前セットが存在する必要はありません。
タイプが portletapplication の MBean に対する MBean 名では、エンタープライズ・アーカイブ (EAR) ファイル名の後に「#」と、ストリング「_portlet」と連結した Web モジュール名が続きます。
例えば、タイプが portletapplication の MBean のフォーマットは、次のようになります。
<EarFileName>#<WarFileName>_portletタイプが portlet の MBean 用に選択される名前は、ポートレットが属する、タイプが portletapplication の MBean の名前に、次のように、ポートレット名を連結したものです。
<EarFileName>#<WarFileName>_portlet.<portletname>
以下に、結果として作成された PortletApplication MBean 名とポートレット名の例を示します。
EarName SampleEar
WebModule SampleWar.war
PortletApplication MBean name: SampleEar#SampleWar_portlet
Portlet: SampleEar#SampleWar_portlet.BookmarkPortlet
MBean 名は、バージョン 6.1 の場合と比較して変更されています。これは、古いネーミング・パターンが固有ではなく、特定の状況下で問題を引き起こす可能性があるためです。
古いネーミング・パターンに依存する場合は、ポートレット・コンテナーのカスタム・プロパティー useShortMBeanNames を true に設定して、以前の既知の MBean 名をアクティブにできます。
これはパフォーマンスに影響を及ぼすため、必要でなければ、古いネーミング・パターンをアクティブにしないようにしてください。Web モジュール名とポートレット名はピリオドで区切られています。 詳しくは、タイプが Portlet および PortletApplication の MBean の API 資料を参照してください。 生成済み API 文書は、インフォメーション・センターの目次で、
をたどって入手できます。次のコードは、名前が SampleWar のアプリケーションに対してタイプが portletapplication の MBean を起動する例を示しています。
String myPortletApplicationName = "SampleEar#SampleWar_portlet";
This name is composed by the Ear file name followed by "#" and
the web module name concatenated with the substring "_portlet"
com.ibm.websphere.management.AdminService adminService =
com.ibm.websphere.management.AdminServiceFactory.getAdminService();
javax.management.ObjectName on =
new ObjectName("WebSphere:type=PortletApplication,name=" + myPortletApplicationName + ",*");
Iterator onIter = adminService.queryNames(on, null).iterator();
while(onIter.hasNext())
{
on = (ObjectName)onIter.next();
}
String ctxRoot = (java.lang.String)adminService.getAttribute(on, "webApplicationContextRoot");
前述の例では、MBeanServer は最初にタイプが PortletApplication の MBean を照会されています。
この照会が成功した場合は、webApplicationContextRoot 属性が、その MBean 上か、最初に見つかった MBean 上で検索されます。
結果は、ctxRoot 変数内に保管されます。
この変数には、検索されたポートレット・アプリケーションを含む Web アプリケーションのコンテキスト・ルートが含まれています。
変数は、「/bookmark」に類似しています。次のコード例は、BookmarkPortlet という名前のポートレットに対して、タイプが portlet の MBean を起動する方法を示したものです。
String myPortletName = "SampleEar#SampleWar_portlet.BookmarkPortlet";
This name is composed by the name of the MBean of type portletapplication and
the portlet name, separated by a full stop because the same portlet name may
be used within different web modules, but must be unique within the system.
com.ibm.websphere.management.AdminService adminService =
com.ibm.websphere.management.AdminServiceFactory.getAdminService();
javax.management.ObjectName on =
new ObjectName("WebSphere:type=Portlet,name=" + myPortletName + ",*");
Iterator iter = adminService.queryNames(on, null).iterator();
while(iter.hasNext())
{
on = (ObjectName)iter.next;
}
java.util.Locale locale = (java.util.Locale) adminService.getAttribute(on, "defaultLocale");
getAttribute メソッドによって戻される MBean のロケールは、このポートレットで定義されているデフォルト・ロケールです。Portlet および PortletApplication の MBean に対するフルネーム
MBean は、完全な識別可能名でも登録されます。
<ApplicationName>#<WARfilename.war>_portlet.<portlet_name> for the Portlet MBean
<ApplicationName>#<WARfilename.war>_portlet for the PortletApplication MBean
ここで、<..> は、対応するアプリケーション・データで置き換えられます。
例えば、SampleApplication#SamplePortlet.war_portlet.SamplePortlet のようになります。短い MBean 名を使用可能にするには、useShortMBeanNames ポートレット・コンテナーのカスタム・プロパティーを true に設定します。