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


Java IZkStateListener类代码示例

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


IZkStateListener类属于org.I0Itec.zkclient包,在下文中一共展示了IZkStateListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ZkclientZookeeperClient

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的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

示例2: ZkclientZookeeperClient

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的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

示例3: init

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的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

示例4: ZookeeperRegistry

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的package包/类
public ZookeeperRegistry(URL url, ZkClient zkClient) {
    super(url);
    this.zkClient = zkClient;
    IZkStateListener zkStateListener = new IZkStateListener() {
        @Override
        public void handleStateChanged(Watcher.Event.KeeperState state) throws Exception {
            // do nothing
        }

        @Override
        public void handleNewSession() throws Exception {
            logger.info("zkRegistry get new session notify.");

        }

        @Override
        public void handleSessionEstablishmentError(Throwable throwable) throws Exception {

        }
    };
    this.zkClient.subscribeStateChanges(zkStateListener);
}
 
开发者ID:TFdream,项目名称:mango,代码行数:23,代码来源:ZookeeperRegistry.java

示例5: DubboZkclientZookeeperClient

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的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);
        }
    });
}
 
开发者ID:zhangxin23,项目名称:zookeeper-sandbox,代码行数:20,代码来源:DubboZkclientZookeeperClient.java

示例6: ZooKeeperRegistry

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的package包/类
public ZooKeeperRegistry(URL url, ZooKeeperClient client) {
    super(url);
    this.client = client;
    IZkStateListener zkStateListener = new IZkStateListener() {
        @Override
        public void handleStateChanged(Watcher.Event.KeeperState state) throws Exception {
            // do nothing
        }

        @Override
        public void handleNewSession() throws Exception {
            if(logger.isInfoEnabled()) logger.info("zkRegistry get new session notify.");
            reconnectService();
        }
    };
    client.subscribeStateChanges(zkStateListener);
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:18,代码来源:ZooKeeperRegistry.java

示例7: test

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的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");
        }
    });
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:26,代码来源:ZclientChange.java

示例8: ZkClientZkClient

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的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);
        }
    });
}
 
开发者ID:WenZuHuai,项目名称:light-task-scheduler,代码行数:23,代码来源:ZkClientZkClient.java

示例9: stateChangesListener

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的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");
		}
	});
}
 
开发者ID:hncdyj123,项目名称:config-manager,代码行数:21,代码来源:ZkClientConnect.java

示例10: ZkclientZookeeperClient

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的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:nince-wyj,项目名称:jahhan,代码行数:21,代码来源:ZkclientZookeeperClient.java

示例11: ZkclientZookeeperClient

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的package包/类
public ZkclientZookeeperClient(URL url) {
    super(url);
    client = new ZkClientWrapper(url.getBackupAddress(), 30000);
    client.addListener(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);
        }
    });
    client.start();
}
 
开发者ID:hufeng,项目名称:dubbo2.js,代码行数:20,代码来源:ZkclientZookeeperClient.java

示例12: registerNotification

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的package包/类
public static void registerNotification(final SessionExpiredNotification notification) {
    getInstance().subscribeStateChanges(new IZkStateListener() {

        public void handleStateChanged(KeeperState state) throws Exception {

        }

        public void handleNewSession() throws Exception {
            notification.notification();
        }

        @Override
        public void handleSessionEstablishmentError(Throwable error) throws Exception {
        }
    });

}
 
开发者ID:alibaba,项目名称:otter,代码行数:18,代码来源:ZooKeeperClient.java

示例13: fireNewSessionEvents

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的package包/类
private void fireNewSessionEvents() {
    for (final IZkStateListener stateListener : _stateListener) {
        _eventThread.send(new ZkEvent("New session event sent to " + stateListener) {

            @Override
            public void run() throws Exception {
                stateListener.handleNewSession();
            }
        });
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:12,代码来源:ZkClientx.java

示例14: fireStateChangedEvent

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的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:luoyaogui,项目名称:otter-G,代码行数:12,代码来源:ZkClientx.java

示例15: connect

import org.I0Itec.zkclient.IZkStateListener; //导入依赖的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);
	}
}
 
开发者ID:yu120,项目名称:coon,代码行数:38,代码来源:ZkclientZkTransporter.java


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