@Override public void close() { if (this.closed) { return; } closeMaster(); shutdownPools(); if (this.metrics != null) { this.metrics.shutdown(); } this.closed = true; registry.close(); this.stubs.clear(); if (clusterStatusListener != null) { clusterStatusListener.close(); } if (rpcClient != null) { rpcClient.close(); } if (authService != null) { authService.shutdown(); } }
@Override public Hbck getHbck(ServerName masterServer) throws IOException { // we will not create a new connection when creating a new protobuf stub, and for hbck there // will be no performance consideration, so for simplification we will create a new stub every // time instead of caching the stub here. return new HBaseHbck(MasterProtos.HbckService.newBlockingStub( rpcClient.createBlockingRpcChannel(masterServer, user, rpcTimeout)), rpcControllerFactory); } }
@Override public void newDead(ServerName sn) { clearCaches(sn); rpcClient.cancelConnections(sn); } }, conf, listenerClass);
private MasterService.Interface createMasterStub(ServerName serverName) throws IOException { return MasterService.newStub(rpcClient.createRpcChannel(serverName, user, rpcTimeout)); }
@Override public boolean hasCellBlockSupport() { return this.rpcClient.hasCellBlockSupport(); }
private AdminService.Interface createAdminServerStub(ServerName serverName) throws IOException { return AdminService.newStub(rpcClient.createRpcChannel(serverName, user, rpcTimeout)); }
@Override public boolean hasCellBlockSupport() { return this.rpcClient.hasCellBlockSupport(); }
public static BlockingInterface newBlockingStub(RpcClient client, InetSocketAddress addr, User user) throws IOException { return TestProtobufRpcProto.newBlockingStub(client.createBlockingRpcChannel( ServerName.valueOf(addr.getHostName(), addr.getPort(), System.currentTimeMillis()), user, 0)); }
@After public void tearDown() throws IOException { if (rpcClient != null) { rpcClient.close(); } if (master != null) { master.stopMaster(); } testUtil.shutdownMiniZKCluster(); }
private ClientService.Interface createRegionServerStub(ServerName serverName) throws IOException { return ClientService.newStub(rpcClient.createRpcChannel(serverName, user, rpcTimeout)); }
rpcClient.cancelConnections(sn); Thread.sleep(5);
@Override public boolean hasCellBlockSupport() { return this.rpcClient.hasCellBlockSupport(); } }
@Override public BlockingInterface getClient(ServerName serverName) throws IOException { checkClosed(); if (isDeadServer(serverName)) { throw new RegionServerStoppedException(serverName + " is dead."); } String key = getStubKey(ClientProtos.ClientService.BlockingInterface.class.getName(), serverName, this.hostnamesCanChange); return (ClientProtos.ClientService.BlockingInterface) computeIfAbsentEx(stubs, key, () -> { BlockingRpcChannel channel = this.rpcClient.createBlockingRpcChannel(serverName, user, rpcTimeout); return ClientProtos.ClientService.newBlockingStub(channel); }); }
this.rpcClient.close();
public static Interface newStub(RpcClient client, InetSocketAddress addr) throws IOException { return TestProtobufRpcProto.newStub(client.createRpcChannel( ServerName.valueOf(addr.getHostName(), addr.getPort(), System.currentTimeMillis()), User.getCurrent(), 0)); }
@Override public void newDead(ServerName sn) { clearCaches(sn); rpcClient.cancelConnections(sn); } }, conf, listenerClass);
@Override public boolean hasCellBlockSupport() { return this.rpcClient.hasCellBlockSupport(); }
@Override public AdminProtos.AdminService.BlockingInterface getAdmin(ServerName serverName) throws IOException { checkClosed(); if (isDeadServer(serverName)) { throw new RegionServerStoppedException(serverName + " is dead."); } String key = getStubKey(AdminProtos.AdminService.BlockingInterface.class.getName(), serverName, this.hostnamesCanChange); return (AdminProtos.AdminService.BlockingInterface) computeIfAbsentEx(stubs, key, () -> { BlockingRpcChannel channel = this.rpcClient.createBlockingRpcChannel(serverName, user, rpcTimeout); return AdminProtos.AdminService.newBlockingStub(channel); }); }
@Test (expected=org.apache.hbase.thirdparty.com.google.protobuf.ServiceException.class /*Thrown when we call stub.error*/) public void testProtoBufRpc() throws Exception { RpcClient rpcClient = RpcClientFactory.createClient(conf, HConstants.CLUSTER_ID_DEFAULT); try { BlockingInterface stub = newBlockingStub(rpcClient, this.isa); // Test ping method TestProtos.EmptyRequestProto emptyRequest = TestProtos.EmptyRequestProto.newBuilder().build(); stub.ping(null, emptyRequest); // Test echo method EchoRequestProto echoRequest = EchoRequestProto.newBuilder().setMessage("hello").build(); EchoResponseProto echoResponse = stub.echo(null, echoRequest); assertEquals("hello", echoResponse.getMessage()); stub.error(null, emptyRequest); fail("Expected exception is not thrown"); } finally { rpcClient.close(); } } }
private MasterService.Interface createMasterStub(ServerName serverName) throws IOException { return MasterService.newStub(rpcClient.createRpcChannel(serverName, user, rpcTimeout)); }