PageRenderTime 149ms CodeModel.GetById 70ms app.highlight 4ms RepoModel.GetById 46ms app.codeStats 12ms

/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
 1/*
 2 * To change this template, choose Tools | Templates
 3 * and open the template in the editor.
 4 */
 5package mpv5.utils.jobs;
 6
 7import java.util.logging.Level;
 8import java.util.logging.Logger;
 9import mpv5.logging.Log;
10
11/**
12 *
13 *  
14 */
15public class Watcher implements Runnable {
16
17    private int interval = 1000;
18    private Object watched;
19    private Object caller;
20    private Thread t = new Thread(this);
21
22    public Watcher(Object parent, Object obj) {
23        this.watched = obj;
24        this.caller = parent;
25        t.start();
26    }
27
28    public void run() {
29        while (true) {
30            Log.Debug(this, "Watching variable from " + getCaller().getClass() + " with type:" + getWatched().getClass() + " has value: " + getWatched());
31            try {
32                Thread.sleep(interval);
33            } catch (InterruptedException ex) {
34                mpv5.logging.Log.Debug(ex);//Logger.getLogger(Watcher.class.getName()).log(Level.SEVERE, null, ex);
35            }
36        }
37    }
38
39    /**
40     * @return the interval
41     */
42    public int getInterval() {
43        return interval;
44    }
45
46    /**
47     * @param interval the interval to set
48     */
49    public void setInterval(int interval) {
50        this.interval = interval;
51    }
52
53    /**
54     * @return the watched
55     */
56    public Object getWatched() {
57        return watched;
58    }
59
60    /**
61     * @return the caller
62     */
63    public Object getCaller() {
64        return caller;
65    }
66}