下面列出了怎么用org.apache.hadoop.hbase.coprocessor.RegionCoprocessor的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public RegionEnvironment createEnvironment(RegionCoprocessor instance, int priority, int seq,
Configuration conf) {
// If coprocessor exposes any services, register them.
for (Service service : instance.getServices()) {
region.registerService(service);
}
ConcurrentMap<String, Object> classData;
// make sure only one thread can add maps
synchronized (SHARED_DATA_MAP) {
// as long as at least one RegionEnvironment holds on to its classData it will
// remain in this map
classData =
SHARED_DATA_MAP.computeIfAbsent(instance.getClass().getName(),
k -> new ConcurrentHashMap<>());
}
// If a CoreCoprocessor, return a 'richer' environment, one laden with RegionServerServices.
return instance.getClass().isAnnotationPresent(CoreCoprocessor.class)?
new RegionEnvironmentForCoreCoprocessors(instance, priority, seq, conf, region,
rsServices, classData):
new RegionEnvironment(instance, priority, seq, conf, region, rsServices, classData);
}
private List<MasterObserver> getAccessControllers() throws IOException {
ArrayList<MasterObserver> oldAccessControllers = accessControllers.get();
if (oldAccessControllers == null) {
oldAccessControllers = new ArrayList<>();
RegionCoprocessorHost cpHost = this.env.getCoprocessorHost();
for (RegionCoprocessor cp : cpHost.findCoprocessors(RegionCoprocessor.class)) {
if (cp instanceof AccessControlService.Interface && cp instanceof MasterObserver) {
oldAccessControllers.add((MasterObserver)cp);
if(cp.getClass().getName().equals(org.apache.hadoop.hbase.security.access.AccessController.class.getName())) {
hbaseAccessControllerEnabled = true;
}
}
}
accessControllers.set(oldAccessControllers);
}
return accessControllers.get();
}
/**
* Constructor
* @param impl the coprocessor instance
* @param priority chaining priority
*/
public RegionEnvironment(final RegionCoprocessor impl, final int priority,
final int seq, final Configuration conf, final Region region,
final RegionServerServices services, final ConcurrentMap<String, Object> sharedData) {
super(impl, priority, seq, conf);
this.region = region;
this.sharedData = sharedData;
this.services = services;
this.metricRegistry =
MetricsCoprocessor.createRegistryForRegionCoprocessor(impl.getClass().getName());
}
@Override
public RegionCoprocessor checkAndGetInstance(Class<?> implClass)
throws InstantiationException, IllegalAccessException {
try {
if (RegionCoprocessor.class.isAssignableFrom(implClass)) {
return implClass.asSubclass(RegionCoprocessor.class).getDeclaredConstructor().newInstance();
} else {
LOG.error("{} is not of type RegionCoprocessor. Check the configuration of {}",
implClass.getName(), CoprocessorHost.REGION_COPROCESSOR_CONF_KEY);
return null;
}
} catch (NoSuchMethodException | InvocationTargetException e) {
throw (InstantiationException) new InstantiationException(implClass.getName()).initCause(e);
}
}
public RegionEnvironmentForCoreCoprocessors(final RegionCoprocessor impl, final int priority,
final int seq, final Configuration conf, final Region region,
final RegionServerServices services, final ConcurrentMap<String, Object> sharedData) {
super(impl, priority, seq, conf, region, services, sharedData);
this.rsServices = services;
}
public BulkLoadObserverOperation(User user) {
super(RegionCoprocessor::getBulkLoadObserver, user);
}
@Override
public RegionCoprocessor getInstance() {
return delegate.getInstance();
}
@Override
public void start(CoprocessorEnvironment env) throws IOException {
if (delegate instanceof RegionCoprocessor) {
((RegionCoprocessor)delegate).start(env);
}
}
@Override
public void stop(CoprocessorEnvironment env) throws IOException {
if (delegate instanceof RegionCoprocessor) {
((RegionCoprocessor)delegate).stop(env);
}
}
@Override
public void start(CoprocessorEnvironment env) throws IOException {
if (delegate instanceof RegionCoprocessor) {
((RegionCoprocessor)delegate).start(env);
}
}
@Override
public void stop(CoprocessorEnvironment env) throws IOException {
if (delegate instanceof RegionCoprocessor) {
((RegionCoprocessor)delegate).stop(env);
}
}
@Override
public void start(CoprocessorEnvironment env) throws IOException {
if (delegate instanceof RegionCoprocessor) {
((RegionCoprocessor)delegate).start(env);
}
}
@Override
public void stop(CoprocessorEnvironment env) throws IOException {
if (delegate instanceof RegionCoprocessor) {
((RegionCoprocessor)delegate).stop(env);
}
}