WebSphere® eXtreme Scale では、組み込みサーバーおよびコンテナーのライフサイクルの管理にプログラマチック API を使用できます。コマンド行オプションやファイル・ベースのサーバー・プロパティーでも構成可能な任意のオプションを使用して、プログラムでサーバーを構成できます。コンテナー・サーバー、カタログ・サービス、またはその両方として、組み込みサーバーの構成が可能です。
管理 API を使用して多くの管理タスクを実行できます。API の一般的な使用法の 1 つとして、Web アプリケーションの状態を保管する内部サーバーとしての使用があります。 Web サーバーは、組み込み WebSphere eXtreme Scale サーバーを始動し、コンテナー・サーバーをカタログ・サービスに報告することができ、サーバーは、より幅広い分散グリッドのメンバーとして追加されます。この使用法では、本来は揮発性のデータ・ストアにスケーラビリティーと高可用性が提供されます。
組み込み eXtreme Scale サーバーの全ライフサイクルをプログラムで制御できます。例は、できる限り汎用的にして、概要を説明したステップの直接的なコードの例のみを示しています。ServerProperties props = ServerFactory.getServerProperties();
props.setCatalogServiceBootstrap("host:port"); // required to connect to specific catalog service
props.setServerName("ServerOne"); // name server
props.setTraceSpecification("com.ibm.ws.objectgrid=all=enabled"); // Sets trace spec
CatalogServerProperties インターフェースについて詳しくは 、CatalogServerProperties インターフェースを 参照してください。
CatalogServerProperties catalogProps = ServerFactory.getCatalogProperties();
catalogProps.setCatalogServer(true); // false by default, it is required to set as a catalog service
catalogProps.setQuorum(true); // enables / disables quorum
Server インターフェースについて詳しくは、 Server インターフェースを参照してください。ServerFactory クラスについて詳しくは、ServerFactory クラスを参照してください。
以下の例は、Server インスタンスの作成方法を示しています。 Server server = ServerFactory.getInstance();
上記の例において、ServerFactory クラスは、
Server インスタンスを返す静的メソッドを提供します。
ServerFactory クラスは、Server インスタンスを取得するための唯一のインターフェースとして意図されています。
そのため、このクラスは必ず、インスタンスが singleton であるか、または各 JVM または独立したクラス・ローダーの 1 つインスタンスであるようにします。
getInstance メソッドで Server インスタンスを初期化します。
インスタンスを初期化する前にすべてのサーバー・プロパティーの構成が必要です。
Server クラスは、新規の Container インスタンスの作成に関与します。
ServerFactory クラスと Server クラスの両方を使用して、組み込み Server インスタンスのライフサイクルを管理できます。
Container インターフェースについて詳しくは、 Container インターフェースを参照してください。
DeploymentPolicy policy = DeploymentPolicyFactory.createDeploymentPolicy(new
URL("file://urltodeployment.xml"),
new URL("file://urltoobjectgrid.xml"));
Container container = server.createContainer(policy);
コンテナー・サーバーを除去してクリーンアップするには、取得した Container インスタンスで teardown メソッドを実行します。コンテナーで teardown メソッドを実行すると、コンテナーを適切にクリーンアップし、組み込みサーバーからコンテナーを除去します。
container.teardown();
ServerFactory.stopServer(); // Uses the factory to kill the Server singleton
// or
server.stopServer(); // Uses the Server instance directly
server.waitFor(); // Returns when the server has properly completed its shutdown procedures
全コードの例: import java.net.MalformedURLException;
import java.net.URL;
import com.ibm.websphere.objectgrid.ObjectGridException;
import com.ibm.websphere.objectgrid.deployment.DeploymentPolicy;
import com.ibm.websphere.objectgrid.deployment.DeploymentPolicyFactory;
import com.ibm.websphere.objectgrid.server.Container;
import com.ibm.websphere.objectgrid.server.Server;
import com.ibm.websphere.objectgrid.server.ServerFactory;
import com.ibm.websphere.objectgrid.server.ServerProperties;
public class ServerFactoryTest {
public static void main(String[] args) {
try {
ServerProperties props = ServerFactory.getServerProperties();
props.setCatalogServiceBootstrap("catalogservice-hostname:catalogservice-port");
props.setServerName("ServerOne"); // name server
props.setTraceSpecification("com.ibm.ws.objectgrid=all=enabled"); // TraceSpec
/*
* In most cases, the server will serve as a container server only
* and will connect to an external catalog service. This is a more
* highly available way of doing things. The commented code excerpt
* below will enable this Server to be a catalog service.
*
*
* CatalogServerProperties catalogProps =
* ServerFactory.getCatalogProperties();
* catalogProps.setCatalogServer(true); // enable catalog service
* catalogProps.setQuorum(true); // enable quorum
*/
Server server = ServerFactory.getInstance();
DeploymentPolicy policy = DeploymentPolicyFactory.createDeploymentPolicy
(new URL("url to deployment xml"), new URL("url to objectgrid xml file"));
Container container = server.createContainer(policy);
/*
* Shard will now be placed on this container if the deployment requirements are met.
* This encompasses embedded server and container creation.
*
* The lines below will simply demonstrate calling the cleanup methods
*/
container.teardown();
server.stopServer();
int success = server.waitFor();
} catch (ObjectGridException e) {
// Container failed to initialize
} catch (MalformedURLException e2) {
// invalid url to xml file(s)
}
}
}