perfsonar-dev - perfsonar: r5410 - in branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler: . singleThread
Subject: perfsonar development work
List archive
perfsonar: r5410 - in branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler: . singleThread
Chronological Thread
- From:
- To:
- Subject: perfsonar: r5410 - in branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler: . singleThread
- Date: Mon, 14 Dec 2009 04:37:18 -0500
Author: trzaszcz
Date: 2009-12-14 04:37:18 -0500 (Mon, 14 Dec 2009)
New Revision: 5410
Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulerTask.java
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/singleThread/SchedulerTaskComparator.java
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/singleThread/SingleThreadScheduler.java
Log:
SingleThreadScheduler added
Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulerTask.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulerTask.java
2009-12-13 20:05:23 UTC (rev 5409)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulerTask.java
2009-12-14 09:37:18 UTC (rev 5410)
@@ -78,9 +78,7 @@
* @return
*/
public boolean canRun() {
- long diff= (timestamp + (interval * 1000) -
System.currentTimeMillis());
- System.out.println("DIFF "+diff);
- return diff<= 0;
+ return (timestamp + (interval * 1000) -
System.currentTimeMillis())<= 0;
}
/**
Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/singleThread/SchedulerTaskComparator.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/singleThread/SchedulerTaskComparator.java
2009-12-13 20:05:23 UTC (rev 5409)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/singleThread/SchedulerTaskComparator.java
2009-12-14 09:37:18 UTC (rev 5410)
@@ -4,7 +4,13 @@
import org.perfsonar.base2.service.scheduler.SchedulerTask;
-public class SchedulerTaskComparator implements Comparator<SchedulerTask>{
+/**
+ * simple Comparator that is used to sort TaskComparators.
+ * Comparison depends on SchedulerTask's interval.
+ *
+ * @author Slawomir Trzaszczka
+ */
+class SchedulerTaskComparator implements Comparator<SchedulerTask>{
public int compare(SchedulerTask o1, SchedulerTask o2) {
Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/singleThread/SingleThreadScheduler.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/singleThread/SingleThreadScheduler.java
2009-12-13 20:05:23 UTC (rev 5409)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/singleThread/SingleThreadScheduler.java
2009-12-14 09:37:18 UTC (rev 5410)
@@ -11,6 +11,8 @@
import org.perfsonar.base2.service.scheduler.SchedulerTask;
/**
+ * manages pool of actions where only one action can be processed in moment.
+ * If one action is invoked others are added to waitQueue.
*
* @author Slawomir Trzaszczka
*
@@ -37,26 +39,17 @@
*/
protected int startDelayTime = 40; // sec
- protected final Logger logger = Logger
- .getLogger(SingleThreadScheduler.class);
+ protected final Logger logger =
Logger.getLogger(SingleThreadScheduler.class);
public void start() {
super.start();
logger.debug("Scheduler started");
-
Collections.sort(tasks, new SchedulerTaskComparator());
- System.out.println("-----------------");
- for(SchedulerTask st:tasks){
-
System.out.println(st.getAction().getClass().getName()+"-"+st.getInterval());
- }
- System.out.println("-----------------");
-
}
public void run() {
-
int iteration = 0;
try {
logger.debug("Scheduler run. Waiting [" +
startDelayTime
@@ -69,7 +62,6 @@
logger.debug("SingleThreadScheduler starts");
while (true) {
-
System.out.println("---------------------------------------------------------------------------------");
for (SchedulerTask task : tasks) {
if(task.canRun()){
logger.debug("task
"+task.getAction()+" can run");
@@ -88,15 +80,12 @@
logger.debug("polled
from wait queue");
lastSchedulerTask=waitQueue.poll();
}
-
System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx");
lastSchedulerTask.runAction();
-
System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx");
}
}else{
logger.debug("task
"+task.getAction()+" CAN'T run");
}
}
-
System.out.println("---------------------------------------------------------------------------------");
try {
Thread.sleep(interval * 1000);
iteration++;
@@ -125,7 +114,6 @@
* Add task to scheduler
*/
public void addTask(SchedulerTask t) {
-
tasks.add(t);
}
@@ -145,10 +133,7 @@
* to remove
*/
public void removeTask(SchedulerAction action) {
-
- // Interval is not important in remove
tasks.remove(new SchedulerTask(0, action));
-
}
public void finish() {
- perfsonar: r5410 - in branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler: . singleThread, svnlog, 12/14/2009
Archive powered by MHonArc 2.6.16.