当前位置: 首页>>代码示例>>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;未经允许,请勿转载。