class CommandStatusReportHandler implements
    EventHandler<CommandStatusReportFromDatanode> {

  @Override
  public void onMessage(CommandStatusReportFromDatanode report,
      EventPublisher publisher) {
    Preconditions.checkNotNull(report);
    List<CommandStatus> cmdStatusList = report.getReport().getCmdStatusList();
    Preconditions.checkNotNull(cmdStatusList);
    if (LOGGER.isTraceEnabled()) {
      LOGGER.trace("Processing command status report for dn: {}", report
          .getDatanodeDetails());
    }

    // Route command status to its watchers.
    cmdStatusList.forEach(cmdStatus -> {
      if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Emitting command status for id:{} type: {}", cmdStatus
            .getCmdId(), cmdStatus.getType());
      }
      if (cmdStatus.getType() == SCMCommandProto.Type.deleteBlocksCommand) {
        if (cmdStatus.getStatus() == CommandStatus.Status.EXECUTED) {
          publisher.fireEvent(SCMEvents.DELETE_BLOCK_STATUS,
              new DeleteBlockStatus(cmdStatus));
        }
      } else {
        LOGGER.debug("CommandStatus of type:{} not handled in " +
            "CommandStatusReportHandler.", cmdStatus.getType());
      }
    });
  }

}