Search in sources :

Example 21 with TerminEventData

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);
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) IOException(java.io.IOException) Test(org.testng.annotations.Test) BaseEventTest(com.alibaba.otter.shared.arbitrate.BaseEventTest)

Example 22 with TerminEventData

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);
            }
        });
    }
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) Date(java.util.Date)

Example 23 with TerminEventData

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);
    }
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) Date(java.util.Date)

Example 24 with TerminEventData

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();
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData)

Example 25 with TerminEventData

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);
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) Test(org.testng.annotations.Test) BaseArbitrateEventTest(com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest)

Aggregations

TerminEventData (com.alibaba.otter.shared.arbitrate.model.TerminEventData)32 Test (org.testng.annotations.Test)12 PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)9 BaseArbitrateEventTest (com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest)9 ArrayList (java.util.ArrayList)7 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)6 Mock (mockit.Mock)5 BaseEventTest (com.alibaba.otter.shared.arbitrate.BaseEventTest)3 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)3 Date (java.util.Date)3 ExtractMemoryArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.memory.ExtractMemoryArbitrateEvent)2 LoadMemoryArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.memory.LoadMemoryArbitrateEvent)2 SelectMemoryArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.memory.SelectMemoryArbitrateEvent)2 TransformMemoryArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.memory.TransformMemoryArbitrateEvent)2 ExtractZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.ExtractZooKeeperArbitrateEvent)2 LoadZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.LoadZooKeeperArbitrateEvent)2 SelectZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.SelectZooKeeperArbitrateEvent)2 TransformZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.TransformZooKeeperArbitrateEvent)2 IOException (java.io.IOException)2 SelectException (com.alibaba.otter.node.etl.select.exceptions.SelectException)1