/** Removes the JMX counters. */
  public void cleanup() {
    if (initialized) {
      if (threadPoolSettings != null) {
        threadPoolSettings.cleanup();
      }

      comp.unregisterComponentTree();
    }
  }
  /**
   * Constructor for StatsObject.
   *
   * @param parentComp subComp
   * @param threadPool Thread pool to be monitored.
   * @param workQueue Work queue to be monitored.
   * @param inProcessCounter Counter for files being processed.
   */
  public JMXWrapperObject(
      IManagedComponent parentComp,
      ThreadPoolExecutor threadPool,
      BlockingQueue<Runnable> workQueue,
      AtomicInteger inProcessCounter) {
    if (parentComp == null) {
      initialized = false;
      return;
    }

    IManagedComponent subComp =
        parentComp.createSubComponent(
            "DirectoryPoller",
            "Directory Poller",
            LogMessages.CONNECTOR_MANAGEMENT_DESCRIPTION,
            parentComp);

    seenFileCount =
        (IEventOccurrenceCounter)
            subComp.createPerformanceCounter(
                "Seen files",
                LogMessages.CNTR_INPUT_FILES,
                CounterFactory.EVENT_OCCURRENCE_COUNTER);
    restartedFileCount =
        (IEventOccurrenceCounter)
            subComp.createPerformanceCounter(
                "Restarted files",
                LogMessages.CNTR_RESTARTED_FILES,
                CounterFactory.EVENT_OCCURRENCE_COUNTER);
    successfulFileCount =
        (IEventOccurrenceCounter)
            subComp.createPerformanceCounter(
                "Successfull files",
                LogMessages.CNTR_PROCESSED_FILES_SUCCESS,
                CounterFactory.EVENT_OCCURRENCE_COUNTER);
    errorFileCount =
        (IEventOccurrenceCounter)
            subComp.createPerformanceCounter(
                "Error files",
                LogMessages.CNTR_PROCESSED_FILES_ERROR,
                CounterFactory.EVENT_OCCURRENCE_COUNTER);
    totalFileCount =
        (IEventOccurrenceCounter)
            subComp.createPerformanceCounter(
                "Total files",
                LogMessages.CNTR_PROCESSED_FILES_TOTAL,
                CounterFactory.EVENT_OCCURRENCE_COUNTER);
    scanTime =
        (ITimerEventValueCounter)
            subComp.createPerformanceCounter(
                "File scanning time",
                LogMessages.CNTR_FILE_SCAN_TIME,
                CounterFactory.TIMER_EVENT_VALUE_COUNTER);
    triggerTime =
        (ITimerEventValueCounter)
            subComp.createPerformanceCounter(
                "SOAP trigger time",
                LogMessages.CNTR_TRIGGER_TIME,
                CounterFactory.TIMER_EVENT_VALUE_COUNTER);
    processingTime =
        (ITimerEventValueCounter)
            subComp.createPerformanceCounter(
                "File processing time",
                LogMessages.CNTR_PROCESSING_TIME,
                CounterFactory.TIMER_EVENT_VALUE_COUNTER);
    fileSize =
        (IEventValueCounter)
            subComp.createPerformanceCounter(
                "Input file size", LogMessages.CNTR_FILE_SIZE, CounterFactory.EVENT_VALUE_COUNTER);

    fileProcessingAlert =
        subComp.defineAlert(
            AlertLevel.WARNING, LogMessages.ALERT_FILE_ERROR, LogMessages.ALERT_FILE_ERROR_DESC);

    threadPoolSettings = new ThreadPoolSettings(subComp, threadPool, workQueue, inProcessCounter);

    subComp.registerComponentTree();

    this.comp = subComp;
    initialized = true;
  }