當前位置: 首頁>>代碼示例>>Java>>正文


Java WatchedEvent.getState方法代碼示例

本文整理匯總了Java中org.apache.zookeeper.WatchedEvent.getState方法的典型用法代碼示例。如果您正苦於以下問題:Java WatchedEvent.getState方法的具體用法?Java WatchedEvent.getState怎麽用?Java WatchedEvent.getState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.zookeeper.WatchedEvent的用法示例。


在下文中一共展示了WatchedEvent.getState方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: connectZooKeeper

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
private static ZooKeeper connectZooKeeper(String ensemble)
    throws IOException, KeeperException, InterruptedException {
  final CountDownLatch latch = new CountDownLatch(1);

  ZooKeeper zkc = new ZooKeeper(HOSTPORT, ZK_SESSION_TIMEOUT, new Watcher() {
    public void process(WatchedEvent event) {
      if (event.getState() == Watcher.Event.KeeperState.SyncConnected) {
        latch.countDown();
      }
    }
  });
  if (!latch.await(ZK_SESSION_TIMEOUT, TimeUnit.MILLISECONDS)) {
    throw new IOException("Zookeeper took too long to connect");
  }
  return zkc;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:TestBookKeeperConfiguration.java

示例2: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
    if (event.getState() == KeeperState.SyncConnected) {
        if (latch != null) {
            latch.countDown();
        }
    }

    if (event.getType() == EventType.None) {
        return;
    }
    try {
        events.put(event);
    } catch (InterruptedException e) {
        Assert.assertTrue("interruption unexpected", false);
    }
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:17,代碼來源:WatcherFuncTest.java

示例3: connectZooKeeper

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
private static ZooKeeper connectZooKeeper(String ensemble)
    throws IOException, KeeperException, InterruptedException {
  final CountDownLatch latch = new CountDownLatch(1);

  ZooKeeper zkc = new ZooKeeper(HOSTPORT, 3600, new Watcher() {
    public void process(WatchedEvent event) {
      if (event.getState() == Watcher.Event.KeeperState.SyncConnected) {
        latch.countDown();
      }
    }
  });
  if (!latch.await(10, TimeUnit.SECONDS)) {
    throw new IOException("Zookeeper took too long to connect");
  }
  return zkc;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:TestCurrentInprogress.java

示例4: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
/**
 * It listen to Zookeeper session events. It is called automatically by Zookeeper when a zookeeper session issues an event.
 *
 * @param event issued by zookeeper session
 * @throws IllegalStateException if {@link ZKClusterWatcher#start()} was not called.
 */
@Override
public void process(final WatchedEvent event) {

    if (zkConnection == null || zkNodeWatchers == null) {
        throw new IllegalStateException("Zookeeper monitoring has not been started.");
    }

    try {
        if (event.getType() == Watcher.Event.EventType.None) {
            switch (event.getState()) {
                case SyncConnected:
                    zkClusterStatus.getAndSet(ZKClusterStatusName.QUORUM);
                    zkMonitorListener.onGetQuorum();
                    zkNodeWatchers.forEach(zkNodeWatcher -> zkNodeWatcher.updateStatus());
                    break;

                case Disconnected:
                    zkClusterStatus.getAndSet(ZKClusterStatusName.NO_QUORUM);
                    zkMonitorListener.onLackOfQuorum();
                    zkNodeWatchers.forEach(zkNodeWatcher -> zkNodeWatcher.updateStatus());
                    break;

                case Expired:
                    zkClusterStatus.set(ZKClusterStatusName.NO_QUORUM);
                    restartZKConnection();
                    break;

                default:
                    break;
            }
        }
    } catch (Exception e) {
        throw new ZKMonitorException(e.getMessage(), e, this.getClass());
    }
}
 
開發者ID:mcafee,項目名稱:management-sdk-for-kafka,代碼行數:42,代碼來源:ZKClusterWatcher.java

示例5: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
/**
 * It listen to Zookeeper events.
 * It is called automatically by Zookeeper when a Kafka broker znode has appeared/disappeared or
 * session connect/disconnect
 *
 * @param event {@link WatchedEvent} instance sent by Zookeeper node
 */
@Override
public void process(final WatchedEvent event) {

    if (zkClient == null) {
        return;
    }

    if (event.getType() != Event.EventType.None) {
        setupWatcherAsync(); // Must initialize the watcher because it is one-shot.
        switch (event.getType()) {
            case NodeChildrenChanged:   // A kafka broker has appeared / disappeared
                updateBrokerStatus();   // Force to update brokers' status
                break;

            default:
        }
    } else {
        switch (event.getState()) {
            case SyncConnected:
            case Disconnected:
                updateBrokerStatus();   // Force to update brokers' status
                break;
            case Expired:
                restartZKConnection();  // ZK connection has expired, let's reconnect
                break;

            default:
        }
    }
}
 
開發者ID:mcafee,項目名稱:management-sdk-for-kafka,代碼行數:38,代碼來源:KFClusterWatcher.java

示例6: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
@Override
public void process(WatchedEvent event) {
	// TODO Auto-generated method stub
	System.out.println("Receive Watcher Event:" + event);
	if (KeeperState.SyncConnected == event.getState()) {
		countDownLatch.countDown();
	}	
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:9,代碼來源:MyWatcher.java

示例7: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
synchronized public void process(WatchedEvent event) {
    if (event.getState() == KeeperState.SyncConnected ||
        event.getState() == KeeperState.ConnectedReadOnly) {
        connected = true;
        notifyAll();
        clientConnected.countDown();
    } else {
        connected = false;
        notifyAll();
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:12,代碼來源:ClientBase.java

示例8: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
    LOG.info(name + " event:" + event.getState() + " "
            + event.getType() + " " + event.getPath());
    if (event.getState() == KeeperState.SyncConnected
            && startSignal != null && startSignal.getCount() > 0)
    {
        startSignal.countDown();
    }
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:10,代碼來源:SessionTest.java

示例9: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
@Override
public void process(WatchedEvent event) {
    KeeperState state = event.getState();

    if (state == KeeperState.SyncConnected) {
        ZooKeeperConnectionDescriptor zooKeeperConnectionDescriptor = getDescriptor();
        List<AuthInfo> authInfos = zooKeeperConnectionDescriptor.getAuthInfos();
        if (authInfos != null && !authInfos.isEmpty()) {

            for (AuthInfo authInfo : authInfos) {
                String scheme = authInfo.getScheme();
                byte[] auth;

                try {
                    auth = authInfo.getAuth();
                }
                catch (IOException e) {
                    e.printStackTrace();
                    continue;
                }

                // TODO: Is the lack of thread saftey of this method a concern here?
                addAuthInfo(scheme, auth);
            }
        }
    }

    fireConnectionStateChanged();        
}
 
開發者ID:baloise,項目名稱:eZooKeeper,代碼行數:30,代碼來源:ZooKeeperConnection.java

示例10: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
    LOG.info("Event:" + event.getState() + " " + event.getType() + " " + event.getPath());
    if (event.getState() == KeeperState.SyncConnected
            && startSignal != null && startSignal.getCount() > 0)
    {
        startSignal.countDown();
    }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:9,代碼來源:UpgradeTest.java

示例11: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
    if (event.getType() == Watcher.Event.EventType.None) {
        synchronized (this) {
            connected = event.getState() == Watcher.Event.KeeperState.SyncConnected;
            notifyAll();
        }
    }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:9,代碼來源:GenerateLoad.java

示例12: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
@Override
public synchronized void process(WatchedEvent event) {
    if (event.getState() == KeeperState.AuthFailed) {
        authFailed.incrementAndGet();
    }
    else {
        super.process(event);
    }
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:10,代碼來源:SaslSuperUserTest.java

示例13: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
    LOG.info("Event:" + event.getState() + " " + event.getType() + " "
             + event.getPath());
    if (event.getState() == KeeperState.SyncConnected) {
        if (startSignal != null && startSignal.getCount() > 0) {
            LOG.info("startsignal.countDown()");
            startSignal.countDown();
        } else {
            LOG.warn("startsignal " + startSignal);
        }
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:13,代碼來源:ACLTest.java

示例14: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
@Override
public synchronized void process(WatchedEvent event) {
    if (event.getState() == KeeperState.AuthFailed) {
        authFailed.countDown();
    }
    else {
        super.process(event);
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:10,代碼來源:AuthTest.java

示例15: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
@Override
public synchronized void process(WatchedEvent event) {
    if (event.getState() == KeeperState.AuthFailed) {
        synchronized(authFailed) {
            authFailed.incrementAndGet();
            authFailed.notify();
        }
    }
    else {
        super.process(event);
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:13,代碼來源:SaslAuthFailNotifyTest.java


注:本文中的org.apache.zookeeper.WatchedEvent.getState方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。