PageRenderTime 34ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mpv5/utils/jobs/Watcher.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 66 lines | 37 code | 9 blank | 20 comment | 1 complexity | 25504d39e8ea7f65382fa43a8d91da4d MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package mpv5.utils.jobs;
  6. import java.util.logging.Level;
  7. import java.util.logging.Logger;
  8. import mpv5.logging.Log;
  9. /**
  10. *
  11. *
  12. */
  13. public class Watcher implements Runnable {
  14. private int interval = 1000;
  15. private Object watched;
  16. private Object caller;
  17. private Thread t = new Thread(this);
  18. public Watcher(Object parent, Object obj) {
  19. this.watched = obj;
  20. this.caller = parent;
  21. t.start();
  22. }
  23. public void run() {
  24. while (true) {
  25. Log.Debug(this, "Watching variable from " + getCaller().getClass() + " with type:" + getWatched().getClass() + " has value: " + getWatched());
  26. try {
  27. Thread.sleep(interval);
  28. } catch (InterruptedException ex) {
  29. mpv5.logging.Log.Debug(ex);//Logger.getLogger(Watcher.class.getName()).log(Level.SEVERE, null, ex);
  30. }
  31. }
  32. }
  33. /**
  34. * @return the interval
  35. */
  36. public int getInterval() {
  37. return interval;
  38. }
  39. /**
  40. * @param interval the interval to set
  41. */
  42. public void setInterval(int interval) {
  43. this.interval = interval;
  44. }
  45. /**
  46. * @return the watched
  47. */
  48. public Object getWatched() {
  49. return watched;
  50. }
  51. /**
  52. * @return the caller
  53. */
  54. public Object getCaller() {
  55. return caller;
  56. }
  57. }