MFT リソース・モニターのユーザー出口

リソース・モニターのユーザー出口を使用して、関連タスクが開始される前に、モニターのトリガー条件が満たされた場合に実行するようカスタム・コードを構成できます。

ユーザー出口コードから直接新しい転送を呼び出すことは推奨されません。 ユーザー出口はエージェントの再始動に対して回復力がないため、場合によってはファイルが複数回転送されることになります。

リソース・モニターのユーザー出口は、ユーザー出口の既存インフラストラクチャーを使用します。 モニター・ユーザー出口は、モニターがトリガーしてから呼び出されますが、この呼び出しは、対応するタスクがモニターのタスクによって実行される前に行われます。 これにより、ユーザー出口は実行されるタスクを変更して、タスクを処理するかどうかを決定できます。 モニター・タスクは、モニター・メタデータを更新することで変更できます。更新されたモニター・メタデータは、元のモニターの作成によって作成されたタスク文書で変数置換に使用されます。 別の方法として、モニター出口は、パラメーターとして渡されるタスク定義 XML ストリングを置換または更新できます。 モニター出口は、タスクに対する結果コード (「proceed」または「cancel」のいずれか) を返すことができます。 cancel が返された場合、タスクは開始されず、モニター対象リソースがトリガー条件と一致するまでモニターは再開されません。 リソースが変更されなければ、トリガーは開始しません。 他のユーザー出口と同様に、モニター出口はまとめてチェーニングできます。 出口の 1 つが cancel の結果コードを返すと、結果全体が cancel となり、タスクは開始されません。

  • 環境メタデータのマップ (他のユーザー出口と同じ)
  • 不変システム・メタデータおよび可変ユーザー・メタデータを含むモニター・メタデータのマップ。 不変システム・メタデータは、以下のとおりです。
    • FILENAME - トリガー条件を満たしたファイルの名前
    • FILEPATH - トリガー条件を満たしたファイルへのパス
    • FILESIZE (バイト単位 - このメタデータは存在しない場合がある) - トリガー条件を満たしたファイルのサイズ
    • LASTMODIFIEDDATE (地域別) - トリガー条件を満たしたファイルの最終変更日。 エージェントを実行しているタイム・ゾーンの現地日付が ISO 8601 の日付形式で表示されます。
    • LASTMODIFIEDTIME (地域別) - トリガー条件を満たしたファイルの最終変更時刻 (地域別形式)。 エージェントを実行しているタイム・ゾーンの現地時間が ISO 8601 の時間形式で表示されます。
    • LASTMODIFIEDDATEUTC - トリガー・ファイルの最終変更日 (世界共通形式)。 この日付は、UTC タイム・ゾーンに変換された現地日付として表され、 ISO 8601 日付として書式設定されます。
    • LASTMODIFIEDTIMEUTC - トリガー条件を満たしたファイルの最終変更時間 (世界共通形式)。 この日付は、UTC タイム・ゾーンに変換された現地時間として表され、 ISO 8601 時間として書式設定されます。
    • AGENTNAME - モニター・エージェント名
  • モニター・トリガーの結果として実行されるタスクを表す XML ストリング。
モニター出口は、以下のデータを返します。
  • さらに進行するかどうか (proceed または cancel) を示す標識
  • トリガー条件を満たしたログ・メッセージに挿入するストリング

モニター出口コードを実行した結果、パラメーターとして最初に渡されたモニター・メタデータおよびタスク定義 XML ストリングも更新されている場合があります。

エージェント・プロパティー monitorExitClasses ( agent.properties ファイル内 ) の値は、ロードするモニター出口クラスを指定します。各出口クラスはコンマで区切ります。 以下に例を示します。

monitorExitClasses=testExits.TestExit1,testExits.testExit2

モニター・ユーザー出口のインターフェースは、以下のとおりです。

package com.ibm.wmqfte.exitroutine.api;

import java.util.Map;

/**
 * An interface that is implemented by classes that want to be invoked as part of
 * user exit routine processing.  This interface defines a method that will be
 * invoked immediately prior to starting a task as the result of a monitor trigger
 */
public interface MonitorExit {

	/**
	 * Invoked immediately prior to starting a task as the result of a monitor 
	 * trigger.
	 * 
	 * @param environmentMetaData
	 *            meta data about the environment in which the implementation
	 *            of this method is running.  This information can only be read,
	 *            it cannot be updated by the implementation.  The constant
	 *            defined in <code>EnvironmentMetaDataConstants</code> class can 
	 *            be used to access the data held by this map.
	 * 
	 * @param monitorMetaData
	 *            meta data to associate with the monitor. The meta data passed
	 *            to this method can be altered, and the changes will be
	 *            reflected in subsequent exit routine invocations. This map
	 *            also contains keys with IBM reserved names.  These entries are
	 *            defined in the <code>MonitorMetaDataConstants</code> class and
	 *            have special semantics. The the values of the IBM reserved names
	 *            cannot be modified by the exit 
	 * 
	 * @param taskDetails
	 *            An XML String representing the task to be executed as a result of
	 *            the monitor triggering. This XML string may be modified by the 
	 *            exit   
	 * 
	 * @return    a monitor exit result object which is used to determine if the
	 *            task should proceed, or be cancelled.
	 */
	MonitorExitResult onMonitor(Map<String, String> environmentMetaData,
			                    Map<String, String> monitorMetaData, 
				                Reference<String> taskDetails);
}

モニター・メタデータ内の IBM 予約値の定数は、以下のとおりです。

package com.ibm.wmqfte.exitroutine.api;

/**
* Constants for IBM reserved values placed into the monitor meta data
* maps used by the monitor exit routines.
*/
public interface MonitorMetaDataConstants {

/**
* The value associated with this key is the name of the trigger 
* file associated with the monitor. Any modification performed 
* to this property by user exit routines will be ignored.
*/
final String FILE_NAME_KEY = "FILENAME";

/**
* The value associated with this key is the path to the trigger 
* file associated with the monitor. Any modification performed 
* to this property by user exit routines will be ignored.
*/
final String FILE_PATH_KEY = "FILEPATH";

/**
* The value associated with this key is the size of the trigger 
* file associated with the monitor. This will not be present in 
* the cases where the size cannot be determined. Any modification 
* performed to this property by user exit routines will be ignored.
*/
final String FILE_SIZE_KEY = "FILESIZE";

/**
* The value associated with this key is the local date on which 
* the trigger file associated with the monitor was last modified.
* Any modification performed to this property by user exit routines 
* will be ignored.
*/
final String LAST_MODIFIED_DATE_KEY = "LASTMODIFIEDDATE";

/**
* The value associated with this key is the local time at which 
* the trigger file associated with the monitor was last modified.
* Any modification performed to this property by user exit routines 
* will be ignored.
*/
final String LAST_MODIFIED_TIME_KEY = "LASTMODIFIEDTIME";

/**
* The value associated with this key is the UTC date on which 
* the trigger file associated with the monitor was last modified.
* Any modification performed to this property by user exit routines 
* will be ignored.
*/
final String LAST_MODIFIED_DATE_KEY_UTC = "LASTMODIFIEDDATEUTC";

/**
* The value associated with this key is the UTC time at which 
* the trigger file associated with the monitor was last modified.
* Any modification performed to this property by user exit routines 
* will be ignored.
*/
final String LAST_MODIFIED_TIME_KEY_UTC = "LASTMODIFIEDTIMEUTC"; 

/**
* The value associated with this key is the name of the agent on which
* the monitor is running. Any modification performed to this property by 
* user exit routines will be ignored.
*/
final String MONITOR_AGENT_KEY = "AGENTNAME";

} 

ユーザー出口の例

このクラスの例では、MonitorExit インターフェースを実装します。 この例では、REDIRECTEDAGENT というモニター・メタデータにカスタム置換変数を追加します。この変数には、時刻が奇数の場合は値LONDONが取り込まれ、時刻が偶数の場合は値PARISが取り込まれます。 モニター出口の結果コードは、常にproceedを戻すように設定されます。
package com.ibm.wmqfte.monitor;

import java.util.Calendar;
import java.util.Map;

import com.ibm.wmqfte.exitroutine.api.MonitorExit;
import com.ibm.wmqfte.exitroutine.api.MonitorExitResult;
import com.ibm.wmqfte.exitroutine.api.Reference;

/**
 * Example resource monitor user exit that changes the monitor mutable 
 * metadata value between 'LONDON' and 'PARIS' depending on the hour of the day.
 *
 */
public class TestMonitorExit implements MonitorExit {

	// custom variable that will substitute destination agent
	final static String REDIRECTED_AGENT = "REDIRECTEDAGENT";

	public MonitorExitResult onMonitor(
Map<String, String> environmentMetaData,
			Map<String, String> monitorMetaData, 
Reference<String> taskDetails) {
		
		// always succeed
		final MonitorExitResult result = MonitorExitResult.PROCEED_RESULT;
				
		final int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
		
		if (hour%2 == 1) {
			monitorMetaData.put(REDIRECTED_AGENT, "LONDON");
		} else {
			monitorMetaData.put(REDIRECTED_AGENT, "PARIS");	
		}
		
		return result;
	}
}
REDIRECTEDAGENT 置換変数を使用するモニターに対応するタスクは、以下のようなものになる可能性があります。
<?xml version="1.0" encoding="UTF-8"?>
<request version="4.00"
         xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
  <managedTransfer>
    <originator>
        <hostName>reportserver.com</hostName>
        <userID>USER1</userID>
    </originator>
    <sourceAgent agent="AGENT1"
                 QMgr="QM1"/>
    <destinationAgent agent="${REDIRECTEDAGENT}"
                      QMgr="QM2"/>
    <transferSet>
      <item mode="binary" checksumMethod="MD5">
        <source recursive="false" disposition="delete">
          <file>c:\sourcefiles\reports.doc</file>
        </source>
        <destination type="file" exist="overwrite">
          <file>c:\destinationfiles\reports.doc</file>
        </destination>
      </item>
    </transferSet>
  </managedTransfer>
</request>

この転送が開始される前に、<destinationAgent>エレメントのエージェント属性の値がLONDONまたはPARISのいずれかに置き換えられます。

モニター出口クラスで置換変数とタスク定義 XML (大文字) を指定する 必要があります。