當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。