本文整理汇总了Java中org.apache.zookeeper.Watcher.Event.KeeperState.Expired方法的典型用法代码示例。如果您正苦于以下问题:Java KeeperState.Expired方法的具体用法?Java KeeperState.Expired怎么用?Java KeeperState.Expired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.zookeeper.Watcher.Event.KeeperState
的用法示例。
在下文中一共展示了KeeperState.Expired方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processStateChanged
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
private void processStateChanged(WatchedEvent event) {
logger.info("zookeeper state changed (" + event.getState() + ")");
setCurrentState(event.getState());
if (getShutdownTrigger()) {
return;
}
try {
fireStateChangedEvent(event.getState());
if (event.getState() == KeeperState.Expired) {
reconnect();
fireNewSessionEvents();
}
} catch (final Exception e) {
throw new RuntimeException("Exception while restarting zk client", e);
}
}
示例2: processStateChanged
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
private void processStateChanged(WatchedEvent event) {
LOG.info("zookeeper state changed (" + event.getState() + ")");
setCurrentState(event.getState());
if (getShutdownTrigger()) {
return;
}
try {
fireStateChangedEvent(event.getState());
if (event.getState() == KeeperState.Expired) {
reconnect();
fireNewSessionEvents();
}
} catch (final Exception e) {
throw new RuntimeException("Exception while restarting zk client", e);
}
}
示例3: processStateChanged
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
private void processStateChanged(WatchedEvent event) {
logger.info("zookeeper state changed (" + event.getState() + ")");
setCurrentState(event.getState());
if (getShutdownTrigger()) {
return;
}
try {
fireStateChangedEvent(event.getState());
if (event.getState() == KeeperState.Expired) {
reconnect();
fireNewSessionEvents();
}
} catch (final Exception e) {
throw new RuntimeException("Exception while restarting zk client",
e);
}
}
示例4: process
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
if (KeeperState.Expired == event.getState()) {
// It's all over
LOG.error("Lost session");
System.exit(4);
}
if (event.getPath() != null && event.getPath().equals(assignmentsNode)) {
// children have changed, so read in the new list
zk.getChildren(assignmentsNode, true, this, null);
}
}
示例5: process
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
@Override
public void process(final WatchedEvent p_event) {
// #if LOGGER >= ERROR
if (p_event.getType() == Event.EventType.None && p_event.getState() == KeeperState.Expired) {
LOGGER.error(getClass().getName(), "ZooKeeper state expired");
}
// #endif /* LOGGER >= ERROR */
}
示例6: sessionEvent
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
/**
* zookeeper 链接事件监听
*
* @param connectionLatch 同步锁
* @param event 事件
*/
private void sessionEvent(CountDownLatch connectionLatch, WatchedEvent event) {
if (event.getState() == KeeperState.SyncConnected) {
log.info("收到ZK连接成功事件!");
connectionLatch.countDown();
} else if (event.getState() == KeeperState.Expired) {
log.error("会话超时,等待重新建立ZK连接...");
try {
reConnection();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
} // Disconnected:Zookeeper会自动处理Disconnected状态重连
}
示例7: testConvertingToEventWrapper
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
@Test
public void testConvertingToEventWrapper() {
WatchedEvent we = new WatchedEvent(EventType.NodeCreated, KeeperState.Expired, "blah");
WatcherEvent wew = we.getWrapper();
Assert.assertEquals(EventType.NodeCreated.getIntValue(), wew.getType());
Assert.assertEquals(KeeperState.Expired.getIntValue(), wew.getState());
Assert.assertEquals("blah", wew.getPath());
}
示例8: testConvertingToEventWrapper
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
@Test
public void testConvertingToEventWrapper() {
WatchedEvent we = new WatchedEvent(EventType.NodeCreated, KeeperState.Expired, "blah");
WatcherEvent wew = we.getWrapper();
Assert.assertEquals(EventType.NodeCreated.getIntValue(), wew.getType());
Assert.assertEquals(KeeperState.Expired.getIntValue(), wew.getState());
Assert.assertEquals("blah", wew.getPath());
}
示例9: process
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
logger.debug("Received event: " + event);
_zookeeperEventThread = Thread.currentThread();
boolean stateChanged = event.getPath() == null;
boolean znodeChanged = event.getPath() != null;
boolean dataChanged = event.getType() == EventType.NodeDataChanged || //
event.getType() == EventType.NodeDeleted || event.getType() == EventType.NodeCreated || //
event.getType() == EventType.NodeChildrenChanged;
getEventLock().lock();
try {
// We might have to install child change event listener if a new node was created
if (getShutdownTrigger()) {
logger.debug("ignoring event '{" + event.getType() + " | " + event.getPath() + "}' since shutdown triggered");
return;
}
if (stateChanged) {
processStateChanged(event);
}
if (dataChanged) {
processDataOrChildChange(event);
}
} finally {
if (stateChanged) {
getEventLock().getStateChangedCondition().signalAll();
// If the session expired we have to signal all conditions, because watches might have been removed and
// there is no guarantee that those
// conditions will be signaled at all after an Expired event
if (event.getState() == KeeperState.Expired) {
getEventLock().getZNodeEventCondition().signalAll();
getEventLock().getDataChangedCondition().signalAll();
// We also have to notify all listeners that something might have changed
fireAllEvents();
}
}
if (znodeChanged) {
getEventLock().getZNodeEventCondition().signalAll();
}
if (dataChanged) {
getEventLock().getDataChangedCondition().signalAll();
}
getEventLock().unlock();
logger.debug("Leaving process event");
}
}
示例10: connect
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
public boolean connect(Properties connectionProps) {
try {
if (this.zooKeeper == null) {
String connectString = connectionProps
.getProperty(CONNECT_STRING);
String sessionTimeout = connectionProps
.getProperty(SESSION_TIMEOUT);
String encryptionManager = connectionProps
.getProperty(DATA_ENCRYPTION_MANAGER);
String authScheme = connectionProps
.getProperty(AUTH_SCHEME_KEY);
String authData = connectionProps
.getProperty(AUTH_DATA_KEY);
if (connectString == null || sessionTimeout == null) {
throw new IllegalArgumentException(
"Both connect string and session timeout are required.");
}
if (encryptionManager == null) {
this.encryptionManager = new BasicDataEncryptionManager();
} else {
Class<?> clazz = Class.forName(encryptionManager);
if (Arrays.asList(clazz.getInterfaces()).contains(
DataEncryptionManager.class)) {
this.encryptionManager = (DataEncryptionManager) Class
.forName(encryptionManager).newInstance();
} else {
throw new IllegalArgumentException(
"Data encryption manager must implement DataEncryptionManager interface");
}
}
this.connectString = connectString;
this.sessionTimeout = Integer.valueOf(sessionTimeout);
this.zooKeeper = new ZooKeeperRetry(connectString, Integer
.valueOf(sessionTimeout), new Watcher() {
public void process(WatchedEvent event) {
if (event.getState() == KeeperState.Expired) {
connected = false;
}
}
});
if (authData != null && authData.length() > 0){
this.zooKeeper.addAuthInfo(authScheme, authData.getBytes());
}
((ZooKeeperRetry) this.zooKeeper).setRetryLimit(10);
connected = ((ZooKeeperRetry) this.zooKeeper).testConnection();
}
} catch (Exception e) {
connected = false;
e.printStackTrace();
}
if (!connected){
disconnect();
}
return connected;
}
示例11: process
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
/**
* Track state - in particular watch for expiration. if it happens for
* re-creation of the ZK client session
*/
synchronized public void process(WatchedEvent event) {
if (event.getState() == KeeperState.Expired) {
close(contextPath);
}
}
示例12: process
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
@Override
public void process(final WatchedEvent p_event) {
String path;
String prefix;
List<String> children;
short nodeID;
NodeRole role;
String node;
String[] splits;
if (!m_shutdown) {
if (p_event.getType() == Event.EventType.None && p_event.getState() == KeeperState.Expired) {
// #if LOGGER >= ERROR
LOGGER.error("ZooKeeper state expired");
// #endif /* LOGGER >= ERROR */
} else {
try {
path = p_event.getPath();
prefix = m_zookeeper.getPath() + '/';
while (m_isStarting) {
try {
Thread.sleep(100);
} catch (final InterruptedException ignored) {
}
}
if (path != null) {
if (path.equals(prefix + "nodes/new")) {
children = m_zookeeper.getChildren("nodes/new", this);
for (String child : children) {
nodeID = Short.parseShort(child);
node = new String(zookeeperGetData("nodes/new/" + nodeID));
splits = node.split(":");
role = NodeRole.toNodeRole(splits[2]);
m_nodes.addNode(nodeID, new NodeEntry(new IPV4Unit(splits[0], Integer.parseInt(splits[1])), (short) 0, (short) 0, role, false));
}
}
}
} catch (final ZooKeeperException e) {
// #if LOGGER >= ERROR
LOGGER.error("Could not access ZooKeeper", e);
// #endif /* LOGGER >= ERROR */
}
}
}
}
示例13: process
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
LOG.debug("Received event: " + event);
_zookeeperEventThread = Thread.currentThread();
boolean stateChanged = event.getPath() == null;
boolean znodeChanged = event.getPath() != null;
boolean dataChanged = event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted
|| event.getType() == EventType.NodeCreated
|| event.getType() == EventType.NodeChildrenChanged;
getEventLock().lock();
try {
// We might have to install child change event listener if a new node was created
if (getShutdownTrigger()) {
LOG.debug("ignoring event '{" + event.getType() + " | " + event.getPath()
+ "}' since shutdown triggered");
return;
}
if (stateChanged) {
processStateChanged(event);
}
if (dataChanged) {
processDataOrChildChange(event);
}
} finally {
if (stateChanged) {
getEventLock().getStateChangedCondition().signalAll();
// If the session expired we have to signal all conditions, because watches might have been removed and
// there is no guarantee that those
// conditions will be signaled at all after an Expired event
// TODO PVo write a test for this
if (event.getState() == KeeperState.Expired) {
getEventLock().getZNodeEventCondition().signalAll();
getEventLock().getDataChangedCondition().signalAll();
// We also have to notify all listeners that something might have changed
fireAllEvents();
}
}
if (znodeChanged) {
getEventLock().getZNodeEventCondition().signalAll();
}
if (dataChanged) {
getEventLock().getDataChangedCondition().signalAll();
}
getEventLock().unlock();
LOG.debug("Leaving process event");
}
}
示例14: connect
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
public boolean connect(Properties connectionProps) {
try {
if (this.zooKeeper == null) {
String connectString = connectionProps
.getProperty(CONNECT_STRING);
String sessionTimeout = connectionProps
.getProperty(SESSION_TIMEOUT);
String encryptionManager = connectionProps
.getProperty(DATA_ENCRYPTION_MANAGER);
String authScheme = connectionProps
.getProperty(AUTH_SCHEME_KEY);
String authData = connectionProps
.getProperty(AUTH_DATA_KEY);
if (connectString == null || sessionTimeout == null) {
throw new IllegalArgumentException(
"Both connect string and session timeout are required.");
}
if (encryptionManager == null) {
this.encryptionManager = new BasicDataEncryptionManager();
} else {
Class<?> clazz = Class.forName(encryptionManager);
if (Arrays.asList(clazz.getInterfaces()).contains(
DataEncryptionManager.class)) {
this.encryptionManager = (DataEncryptionManager) Class
.forName(encryptionManager).newInstance();
} else {
throw new IllegalArgumentException(
"Data encryption manager must implement DataEncryptionManager interface");
}
}
this.connectString = connectString;
this.sessionTimeout = Integer.valueOf(sessionTimeout);
this.zooKeeper = new ZooKeeperRetry(connectString, Integer
.valueOf(sessionTimeout), new Watcher() {
public void process(WatchedEvent event) {
if (event.getState() == KeeperState.Expired) {
connected = false;
}
}
});
if (authData != null && authData.length() > 0){
this.zooKeeper.addAuthInfo(authScheme, authData.getBytes());
}
((ZooKeeperRetry) this.zooKeeper).setRetryLimit(10);
connected = ((ZooKeeperRetry) this.zooKeeper).testConnection();
}
} catch (Exception e) {
connected = false;
e.printStackTrace();
}
if (!connected){
disconnect();
} else {
this.nodesCache = new NodesCache(zooKeeper);
}
return connected;
}
示例15: process
import org.apache.zookeeper.Watcher.Event.KeeperState; //导入方法依赖的package包/类
@Override
public void process(WatchedEvent event) {
_zookeeperEventThread = Thread.currentThread();
boolean stateChanged = event.getPath() == null;
boolean znodeChanged = event.getPath() != null;
boolean dataChanged = event.getType() == EventType.NodeDataChanged
|| event.getType() == EventType.NodeDeleted
|| event.getType() == EventType.NodeCreated
|| event.getType() == EventType.NodeChildrenChanged;
getEventLock().lock();
try {
// We might have to install child change event listener if a new
// node was created
if (getShutdownTrigger()) {
logger.debug("ignoring event '{" + event.getType() + " | " + event.getPath() + "}' since shutdown triggered");
return;
}
if (stateChanged) {
processStateChanged(event);
}
if (dataChanged) {
processDataOrChildChange(event);
}
} finally {
if (stateChanged) {
getEventLock().getStateChangedCondition().signalAll();
// If the session expired we have to signal all conditions,
// because watches might have been removed and
// there is no guarantee that those
// conditions will be signaled at all after an Expired event
// TODO PVo write a test for this
if (event.getState() == KeeperState.Expired) {
getEventLock().getZNodeEventCondition().signalAll();
getEventLock().getDataChangedCondition().signalAll();
// We also have to notify all listeners that something might
// have changed
fireAllEvents();
}
}
if (znodeChanged) {
getEventLock().getZNodeEventCondition().signalAll();
}
if (dataChanged) {
getEventLock().getDataChangedCondition().signalAll();
}
getEventLock().unlock();
logger.debug("Leaving process event");
}
}