perfsonar-dev - r1703 - trunk/perfsonar/src/org/perfsonar/commons/auxiliary/components/simplescheduler
Subject: perfsonar development work
List archive
r1703 - trunk/perfsonar/src/org/perfsonar/commons/auxiliary/components/simplescheduler
Chronological Thread
- From:
- To:
- Subject: r1703 - trunk/perfsonar/src/org/perfsonar/commons/auxiliary/components/simplescheduler
- Date: Thu, 19 Oct 2006 12:57:43 -0400
Author: uros
Date: 2006-10-19 12:57:42 -0400 (Thu, 19 Oct 2006)
New Revision: 1703
Modified:
trunk/perfsonar/src/org/perfsonar/commons/auxiliary/components/simplescheduler/Scheduler.java
trunk/perfsonar/src/org/perfsonar/commons/auxiliary/components/simplescheduler/SchedulerTask.java
Log:
Added remSchedulerTask method to simple scheduler.
For the remove to work properly, two functions have been implemented
in the SchedulerTask (equals, hashCode), which compare only
SchedulerAction part of the SchedulerTask (interval is ignored
in the comparison).
I shall be using those for the scheduled start of the TCMP measurement.
Modified:
trunk/perfsonar/src/org/perfsonar/commons/auxiliary/components/simplescheduler/Scheduler.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/commons/auxiliary/components/simplescheduler/Scheduler.java
2006-10-19 14:49:52 UTC (rev 1702)
+++
trunk/perfsonar/src/org/perfsonar/commons/auxiliary/components/simplescheduler/Scheduler.java
2006-10-19 16:57:42 UTC (rev 1703)
@@ -7,6 +7,8 @@
import java.util.HashSet;
import java.util.Set;
+import java.util.Collections;
+import java.util.ConcurrentModificationException;
import org.perfsonar.commons.auxiliary.AuxiliaryThreadedComponent;
import org.perfsonar.commons.auxiliary.AuxiliaryComponentManager;
@@ -42,7 +44,7 @@
private int wakeupInterval = 1000; //milliseconds
- private Set<SchedulerTask> tasks = new HashSet<SchedulerTask>();
+ private Set<SchedulerTask> tasks = Collections.synchronizedSet(new
HashSet<SchedulerTask>());
// -------------------------------------------------- Constructor
@@ -117,12 +119,18 @@
//if paused - not schedule any tasks
if (!paused) {
- for (SchedulerTask task : tasks) {
+ // Let's protect iteration over tasks by
+ // corrupted iterator exception catcher,
+ // which prevents this thread from dieing
+ try {
+ for (SchedulerTask task : tasks) {
- // run action in new thread
- task.runAction();
+ // run action in new thread
+ task.runAction();
+
+ }
- }
+ } catch (ConcurrentModificationException cme) {}
}
@@ -176,6 +184,20 @@
}
+
+ /**
+ * Remove scheduler task specified by action.
+ *
+ * @param action to remove
+ */
+ public void remSchedulerTask(SchedulerAction action) {
+
+ // Interval is not important in remove
+ tasks.remove(new SchedulerTask(0, action));
+
+ }
+
+
// ---------------------------- Private Methods
@@ -217,4 +239,4 @@
}
-} //Scheduler
\ No newline at end of file
+} //Scheduler
Modified:
trunk/perfsonar/src/org/perfsonar/commons/auxiliary/components/simplescheduler/SchedulerTask.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/commons/auxiliary/components/simplescheduler/SchedulerTask.java
2006-10-19 14:49:52 UTC (rev 1702)
+++
trunk/perfsonar/src/org/perfsonar/commons/auxiliary/components/simplescheduler/SchedulerTask.java
2006-10-19 16:57:42 UTC (rev 1703)
@@ -120,5 +120,38 @@
}
+
+ /**
+ * Return hash code for this SchedulerTask, which in turn returns
+ * action's hash code or 0 if action is null.
+ *
+ * @return hash code
+ */
+ public int hashCode() {
+
+ return action == null ? 0 : action.hashCode();
+
+ }
+
+
+ /**
+ * Return equality of this object based only on equality of action
+ * objects.
+ *
+ * @param o other objects (should be instanceof SchedulerTask
+ * @return true if both action objects are equal
+ */
+ public boolean equals(Object o) {
+
+ if (o == null) return false;
+
+ return o instanceof SchedulerTask ?
+ (((SchedulerTask)o).action == null ?
+ action == null :
+ ((SchedulerTask)o).action.equals(action)) :
+ false;
+
+ }
+
} //SchedulerTask
- r1703 - trunk/perfsonar/src/org/perfsonar/commons/auxiliary/components/simplescheduler, svnlog, 10/19/2006
Archive powered by MHonArc 2.6.16.