/**
   * Records undeploy event.
   *
   * @param dep Undeployed class loader.
   * @param recordEvt Flag indicating whether to record events.
   */
  private void recordUndeploy(GridDeployment dep, boolean recordEvt) {
    assert dep.isUndeployed();

    if (ctx.event().isRecordable(EVT_TASK_UNDEPLOYED)
        || ctx.event().isRecordable(EVT_CLASS_UNDEPLOYED)) {
      for (Class<?> cls : dep.deployedClasses()) {
        boolean isTask = isTask(cls);

        String msg =
            isTask ? "Task locally undeployed: " + cls : "Class locally undeployed: " + cls;

        if (ctx.event().isRecordable(isTask ? EVT_TASK_UNDEPLOYED : EVT_CLASS_UNDEPLOYED)) {
          if (recordEvt) {
            GridDeploymentEvent evt = new GridDeploymentEvent();

            evt.message(msg);
            evt.nodeId(ctx.localNodeId());
            evt.type(isTask ? EVT_TASK_UNDEPLOYED : EVT_CLASS_UNDEPLOYED);
            evt.alias(getAlias(dep, cls));

            ctx.event().record(evt);
          }
        }

        if (log.isInfoEnabled()) {
          log.info(msg);
        }
      }
    }
  }