开发者指南¶
Task Types -编写自己的操作
Actions -为您的任务扩展GUI
Reporting -选择批处理报告的内容和目标
任务类型¶
可以使用自定义任务类型扩展任务管理器。自己实现接口 TaskType
让它变成春豆。通过 Named
接口用作引用。
/**
* A Task Type.
*
*/
public interface TaskType extends Named {
/**
* Return parameter info for this task type.
* It is recommended to use a LinkedHashMap and add the parameters in a intuitive order.
* This order will be preserved to present parameters to the user.
*
* @return the parameter info
*/
Map<String, ParameterInfo> getParameterInfo();
/**
* Run a task, based on these parameter values.
* @param ctx task context
* @return the task result
*/
TaskResult run(TaskContext ctx) throws TaskException;
/**
* Do a clean-up for this task (for example, if this task publishes something, remove it).
* @param ctx task context
* @throws TaskException
*/
void cleanup(TaskContext ctx) throws TaskException;
/**
* task type can specify whether it supports clean-up or not
*
* @return true if clean-up is supported
*/
default boolean supportsCleanup() {
return true;
}
}
ParameterInfo对象包含名称 type ,它们是否是必需的,以及它们所依赖的其他参数(例如,数据库表依赖于数据库)。
任务上下文如下:
/**
* Task Context used during batch run or task clean-up.
*
*/
public interface TaskContext {
/**
* @return the task
*/
Task getTask();
/**
* @return the batch context, null if this is a clean-up
*/
BatchContext getBatchContext();
/**
*
* @return the parameter values, lazy loaded from task and configuration.
*
* @throws TaskException
*/
Map<String, Object> getParameterValues() throws TaskException;
/**
* Tasks can call this function to check if the user wants to interrupt the batch
* and interrupt themselves.
* If they do, they should still return a TaskResult that implements a roll back
* of what was already done.
*
* @return whether the batch run should be interrupted, false if this is a clean-up
*/
boolean isInterruptMe();
}
批处理上下文如下:
/**
* During run, tasks create temporary objects that are committed to real objects during
* the commit phase (such as a table name) This maps real objects
* to temporary objects during a single batch run. Tasks should save and look up temporary
* objects so that tasks within a batch can work together.
*
*/
public interface BatchContext {
public static interface Dependency {
public void revert() throws TaskException;
}
Object get(Object original);
Object get(Object original, Dependency dependency);
/**
* Whatever is put here in the task, must be removed in the commit!
*
* @param original
* @param temp
*/
void put(Object original, Object temp);
void delete(Object original) throws TaskException;
BatchRun getBatchRun();
}
任务结果如下:
/**
* A handle of a task that was run but must still be committed or rolled back.
*
*
*/
public interface TaskResult {
/**
* finalize and clean-up resources any roll-back data
*/
void commit() throws TaskException;
/**
* batch has failed - cancel all changes
*/
void rollback() throws TaskException;
}
以下是任务类型如何创建临时对象的示例:
//inside TaskType.run method
ctx.getBatchContext().put(originalObject, tempObject)
...
return new TaskResult() {
@Override
public void commit() throws TaskException {
//this MUST be done!!!
ctx.getBatchContext.delete(originalObject)
}
...
}
另一个任务类型将使用此临时对象,如下所示:
//inside TaskType.run method
Object tempObject = ctx.getBatchContext().get(originalObject, new Dependency() {
@Override
public void revert() {
Object object = ctx.getBatchContext().get(originalObject);
mySomething.setMyProperty(object);
mySomething.save();
}
});
mySomething.setMyProperty(tempObject);
mySomething.save();
参数类型¶
自定义任务类型可以使用现有的或定义新的参数类型。它们处理参数验证,将参数字符串解析为其他对象类型,并向GUI提供有关参数的信息。
现有的常规参数类型(的静态成员 ParameterType
接口):
STRING
INTEGER
BOOLEAN
URI
SQL
(防止';'黑客攻击)
外部参数类型(成员 ExtTypes
spring bean): * dbName
: database name * tableName
: table name (parameter must depend on parameter of dbName
type) * extGeoserver
: external geoserver * internalLayer
: layer from geoserver catalog * name
: name qualified with namespace from geoserver catalog * fileService
: file service * file
:对文件的引用(参数必须是的参数的末尾 fileService
类型)
定义新参数类型:
/**
*
* A Parameter Type For a Task
*
*/
public interface ParameterType {
/**
* List possible values for this parameter (when applicable).
* Include an empty string if custom value is also allowed.
*
* @param dependsOnRawValues raw values of depending parameters.
* @return list of possible values, null if not applicable.
*/
public List<String> getDomain(List<String> dependsOnRawValues);
/**
* Validate and parse a parameter value for this parameter (at run time).
*
* @param value the raw value.
* @param dependsOnRawValues raw values of depending parameters.
* @return the parsed value, NULL if the value is invalid.
*/
public Object parse(String value, List<String> dependsOnRawValues);
/**
* Validate a parameter value (at configuration time).
*
* @param value the raw value.
* @param dependsOnRawValues raw values of depending parameters.
* @return true if the value is considered valid at configuration time (may still be considered
* invalid at parse time)
*/
public default boolean validate(String value, List<String> dependsOnRawValues) {
return parse(value, dependsOnRawValues) != null;
}
/**
* Returns a list of web actions related to this type
*
* @return list of web actions
*/
public default List<String> getActions() {
return Collections.emptyList();
}
}
行动¶
操作是附加到特定参数类型的TaskManager WebGUI的扩展。
public interface Action extends Named, Serializable {
/**
* Execute this action.
*
* @param onPage the configuration page.
* @param target the target of the ajax request that executed this action.
* @param valueModel the value of the attribute, for reading and writing.
* @param dependsOnRawValues raw values of depending attributes.
*/
void execute(ConfigurationPage onPage, AjaxRequestTarget target, IModel<String> valueModel, List<String> dependsOnRawValues);
/**
* Check whether this action can be executed with current values.
* \
* @param value the value of the attribute.
* @param dependsOnRawValues raw values of depending attributes.
* @return whether this action accepts these values.
*/
default boolean accept(String value, List<String> dependsOnRawValues) {
return true;
}
}
为了链接到参数类型,动作必须是spring be an。通过 Named
接口用作引用。
报告¶
报表生成器¶
报告是已完成批处理运行的用户友好表示,在批处理运行完成后立即发送到某个目标。报表具有类型 (FAILED
, CANCELLED
或 SUCCESS
)一个标题和一个内容。使用Spring配置单个报表生成器。
/**
* A report builder generates a report from a batch.
* One could write a custom one.
*
*/
public interface ReportBuilder {
Report buildBatchRunReport(BatchRun batchRun);
}
报告服务。¶
使用Spring配置任意数量的报表服务。
/**
* A report service sends a report to a particular destination.
* One can add an unlimited amount of report services which will all be used.
*
*/
public interface ReportService {
/**
* Enumeration for filter.
*
*/
public enum Filter {
/** All batch runs are reported **/
ALL (Report.Type.FAILED, Report.Type.CANCELLED, Report.Type.SUCCESS),
/** Only failed and cancelled batch runs are reported **/
FAILED_AND_CANCELLED (Report.Type.FAILED, Report.Type.CANCELLED),
/** Only failed batch runs are reported **/
FAILED_ONLY (Report.Type.FAILED);
Report.Type[] types;
private Filter(Report.Type... types) {
this.types = types;
}
public boolean matches(Report.Type type) {
return ArrayUtils.contains(types, type);
}
}
/**
* Return the filter of the report.
*
* @return the filter of the report.
*/
public Filter getFilter();
/**
* Send a report.
*
* @param report the report.
*/
public void sendReport(Report report);
}