package com.cm.service;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.OnExceptionDefinition;
import org.apache.camel.model.RouteDefinition;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jetty.util.StringUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Service;
import com.cm.bean.TDEndpoints;
import com.cm.dao.TDCustomrouterulesMapper;
import com.cm.dao.TDDatasourceMapper;
import com.cm.dao.TDEndpointparamsMapper;
import com.cm.dao.TDEndpointsMapper;
import com.cm.dao.TDEndpointtypeMapper;
import com.cm.dao.TDEndpointtypeparamsMapper;
import com.cm.dao.TDExceptioninfoMapper;
import com.cm.dao.TDExceptionrulesMapper;
import com.cm.dao.TDJobserverMapper;
import com.cm.dao.TDRoutedefinitionMapper;
import com.cm.dao.TDRouteexceptionrulesMapper;
import com.cm.dao.TDRoutenodeMapper;
import com.cm.dao.TDRouterulesMapper;
import com.cm.dto.ExceptionRule;
import com.cm.dto.MyEndPoint;
import com.cm.dto.RouteDef;
import com.cm.dto.RouteNode;
import com.cm.util.SpringContextUtil;
@Service(value = "CamelEditImpl")
public class CamelEditImpl implements CamelEditInterface {
/**
* 客户自定义规则
*/
private TDCustomrouterulesMapper tDCustomrouterulesMapper;
/**
* 数据源
*/
private TDDatasourceMapper tDDatasourceMapper;
/**
* 控制端点参数
*/
private TDEndpointparamsMapper tDEndpointparamsMapper;
/**
* 控制端点
*/
private TDEndpointsMapper tDEndpointsMapper;
/**
* 控制端点类型
*/
private TDEndpointtypeMapper tDEndpointtypeMapper;
/**
* 控制端点类型参数
*/
private TDEndpointtypeparamsMapper tDEndpointtypeparamsMapper;
/**
* 异常信息
*/
private TDExceptioninfoMapper tDExceptioninfoMapper;
/**
* 异常规则
*/
private TDExceptionrulesMapper tDExceptionrulesMapper;
/**
* 定时任务
*/
private TDJobserverMapper tDJobserverMapper;
/**
* 路由定义
*/
private TDRoutedefinitionMapper tDRoutedefinitionMapper;
/**
* 路由异常规则
*/
private TDRouteexceptionrulesMapper tDRouteexceptionrulesMapper;
/**
* 路由节点
*/
private TDRoutenodeMapper tDRoutenodeMapper;
/**
* 路由规则
*/
private TDRouterulesMapper tDRouterulesMapper;
@Autowired
@Qualifier("camel")
CamelContext camelContext;
/*
* 路由定义 路由控制端点 路由节点 (non-Javadoc)
*
* @see com.cm.service.CamelEditInterface#addCamelRoute(com.cm.dto.RouteDef,
* com.cm.dto.MyEndPoint, java.util.List)
*/
public void addCamelRoute(final RouteDef routeDef, final MyEndPoint myEndPoint, final List<RouteNode> routeNodes) {
// 第一步 增加数据库数据保存,伪代码,需后续完善
TDEndpoints tDEndpoints = new TDEndpoints();
BeanUtils.copyProperties(myEndPoint, tDEndpoints);
this.tDEndpointsMapper.insert(tDEndpoints);
// 第二部 开始操作路由节点
try {
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
// 初始化异常处理
errorHandler(defaultErrorHandler().maximumRedeliveries(3).redeliveryDelay(2000)
.onRedelivery(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("onRedelivery");
}
}));
for (ExceptionRule exceptionRule : routeDef.getExceptionRules()) {
OnExceptionDefinition onExceptionDefinition = onException(
exceptionRule.getException().getClass())
.redeliveryDelay(exceptionRule.getRedeliverydelay())
.maximumRedeliveries(exceptionRule.getMaxredeliveries());
}
;
// 初始化from节点
final RouteNode fromNode = routeNodes.get(0);
if (!fromNode.getNodetype().trim().equals("0")) {
throw new RuntimeException("起始节点必须为接入终端。。。");
}
RouteDefinition rd = null;
if (myEndPoint.istrigger()) {// 使用触发器
rd = from("quartz://" + myEndPoint.getEndpointTypeName() + "?" + "cron="
+ myEndPoint.getJobtrigger().getCronexpress()).to("id:" + fromNode.getEndpointid())
.routeId(myEndPoint.getEndpointid() + "");
} else {
rd = from("id:" + fromNode.getEndpointid()).routeId(myEndPoint.getEndpointid() + "");
}
// 加载路由规则,按照RANK排序
List<Map<String, Object>> rules = routeDef.getRouteRule();
Collections.sort(rules, new Comparator<Map<String, Object>>() {
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
return MapUtils.getIntValue(o1, "RANK", 1) - MapUtils.getIntValue(o2, "RANK", 1);
}
});
Iterator<Map<String, Object>> iterator = rules.iterator();
RouteNode node = null;
Map<String, Object> rule = null;
while (iterator.hasNext()) {
rule = iterator.next();
// 含有自定义路由规则
if (MapUtils.getLong(rule, "CUSTOMROUTERULEID", -1L) != -1L) {
break;
} else {
for(RouteNode routeNode : routeNodes){
if(routeNode.getRoutenodeid() !=0){
if(rule.get("ROUTENODEID").equals((routeNode.getRoutenodeid()+""))){
node = routeNode;
}
}
}
}
String nodeType = node.getNodetype().trim();
ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) SpringContextUtil
.getApplicationContext();
final DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) configurableApplicationContext
.getBeanFactory();
// 终端节点
if ("0".equals(nodeType)) {
rd = rd.to("id:" + node.getEndpointid());
} else if ("1".equals(nodeType)) {// processor节点
Processor processor = null;
if (!StringUtils.isEmpty(node.getSpringnoderef())) {
processor = defaultListableBeanFactory.getBean(node.getSpringnoderef(),
Processor.class);
} else {
Class clazz = Thread.currentThread().getContextClassLoader()
.loadClass(node.getNodeclasspath());
processor = (Processor) clazz.newInstance();
}
rd = rd.process(processor);
} else if ("3".equals(nodeType)) {// bean节点
Object o = defaultListableBeanFactory.getBean(node.getSpringnoderef());
rd = rd.bean(o);
}
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @param routeId
* @Description:删除指定路由
*/
public void deleteRoute(String routeId) {
try {
camelContext.removeRoute(routeId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
chinaMobile.rar_chinamobile_3704_平台_数据分析平台
共285个文件
gif:75个
class:55个
java:48个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 120 浏览量
2022-09-21
22:56:42
上传
评论
收藏 2.49MB RAR 举报
温馨提示
数据分析平台整体框架,配置和代码示例。。。。。。
资源推荐
资源详情
资源评论
收起资源包目录
chinaMobile.rar_chinamobile_3704_平台_数据分析平台 (285个子文件)
CamelEditImpl$1.class 7KB
StartCamelServer$1.class 6KB
CenterConfig.class 6KB
DataSource.class 5KB
Dom4jUtil.class 5KB
MyEndPoint.class 4KB
JDBCHelper.class 4KB
StartCamelServer.class 4KB
CamelEditImpl.class 3KB
TDDatasource.class 3KB
ExceptionRule.class 2KB
TDJobserver.class 2KB
TDExceptionrules.class 2KB
CommException.class 2KB
RouteDef.class 2KB
Trigger.class 2KB
TDRoutenode.class 2KB
RouteNode.class 2KB
TDEndpointtypeparams.class 2KB
TDEndpoints.class 1KB
BussinessException.class 1KB
StartCamelServer$1$2.class 1KB
CamelEditImpl$1$2.class 1KB
TDRouterules.class 1KB
SpringContextUtil.class 1KB
IdComponent.class 1KB
TDCustomrouterules.class 1KB
TDEndpointtype.class 1KB
TDExceptioninfo.class 1KB
TDEndpointparams.class 1KB
TDRoutedefinition.class 1KB
TreeNodes.class 1018B
ExceptionInfo.class 1013B
ApplicationInit.class 937B
StartCamelServer$1$1.class 928B
CamelEditImpl$1$1.class 925B
CamelInitDao.class 881B
TDRouteexceptionrulesKey.class 822B
Dom4jVisitorUtil.class 814B
Test.class 704B
TDEndpointtypeparamsMapper.class 431B
TDCustomrouterulesMapper.class 423B
TDRoutedefinitionMapper.class 419B
TDExceptionrulesMapper.class 415B
TDEndpointparamsMapper.class 415B
TDExceptioninfoMapper.class 411B
TDEndpointtypeMapper.class 407B
TDDatasourceMapper.class 399B
TDRoutenodeMapper.class 395B
TDJobserverMapper.class 395B
TDEndpointsMapper.class 395B
CamelEditInterface.class 332B
TDRouteexceptionrulesMapper.class 262B
CustomRouteRule.class 225B
TDRouterulesMapper.class 203B
.classpath 1KB
org.eclipse.wst.common.component 758B
org.eclipse.wst.jsdt.ui.superType.container 49B
layui.css 52KB
layer.css 14KB
layui.mobile.css 10KB
laydate.css 7KB
code.css 1KB
iconfont.eot 37KB
59.gif 10KB
22.gif 10KB
24.gif 8KB
13.gif 7KB
16.gif 7KB
39.gif 6KB
64.gif 6KB
63.gif 6KB
50.gif 6KB
loading-0.gif 6KB
4.gif 6KB
1.gif 5KB
42.gif 5KB
71.gif 5KB
21.gif 5KB
20.gif 5KB
29.gif 5KB
70.gif 4KB
5.gif 4KB
17.gif 4KB
27.gif 4KB
9.gif 4KB
44.gif 4KB
11.gif 4KB
8.gif 4KB
3.gif 4KB
23.gif 4KB
34.gif 4KB
41.gif 4KB
38.gif 4KB
65.gif 3KB
32.gif 3KB
45.gif 3KB
7.gif 3KB
12.gif 3KB
26.gif 3KB
共 285 条
- 1
- 2
- 3
资源评论
weixin_42651887
- 粉丝: 75
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
- 音乐展示网页、基于Stenography的图像数字水印添加与提取,以及基于颜色矩和Tamura算法的图像相似度评估算法py源码
- 基于EmguCV(OpenCV .net封装),图像数字水印加解密算法的实现,其中包含最低有效位算法,离散傅里叶变换算法+文档书
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功