`
dalan_123
  • 浏览: 83670 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论

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

阅读更多
一、源码分析
/**
* 设定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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics