use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.MainstemMonitor in project otter by alibaba.
the class MainStemArbitrateEvent method release.
/**
* 释放mainStem的节点,重新选择工作节点
*/
public void release(Long pipelineId) {
MainstemMonitor mainstemMonitor = ArbitrateFactory.getInstance(pipelineId, MainstemMonitor.class);
mainstemMonitor.releaseMainstem();
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.MainstemMonitor in project otter by alibaba.
the class MainStemArbitrateEvent method single.
/**
* 更新mainStem的同步状态数据
*/
public void single(MainStemEventData data) {
MainstemMonitor mainstemMonitor = ArbitrateFactory.getInstance(data.getPipelineId(), MainstemMonitor.class);
mainstemMonitor.single(data);
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.MainstemMonitor in project otter by alibaba.
the class MainStemMonitorTest method testManualRelease.
@Test
public void testManualRelease() {
MainstemMonitor mainstemMonitor = ArbitrateFactory.getInstance(pipelineId, MainstemMonitor.class);
boolean running = mainstemMonitor.check();
want.bool(running).is(true);
mainstemMonitor.setDelayTime(5);
switchWarmup(channelId, pipelineId);
// 等manual release被响应
sleep(1000L);
long start = System.currentTimeMillis();
try {
mainstemMonitor.waitForActive();
} catch (InterruptedException e) {
want.fail();
}
want.number(System.currentTimeMillis() - start).isGe(4000L);
ArbitrateFactory.destory(pipelineId);
mainstemMonitor.releaseMainstem();
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.MainstemMonitor in project otter by alibaba.
the class MainStemMonitorTest method testInit.
@Test
public void testInit() {
MainstemMonitor mainstemMonitor = ArbitrateFactory.getInstance(pipelineId, MainstemMonitor.class);
boolean running = mainstemMonitor.check();
want.bool(running).is(true);
try {
mainstemMonitor.waitForActive();
} catch (InterruptedException e) {
want.fail();
}
ArbitrateFactory.destory(pipelineId);
mainstemMonitor.releaseMainstem();
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.MainstemMonitor in project otter by alibaba.
the class MainStemArbitrateEvent method await.
/**
* <pre>
* 算法:
* 1. 检查当前的Permit,阻塞等待其授权(解决Channel的pause状态处理)
* 2. 尝试创建对应的mainStem节点(非持久化节点)
* a. 如果创建成功,则直接构造结果返回
* b. 如果创建失败,则关注该节点的exist信号. 继续执行步骤2
* </pre>
*/
public void await(Long pipelineId) throws InterruptedException {
Assert.notNull(pipelineId);
PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
ChannelStatus status = permitMonitor.getChannelPermit(true);
boolean isRuning = check(pipelineId);
if (!status.isStart() && isRuning) {
// 当前状态不为启动,强制设置为taking,下次授权启动后重新追数据
MainStemEventData data = new MainStemEventData();
data.setPipelineId(pipelineId);
data.setStatus(MainStemEventData.Status.TAKEING);
single(data);
// 阻塞等待挂起
permitMonitor.waitForChannelPermit();
return;
} else if (status.isStart() && isRuning) {
// 正常状态
return;
} else if (isRuning == false) {
if (!status.isStart()) {
// 阻塞等待挂起
permitMonitor.waitForChannelPermit();
}
MainstemMonitor mainstemMonitor = ArbitrateFactory.getInstance(pipelineId, MainstemMonitor.class);
// 等待自己成为active
mainstemMonitor.waitForActive();
status = permitMonitor.getChannelPermit(false);
if (status.isStart()) {
return;
} else {
logger.info("pipelineId[{}] mainstem ignore by status[{}]", new Object[] { pipelineId, status });
// 重新进行check一次
await(pipelineId);
}
}
}
Aggregations