@Override
 protected void doStop() {
   if (outputSink != null) {
     try {
       outputSink.finishWritingAndClose();
     } catch (IOException ex) {
       LOG.warn("Got exception while trying to close OutputSink");
       LOG.warn(ex);
     }
   }
   if (this.pool != null) {
     this.pool.shutdownNow();
     try {
       // wait for 10 sec
       boolean shutdown = this.pool.awaitTermination(10000, TimeUnit.MILLISECONDS);
       if (!shutdown) {
         LOG.warn("Failed to shutdown the thread pool after 10 seconds");
       }
     } catch (InterruptedException e) {
       LOG.warn("Got interrupted while waiting for the thread pool to shut down" + e);
     }
   }
   if (connection != null) {
     try {
       connection.close();
     } catch (IOException ex) {
       LOG.warn("Got exception closing connection :" + ex);
     }
   }
   super.doStop();
 }
  @Override
  public void init(Context context) throws IOException {
    super.init(context);

    this.conf = HBaseConfiguration.create(context.getConfiguration());
    this.tableDescriptors = context.getTableDescriptors();

    // HRS multiplies client retries by 10 globally for meta operations, but we do not want this.
    // We are resetting it here because we want default number of retries (35) rather than 10 times
    // that which makes very long retries for disabled tables etc.
    int defaultNumRetries =
        conf.getInt(
            HConstants.HBASE_CLIENT_RETRIES_NUMBER, HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
    if (defaultNumRetries > 10) {
      int mult = conf.getInt("hbase.client.serverside.retries.multiplier", 10);
      defaultNumRetries = defaultNumRetries / mult; // reset if HRS has multiplied this already
    }

    conf.setInt("hbase.client.serverside.retries.multiplier", 1);
    int numRetries = conf.getInt(CLIENT_RETRIES_NUMBER, defaultNumRetries);
    conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, numRetries);

    this.numWriterThreads = this.conf.getInt("hbase.region.replica.replication.writer.threads", 3);
    controller = new PipelineController();
    entryBuffers =
        new EntryBuffers(
            controller,
            this.conf.getInt("hbase.region.replica.replication.buffersize", 128 * 1024 * 1024));

    // use the regular RPC timeout for replica replication RPC's
    this.operationTimeout =
        conf.getInt(
            HConstants.HBASE_CLIENT_OPERATION_TIMEOUT,
            HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT);
  }
 @Override
 protected void doStart() {
   try {
     connection = (ClusterConnection) ConnectionFactory.createConnection(this.conf);
     this.pool = getDefaultThreadPool(conf);
     outputSink =
         new RegionReplicaOutputSink(
             controller,
             tableDescriptors,
             entryBuffers,
             connection,
             pool,
             numWriterThreads,
             operationTimeout);
     outputSink.startWriterThreads();
     super.doStart();
   } catch (IOException ex) {
     LOG.warn("Received exception while creating connection :" + ex);
     notifyFailed(ex);
   }
 }