execJava 機能は、XML スキーマを通じてプランおよびコンポーネントに使用できます。必要に応じて XML で Java コードを実行できます。また、execJava には API もあります。
プリフライトと実際の動作を指定できます。クラスは通常、コンポーネントの JAR リソースを使用して配備します。execJava のクラス、メソッド、およびインタフェースについては、『Sun N1 Service Provisioning System JavaDoc』を参照してください。
<execJava className= classname of the executor factory class class Path=... >
execJava API は com.sun.n1.sps.plugin.execJava パッケージに含まれます。execJava API は、5 つのインタフェースと 2 つの例外クラスから構成されます。
このインタフェースは、execJava の実装が配備段階または実際の実行段階で呼び出されたときに使用可能なサービスを発行します。
このインタフェースは、プリフライトと実際の実行レベルの両方に共通の execJava の実装の実行コンテキストを提供します。
このインタフェースは、execJava を使用してエージェントのコードを実行する必要があるクラスで実装されます。
このインタフェースは、execJava のステップを使用してリモートエージェントで任意のコードを実行するインフラストラクチャーの一部です。
このインタフェースは、execJava の実装が実行のプリフライト段階で呼び出されたときに使用可能なサービスを発行します。
ExecutionException のインスタンスを使用して、execJava の呼び出しのエラーや警告にフラグを付けます。
execJava の実行がタイムアウトになったときにこの例外のインスタンスがスローされます。
ExecutorFactory インタフェースを使用して、特定のステップのプリフライトおよび実際の実行環境のインスタンスを取得します。
Executor getActualExecutor(AgentContext callContext) Executor getPreflightExecutor(AgentContext callContext)
プリフライトと実際の実行のステップの間で渡される呼び出しコンテキストが同じである必要はありません。
AgentContext メソッドは、特定のリモートエージェントに呼び出しコンテキストを提供します。
VariableSettingsHolder getVariables()
// Returns the variables passed to the execJava step using <argList>
PrintStream getStandardOutput()
PrintStream getStandardError()
InputStream getStandardInput()
File getWorkingDir()
Executor インタフェースは、ステップの本体の実行に使用されるエントリポイントを提供します。
void execute() throw ExecutionException
実行出力とエラー出力は、関連付けられているエージェントコンテキストの stdout と stderr のストリームに書き込まれます。入力は、関連付けられているエージェントコンテキストの入力ストリームから読み取られます。エラーは、ExecutionException クラスのインスタンスを呼び出して報告されます。
public class StopServerFactory extends WLFactoryBase {
public static final String TARGET = "serverName";
public Executor
getActualExecutor(AgentContext inAgentContext, ActualExecJavaContext inContext)
{
VariableSettingsSource variableSettings = inContext.getVariableSettings();
String target = variableSettings.getVarValue(TARGET);
return new StopServerExecutor(getConnect(variableSettings), target);
}
public VariableSettingsSource getParams() {
VariableSettingsHolder list = getWLParams();
list.setVarValue(TARGET, null);
return list;
}
}
public class StopServerExecutor implements Executor {
private WLConnect mConnect;
private String mTarget;
/**
*
**/
public StopServerExecutor(WLConnect connect, String target) {
mConnect = connect;
mTarget = target;
}
/**
*
**/
public void execute() throws ExecutionException {
try {
WLAdminServer server = new WLAdminServer(mConnect);
server.stopServer(server.getServer(mTarget));
}
catch (Exception e) {
throw new ExecutionException
(new PluginMessage(WLPluginHierarchyException.MSG_WEBLOGIC_ERROR), e);
}
}
}
public class SampleExecutorFactory implements ExecutorFactory
{
public Executor getActualExecutor(AgentContext inAgentContext,
ActualExecJavaContext inActualExecJavaContext)
{
return new EnvParamSettingActualExecutor(inActualExecJavaContext);
}
public Executor getPreflightExecutor(AgentContext inAgentContext,
PreflightExecJavaContext inPreflightExecJavaContext)
{
return new EnvParamSettingPreflightExecutor(inPreflightExecJavaContext);
}
public VariableSettingsSource getParams()
{
VariableSettingsHolder params = new VariableSettingsHolder();
params.setVarValue(PARAM_NAME, "");
params.setVarValue(PARAM_VALUE, "");
return params;
}
public static final String PARAM_NAME = "nameParam";
public static final String PARAM_VALUE = "valueParam";
}
public class EnvParamSettingPreflightExecutor implements Executor
{
VariableSettingsSource mVars;
public EnvParamSettingPreflightExecutor
(PreflightExecJavaContext inPreflightExecJavaContext)
{
mVars = inPreflightExecJavaContext.getVariableSettings();
}
public void execute() throws ExecutionException
{
String propName = mVars.getVarValue(SampleExecutorFactory.PARAM_NAME);
if("".equals(propName)) {
throw new ExecutionException(new PluginMessage("sample.noNameParam"));
}
String propValue=System.getProperty(propName);
if(!(propValue == null || "".equals(propValue))) {
// property already set, error out
throw new ExecutionException(new PluginMessage("sample.propAlreadySet",
new String[]{propName, propValue}));
}
}
}
public class EnvParamSettingActualExecutor implements Executor
{
VariableSettingsSource mVars;
public EnvParamSettingActualExecutor(ActualExecJavaContext inCtx)
{
mVars = inCtx.getVariableSettings();
}
public void execute() throws ExecutionException
{
String propName = mVars.getVarValue(SampleExecutorFactory.PARAM_NAME);
String propValue = mVars.getVarValue(SampleExecutorFactory.PARAM_VALUE);
System.setProperty(propName, propValue);
if(Logger.isDebugEnabled(this)) {
Logger.debug("Setting prop "+propName + " to " + propValue, this);
}
System.out.println("Setting prop "+propName + " to " + propValue);
}
}