WebSphere® eXtreme Scale には、既存の Java アプリケーション内に eXtreme Scale サーバーおよびクライアントを組み込む、アプリケーション・プログラミング・インターフェース (API) およびシステム・プログラミング・インターフェースが含まれています。 以下のトピックで、使用可能な組み込みサーバー API について説明します。
eXtreme Scale サーバー・インスタンスの構成には、いくつかのプロパティーを使用できますが、これは、ServerFactory.getServerProperties メソッドから取得できます。ServerProperties オブジェクトは singleton のため、getServerProperties メソッドの各呼び出しでは同じインスタンスが取得されます。
次のコードを使用して、新規サーバーを作成することができます。
Server server = ServerFactory.getInstance();
getInstance の最初の呼び出しの前に設定されたすべてのプロパティーは、サーバーの初期化に使用されます。
サーバー・プロパティーは、ServerFactory.getInstance が最初に呼び出されるまで設定できます。 getInstance メソッドの最初の呼び出しで、eXtreme Scale サーバーがインスタンス化され、構成されたすべてのプロパティーが読み取られます。作成後にプロパティーを設定しても効果はありません。以下の例は、Server インスタンスをインスタンス化する前のプロパティーの設定方法を示しています。
// Get the server properties associated with this process.
ServerProperties serverProperties = ServerFactory.getServerProperties();
// Set the server name for this process.
serverProperties.setServerName("EmbeddedServerA");
// Set the name of the zone this process is contained in.
serverProperties.setZoneName("EmbeddedZone1");
// Set the end point information required to bootstrap to the catalog service.
serverProperties.setCatalogServiceBootstrap("localhost:2809");
// Set the ORB listener host name to use to bind to.
serverProperties.setListenerHost("host.local.domain");
// Set the ORB listener port to use to bind to.
serverProperties.setListenerPort(9010);
// Turn off all MBeans for this process.
serverProperties.setMBeansEnabled(false);
Server server = ServerFactory.getInstance();
CatalogServerProperties catalogServerProperties =
ServerFactory.getCatalogProperties();
catalogServerProperties.setCatalogServer(true);
Server server = ServerFactory.getInstance();
JVM が複数の eXtreme Scale コンテナーをホストするようにするには、Server.createContainer メソッドを発行します。 以下のコードは、eXtreme Scale コンテナーをインスタンス化する方法を示しています。
Server server = ServerFactory.getInstance();
DeploymentPolicy policy = DeploymentPolicyFactory.createDeploymentPolicy(
new File("META-INF/embeddedDeploymentPolicy.xml").toURI().toURL(),
new File("META-INF/embeddedObjectGrid.xml").toURI().toURL());
Container container = server.createContainer(policy);
すべてのサービスは、まとめて開始することができ、これは開発に便利で、実動中にも実用的です。 サービスをまとめて開始することにより、1 つのプロセスで、 カタログ・サービスの開始、コンテナー・セットの開始、クライアント接続ロジックの 実行をすべて行うことができます。このような方法でサービスを開始すると、 分散環境にデプロイする前にプログラム上の問題を整理する ことができます。以下のコードは、自己完結型の eXtreme Scale サーバーをインスタンス化する方法を示しています。
CatalogServerProperties catalogServerProperties =
ServerFactory.getCatalogProperties();
catalogServerProperties.setCatalogServer(true);
Server server = ServerFactory.getInstance();
DeploymentPolicy policy = DeploymentPolicyFactory.createDeploymentPolicy(
new File("META-INF/embeddedDeploymentPolicy.xml").toURI().toURL(),
new File("META-INF/embeddedObjectGrid.xml").toURI().toURL());
Container container = server.createContainer(policy);
eXtreme Scale の構成は、eXtreme Scale を WebSphere Application Server 環境にインストールすると、自動的にセットアップされます。サーバーにアクセスしてコンテナーを作成する前にプロパティーを設定する必要はありません。 以下のコードは、eXtreme Scale サーバーを WebSphere Application Server でインスタンス化する方法を示しています。
Server server = ServerFactory.getInstance();
DeploymentPolicy policy = DeploymentPolicyFactory.createDeploymentPolicy(
new File("META-INF/embeddedDeploymentPolicy.xml").toURI().toURL(),
new File("META-INF/embeddedObjectGrid.xml").toURI().toURL);
Container container = server.createContainer(policy);