use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor in project otter by alibaba.
the class LoadMemoryArbitrateEvent method await.
public EtlEventData await(Long pipelineId) throws InterruptedException {
Assert.notNull(pipelineId);
PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
// 阻塞等待授权
permitMonitor.waitForPermit();
MemoryStageController stageController = ArbitrateFactory.getInstance(pipelineId, MemoryStageController.class);
// 符合条件的processId
Long processId = stageController.waitForProcess(StageType.LOAD);
ChannelStatus status = permitMonitor.getChannelPermit();
if (status.isStart()) {
// 即时查询一下当前的状态,状态随时可能会变
return stageController.getLastData(processId);
} else {
logger.warn("pipelineId[{}] load ignore processId[{}] by status[{}]", new Object[] { pipelineId, processId, status });
// 递归调用
return await(pipelineId);
}
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor in project otter by alibaba.
the class ToolArbitrateEvent method waitForPermit.
/**
* 阻塞等待授权通过
*
* @param pipelineId
* @throws InterruptedException
*/
public void waitForPermit(Long pipelineId) throws InterruptedException {
Assert.notNull(pipelineId);
PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
// 阻塞等待授权
permitMonitor.waitForPermit();
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor in project otter by alibaba.
the class ArbitrateOppositeIntegration 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.impl.setl.monitor.PermitMonitor in project otter by alibaba.
the class TerminMemoryArbitrateEventTest 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(true).isStop()).is(true);
destoryTermin();
ArbitrateFactory.destory(pipelineId);
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor in project otter by alibaba.
the class TerminMemoryArbitrateEventTest method test_Rollback.
@Test
public void test_Rollback() {
normalProcess();
// 发送rollback信号
TerminEventData rollback = new TerminEventData();
rollback.setPipelineId(pipelineId);
rollback.setType(TerminType.ROLLBACK);
terminEvent.single(rollback);
PermitMonitor monitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
want.bool(monitor.getChannelPermit(true).isPause()).is(true);
destoryTermin();
ArbitrateFactory.destory(pipelineId);
}
Aggregations