class FragmentStatusReporter implements AutoCloseable {

  void stateChanged(final FragmentState newState) {
    final FragmentStatus status = getStatus(newState, null);
    logger.info("{}: State to report: {}", QueryIdHelper.getQueryIdentifier(context.getHandle()), newState);
    switch (newState) {
      case AWAITING_ALLOCATION:
      case CANCELLATION_REQUESTED:
      case CANCELLED:
      case FINISHED:
      case RUNNING:
        sendStatus(status);
        break;
      case SENDING:
        // no op.
        break;
      case FAILED:
        // shouldn't get here since fail() should be called.
      default:
        throw new IllegalStateException(String.format("Received state changed event for unexpected state of %s.", newState));
    }
  }

  public  FragmentStatusReporter(final ExecutorFragmentContext context);

}