![JAR search and dependency download from the Maven repository](/logo.png)
org.cloudgraph.hbase.connect.HBasePooledConnectionFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cloudgraph-hbase Show documentation
Show all versions of cloudgraph-hbase Show documentation
CloudGraph(tm) is a suite of Service Data Object (SDO) 2.1 services designed for relational and big-table style "cloud" databases, such as HBase and others.
The newest version!
/**
* Copyright 2017 TerraMeta Software, Inc.
*
* Licensed 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 org.cloudgraph.hbase.connect;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.ObjectPool;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.cloudgraph.core.Connection;
/**
* Connection factory which creates pooled connections.
*
*
* The new HBase Client API changes removed the existing connection pool
* implementation and placed the responsibility of managing the lifecycle of
* connections on the caller. A pool is necessary as creating connections to the
* cluster via. zookeeper is fairly expensive.
*
* @author Scott Cinnamond
* @since 0.6.3
*/
public class HBasePooledConnectionFactory extends BasePooledObjectFactory {
private static Log log = LogFactory.getLog(HBasePooledConnectionFactory.class);
private Configuration config;
private ObjectPool pool;
public HBasePooledConnectionFactory(Configuration config) {
super();
this.config = config;
}
public void setPool(ObjectPool pool) {
this.pool = pool;
}
@Override
public Connection create() throws Exception {
org.apache.hadoop.hbase.client.Connection con = ConnectionFactory.createConnection(config);
if (log.isDebugEnabled())
log.debug("creating new hbase connection" + con);
return new HBaseConnection(con, this.pool, this.config);
}
@Override
public PooledObject wrap(Connection con) {
return new DefaultPooledObject(con);
}
@Override
public void destroyObject(PooledObject p) throws Exception {
if (log.isDebugEnabled())
log.debug("destroying connection" + p.getObject());
p.getObject().destroy();
super.destroyObject(p);
}
@Override
public boolean validateObject(PooledObject p) {
if (log.isDebugEnabled())
log.debug("validating connection" + p.getObject());
return super.validateObject(p);
}
@Override
public void activateObject(PooledObject p) throws Exception {
if (log.isDebugEnabled())
log.debug("activate connection" + p.getObject());
super.activateObject(p);
}
@Override
public void passivateObject(PooledObject p) throws Exception {
if (log.isDebugEnabled())
log.debug("passivate connection" + p.getObject());
super.passivateObject(p);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy