Revision: 2305
http://sourceforge.net/p/swingme/code/2305
Author: yuranet
Date: 2014-02-22 18:21:10 +0000 (Sat, 22 Feb 2014)
Log Message:
-----------
QueueProcessorThread by default handles Runnable
Modified Paths:
--------------
UtilME/src/net/yura/mobile/util/QueueProcessorThread.java
Added Paths:
-----------
UtilME/src/net/yura/mobile/util/Timer.java
Modified: UtilME/src/net/yura/mobile/util/QueueProcessorThread.java
===================================================================
--- UtilME/src/net/yura/mobile/util/QueueProcessorThread.java 2014-02-22 18:19:13 UTC (rev 2304)
+++ UtilME/src/net/yura/mobile/util/QueueProcessorThread.java 2014-02-22 18:21:10 UTC (rev 2305)
@@ -6,7 +6,7 @@
/**
* @author Yura Mamyrin
*/
-public abstract class QueueProcessorThread implements Runnable {
+public class QueueProcessorThread implements Runnable {
public static boolean CHANGE_PRIORITY=true;
@@ -142,6 +142,11 @@
return inbox;
}
- public abstract void process(Object object) throws Exception;
+ /**
+ * Override this method to be able to handle other types of object apart from Runnable.
+ */
+ public void process(Object object) throws Exception {
+ ((Runnable)object).run();
+ }
}
Added: UtilME/src/net/yura/mobile/util/Timer.java
===================================================================
--- UtilME/src/net/yura/mobile/util/Timer.java (rev 0)
+++ UtilME/src/net/yura/mobile/util/Timer.java 2014-02-22 18:21:10 UTC (rev 2305)
@@ -0,0 +1,72 @@
+package net.yura.mobile.util;
+
+import net.yura.mobile.logging.Logger;
+
+public class Timer extends Thread {
+
+ private String id;
+ private long delay;
+ private Runnable task;
+ private boolean cancelled = false;
+
+ /**
+ * @see java.util.Timer#schedule(java.util.TimerTask, long) Timer.schedule
+ */
+ public void schedule(String id, Runnable task, long delay){
+
+ //#debug debug
+ Logger.debug("Setting schedule for (" + id + ") with delay of: " + delay);
+
+ this.id = id;
+ this.delay = delay;
+ this.task = task;
+ this.setPriority(MIN_PRIORITY);
+ this.start();
+ }
+
+ /**
+ * @see java.util.Timer#schedule(java.util.TimerTask, long, long) Timer.schedule
+ */
+ public void schedule(String id, Runnable task, long delay, long period){
+ throw new RuntimeException("not done yet :-)");
+ }
+
+ public final void run() {
+
+ try {
+ if (!cancelled) {
+ try {
+ Thread.sleep(delay);
+ }
+ catch (InterruptedException e) {
+ //#debug info
+ Logger.info(e);
+ }
+
+ if (cancelled) return;
+
+ //#debug debug
+ Logger.debug("Running task (" + id + ") after a schedule of: " + delay);
+ task.run();
+ }
+ }
+ catch (Throwable t) {
+ //#debug warn
+ Logger.warn("error in ("+id+") timer: "+t.toString());
+ Logger.error(t);
+ }
+
+ }
+
+
+ /**
+ * @see java.util.Timer#cancel() Timer.cancel
+ */
+ public void cancel(){
+
+ //#debug debug
+ Logger.debug("Cancelling task (" + id + ")");
+
+ cancelled = true;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|