Changeset 19000 in osm
- Timestamp:
- 2009-12-08T23:43:51+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsSuppressor.java
r18942 r19000 18 18 public class LiveGpsSuppressor implements Runnable { 19 19 20 21 22 23 20 /** 21 * Default sleep time is 5 seconds. 22 */ 23 private static final int DEFAULT_SLEEP_TIME = 5000; 24 24 25 26 27 28 25 /** 26 * The currently used sleepTime. 27 */ 28 private int sleepTime = DEFAULT_SLEEP_TIME; 29 29 30 31 32 33 30 /** 31 * The flag allowUpdate is enabled once during the sleepTime. 32 */ 33 private boolean allowUpdate = false; 34 34 35 36 37 38 35 /** 36 * Controls if this thread is still in used. 37 */ 38 boolean shutdownFlag = false; 39 39 40 41 42 43 44 45 40 /** 41 * Run thread enables the allowUpdate flag once during its cycle. 42 * @see java.lang.Runnable#run() 43 */ 44 public void run() { 45 initSleepTime(); 46 46 47 48 49 47 shutdownFlag = false; 48 while (!shutdownFlag) { 49 setAllowUpdate(true); 50 50 51 try { 52 Thread.sleep(getSleepTime()); 53 } catch (InterruptedException e) { 54 // TODO I never knew, how to handle this??? Probably just carry on 55 } 56 } 51 try { 52 Thread.sleep(getSleepTime()); 53 } catch (InterruptedException e) { 54 // TODO I never knew, how to handle this??? Probably just carry 55 // on 56 } 57 } 57 58 58 59 } 59 60 60 61 62 63 64 65 66 sleepTime = Main.pref.getInteger("livegps.refreshinterval", 67 DEFAULT_SLEEP_TIME); 68 // creates the setting, if none present. 69 Main.pref.putInteger("livegps.refreshinterval", sleepTime); 70 } 61 /** 62 * Retrieve the sleepTime from the configuration. 63 * If no such configuration key exists, it will be initialized here. 64 */ 65 private void initSleepTime() { 66 // fetch it from the user setting, or use the default value. 67 int sleepSeconds = 0; 68 sleepSeconds = Main.pref.getInteger("livegps.refreshinterval", 69 DEFAULT_SLEEP_TIME); 70 // creates the setting, if none present. 71 Main.pref.putInteger("livegps.refreshinterval", sleepSeconds); 71 72 72 /** 73 * Set the allowUpdate flag. May only privately accessible! 74 * @param allowUpdate the allowUpdate to set 75 */ 76 private synchronized void setAllowUpdate(boolean allowUpdate) { 77 this.allowUpdate = allowUpdate; 78 } 73 // convert seconds into milliseconds internally. 74 this.sleepTime = sleepSeconds * 1000; 75 } 79 76 80 /** 81 * Query, if an update is currently allowed. 82 * When it is allowed, it will disable the allowUpdate flag as a side effect. 83 * (this means, one thread got to issue an update event) 84 * 85 * @return true, if an update is currently allowed; false, if the update shall be suppressed. 86 */ 87 public synchronized boolean isAllowUpdate() { 77 /** 78 * Set the allowUpdate flag. May only privately accessible! 79 * @param allowUpdate the allowUpdate to set 80 */ 81 private synchronized void setAllowUpdate(boolean allowUpdate) { 82 this.allowUpdate = allowUpdate; 83 } 88 84 89 if (allowUpdate) { 90 allowUpdate = false; 91 return true; 92 } else { 93 return false; 94 } 95 } 85 /** 86 * Query, if an update is currently allowed. 87 * When it is allowed, it will disable the allowUpdate flag as a side effect. 88 * (this means, one thread got to issue an update event) 89 * 90 * @return true, if an update is currently allowed; false, if the update shall be suppressed. 91 */ 92 public synchronized boolean isAllowUpdate() { 96 93 97 /** 98 * Shut this thread down. 99 */ 100 public void shutdown() { 101 shutdownFlag = true; 102 } 94 if (allowUpdate) { 95 allowUpdate = false; 96 return true; 97 } else { 98 return false; 99 } 100 } 103 101 104 /** 105 * @return the defaultSleepTime 106 */ 107 private int getSleepTime() { 108 return this.sleepTime; 109 } 102 /** 103 * Shut this thread down. 104 */ 105 public void shutdown() { 106 shutdownFlag = true; 107 } 108 109 /** 110 * @return the defaultSleepTime 111 */ 112 private int getSleepTime() { 113 return this.sleepTime; 114 } 110 115 111 116 }
Note:
See TracChangeset
for help on using the changeset viewer.