职责链实现的apache.chain使用
其实职责链在老早就使用过了,以前在HW给Vodafone做金融项目的时候,使用职责链完成交易步骤,那时觉得这东西真好用,可以直接通过配置决定业务流程,现在终于有机会实践一下。
/**
* 职责链的组织类,负责构造整个链
*/
public class RootCauseChain extends ChainBase
{
/**
* 通过此方法增减生效的分析器
*/
public RootCauseChain()
{
addCommand(new DataRootCauseAnalyzer());
//addCommand(new EnvRootCauseAnalyzer());
//addCommand(new PifRootCauseAnalyzer());
//addCommand(new TaskRootCauseAnalyzer());
}
}
具体的业务:
/**
* 实现了command接口,数据均通过context组织
*/
public class DataRootCauseAnalyzer implements Command
{
private DataQueryService dqService = new DataQueryService(); private static final String ROOT_CAUSE_FORMAT = "indicator value is abnormal: check ? for more information"; @SuppressWarnings("unchecked")
@Override
public boolean execute(Context arg0) throws Exception
{
boolean res = false; Log.info(RootCauseConstant.MODULE_CODE, "0000",
"begin to execute DataRootCauseAnalyzer.execute"); List<DataPoint> exceptionDataPoints = (List<DataPoint>) arg0.get("expData");
ExceptionRule exceptionRule = (ExceptionRule) arg0.get("rule"); List<RootCause> result = new ArrayList<RootCause>(); if (exceptionDataPoints != null && !exceptionDataPoints.isEmpty())
{
for (DataPoint dataPoint : exceptionDataPoints)
{
List<RootCause> rootCauseList = generateRootCause(dataPoint, exceptionRule); result.addAll(rootCauseList);
}
} // 如果分析出了根因,则结束分析流程
if (result != null && !result.isEmpty())
{
arg0.put("result", result); res = true;
} // 没有分析出根因,交到下一个分析器进行分析
return res;
} /**
* 生成具体的异常信息
*
* @param exceptionPoint
* 异常数据点
* @param rule
* 异常规则
* @return 查询上下级关系
*/
private List<RootCause> generateRootCause(DataPoint exceptionPoint, ExceptionRule rule)
{
List<RootCause> rclist = new ArrayList<RootCause>(); return rclist;
}
}
调用:
public class RootCauseService
{
/**
* 分析异常点的根因
*
* @param points
* 异常数据点
* @param rule
* 异常数据发现规则
* @return 异常数据点及根因
*/
@SuppressWarnings("unchecked")
public List<RootCause> getRootCause(List<DataPoint> points, ExceptionRule rule)
{
Log.info(RootCauseConstant.MODULE_CODE, "0000", "begin to execute getRootCause, points="
+ points + ", rule=" + rule); List<RootCause> result = new ArrayList<RootCause>(); try
{
Command command = new RootCauseChain();
ContextBase ctx = new ContextBase(); ctx.put("expData", points);
ctx.put("rule", rule); command.execute(ctx);
result = (List<RootCause>) ctx.get("result");
}
catch (Exception e)
{
Log.error(RootCauseConstant.MODULE_CODE, "0000",
"execute analysisRootCauseByCommandChain exception.", e);
} Log.info(RootCauseConstant.MODULE_CODE, "0000", "execute getRootCause finished, result="
+ result); return result;
}
}
职责链实现的apache.chain使用的更多相关文章
- OOP设计模式[JAVA]——03职责链模式
职责链模式 Responsibility of Chain 在职责链模式里,很多对象由每一个对象对其下家的引用而连接起来形成一条链.请求在这个链上传递,直到链上的某一个对象决定处理此请求.发出这个请求 ...
- 18职责链模式CoR
一.什么是职责链模式 Chain of Responsibility(CoR)模式也叫职 责链模式或者职责连锁模式,是行为模式之一, 该模式构造一系列分别担当不同的职责的类的对 象来共同完成一个任务, ...
- js职责链模式
职责链模式(Chain of Responsiblity),使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系.将这个对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它为 ...
- C#设计模式系列:职责链模式(Chain of Responsibility)
1.职责链模式简介 1.1>.定义 职责链模式是一种行为模式,为解除请求的发送者和接收者之间的耦合,而使多个对象都有机会处理这个请求.将这些对象连接成一条链,并沿着这条链传递该请求,直到有一个对 ...
- 职责链(Chain of Responsibility)模式在航空货运中的运用实例
设计模式这东西,基本上属于“看懂一瞬间,用会好几年”.只有实际开发中,当某一模式很好的满足了业务需求时,才会有真切的感觉.借用一句<闪电侠>中,绿箭侠教导闪电侠的台词:“不是你碰巧遇到了它 ...
- 深入浅出设计模式——职责链模式(Chain of Responsibility Pattern)
模式动机 职责链可以是一条直线.一个环或者一个树形结构,最常见的职责链是直线型,即沿着一条单向的链来传递请求.链上的每一个对象都是请求处理者,职责链模式可以将请求的处理者组织成一条链,并使请求沿着链传 ...
- atitit.设计模式(1)--—职责链模式(chain of responsibility)最佳实践O7 日期转换
atitit.设计模式(1)---职责链模式(chain of responsibility)最佳实践O7 日期转换 1. 需求:::日期转换 1 2. 可以选择的模式: 表格模式,责任链模式 1 3 ...
- 设计模式:职责链模式(Chain Of Responsibility)
定 义:使多个对象都有机会处理请求,从而避免请求的发送者和接受者之间的耦合关系.将这些对象连成一条链,并沿着这条链传递请求,直到有一个对象处理它为止. 结构图: 处理请求类: //抽象处理类 abs ...
- 设计模式(十二)职责链模式(Chain of Responsibility)(对象行为型)
设计模式(十二)职责链模式(Chain of Responsibility)(对象行为型) 1.概述 你去政府部门求人办事过吗?有时候你会遇到过官员踢球推责,你的问题在我这里能解决就解决,不能解决就 ...
随机推荐
- 使用node.js抓取有路网图书信息(原创)
之前写过使用python抓取有路网图书信息,见http://www.cnblogs.com/dyf6372/p/3529703.html. 最近想学习一下Node.js,所以想试试手,比较一下http ...
- PHP开发环境和软件
1/很方便的软件XAMMP集成了PHP+MYSQL+MYPHPADMIN等等软件 2/sublime text 程序员神器,都明白的 ps.如果装了vm虚拟机,80端口有时候会被占用,进程关闭就好.
- DrawWindowFrame
extern void DrawWindowFrame(HWND hWnd)//画窗口边框 { RECT rc; HWND DeskHwnd = ::GetDesktopWindow(); //取得桌 ...
- 插入排序(insertion_sort)
最简单的排序算法,又称插值排序,原理类似于打扑克牌时把摸到的牌插入手中已有序牌的过程. void insertion_sort(int* A ,int n){ int i,j,key; ;i < ...
- parsing html in asp.net
http://stackoverflow.com/questions/5307374/parsing-html-page-in-asp-net http://htmlagilitypack.codep ...
- Linux下反斜杠号"\"引发的思考
今天在检查home目录时发现有一个名为“\”的文件,觉得很奇怪,从来没见过,就准备用Vim打开看看,很自然地输入命令查看一下,结果居然打不开. ubuntu@ubuntu:~$ vi \> ub ...
- bnuoj 31796 键盘上的蚂蚁(搜索模拟)
http://www.bnuoj.com/bnuoj/contest_show.php?cid=2876#problem/31796 [题意]: 如题,注意大小写情况 [code]: #include ...
- CQRS学习——一个例子(其六)
[先上链接:http://pan.baidu.com/s/1o62AHbc ] 多图杀猫 先用一组图看看实现的功能: 添加一个功能 假定现在要添加一个书本录入的功能,那么执行如下的操作: 1.添加Co ...
- 修改MYSQL数据库表的字符集
MySQL 乱码的根源是的 MySQL 字符集设置不当的问题,本文汇总了有关查看 MySQL 字符集的命令.包括查看 MySQL 数据库服务器字符集.查看 MySQL 数据库字符集,以及数据表和字段的 ...
- SDUT 2527 斗地主
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2527 思路 :以前的结训比赛,当时不会做,比完 ...