diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/client/CoprocessorHConnection.java hbase-server/src/main/java/org/apache/hadoop/hbase/client/CoprocessorHConnection.java index 285737d..96d6aaf 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/client/CoprocessorHConnection.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/client/CoprocessorHConnection.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hbase.client; import java.io.IOException; +import java.util.concurrent.ExecutorService; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.classification.InterfaceStability; @@ -62,7 +63,31 @@ public class CoprocessorHConnection extends ConnectionImplementation { } return (ClusterConnection) ConnectionFactory.createConnection(env.getConfiguration()); } - + /** + * Create an {@link HConnection} based on the environment in which we are running the + * coprocessor and provided custom executor service. + * The {@link HConnection} must be externally cleaned up (we bypass the usual HTable + * cleanup mechanisms since we own everything). + * @param env environment hosting the {@link HConnection} + * @param service - executor service + * @return instance of {@link HConnection}. + * @throws IOException if we cannot create the connection + */ + public static ClusterConnection getConnectionForEnvironment(CoprocessorEnvironment env, + ExecutorService service) + throws IOException { + // this bit is a little hacky - just trying to get it going for the moment + if (env instanceof RegionCoprocessorEnvironment) { + RegionCoprocessorEnvironment e = (RegionCoprocessorEnvironment) env; + RegionServerServices services = e.getRegionServerServices(); + if (services instanceof HRegionServer) { + return new CoprocessorHConnection((HRegionServer) services, service); + } + } + return (ClusterConnection) ConnectionFactory.createConnection(env.getConfiguration()); + } + + private final ServerName serverName; private final HRegionServer server; @@ -76,7 +101,16 @@ public class CoprocessorHConnection extends ConnectionImplementation { } /** - * Constructor that accepts custom configuration + * Constructor that uses server and executor service + * @param server + * @throws IOException if we cannot create the connection + */ + public CoprocessorHConnection(HRegionServer server, ExecutorService service) throws IOException { + this(server.getConfiguration(), server, service); + } + + /** + * Constructor that accepts custom configuration, region server * @param conf * @param server * @throws IOException if we cannot create the connection @@ -87,6 +121,20 @@ public class CoprocessorHConnection extends ConnectionImplementation { this.serverName = server.getServerName(); } + /** + * Constructor that accepts custom configuration, region server, + * executor service + * @param conf + * @param server + * @throws IOException if we cannot create the connection + */ + public CoprocessorHConnection(Configuration conf, HRegionServer server, + ExecutorService service) throws IOException { + super(conf, service, UserProvider.instantiate(conf).getCurrent()); + this.server = server; + this.serverName = server.getServerName(); + } + @Override public org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ClientService.BlockingInterface getClient(ServerName serverName) throws IOException {