use of com.alibaba.otter.shared.arbitrate.model.TerminEventData in project otter by alibaba.
the class ArbitrateForwardIntegration method testDemo.
@Test
public void testDemo() {
// 设置启动标志
channelEvent.start(channelId);
// 停顿一下
sleep();
// 优先启动主导线程
mainStem.submit(pipelineId);
PermitMonitor permit = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
try {
// 阻塞等待授权
permit.waitForPermit();
} catch (InterruptedException e1) {
want.fail();
}
// 启动
select.submit(pipelineId);
extract.submit(pipelineId);
view.submit(pipelineId);
this.termin.submit(pipelineId);
// 注意是反方向的
transform.submit(oppositePipelineId);
// 注意是反方向的
load.submit(oppositePipelineId);
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
// 发送结束事件
TerminEventData termin = new TerminEventData();
termin.setPipelineId(pipelineId);
termin.setType(TerminType.SHUTDOWN);
arbitrateEventService.terminEvent().single(termin);
// 等待处理完所有的termin事件
sleep(5 * 1000L);
// 关闭
select.destory(pipelineId);
extract.destory(pipelineId);
view.destory(pipelineId);
this.termin.destory(pipelineId);
transform.destory(oppositePipelineId);
load.destory(oppositePipelineId);
ArbitrateFactory.destory(pipelineId);
}
use of com.alibaba.otter.shared.arbitrate.model.TerminEventData in project otter by alibaba.
the class LoadRpcArbitrateEvent method single.
public void single(final EtlEventData data) {
Assert.notNull(data);
// 返回当前时间
data.setEndTime(new Date().getTime());
// 通知下一个节点,下一个节点也肯定会是自己
boolean result = rpcStageEventDispatcher.single(StageType.LOAD, data);
if (result) {
// 直接异步处理termin,更快速的返回, modify by ljh at 2013-02-25
// 减少Load await/single所占用的时间,尽快返回,因为两个load之间的传递可以尽可能不走zookeeper完成
TerminExecutor executor = ArbitrateFactory.getInstance(data.getPipelineId(), TerminExecutor.class);
executor.submit(new Runnable() {
public void run() {
// 调用Termin信号
TerminEventData termin = new TerminEventData();
termin.setPipelineId(data.getPipelineId());
termin.setProcessId(data.getProcessId());
termin.setStartTime(data.getStartTime());
termin.setEndTime(data.getEndTime());
termin.setFirstTime(data.getFirstTime());
termin.setNumber(data.getNumber());
termin.setBatchId(data.getBatchId());
termin.setSize(data.getSize());
termin.setExts(data.getExts());
termin.setType(TerminType.NORMAL);
termin.setCode("setl");
termin.setDesc("");
termin.setCurrNid(ArbitrateConfigUtils.getCurrentNid());
terminEvent.single(termin);
}
});
}
}
use of com.alibaba.otter.shared.arbitrate.model.TerminEventData in project otter by alibaba.
the class LoadMemoryArbitrateEvent method single.
public void single(EtlEventData data) {
Assert.notNull(data);
// 返回当前时间
data.setEndTime(new Date().getTime());
MemoryStageController stageController = ArbitrateFactory.getInstance(data.getPipelineId(), MemoryStageController.class);
// 通知下一个节点
boolean result = stageController.single(StageType.LOAD, data);
if (result) {
// 可能已经被rollback了,需要直接忽略
// 调用Termin信号
TerminEventData termin = new TerminEventData();
termin.setPipelineId(data.getPipelineId());
termin.setProcessId(data.getProcessId());
termin.setStartTime(data.getStartTime());
termin.setEndTime(data.getEndTime());
termin.setFirstTime(data.getFirstTime());
termin.setNumber(data.getNumber());
termin.setBatchId(data.getBatchId());
termin.setSize(data.getSize());
termin.setExts(data.getExts());
termin.setType(TerminType.NORMAL);
termin.setCode("setl");
termin.setDesc("");
termin.setCurrNid(ArbitrateConfigUtils.getCurrentNid());
terminEvent.single(termin);
}
}
use of com.alibaba.otter.shared.arbitrate.model.TerminEventData in project otter by alibaba.
the class MemoryStageController method termin.
/**
* 处理异常termin结束
*/
public synchronized void termin(TerminType type) {
// 构建termin信号
List<Long> processIds = new ArrayList<Long>(progress.keySet());
// 做一下排序
Collections.sort(processIds);
for (Long processId : processIds) {
EtlEventData eventData = progress.get(processId).getData();
TerminEventData data = new TerminEventData();
data.setPipelineId(getPipelineId());
data.setType(type);
data.setCode("channel");
data.setDesc(type.toString());
data.setProcessId(processId);
if (eventData != null) {
data.setBatchId(eventData.getBatchId());
data.setCurrNid(eventData.getCurrNid());
data.setStartTime(eventData.getStartTime());
data.setEndTime(eventData.getEndTime());
data.setFirstTime(eventData.getFirstTime());
data.setNumber(eventData.getNumber());
data.setSize(eventData.getSize());
data.setExts(eventData.getExts());
}
offerTermin(data);
progress.remove(processId);
}
// 重新初始化一下select调度
initSelect();
}
use of com.alibaba.otter.shared.arbitrate.model.TerminEventData in project otter by alibaba.
the class TerminArbitrateEventTest method test_Shutdown.
@Test
public void test_Shutdown() {
normalProcess();
// 发送shutdown信号
TerminEventData shutdown = new TerminEventData();
shutdown.setPipelineId(pipelineId);
shutdown.setType(TerminType.SHUTDOWN);
terminEvent.single(shutdown);
PermitMonitor monitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
want.bool(monitor.getChannelPermit().isStop()).is(true);
destoryTermin();
ArbitrateFactory.destory(pipelineId);
}
Aggregations