List of usage examples for org.apache.commons.pool PoolUtils synchronizedPoolableFactory
public static KeyedPoolableObjectFactory synchronizedPoolableFactory( final KeyedPoolableObjectFactory keyedFactory)
From source file:co.nubetech.crux.servlet.filter.CruxFilter.java
@Override public void init(FilterConfig filter) { try {/*from w w w . j a v a2 s.c o m*/ super.init(filter); ConnectionDAO connectionDAO = new ConnectionDAO(); connectionDAO.session = com.googlecode.s2hibernate.struts2.plugin.util.HibernateSessionFactory .getNewSession(); List<Connection> connectionList = connectionDAO.findAll(); logger.debug("connectionList size is: " + connectionList.size()); KeyedPoolableObjectFactory factory = PoolUtils .synchronizedPoolableFactory(new HBaseConnectionPoolFactory()); HBaseConnectionPool pool = new HBaseConnectionPool(factory); for (Connection connection : connectionList) { logger.debug("Connection is: " + connection); pool.addObject(connection); } filter.getServletContext().setAttribute(CruxConstants.HBASE_POOL, pool); } catch (Exception e) { e.printStackTrace(); } }
From source file:co.nubetech.crux.server.TestHBaseFacade.java
@BeforeClass public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(3);// w w w .j a v a 2 s. com // REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration()); HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); if (!admin.tableExists(TABLE)) { HTableDescriptor htd = new HTableDescriptor(TABLE); htd.addFamily(new HColumnDescriptor(COLUMN_1)); htd.addFamily(new HColumnDescriptor(COLUMN_2)); admin.createTable(htd); HTable table = new HTable(TEST_UTIL.getConfiguration(), TABLE); for (long i = 0; i < 10; ++i) { Put put = new Put(Bytes.toBytes("row" + i)); put.add(COLUMN_1, Bytes.toBytes("qualifier"), Bytes.toBytes("value" + i)); table.put(put); } table.flushCommits(); } if (!admin.tableExists(TABLE_1)) { HTableDescriptor htd1 = new HTableDescriptor(TABLE_1); htd1.addFamily(new HColumnDescriptor(COLUMN_1)); htd1.addFamily(new HColumnDescriptor(COLUMN_2)); admin.createTable(htd1); HTable table1 = new HTable(TEST_UTIL.getConfiguration(), TABLE_1); for (long i = 0; i < 10; ++i) { Put put1 = new Put(Bytes.toBytes(new Long(i))); put1.add(COLUMN_1, Bytes.toBytes("qualifier"), Bytes.toBytes("value" + i)); put1.add(COLUMN_2, Bytes.toBytes("qualifier"), Bytes.toBytes(i)); put1.add(COLUMN_2, Bytes.toBytes("qualifier1"), Bytes.toBytes((int) i)); table1.put(put1); } table1.flushCommits(); } if (!admin.tableExists(TABLE_2)) { HTableDescriptor htd1 = new HTableDescriptor(TABLE_2); htd1.addFamily(new HColumnDescriptor(COLUMN_1)); htd1.addFamily(new HColumnDescriptor(COLUMN_2)); admin.createTable(htd1); HTable table1 = new HTable(TEST_UTIL.getConfiguration(), TABLE_2); for (long i = 10; i < 20; ++i) { byte[] longBytes = Bytes.toBytes(new Long(i)); byte[] intBytes = Bytes.toBytes((int) i); byte[] stringBytes = Bytes.toBytes("I am a String" + i); Put put1 = new Put(Bytes.add(longBytes, intBytes, stringBytes)); put1.add(COLUMN_1, Bytes.toBytes("qualifier"), Bytes.toBytes("value" + i)); put1.add(COLUMN_1, Bytes.toBytes("qualifier1"), Bytes.toBytes("I am a sub" + i * 2 + " and I am a long")); put1.add(COLUMN_2, Bytes.toBytes("qualifier"), Bytes.toBytes(i)); put1.add(COLUMN_2, Bytes.toBytes("qualifier1"), Bytes.toBytes((int) i)); table1.put(put1); for (int k = 0; k < put1.getRow().length; ++k) { logger.debug("Entered " + put1.getRow()[k]); } } table1.flushCommits(); } if (!admin.tableExists(TABLE_3)) { HTableDescriptor htd1 = new HTableDescriptor(TABLE_3); htd1.addFamily(new HColumnDescriptor(COLUMN_1)); htd1.addFamily(new HColumnDescriptor(COLUMN_2)); admin.createTable(htd1); HTable table1 = new HTable(TEST_UTIL.getConfiguration(), TABLE_3); for (long i = 0; i < 10; ++i) { Put put1 = new Put(Bytes.toBytes((short) i)); put1.add(COLUMN_1, Bytes.toBytes("qualifier"), Bytes.toBytes("value" + i)); put1.add(COLUMN_2, Bytes.toBytes("qualifier"), Bytes.toBytes(i)); put1.add(COLUMN_2, Bytes.toBytes("qualifier1"), Bytes.toBytes((int) i)); table1.put(put1); } table1.flushCommits(); } if (!admin.tableExists(TABLE_4)) { HTableDescriptor htd1 = new HTableDescriptor(TABLE_4); htd1.addFamily(new HColumnDescriptor(COLUMN_1)); htd1.addFamily(new HColumnDescriptor(COLUMN_2)); admin.createTable(htd1); HTable table1 = new HTable(TEST_UTIL.getConfiguration(), TABLE_4); for (long i = 10; i < 20; ++i) { byte[] longBytes = Bytes.toBytes(new Long(i)); byte[] boleanBytes = Bytes.toBytes(true); Put put1 = new Put(Bytes.add(longBytes, boleanBytes)); put1.add(COLUMN_1, Bytes.toBytes("qualifier"), Bytes.toBytes("value" + i)); put1.add(COLUMN_2, Bytes.toBytes("qualifier"), Bytes.toBytes(i)); put1.add(COLUMN_2, Bytes.toBytes("qualifier1"), Bytes.toBytes((int) i)); table1.put(put1); for (int k = 0; k < put1.getRow().length; ++k) { logger.debug("Entered " + put1.getRow()[k]); } } table1.flushCommits(); } if (!admin.tableExists(TABLE_5)) { HTableDescriptor htd1 = new HTableDescriptor(TABLE_5); htd1.addFamily(new HColumnDescriptor(COLUMN_1)); htd1.addFamily(new HColumnDescriptor(COLUMN_2)); admin.createTable(htd1); HTable table1 = new HTable(TEST_UTIL.getConfiguration(), TABLE_5); for (long i = 1; i < 2; ++i) { Put put1 = new Put(Bytes.toBytes(true)); put1.add(COLUMN_1, Bytes.toBytes("qualifier"), Bytes.toBytes("value" + i)); put1.add(COLUMN_2, Bytes.toBytes("qualifier"), Bytes.toBytes(i)); put1.add(COLUMN_2, Bytes.toBytes("qualifier1"), Bytes.toBytes((int) i)); table1.put(put1); } table1.flushCommits(); } KeyedPoolableObjectFactory factory = PoolUtils .synchronizedPoolableFactory(new HBaseConnectionPoolFactory()); connection = new Connection(); ConnectionProperty connectionProperty = new ConnectionProperty(); connectionProperty.setProperty(CruxConstants.HBASE_ZOOKEEPER_PROPERTY); logger.debug("Port is: " + TEST_UTIL.getConfiguration().get("hbase.zookeeper.property.clientPort")); connectionProperty .setValue("localhost:" + TEST_UTIL.getConfiguration().get("hbase.zookeeper.property.clientPort")); connection.addProperty(connectionProperty); pool = new HBaseConnectionPool(factory); }
From source file:de.escidoc.core.common.business.fedora.FedoraUtility.java
/** * See Interface for functional description. * //from w w w.ja va 2 s .co m * @see InitializingBean #afterPropertiesSet() */ @Override public void afterPropertiesSet() throws IOException, MalformedURLException, ServiceException { this.fedoraClientPool = new StackObjectPool( PoolUtils.synchronizedPoolableFactory(new BasePoolableObjectFactory() { /** * See Interface for functional description. * * @return * @see BasePoolableObjectFactory #makeObject() */ @Override public Object makeObject() throws MalformedURLException { return new FedoraClient(FedoraUtility.this.fedoraUrl, FedoraUtility.this.fedoraUser, FedoraUtility.this.fedoraPassword); } }), MAX_IDLE, INIT_IDLE_CAPACITY); this.apiaPool = new StackObjectPool(PoolUtils.synchronizedPoolableFactory(new BasePoolableObjectFactory() { /** * See Interface for functional description. * * @return * @see BasePoolableObjectFactory #makeObject() */ @Override public Object makeObject() throws IOException, MalformedURLException, ServiceException { return new FedoraClient(FedoraUtility.this.fedoraUrl, FedoraUtility.this.fedoraUser, FedoraUtility.this.fedoraPassword).getAPIA(); } }), MAX_IDLE, INIT_IDLE_CAPACITY); this.apimPool = new StackObjectPool(new BasePoolableObjectFactory() { /** * See Interface for functional description. * * @return * @see BasePoolableObjectFactory #makeObject() */ @Override public Object makeObject() throws IOException, MalformedURLException, ServiceException { return new FedoraClient(FedoraUtility.this.fedoraUrl, FedoraUtility.this.fedoraUser, FedoraUtility.this.fedoraPassword).getAPIM(); } }, MAX_IDLE, INIT_IDLE_CAPACITY); this.syncRestQuery = this.fedoraUrl + "/risearch?flush=true"; }