本文整理匯總了Java中org.I0Itec.zkclient.ZkClient.subscribeStateChanges方法的典型用法代碼示例。如果您正苦於以下問題:Java ZkClient.subscribeStateChanges方法的具體用法?Java ZkClient.subscribeStateChanges怎麽用?Java ZkClient.subscribeStateChanges使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.I0Itec.zkclient.ZkClient
的用法示例。
在下文中一共展示了ZkClient.subscribeStateChanges方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ZkclientZookeeperClient
import org.I0Itec.zkclient.ZkClient; //導入方法依賴的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);
}
});
}
示例2: ZkclientZookeeperClient
import org.I0Itec.zkclient.ZkClient; //導入方法依賴的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);
}
});
}
示例3: DubboZkclientZookeeperClient
import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
public DubboZkclientZookeeperClient(URL url) {
super(url);
client = new ZkClient(url.getBackupAddress());
client.subscribeStateChanges(new IZkStateListener() {
public void handleStateChanged(Watcher.Event.KeeperState keeperState) throws Exception {
DubboZkclientZookeeperClient.this.state = state;
if(state == Watcher.Event.KeeperState.Disconnected) {
stateChanged(StateListener.DISCONNECTED);
} else if(state == Watcher.Event.KeeperState.SyncConnected) {
stateChanged(StateListener.CONNECTED);
}
}
public void handleNewSession() throws Exception {
stateChanged(StateListener.RECONNECTED);
}
});
}
示例4: test
import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
private static void test() {
final ZkClient zkClient = new ZkClient("localhost:2181");
zkClient.subscribeStateChanges(new IZkStateListener() {
@Override
public void handleStateChanged(Watcher.Event.KeeperState state) throws Exception {
//當zookeeper被關閉時候 會觸發這個事件
if (state == Watcher.Event.KeeperState.Disconnected) {
log.info("Disconnected");
} else if (state == Watcher.Event.KeeperState.SyncConnected) {
// 當zookeeper被重新連接的時候 會觸發這個事件
log.info("SyncConnected");
}
}
@Override
public void handleNewSession() throws Exception {
log.info("handleNewSession");
}
@Override
public void handleSessionEstablishmentError(Throwable error) throws Exception {
log.info("handleSessionEstablishmentError");
}
});
}
示例5: ZkClientZkClient
import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
public ZkClientZkClient(Config config) {
String registryAddress = NodeRegistryUtils.getRealRegistryAddress(config.getRegistryAddress());
zkClient = new ZkClient(registryAddress, connectionTimeout);
zkClient.subscribeStateChanges(new IZkStateListener() {
public void handleStateChanged(Watcher.Event.KeeperState state) throws Exception {
ZkClientZkClient.this.state = state;
if (state == KeeperState.Disconnected) {
stateChanged(StateListener.DISCONNECTED);
} else if (state == KeeperState.SyncConnected) {
stateChanged(StateListener.CONNECTED);
} else if (state == KeeperState.Expired) {
stateChanged(StateListener.DISCONNECTED);
}
}
public void handleNewSession() throws Exception {
stateChanged(StateListener.RECONNECTED);
}
});
}
示例6: stateChangesListener
import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
/**
* 訂閱連接狀態的變化
*
* @param zkClient
*/
public void stateChangesListener(ZkClient zkClient) {
zkClient.subscribeStateChanges(new IZkStateListener() {
public void handleStateChanged(KeeperState state) throws Exception {
LOGGER.warn("handleStateChanged");
}
public void handleSessionEstablishmentError(Throwable error) throws Exception {
LOGGER.warn("handleSessionEstablishmentError");
}
public void handleNewSession() throws Exception {
LOGGER.warn("handleNewSession");
}
});
}
示例7: ZkclientZookeeperClient
import org.I0Itec.zkclient.ZkClient; //導入方法依賴的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);
}
});
}
示例8: connect
import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
@Override
public void connect(NURL nurl) {
super.connect(nurl);
client = new ZkClient(
nurl.getBackupAddress(),
nurl.getParameter(Consts.SESSION_TIMEOUT_KEY, Consts.DEFAULT_SESSION_TIMEOUT),
nurl.getParameter(Consts.TIMEOUT_KEY, Consts.DEFAULT_REGISTRY_CONNECT_TIMEOUT));
client.subscribeStateChanges(new IZkStateListener() {
@Override
public void handleStateChanged(KeeperState state) throws Exception {
ZkclientZkTransporter.this.state = state;
if (state == KeeperState.Disconnected) {
stateChanged(StateListener.DISCONNECTED);
} else if (state == KeeperState.SyncConnected) {
stateChanged(StateListener.CONNECTED);
countDownLatch.countDown();
}
}
@Override
public void handleNewSession() throws Exception {
stateChanged(StateListener.RECONNECTED);
}
@Override
public void handleSessionEstablishmentError(Throwable error) throws Exception {
}
});
try {
countDownLatch.await(nurl.getParameter(Consts.TIMEOUT_KEY,
Consts.DEFAULT_REGISTRY_CONNECT_TIMEOUT), TimeUnit.MILLISECONDS);
} catch (Exception e) {
logger.error("The countDownLatch exception", e);
}
}
示例9: start
import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
public synchronized void start() {
if (started) {
return;
}
try {
String ip = AppInfo.get("soa.host", AppInfo.getIp());
path = ZKConst.SOA_ROOT + "/" + AppInfo.get("soa.zk.host", ip) + ":"
+ AppInfo.get("soa.zk.port", String.valueOf(port));
zkUrl = AppInfo.getZKUrl();
ZkClient client = ZkClientHolder.getZkClient(zkUrl);
ZkClientHolder.makeSure(client, ZKConst.SOA_ROOT);
startServer(ip, port);
client.delete(path);
IZkStateListener stateListener = new IZkStateListener() {
@Override
public void handleStateChanged(KeeperState state) throws Exception {
Log.get("sumk.rpc").info("zk state changed:{}", state);
}
@Override
public void handleNewSession() throws Exception {
client.createEphemeral(path, createZkRouteData());
}
@Override
public void handleSessionEstablishmentError(Throwable error) throws Exception {
Log.get("sumk.rpc").error("SessionEstablishmentError#" + error.getMessage(), error);
}
};
client.createEphemeral(path, createZkRouteData());
client.subscribeStateChanges(stateListener);
started = true;
} catch (Exception e) {
Log.printStack(e);
System.exit(-1);
}
}