spring hadoop 系列(三)--spring hadoop hbase HbaseConfigurationFactoryBean

5 篇文章 0 订阅
2 篇文章 0 订阅
一、源码分析
/**
* 设定Hbase指定Configuration;在默认情况是删除当前配置管理的连接信息
* 有参数deleteConnection 控制
*/
public class HbaseConfigurationFactoryBean implements InitializingBean, DisposableBean, FactoryBean<Configuration> {

private static final Log log = LogFactory.getLog(HbaseConfigurationFactoryBean.class);
// 是否删除当前配置相关的连接信息
private boolean deleteConnection = true;
// hbase配置
private Configuration configuration;
// hadoop配置
private Configuration hadoopConfig;
// hbase默认属性参数配置信息
private Properties properties;
// 连接zookeeper的连接数
private String quorum;
// 端口
private Integer port;

/**
* Indicates whether the potential connection created by this config is destroyed at shutdown (default).
* Configuration被清除时,与之关联的Connection信息也要删除
* @param deleteConnection The deleteConnection to set.
*/
public void setDeleteConnection(boolean deleteConnection) {
this.deleteConnection = deleteConnection;
}

/**
* Indicates whether, when/if the associated connection is destroyed, whether the proxy is stopped or not.
* 目前该方法已不再使用
* @param stopProxy The stopProxy to set.
*/
public void setStopProxy(boolean stopProxy) {
log.warn("Use of 'stopProxy' has been deprecated");
}

/**
* Sets the Hadoop configuration to use.
* 设置Hadoop Config
* @param configuration The configuration to set.
*/
public void setConfiguration(Configuration configuration) {
this.hadoopConfig = configuration;
}
// 销毁连接信息
@SuppressWarnings("deprecation")
public void destroy() {
if (deleteConnection) {
HConnectionManager.deleteConnection(getObject());
}
}

/**
* 设置Configuration的属性参数.
*
* @param properties The properties to set.
*/
public void setProperties(Properties properties) {
this.properties = properties;
}
// 属性设置
// 根据hadoopConfig参数内容是否为空 决定是否使用
// hadoop Configuration 构建 Hbase Configuration
// quorum 连接数替换默认zookeeper connection
// port 设定zookeeper port
public void afterPropertiesSet() {
configuration = (hadoopConfig != null ? HBaseConfiguration.create(hadoopConfig) : HBaseConfiguration.create());
ConfigurationUtils.addProperties(configuration, properties);

// set host and port last to override any other properties
if (StringUtils.hasText(quorum)) {
configuration.set(HConstants.ZOOKEEPER_QUORUM, quorum.trim());
}
if (port != null) {
configuration.set(HConstants.ZOOKEEPER_CLIENT_PORT, port.toString());
}
}
// 返回hbase configuration
public Configuration getObject() {
return configuration;
}

public Class<? extends Configuration> getObjectType() {
return (configuration != null ? configuration.getClass() : Configuration.class);
}

public boolean isSingleton() {
return true;
}

/**
* Sets the HBase Zookeeper Quorum host(s). If not specified, the default value (picked the the classpath) is used.
*
* @param quorum HBase ZK quorum hosts.
*/
public void setZkQuorum(String quorum) {
this.quorum = quorum;
}

/**
* Sets the HBase Zookeeper port for clients to connect to. If not specified, the default value (picked from the classpath) is used.
*
* @param port HBase ZK client port.
*/
public void setZkPort(Integer port) {
this.port = port;
}
}
该类主要是设定hbase configuration factory的;同时该类在默认情况下是清除当前Configuration所关联的Connection
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值