All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.nicklaus4.hbase.wrapper.HBaseClientFacade Maven / Gradle / Ivy

The newest version!
package com.github.nicklaus4.hbase.wrapper;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.springframework.beans.factory.DisposableBean;

import com.google.common.base.Throwables;

/**
 * hbase client facade
 *
 * @author weishibai
 * @date 2019/03/20 5:01 PM
 */
public class HBaseClientFacade implements DisposableBean {

    private final Configuration configuration;

    private final Connection connection;

    public HBaseClientFacade(Configuration configuration) {
        this.configuration = configuration;
        try {
            this.connection = ConnectionFactory.createConnection(configuration);
        } catch (IOException e) {
            Throwables.throwIfUnchecked(e);
            throw new RuntimeException("create hbase connection error: ", e);
        }
    }

    public Connection connection() {
        return connection;
    }

    public Configuration configuration() {
        return configuration;
    }

    @Override
    public void destroy() throws Exception {
        connection.close();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy