本文整理匯總了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);
}
}
示例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);
}
});
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
});
}
示例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");
}
});
}
示例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("會話建立成功!");
}
});
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
示例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);
}
});
}
}
示例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狀態重連
}