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


Java StateListener类代码示例

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


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

示例1: ZkclientZookeeperClient

import com.alibaba.dubbo.remoting.zookeeper.StateListener; //导入依赖的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: ZookeeperRegistry

import com.alibaba.dubbo.remoting.zookeeper.StateListener; //导入依赖的package包/类
public ZookeeperRegistry(URL url, ZookeeperTransporter zookeeperTransporter) {
    super(url);
    if (url.isAnyHost()) {
		throw new IllegalStateException("registry address == null");
	}
    String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
    if (! group.startsWith(Constants.PATH_SEPARATOR)) {
        group = Constants.PATH_SEPARATOR + group;
    }
    this.root = group;
    zkClient = zookeeperTransporter.connect(url);
    zkClient.addStateListener(new StateListener() {
        public void stateChanged(int state) {
        	if (state == RECONNECTED) {
         	try {
		recover();
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	}
        	}
        }
    });
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:24,代码来源:ZookeeperRegistry.java

示例3: ZkclientZookeeperClient

import com.alibaba.dubbo.remoting.zookeeper.StateListener; //导入依赖的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

示例4: ZookeeperRegistry

import com.alibaba.dubbo.remoting.zookeeper.StateListener; //导入依赖的package包/类
public ZookeeperRegistry(URL url, ZookeeperTransporter zookeeperTransporter) {
    super(url);
    if (url.isAnyHost()) {
        throw new IllegalStateException("registry address == null");
    }
    String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
    if (!group.startsWith(Constants.PATH_SEPARATOR)) {
        group = Constants.PATH_SEPARATOR + group;
    }
    this.root = group;
    zkClient = zookeeperTransporter.connect(url);
    zkClient.addStateListener(new StateListener() {
        public void stateChanged(int state) {
            if (state == RECONNECTED) {
                try {
                    recover();
                } catch (Exception e) {
                    logger.error(e.getMessage(), e);
                }
            }
        }
    });
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:24,代码来源:ZookeeperRegistry.java

示例5: CuratorZookeeperClient

import com.alibaba.dubbo.remoting.zookeeper.StateListener; //导入依赖的package包/类
public CuratorZookeeperClient(URL url) {
    super(url);
    try {
        Builder builder = CuratorFrameworkFactory.builder()
                .connectString(url.getBackupAddress())
                .retryPolicy(new RetryNTimes(Integer.MAX_VALUE, 1000))
                .connectionTimeoutMs(5000);
        String authority = url.getAuthority();
        if (authority != null && authority.length() > 0) {
            builder = builder.authorization("digest", authority.getBytes());
        }
        client = builder.build();
        client.getConnectionStateListenable().addListener((client, state) -> {
            if (state == ConnectionState.LOST) {
                CuratorZookeeperClient.this.stateChanged(StateListener.DISCONNECTED);
            } else if (state == ConnectionState.CONNECTED) {
                CuratorZookeeperClient.this.stateChanged(StateListener.CONNECTED);
            } else if (state == ConnectionState.RECONNECTED) {
                CuratorZookeeperClient.this.stateChanged(StateListener.RECONNECTED);
            }
        });
        client.start();
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
开发者ID:linux-china,项目名称:dubbo3,代码行数:27,代码来源:CuratorZookeeperClient.java

示例6: ZookeeperRegistry

import com.alibaba.dubbo.remoting.zookeeper.StateListener; //导入依赖的package包/类
public ZookeeperRegistry(URL url, ZookeeperTransporter zookeeperTransporter) {
    super(url);
    if (url.isAnyHost()) {
        throw new IllegalStateException("registry address == null");
    }
    String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
    if (!group.startsWith(Constants.PATH_SEPARATOR)) {
        group = Constants.PATH_SEPARATOR + group;
    }
    this.root = group;
    zkClient = zookeeperTransporter.connect(url);
    zkClient.addStateListener(state -> {
        if (state == StateListener.RECONNECTED) {
            try {
                recover();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    });
}
 
开发者ID:linux-china,项目名称:dubbo3,代码行数:22,代码来源:ZookeeperRegistry.java

示例7: ZookeeperRegistry

import com.alibaba.dubbo.remoting.zookeeper.StateListener; //导入依赖的package包/类
public ZookeeperRegistry(URL url, ZookeeperTransporter zookeeperTransporter) {
    super(url);
    /*if (url.isAnyHost()) {
		throw new IllegalStateException("registry address == null");
	}*/
    String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
    if (! group.startsWith(Constants.PATH_SEPARATOR)) {
        group = Constants.PATH_SEPARATOR + group;
    }
    this.root = group;
    zkClient = zookeeperTransporter.connect(url);
    //主要处理Session失效之后重连的逻辑
    zkClient.addStateListener(new StateListener() {
        public void stateChanged(int state) {
        	if (state == RECONNECTED) {
         	try {
		recover();
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	}
        	}
        }
    });
}
 
开发者ID:DoubleSmile,项目名称:dubbo-learning,代码行数:25,代码来源:ZookeeperRegistry.java

示例8: ZkclientZookeeperClient

import com.alibaba.dubbo.remoting.zookeeper.StateListener; //导入依赖的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

示例9: ZkclientZookeeperClient

import com.alibaba.dubbo.remoting.zookeeper.StateListener; //导入依赖的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

示例10: ZookeeperRegistry

import com.alibaba.dubbo.remoting.zookeeper.StateListener; //导入依赖的package包/类
public ZookeeperRegistry(URL url, ZookeeperTransporter zookeeperTransporter) {
    super(url);
    if (url.isAnyHost()) {
		throw new IllegalStateException("registry address == null");
	}

    // 这里获取在dubbo:registry的group配置
    String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);

    // 如果group没有以/开头,则给他加上
    if (! group.startsWith(Constants.PATH_SEPARATOR)) {
        group = Constants.PATH_SEPARATOR + group;
    }
    this.root = group;
    zkClient = zookeeperTransporter.connect(url);//连接上zk服务器上
    zkClient.addStateListener(new StateListener() {// 增加绑定在连接上的状态变更监听器,如果RECONNECTED,则恢复连接
        public void stateChanged(int state) {
        	if (state == RECONNECTED) {
         	try {
		recover();
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	}
        	}
        }
    });
}
 
开发者ID:ketao1989,项目名称:exDubbo,代码行数:28,代码来源:ZookeeperRegistry.java

示例11: addStateListener

import com.alibaba.dubbo.remoting.zookeeper.StateListener; //导入依赖的package包/类
public void addStateListener(StateListener listener) {
	stateListeners.add(listener);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:4,代码来源:AbstractZookeeperClient.java

示例12: removeStateListener

import com.alibaba.dubbo.remoting.zookeeper.StateListener; //导入依赖的package包/类
public void removeStateListener(StateListener listener) {
	stateListeners.remove(listener);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:4,代码来源:AbstractZookeeperClient.java


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