本文整理了Java中org.apache.hadoop.hbase.client.Connection.isClosed()
方法的一些代码示例,展示了Connection.isClosed()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Connection.isClosed()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Connection
类名称:Connection
方法名:isClosed
[英]Returns whether the connection is closed or not.
[中]返回连接是否关闭。
代码示例来源:origin: apache/hbase
@Override
public boolean isClosed() {
return this.conn.isClosed();
}
代码示例来源:origin: apache/hbase
@Override
public void close() throws IOException {
if (this.connection != null && !this.connection.isClosed()) {
this.connection.close();
}
}
代码示例来源:origin: apache/hbase
@Override
public void close() throws IOException {
if (this.connection != null && !this.connection.isClosed()) {
this.connection.close();
}
}
代码示例来源:origin: apache/drill
private boolean isValid(Connection conn) {
return conn != null
&& !conn.isAborted()
&& !conn.isClosed();
}
代码示例来源:origin: apache/hbase
/**
* Callers should call close on the returned {@link Table} instance.
* @param connection connection we're using to access Meta
* @return An {@link Table} for <code>hbase:meta</code>
*/
public static Table getMetaHTable(final Connection connection)
throws IOException {
// We used to pass whole CatalogTracker in here, now we just pass in Connection
if (connection == null) {
throw new NullPointerException("No connection");
} else if (connection.isClosed()) {
throw new IOException("connection is closed");
}
return connection.getTable(TableName.META_TABLE_NAME);
}
代码示例来源:origin: alibaba/canal
public Connection getConnection() {
if (conn == null || conn.isAborted() || conn.isClosed()) {
initConn();
}
return conn;
}
代码示例来源:origin: apache/hbase
synchronized boolean updateAccessTime() {
if (closed) {
return false;
}
if (connection.isAborted() || connection.isClosed()) {
LOG.info("Unexpected: cached Connection is aborted/closed, removed from cache");
connections.remove(userName);
return false;
}
lastAccessTime = EnvironmentEdgeManager.currentTime();
return true;
}
代码示例来源:origin: apache/kylin
@SuppressWarnings("resource")
public static Connection get(StorageURL url) {
// find configuration
Configuration conf = configCache.get(url);
if (conf == null) {
conf = newHBaseConfiguration(url);
configCache.put(url, conf);
}
Connection connection = connPool.get(url);
try {
while (true) {
// I don't use DCL since recreate a connection is not a big issue.
if (connection == null || connection.isClosed()) {
logger.info("connection is null or closed, creating a new one");
connection = ConnectionFactory.createConnection(conf);
connPool.put(url, connection);
}
if (connection == null || connection.isClosed()) {
Thread.sleep(10000);// wait a while and retry
} else {
break;
}
}
} catch (Throwable t) {
logger.error("Error when open connection " + url, t);
throw new RuntimeException("Error when open connection " + url, t);
}
return connection;
}
代码示例来源:origin: apache/drill
@Override
public synchronized void close() {
if (this.hbaseTable != null) {
try {
this.hbaseTable.close();
this.hbaseTable = null;
} catch (IOException e) {
logger.warn("Caught exception while closing HBase table.", e);
}
}
if (this.connection != null && !this.connection.isClosed()) {
try {
this.connection.close();
} catch (IOException e) {
logger.warn("Caught exception while closing HBase connection.", e);
}
this.connection = null;
}
}
代码示例来源:origin: apache/hbase
@Override
public void close() throws IOException {
if (this.admin != null) {
admin.close();
}
if (this.connection != null && !this.connection.isClosed()) {
this.connection.close();
}
}
代码示例来源:origin: apache/hbase
@Before
public void setUp() throws IOException {
ReplicationSource source = mock(ReplicationSource.class);
when(source.getPeerId()).thenReturn(PEER_ID);
when(source.getQueueStorage()).thenReturn(QUEUE_STORAGE);
conn = mock(Connection.class);
when(conn.isClosed()).thenReturn(false);
doAnswer(new Answer<Table>() {
@Override
public Table answer(InvocationOnMock invocation) throws Throwable {
return UTIL.getConnection().getTable((TableName) invocation.getArgument(0));
}
}).when(conn).getTable(any(TableName.class));
Server server = mock(Server.class);
when(server.getConnection()).thenReturn(conn);
when(source.getServer()).thenReturn(server);
checker = new SerialReplicationChecker(UTIL.getConfiguration(), source);
tableName = TableName.valueOf(name.getMethodName());
}
代码示例来源:origin: apache/hbase
@Test
public void testClosing() throws Exception {
Configuration configuration =
new Configuration(TEST_UTIL.getConfiguration());
configuration.set(HConstants.HBASE_CLIENT_INSTANCE_ID,
String.valueOf(ThreadLocalRandom.current().nextInt()));
// as connection caching is going away, now we're just testing
// that closed connection does actually get closed.
Connection c1 = ConnectionFactory.createConnection(configuration);
Connection c2 = ConnectionFactory.createConnection(configuration);
// no caching, different connections
assertTrue(c1 != c2);
// closing independently
c1.close();
assertTrue(c1.isClosed());
assertFalse(c2.isClosed());
c2.close();
assertTrue(c2.isClosed());
}
代码示例来源:origin: apache/hbase
@AfterClass
public static void tearDownAfterClass() throws Exception {
if (ADMIN != null) ADMIN.close();
if (CONNECTION != null && !CONNECTION.isClosed()) CONNECTION.close();
TEST_UTIL.shutdownMiniCluster();
}
代码示例来源:origin: apache/hbase
/**
* 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();
}
代码示例来源:origin: apache/hbase
if(admin != null) {
admin.close();
if (admin.getConnection().isClosed()) {
rpcClient = (RandomTimeoutRpcClient) RpcClientFactory
.createClient(TEST_UTIL.getConfiguration(), TEST_UTIL.getClusterKey());
代码示例来源:origin: apache/hbase
/**
* Test that Connection or Pool are not closed when managed externally
* @throws Exception
*/
@Test
public void testConnectionManagement() throws Exception{
Table table0 = TEST_UTIL.createTable(TABLE_NAME1, FAM_NAM);
Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
Table table = conn.getTable(TABLE_NAME1);
table.close();
assertFalse(conn.isClosed());
if(table instanceof HTable) {
assertFalse(((HTable) table).getPool().isShutdown());
}
table = conn.getTable(TABLE_NAME1);
table.close();
if(table instanceof HTable) {
assertFalse(((HTable) table).getPool().isShutdown());
}
conn.close();
if(table instanceof HTable) {
assertTrue(((HTable) table).getPool().isShutdown());
}
table0.close();
}
代码示例来源:origin: hugegraph/hugegraph
@Override
protected void doClose() {
if (this.hbase == null || this.hbase.isClosed()) {
return;
}
try {
this.hbase.close();
} catch (IOException e) {
throw new BackendException("Failed to close HBase connection", e);
}
}
代码示例来源:origin: apache/phoenix
@SuppressWarnings("unchecked")
@Test
public void testCheckRegionServerStoppingOnException() throws Exception {
StatisticsScannerCallable realCallable = mockScanner.new StatisticsScannerCallable();
doThrow(new IOException()).when(statsWriter).deleteStatsForRegion(any(Region.class), any(StatisticsCollector.class),
any(ImmutableBytesPtr.class), any(List.class));
when(conn.isClosed()).thenReturn(true);
when(conn.isAborted()).thenReturn(false);
// Should not throw an exception
realCallable.call();
verify(conn).isClosed();
}
代码示例来源:origin: apache/phoenix
@Test
public void testCheckRegionServerStoppingOnClose() throws Exception {
when(conn.isClosed()).thenReturn(true);
when(conn.isAborted()).thenReturn(false);
mockScanner.close();
verify(conn).isClosed();
verify(callable, never()).call();
verify(runTracker, never()).runTask(callable);
}
代码示例来源:origin: apache/phoenix
@Test
public void testCheckRegionServerStoppedOnClose() throws Exception {
when(conn.isClosed()).thenReturn(false);
when(conn.isAborted()).thenReturn(true);
mockScanner.close();
verify(conn).isClosed();
verify(conn).isAborted();
verify(callable, never()).call();
verify(runTracker, never()).runTask(callable);
}
内容来源于网络,如有侵权,请联系作者删除!