/** * Caller closes the table afterwards. */ public Table getTable(String tableName) throws IOException { ConnectionInfo connInfo = getCurrentConnection(); return connInfo.connection.getTable(TableName.valueOf(tableName)); }
/** * Retrieve a regionLocator for the table. The user should close the RegionLocator. */ public RegionLocator getRegionLocator(byte[] tableName) throws IOException { return getCurrentConnection().connection.getRegionLocator(TableName.valueOf(tableName)); }
/** * Caller doesn't close the admin afterwards. * We need to manage it and close it properly. */ public Admin getAdmin() throws IOException { ConnectionInfo connInfo = getCurrentConnection(); if (connInfo.admin == null) { Lock lock = locker.acquireLock(getEffectiveUser()); try { if (connInfo.admin == null) { connInfo.admin = connInfo.connection.getAdmin(); } } finally { lock.unlock(); } } return connInfo.admin; }
/** * test for ConnectionCache cleaning expired Connection */ @Test public void testConnectionChore() throws Exception { UTIL.startMiniCluster(); //1s for clean interval & 5s for maxIdleTime ConnectionCache cache = new ConnectionCache(UTIL.getConfiguration(), UserProvider.instantiate(UTIL.getConfiguration()), 1000, 5000); ConnectionCache.ConnectionInfo info = cache.getCurrentConnection(); assertEquals(false, info.connection.isClosed()); Thread.sleep(7000); assertEquals(true, info.connection.isClosed()); UTIL.shutdownMiniCluster(); }
/** * Retrieve a regionLocator for the table. The user should close the RegionLocator. */ public RegionLocator getRegionLocator(byte[] tableName) throws IOException { return getCurrentConnection().connection.getRegionLocator(TableName.valueOf(tableName)); }
/** * Caller closes the table afterwards. */ public Table getTable(String tableName) throws IOException { ConnectionInfo connInfo = getCurrentConnection(); return connInfo.connection.getTable(TableName.valueOf(tableName)); }
/** * Caller doesn't close the admin afterwards. * We need to manage it and close it properly. */ public Admin getAdmin() throws IOException { ConnectionInfo connInfo = getCurrentConnection(); if (connInfo.admin == null) { Lock lock = locker.acquireLock(getEffectiveUser()); try { if (connInfo.admin == null) { connInfo.admin = connInfo.connection.getAdmin(); } } finally { lock.unlock(); } } return connInfo.admin; }
/** * test for ConnectionCache cleaning expired Connection */ @Test public void testConnectionChore() throws Exception { UTIL.startMiniCluster(); //1s for clean interval & 5s for maxIdleTime ConnectionCache cache = new ConnectionCache(UTIL.getConfiguration(), UserProvider.instantiate(UTIL.getConfiguration()), 1000, 5000); ConnectionCache.ConnectionInfo info = cache.getCurrentConnection(); assertEquals(false, info.connection.isClosed()); Thread.sleep(7000); assertEquals(true, info.connection.isClosed()); UTIL.shutdownMiniCluster(); }