Java Code Examples for com.alibaba.otter.canal.common.utils.BooleanMutex#state()

The following examples show how to use com.alibaba.otter.canal.common.utils.BooleanMutex#state() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SyncSwitch.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
private synchronized void initMutex(CuratorFramework curator, String destination, BooleanMutex mutex) {
    try {
        String path = SYN_SWITCH_ZK_NODE + destination;
        Stat stat = curator.checkExists().forPath(path);
        if (stat == null) {
            if (!mutex.state()) {
                mutex.set(true);
            }
        } else {
            String data = new String(curator.getData().forPath(path), StandardCharsets.UTF_8);
            if ("on".equals(data)) {
                if (!mutex.state()) {
                    mutex.set(true);
                }
            } else {
                if (mutex.state()) {
                    mutex.set(false);
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
    }
}
 
Example 2
Source File: SyncSwitch.java    From canal with Apache License 2.0 6 votes vote down vote up
private synchronized void initMutex(CuratorFramework curator, String destination, BooleanMutex mutex) {
    try {
        String path = SYN_SWITCH_ZK_NODE + destination;
        Stat stat = curator.checkExists().forPath(path);
        if (stat == null) {
            if (!mutex.state()) {
                mutex.set(true);
            }
        } else {
            String data = new String(curator.getData().forPath(path), StandardCharsets.UTF_8);
            if ("on".equals(data)) {
                if (!mutex.state()) {
                    mutex.set(true);
                }
            } else {
                if (mutex.state()) {
                    mutex.set(false);
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
    }
}