MFT 资源监视器用户出口
通过资源监视器用户出口,您可以配置在满足监视器的触发条件的情况下,要在关联任务启动之前运行的定制代码。
建议不要直接通过用户出口代码调用新传输。 在某些情况下,由于用户出口无法适应代理重新启动,这将导致传输文件多次。
资源监视器用户出口将现有基础结构用于用户出口。 调用监视器用户出口的时间为:在触发监视器后,但在监视器的任务运行相应的任务前。 这允许用户出口修改要运行的任务并确定任务是否应继续。 您可以通过更新监视器元数据来修改监视器任务,此元数据随后用于在创建原始监视器时创建的任务文档中进行变量替换。 或者,监视器出口可替换或更新作为参数传递的任务定义 XML 字符串。 监视器出口可针对任务返回结果代码“proceed”或“cancel”。 如果返回“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> 元素的 agent 属性的值将替换为 LONDON 或 PARIS。
必须以大写形式指定监视器出口类和任务定义 XML 中的替换变量。