/** * Instantiates a new ObserverContext instance if the passed reference is * <code>null</code> and sets the environment in the new or existing instance. * This allows deferring the instantiation of a ObserverContext until it is * actually needed. * * @param env The coprocessor environment to set * @param context An existing ObserverContext instance to use, or <code>null</code> * to create a new instance * @param <T> The environment type for the context * @return An instance of <code>ObserverContext</code> with the environment set */ public static <T extends CoprocessorEnvironment> ObserverContext<T> createAndPrepare( T env, ObserverContext<T> context) { if (context == null) { context = new ObserverContext<T>(); } context.prepare(env); return context; } }
/** * Instantiates a new ObserverContext instance if the passed reference is * <code>null</code> and sets the environment in the new or existing instance. * This allows deferring the instantiation of a ObserverContext until it is * actually needed. * * @param env The coprocessor environment to set * @param context An existing ObserverContext instance to use, or <code>null</code> * to create a new instance * @param <T> The environment type for the context * @return An instance of <code>ObserverContext</code> with the environment set */ public static <T extends CoprocessorEnvironment> ObserverContext<T> createAndPrepare( T env, ObserverContext<T> context) { if (context == null) { context = new ObserverContext<T>(); } context.prepare(env); return context; } }
@Override public void cleanupBulkLoad(RpcController controller, CleanupBulkLoadRequest request, RpcCallback<CleanupBulkLoadResponse> done) { try { List<BulkLoadObserver> bulkLoadObservers = getBulkLoadObservers(); if(bulkLoadObservers != null) { ObserverContext<RegionCoprocessorEnvironment> ctx = new ObserverContext<RegionCoprocessorEnvironment>(); ctx.prepare(env); for(BulkLoadObserver bulkLoadObserver : bulkLoadObservers) { bulkLoadObserver.preCleanupBulkLoad(ctx, request); } } fs.delete(new Path(request.getBulkToken()), true); done.run(CleanupBulkLoadResponse.newBuilder().build()); } catch (IOException e) { ResponseConverter.setControllerException(controller, e); } done.run(null); }
@Override public void prepareBulkLoad(RpcController controller, PrepareBulkLoadRequest request, RpcCallback<PrepareBulkLoadResponse> done){ try { List<BulkLoadObserver> bulkLoadObservers = getBulkLoadObservers(); if(bulkLoadObservers != null) { ObserverContext<RegionCoprocessorEnvironment> ctx = new ObserverContext<RegionCoprocessorEnvironment>(); ctx.prepare(env); for(BulkLoadObserver bulkLoadObserver : bulkLoadObservers) { bulkLoadObserver.prePrepareBulkLoad(ctx, request); } } String bulkToken = createStagingDir(baseStagingDir, getActiveUser(), ProtobufUtil.toTableName(request.getTableName())).toString(); done.run(PrepareBulkLoadResponse.newBuilder().setBulkToken(bulkToken).build()); } catch (IOException e) { ResponseConverter.setControllerException(controller, e); } done.run(null); }