二、stormkafka之ZkBrokerReader
来源:互联网 发布:祁县哪个宽带网络好 编辑:程序博客网 时间:2024/06/07 03:09
/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package storm.kafka.trident;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import storm.kafka.DynamicBrokersReader;import storm.kafka.ZkHosts;import java.util.Map;public class ZkBrokerReader implements IBrokerReader { public static final Logger LOG = LoggerFactory.getLogger(ZkBrokerReader.class); GlobalPartitionInformation cachedBrokers; DynamicBrokersReader reader; long lastRefreshTimeMs; long refreshMillis; public ZkBrokerReader(Map conf, String topic, ZkHosts hosts) { try { reader = new DynamicBrokersReader(conf, hosts.brokerZkStr, hosts.brokerZkPath, topic); cachedBrokers = reader.getBrokerInfo(); lastRefreshTimeMs = System.currentTimeMillis(); refreshMillis = hosts.refreshFreqSecs * 1000L; } catch (java.net.SocketTimeoutException e) { LOG.warn("Failed to update brokers", e); } } /** * 获取当前的kafka服务器列表 * @return */ @Override public GlobalPartitionInformation getCurrentBrokers() { long currTime = System.currentTimeMillis(); if (currTime > lastRefreshTimeMs + refreshMillis) { try { LOG.info("brokers need refreshing because " + refreshMillis + "ms have expired"); cachedBrokers = reader.getBrokerInfo(); lastRefreshTimeMs = currTime; } catch (java.net.SocketTimeoutException e) { LOG.warn("Failed to update brokers", e); } } return cachedBrokers; } @Override public void close() { reader.close(); }}
阅读全文
0 0
- 二、stormkafka之ZkBrokerReader
- 一、stormkafka之DynamicBrokersReader
- 之二
- 赠别 二首之二
- 框架之 hibernate之二
- DoxyGen文档之二
- 感受Longhorn之二
- 揭短之二
- 近日二三事之二
- 成功誓言之二
- delphi2005探讨之二
- [随时感动]之二
- 童年趣事之二
- C#速成(之二)
- Linux常用命令之二
- 皮皮之二
- 关于XFS之二
- STL学习之(二)
- 面试题28:字符串的排列
- ajax 设置Access-Control-Allow-Origin实现跨域访问
- 获取UIAlertController中textField的值
- UnityShader案例(八)——透明效果(1)
- IntelliJ IDEA上创建Maven Spring MVC项目
- 二、stormkafka之ZkBrokerReader
- VS2015+VisualGDB真机调试NativieAndroid工程
- 江windows盘挂载到ubuntu下
- hdoj 2000
- 如何生成KeyStore
- 单KEY业务,数据库水平切分架构实践 | 架构师之路
- okHttp工具类,实现get和post
- yii2常用方法
- Js控制iphone端的input/textarea元素失去焦点时隐藏键盘