Example usage for org.apache.zookeeper WatchedEvent getState

List of usage examples for org.apache.zookeeper WatchedEvent getState

Introduction

In this page you can find the example usage for org.apache.zookeeper WatchedEvent getState.

Prototype

public KeeperState getState() 

Source Link

Usage

From source file:me.tfeng.play.plugins.AvroD2Plugin.java

License:Apache License

@Override
public void process(WatchedEvent event) {
    LOG.info(event.toString());//from   ww w .  j a  v  a 2 s. c  o  m
    switch (event.getState()) {
    case SyncConnected:
        if (expired) {
            expired = false;
            servers.forEach(AvroD2Server::register);
        }
        break;
    case Expired:
        expired = true;
        try {
            zk.close();
        } catch (InterruptedException e) {
            // Ignore.
        }
        connect();
    default:
    }
}

From source file:ml.shifu.guagua.BasicCoordinator.java

License:Apache License

@Override
public void process(final WatchedEvent event) {
    LOG.debug("process: Got a new event, path = {}, type = {}, state = {}", event.getPath(), event.getType(),
            event.getState());

    if ((event.getPath() == null) && (event.getType() == EventType.None)) {
        if (event.getState() == KeeperState.SyncConnected) {
            LOG.info("process: Asynchronous connection complete.");
            this.getZkConnLatch().countDown();
        } else {/*from www.  j a va  2 s .  co  m*/
            LOG.warn("process: Got unknown null path event {}.", event);
        }
        return;
    }
}

From source file:ml.shifu.guagua.master.AsyncMasterCoordinator.java

License:Apache License

@Override
public void process(WatchedEvent event) {
    LOG.debug("DEBUG: process: Got a new event, path = {}, type = {}, state = {}", event.getPath(),
            event.getType(), event.getState());

    if ((event.getPath() == null) && (event.getType() == EventType.None)) {
        if (event.getState() == KeeperState.SyncConnected) {
            LOG.info("process: Asynchronous connection complete.");
            super.getZkConnLatch().countDown();
        } else {//  w w  w .ja  va 2s. co m
            LOG.warn("process: Got unknown null path event " + event);
        }
        return;
    }

    /**
     * Check lock signal condition.
     */
    String appWorkerBaseNode = getWorkerBaseNode(getAppId(), getCurrentIteration()).toString();
    if (event.getPath().equals(appWorkerBaseNode) && (event.getType() == EventType.NodeChildrenChanged)) {
        if (getCurrentIteration() == 0) {
            this.workerInitLock.signal();
        } else {
            this.workerIterationLock.signal();
        }
    }
}

From source file:ml.shifu.guagua.worker.AsyncWorkerCoordinator.java

License:Apache License

@Override
public void process(WatchedEvent event) {
    LOG.info("DEBUG: process: Got a new event, path = {}, type = {}, state = {}", event.getPath(),
            event.getType(), event.getState());

    if ((event.getPath() == null) && (event.getType() == EventType.None)) {
        if (event.getState() == KeeperState.SyncConnected) {
            LOG.info("process: Asynchronous connection complete.");
            super.getZkConnLatch().countDown();
        } else {/*from   w w  w.j  a  v a2s.c om*/
            LOG.warn("process: Got unknown null path event " + event);
        }
        return;
    }

    String appMasterNode = getCurrentMasterNode(getAppId(), getCurrentIteration()).toString();

    if (event.getPath().equals(appMasterNode)
            && (event.getType() == EventType.NodeCreated || event.getType() == EventType.NodeDataChanged)) {
        if (getCurrentIteration() == 0) {
            this.masterInitLock.signal();
        } else {
            this.masterIterationLock.signal();
        }
    }
}

From source file:msec.org.AccessZooKeeper.java

License:Open Source License

private void connectZooKeeper() {
    try {//from w w w. j  a  va2s  .  com
        zk = new ZooKeeper(connectStr, 5000, new Watcher() {
            @Override
            public void process(WatchedEvent event) {

                if (event.getState() == Event.KeeperState.SyncConnected) {
                    countDownLatch.countDown();
                }
            }
        });
        countDownLatch.await();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.freelabs.fidelio.core.zookeeper.ZkConnectionWatcher.java

License:Open Source License

/**
 * Processes a watched event when a//from www  . j  av a  2s .c  o m
 * {@link ZkConnectionWatcher ZkConnectionWatcher} object is passed as a
 * watcher.
 *
 * @param event a watched event.
 */
@Override
public void process(WatchedEvent event) {
    LOG.info("Session state event: {}", event.getState());
    if (event.getState() == KeeperState.SyncConnected) {
        connectedSignal.countDown();
    }
}

From source file:net.freelabs.maestro.core.zookeeper.ZkConnectionWatcher.java

License:Open Source License

/**
 * Processes a watched event when a//from ww w. j av  a  2s  .  c  om
 * {@link ZkConnectionWatcher ZkConnectionWatcher} object is passed as a
 * watcher.
 *
 * @param event a watched event.
 */
@Override
public void process(WatchedEvent event) {
    if (event.getState() == KeeperState.SyncConnected) {
        connectedSignal.countDown();
    }
}

From source file:net.killa.kept.CountDownOnConnectWatcher.java

License:Apache License

@Override
public void process(WatchedEvent event) {
    if (event.getState() == KeeperState.SyncConnected)
        this.latch.countDown();
}

From source file:net.killa.kept.SynchronizingWatcher.java

License:Apache License

/**
 * Synchronize a {@link Synchronizable} with the {@link ZooKeeper} cluster
 * when a NodeChildrenChangedEvent is detected, or the client reconnects to
 * the cluster.//  w  w  w .  j  ava  2 s .  c o  m
 * 
 * @param event
 *            A {@link WatchedEvent} that triggers synchronization
 * 
 */
@Override
public void process(WatchedEvent event) {
    // ignore no-op events and states in which we cannot read from the zk
    // cluster
    if (event.getType() == EventType.None || event.getState() == KeeperState.Disconnected
            || event.getState() == KeeperState.Expired) {
        SynchronizingWatcher.LOG
                .debug("ignoring no-op event " + event.getType() + " in state " + event.getState());

        return;
    }

    try {
        // synchronize the target
        SynchronizingWatcher.LOG.debug("synchronizing");

        this.synchronizable.synchronize();

        return;
    } catch (KeeperException e) {
        throw new RuntimeException("KeeperException caught", e);
    } catch (InterruptedException e) {
        throw new RuntimeException("InterruptedException caught", e);
    }
}

From source file:net.phoenix.thrift.server.ZookeeperRegisterHandler.java

License:Apache License

/**
 * process none event;// ww  w  . jav a  2s  .  co  m
 *
 * @param event
 */
private void processNoneEvent(WatchedEvent event) {
    switch (event.getState()) {
    case SyncConnected:
        this.processSyncConnectedEvent(event);
        break;
    case Expired:
        this.processExpiredEvent(event);
        break;
    case Disconnected:
        log.error("Disconnect with zookeeper " + znodePath + ".");
        break;
    default:
        break;
    }
}