<commit_before>/*  Copyright (C) 2003-2011 JabRef contributors.
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.collab;

import net.sf.jabref.Globals;
import net.sf.jabref.Util;
import java.util.HashMap;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;

/**
 * This thread monitors a set of files, each associated with a FileUpdateListener, for changes
* in the file's last modification time stamp. The
 */
public class FileUpdateMonitor extends Thread {

  final int WAIT = 4000;
  static int tmpNum = 0;
  int no = 0;
  HashMap<String, Entry> entries = new HashMap<String, Entry>();
  boolean running;

  public FileUpdateMonitor() {
    setPriority(MIN_PRIORITY);
  }

  public void run() {
    running = true;

    // The running variable is used to make the thread stop when needed.
    while (running) {
      //System.out.println("Polling...");
      Iterator<String> i = entries.keySet().iterator();
      for (;i.hasNext();) {
        Entry e = entries.get(i.next());
        try {
          if (e.hasBeenUpdated())
            e.notifyListener();

          //else
          //System.out.println("File '"+e.file.getPath()+"' not modified.");
        } catch (IOException ex) {
          e.notifyFileRemoved();
        }
      }

      // Sleep for a while before starting a new polling round.
      try {
        sleep(WAIT);
      } catch (InterruptedException ex) {
    	  /*  the (?) correct way to interrupt threads, according to
    	   *  http://www.roseindia.net/javatutorials/shutting_down_threads_cleanly.shtml
    	   */
    	  Thread.currentThread().interrupt(); // very important
    	  break;
      }
    }
  }

  /**
   * Cause the thread to stop monitoring. It will finish the current round before stopping.
   */
  public void stopMonitoring() {
    running = false;
  }

  /**
   * Add a new file to monitor. Returns a handle for accessing the entry.
   * @param ul FileUpdateListener The listener to notify when the file changes.
   * @param file File The file to monitor.
   * @throws IOException if the file does not exist.
   */
  public String addUpdateListener(FileUpdateListener ul, File file) throws IOException {
     // System.out.println(file.getPath());
    if (!file.exists())
      throw new IOException("File not found");
    no++;<commit_msg>Adds log output if FileUpdateMonitor was shut down.<commit_after>/*  Copyright (C) 2003-2011 JabRef contributors.
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.collab;

import net.sf.jabref.Globals;
import net.sf.jabref.Util;

import java.util.HashMap;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.logging.Logger;

/**
 * This thread monitors a set of files, each associated with a FileUpdateListener, for changes
* in the file's last modification time stamp. The
 */
public class FileUpdateMonitor extends Thread {

	private static Logger logger = Logger.getLogger(FileUpdateMonitor.class.getName());

  final int WAIT = 4000;
  static int tmpNum = 0;
  int no = 0;
  HashMap<String, Entry> entries = new HashMap<String, Entry>();
  boolean running;

  public FileUpdateMonitor() {
    setPriority(MIN_PRIORITY);
  }

  public void run() {
    running = true;

    // The running variable is used to make the thread stop when needed.
    while (running) {
      //System.out.println("Polling...");
      Iterator<String> i = entries.keySet().iterator();
      for (;i.hasNext();) {
        Entry e = entries.get(i.next());
        try {
          if (e.hasBeenUpdated())
            e.notifyListener();

          //else
          //System.out.println("File '"+e.file.getPath()+"' not modified.");
        } catch (IOException ex) {
          e.notifyFileRemoved();
        }
      }

      // Sleep for a while before starting a new polling round.
      try {
        sleep(WAIT);
      } catch (InterruptedException ex) {
    	  logger.finest("FileUpdateMonitor has been interrupted.");
    	  /*  the (?) correct way to interrupt threads, according to
    	   *  http://www.roseindia.net/javatutorials/shutting_down_threads_cleanly.shtml
    	   */
    	  Thread.currentThread().interrupt(); // very important
    	  break;
      }
    }
  }

  /**
   * Cause the thread to stop monitoring. It will finish the current round before stopping.
   */
  public void stopMonitoring() {
    running = false;
  }

  /**
   * Add a new file to monitor. Returns a handle for accessing the entry.
   * @param ul FileUpdateListener The listener to notify when the file changes.
   * @param file File The file to monitor.
   * @throws IOException if the file does not exist.
   */
  public String addUpdateListener(FileUpdateListener ul, File file) throws IOException {
     // System.out.println(file.getPath());
    if (!file.exists())
      throw new IOException("File not found");
    no++;
{'fraction_non_alphanumeric': 0.09393502960473676, 'fraction_numerical': 0.008321331413026083, 'mean_word_length': 2.8273116962645437, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5102641', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1689, 'n_words': 669}