当前位置: 首页>>代码示例>>Java>>正文


Java KeeperState类代码示例

本文整理汇总了Java中org.apache.zookeeper.Watcher.Event.KeeperState的典型用法代码示例。如果您正苦于以下问题:Java KeeperState类的具体用法?Java KeeperState怎么用?Java KeeperState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


KeeperState类属于org.apache.zookeeper.Watcher.Event包,在下文中一共展示了KeeperState类的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);
    }
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:18,代码来源:ZkClient.java

示例2: ZkclientZookeeperClient

import org.apache.zookeeper.Watcher.Event.KeeperState; //导入依赖的package包/类
public ZkclientZookeeperClient(URL url) {
	super(url);
	client = new ZkClient(url.getBackupAddress());
	client.subscribeStateChanges(new IZkStateListener() {
		public void handleStateChanged(KeeperState state) throws Exception {
			ZkclientZookeeperClient.this.state = state;
			if (state == KeeperState.Disconnected) {
				stateChanged(StateListener.DISCONNECTED);
			} else if (state == KeeperState.SyncConnected) {
				stateChanged(StateListener.CONNECTED);
			}
		}
		public void handleNewSession() throws Exception {
			stateChanged(StateListener.RECONNECTED);
		}
	});
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:18,代码来源:ZkclientZookeeperClient.java

示例3: init

import org.apache.zookeeper.Watcher.Event.KeeperState; //导入依赖的package包/类
/**
 * 连接zookeeper
 * 
 * @author gaoxianglong
 */
public void init() {
	try {
		zkClient = new ZooKeeper(zkAddress, zkSessionTimeout, new Watcher() {
			@Override
			public void process(WatchedEvent event) {
				KeeperState state = event.getState();
				switch (state) {
				case SyncConnected:
					countDownLatch.countDown();
					logger.info("connection zookeeper success");
					break;
				case Disconnected:
					logger.warn("zookeeper connection is disconnected");
					break;
				case Expired:
					logger.error("zookeeper session expired");
					break;
				case AuthFailed:
					logger.error("authentication failure");
					break;
				default:
					break;
				}
			}
		});
		countDownLatch.await();
	} catch (Exception e) {
		logger.error("error", e);
	}
}
 
开发者ID:yunjiweidian,项目名称:TITAN,代码行数:36,代码来源:ZookeeperConnManager.java

示例4: 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);
	}
}
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:19,代码来源:ZkClient.java

示例5: process

import org.apache.zookeeper.Watcher.Event.KeeperState; //导入依赖的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:maoling,项目名称:fuck_zookeeper,代码行数:17,代码来源:WatcherFuncTest.java

示例6: ZkclientZookeeperClient

import org.apache.zookeeper.Watcher.Event.KeeperState; //导入依赖的package包/类
public ZkclientZookeeperClient(URL url) {
	super(url);
	client = new ZkClient(
               url.getBackupAddress(),
               url.getParameter(Constants.SESSION_TIMEOUT_KEY, Constants.DEFAULT_SESSION_TIMEOUT),
               url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_REGISTRY_CONNECT_TIMEOUT));
	client.subscribeStateChanges(new IZkStateListener() {
		public void handleStateChanged(KeeperState state) throws Exception {
			ZkclientZookeeperClient.this.state = state;
			if (state == KeeperState.Disconnected) {
				stateChanged(StateListener.DISCONNECTED);
			} else if (state == KeeperState.SyncConnected) {
				stateChanged(StateListener.CONNECTED);
			}
		}
		public void handleNewSession() throws Exception {
			stateChanged(StateListener.RECONNECTED);
		}
	});
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:21,代码来源:ZkclientZookeeperClient.java

示例7: subscribeStateChanges

import org.apache.zookeeper.Watcher.Event.KeeperState; //导入依赖的package包/类
private static void subscribeStateChanges() {
    getZkClient().subscribeStateChanges(new IZkStateListener() {
        public void handleStateChanged(KeeperState state) throws Exception {
            if(state == null) {
                ZkClientFactory.LOGGER.info("ZOOKEEPER连接状态改变");
            } else {
                ZkClientFactory.LOGGER.info("ZOOKEEPER连接状态改变为" + state.name());
            }

        }

        public void handleNewSession() throws Exception {
            ZkClientFactory.LOGGER.info("SESSIONTIMEOUT,ZOOKEEPER重连,产生新SESSION");
        }
    });
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:17,代码来源:ZkClientFactory.java

示例8: init

import org.apache.zookeeper.Watcher.Event.KeeperState; //导入依赖的package包/类
@Override
public void init() {
	this.zkClient = new ZkClient(this.zkAddress, this.zkSessionTimeOut, this.zkConnectionTimeOut, new SerializableSerializer());
	initRootPath();
	this.zkClient.subscribeStateChanges(new IZkStateListener() {
		@Override
		public void handleStateChanged(KeeperState state) throws Exception {
			if(zkReconnectionListener != null && state.name().equals(KeeperState.SyncConnected.name())){
				zkReconnectionListener.handleStateForSyncConnected();
			}
		}
		@Override
		public void handleSessionEstablishmentError(Throwable error)throws Exception {
			log.error("处理会话建立错误:{}",error);
		}
		@Override
		public void handleNewSession() throws Exception {
			log.info("会话建立成功!");
		}
	});
}
 
开发者ID:yanghuijava,项目名称:elephant,代码行数:22,代码来源:ZkClientRegisterCenter.java

示例9: 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);
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:18,代码来源:ZkClientx.java

示例10: waitForKeeperState

import org.apache.zookeeper.Watcher.Event.KeeperState; //导入依赖的package包/类
public boolean waitForKeeperState(KeeperState keeperState, long time, TimeUnit timeUnit)
                                                                                        throws ZkInterruptedException {
    if (_zookeeperEventThread != null && Thread.currentThread() == _zookeeperEventThread) {
        throw new IllegalArgumentException("Must not be done in the zookeeper event thread.");
    }
    Date timeout = new Date(System.currentTimeMillis() + timeUnit.toMillis(time));

    LOG.debug("Waiting for keeper state " + keeperState);
    acquireEventLock();
    try {
        boolean stillWaiting = true;
        while (_currentState != keeperState) {
            if (!stillWaiting) {
                return false;
            }
            stillWaiting = getEventLock().getStateChangedCondition().awaitUntil(timeout);
        }
        LOG.debug("State is " + _currentState);
        return true;
    } catch (InterruptedException e) {
        throw new ZkInterruptedException(e);
    } finally {
        getEventLock().unlock();
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:26,代码来源:ZkClientx.java

示例11: waitForKeeperState

import org.apache.zookeeper.Watcher.Event.KeeperState; //导入依赖的package包/类
public boolean waitForKeeperState(KeeperState keeperState, long time,
		TimeUnit timeUnit) {

	Date timeout = new Date(System.currentTimeMillis()
			+ timeUnit.toMillis(time));

	logger.debug("Waiting for keeper state " + keeperState);
	acquireEventLock();
	try {
		boolean stillWaiting = true;
		while (_currentState != keeperState) {
			if (!stillWaiting) {
				return false;
			}
			stillWaiting = getEventLock().getStateChangedCondition()
					.awaitUntil(timeout);
		}
		logger.debug("State is " + _currentState);
		return true;
	} catch (InterruptedException e) {
		throw new RuntimeException("error when conn");
	} finally {
		getEventLock().unlock();
	}
}
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:26,代码来源:ZkClient.java

示例12: process

import org.apache.zookeeper.Watcher.Event.KeeperState; //导入依赖的package包/类
synchronized public void process(WatchedEvent event) {
    KeeperState state = event.getState();
    if (state == KeeperState.SyncConnected) {
        connected = true;
        syncConnected = true;
        readOnlyConnected = false;
    } else if (state == KeeperState.ConnectedReadOnly) {
        connected = true;
        syncConnected = false;
        readOnlyConnected = true;
    } else {
        connected = false;
        syncConnected = false;
        readOnlyConnected = false;
    }

    notifyAll();
    if (connected) {
        clientConnected.countDown();
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:22,代码来源:ClientBase.java

示例13: process

import org.apache.zookeeper.Watcher.Event.KeeperState; //导入依赖的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

示例14: fireStateChangedEvent

import org.apache.zookeeper.Watcher.Event.KeeperState; //导入依赖的package包/类
private void fireStateChangedEvent(final KeeperState state) {
    for (final IZkStateListener stateListener : _stateListener) {
        _eventThread.send(new ZkEvent("State changed to " + state + " sent to " + stateListener) {

            @Override
            public void run() throws Exception {
                stateListener.handleStateChanged(state);
            }
        });
    }
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:12,代码来源:ZkClient.java

示例15: 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状态重连
}
 
开发者ID:liuht777,项目名称:uncode-scheduler,代码行数:20,代码来源:ZKManager.java


注:本文中的org.apache.zookeeper.Watcher.Event.KeeperState类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。