@Override
  public void destroy() {
    log.debug("destroy()... " + reportStatus());
    if (configuration.metricsEnabled()) {
      metricsReporter.stop();
    }

    messageProducer.terminate();
    super.destroy();
  }
  @Override
  public void init(DsConfiguration conf, DsMetaData metaData) {
    super.init(conf, metaData);
    log.info("Initializing handler: Mode =" + getMode());
    configuration = configurationFactory.load(configurationPath);
    messageProducer = KafkaProducerFactory.create(configuration.kafka());
    messageEncoder = MessageEncoderFactory.create(configuration);
    txFactory = new TxFactory();

    if (configuration.metrics().isEnabled()) {
      metricsReporter = MetricsReporterFactory.createReporter(configuration.metrics(), metrics);
    }
  }
  @Override
  public Status transactionBegin(DsEvent e, DsTransaction transaction) {
    super.transactionBegin(e, transaction);

    if (log.isDebugEnabled()) {
      log.debug(
          "Received begin tx event, numTx="
              + numTxs.get()
              + " : position="
              + transaction.getTranID()
              + ", totalOps="
              + transaction.getTotalOps());
    }

    return Status.OK;
  }
  @Override
  public Status operationAdded(DsEvent e, DsTransaction transaction, DsOperation operation) {
    Status overallStatus = Status.OK;
    super.operationAdded(e, transaction, operation);
    numOps.incrementAndGet();

    final Tx tx = new Tx(transaction, getMetaData(), getConfig());
    final TableMetaData tMeta = getMetaData().getTableMetaData(operation.getTableName());
    final Op op = new Op(operation, tMeta, getConfig());

    operation.getTokens();
    if (isOperationMode()) {

      if (log.isDebugEnabled()) {
        log.debug(
            " Received operation: table='"
                + op.getTableName()
                + "'"
                + ", pos="
                + op.getPosition()
                + " (total_ops= "
                + tx.getTotalOps()
                + ", buffered="
                + tx.getSize()
                + ")"
                + ", ts="
                + op.getTimestamp());
      }

      Status operationStatus = processOperation(tx, op);

      if (Status.ABEND.equals(operationStatus)) {
        overallStatus = Status.ABEND;
      }
    }
    return overallStatus;
  }
  @Override
  public Status transactionCommit(DsEvent e, DsTransaction transaction) {
    Status overallStatus = Status.OK;
    super.transactionCommit(e, transaction);

    Tx tx = txFactory.createAdapterTx(transaction, getMetaData(), getConfig());
    numTxs.incrementAndGet();

    if (log.isDebugEnabled()) {
      log.debug(
          "transactionCommit event, tx #"
              + numTxs.get()
              + ":"
              + ", pos="
              + tx.getTranID()
              + " (total_ops= "
              + tx.getTotalOps()
              + ", buffered="
              + tx.getSize()
              + ")"
              + ", ts="
              + tx.getTimestamp()
              + ")");
    }

    if (!isOperationMode()) {
      for (Op op : tx) {
        Status operationStatus = processOperation(tx, op);

        if (Status.ABEND.equals(operationStatus)) {
          overallStatus = Status.ABEND;
        }
      }
    }

    return overallStatus;
  }