カスタム・スケーリング・リスナーの追加
WebSphere® Application Server Developer Tools for Eclipse を使用してカスタム・スケーリング・リスナー・バンドルを作成できます。カスタム・スケーリング・リスナーには、すべての保留中のスケーリング・アクションが通知されます。このリスナーは、そのスケーリング・アクションを許可または拒否することができます。また、アクションを処理することを決定し、スケーリング動作を完全にカスタマイズすることもできます。
始める前に
Liberty インストール済み環境に scalingController-1.0 フィーチャーがあることを確認します。スケーリング・コントローラーについて詳しくは、『Liberty 集合の自動スケーリングのセットアップ』および『スケーリング・コントローラー』を参照してください。
このタスクについて
リスナー・インターフェースを実装し、実装クラスをサービス・レジストリーに登録する必要があります。スケーリング・リスナーはスケーリング・アクションの許可または拒否、および処理を実行することができます。
各 Liberty SPI 用の Java API 資料は、${wlp.install.dir}/dev ディレクトリーのいずれかの API 文書サブディレクトリー内に別個の圧縮ファイルとしてあります。
手順
- 「ファイル」 > 「新規」 > 「その他」をクリックし、「OSGi」を展開します。
- 「OSGi バンドル・プロジェクト」をクリックし、「次へ」をクリックします。 「新規 OSGi バンドル・プロジェクト」ウィンドウが開きます。
- プロジェクト名として ScalingSPISampleBundle を入力します。「ターゲット・ランタイム」リストで、「WebSphere Application Server Liberty」を選択します。ランタイムが存在しない場合は、「新規ランタイム」をクリックして WebSphere Application Server Liberty ランタイムを作成します。
- 「バンドルをアプリケーションに追加」ラジオ・ボタンをクリアします。
- 「次へ」を 2 回クリックし、「OSGi バンドル」ページに進みます。
- 「OSGi バンドル」ページで、「アクティベーター (バンドルのライフサイクルを制御する Java クラス) を生成する」をチェックします。 「アクティベーター名」 を scalingspisamplebundle.Activator のままにし、「終了」をクリックします。
- 「ファイル」 > 「新規」 > 「その他」をクリックし、「OSGi」を展開します。
- 「Liberty フィーチャー・プロジェクト」をクリックし、「次へ」をクリックします。「Liberty フィーチャー・プロジェクト」ウィンドウが開きます。
- プロジェクト名として ScalingSPISampleFeature と指定します。
- 「ターゲット・ランタイム」リストで、「WebSphere Application Server Liberty」を選択し、「次へ」をクリックします。 「OSGi バンドル選択」ページが開きます。
- 「OSGi バンドル選択」ページで、「含まれるバンドル」として「ScalingSPISampleBundle 1.0.0」を選択し、「終了」をクリックします。
- 「ウィンドウ」 > 「設定」 > 「プラグイン開発」 > 「ターゲット・プラットフォーム」をクリックし、「WebSphere Application Server Liberty with SPI」を選択します。
- 「適用」をクリックし、「OK」をクリックします。
- ScalingSPISampleBundle > BundleContent > META-INF を展開し、プラグイン・マニフェスト・エディターを使用して MANIFEST.MF ファイルを開きます。
- 「依存関係」タブを選択し、com.ibm.wsspi.scaling.action.consumer パッケージと com.ibm.wsspi.scaling.action.controller パッケージを「インポート済みパッケージ」ペインに追加します。Ctrl+S を押して変更を保存する必要がある場合があります。
- ScalingSPISampleBundle プロジェクトで、ScalingSPISamplePlugin と呼ばれる実装クラスを追加します。この新しいクラスは、com.ibm.wsspi.scaling.action.consumer.ScalingActionPlugin インターフェースを実装します。
package scalingspisamplebundle; import com.ibm.wsspi.scaling.action.consumer.ScalingActionPlugin; import com.ibm.wsspi.scaling.action.controller.ScalingActionContext; import com.ibm.wsspi.scaling.action.controller.ScalingActionContext.ActionType; import com.ibm.wsspi.scaling.action.controller.ScalingActionContext.ActionDecision;; /** * This a sample Liberty scaling SPI plugin that acts as a template for developing a custom * SPI plugin. In this plugin, no actual work is done and the return value to the Liberty Scaling * controller is always DEFAULT_ACTION. * */ public class ScalingSPISamplePlugin implements ScalingActionPlugin { /** {@inheritDoc} */ @Override public ActionDecision actionRequired(ScalingActionContext action) { ActionDecision returnType = ActionDecision.DEFAULT_ACTION; if (action.getActionType() == ActionType.START_SERVER) { returnType = startServer(action); } else if (action.getActionType() == ActionType.CREATE_SERVER) { returnType = createServer(action); } else if (action.getActionType() == ActionType.STOP_SERVER) { returnType = stopServer(action); } return returnType; } private ActionDecision startServer(ScalingActionContext action) { // perform some action to start a server return ActionDecision.DEFAULT_ACTION; } private ActionDecision createServer(ScalingActionContext action) { // perform some action to create a server return ActionDecision.DEFAULT_ACTION; } private ActionDecision stopServer(ScalingActionContext action) { // perform some action to stop a server return ActionDecision.DEFAULT_ACTION; } }
- ScalingSPISampleBundle プロジェクトで、Activator クラスを開き、start(BundleContext) メソッドを編集して、新規リスナー・サービスを登録するコードを追加します。
public void start(BundleContext context) throws Exception { final Hashtable<String, Object> properties = new Hashtable<String, Object>(); ScalingSPISamplePlugin scalingSPISamplePlugin = new ScalingSPISamplePlugin(); context.registerService(ScalingActionPlugin.class, scalingSPISamplePlugin, properties); }
HashMap をインポートするよう要求するプロンプトが出されたら、java.util.HashMap をインポートすることを選択します。
- ScalingSPISampleFeature プロジェクトを右クリックし、「フィーチャーのインストール」をクリックして、フィーチャーを Liberty ランタイムにインストールします。
「フィーチャーのインストール」メニュー・オプションは、 Java EE パースペクティブの「エンタープライズ・エクスプローラー」ビューにあります。
- server.xml ファイルを編集して、ScalingSPISampleFeature を使用可能にします。
... <featureManager> ... <feature>scalingController-1.0</feature> <feature>usr:ScalingSPISampleFeature</feature> </featureManager>...
親トピック: Liberty SPI ユーティリティー

ファイル名: twlp_wve_add_scaling_listener.html