Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r5044 - in branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service: configuration scheduler

Subject: perfsonar development work

List archive

perfsonar: r5044 - in branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service: configuration scheduler


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r5044 - in branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service: configuration scheduler
  • Date: Mon, 9 Mar 2009 10:37:12 -0400

Author: mac
Date: 2009-03-09 10:37:12 -0400 (Mon, 09 Mar 2009)
New Revision: 5044

Modified:

branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/AuxiliaryComponents.java

branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/ConfigurationManager.java

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/SchedulingComponent.java

branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SimpleAction.java

branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SimpleScheduler.java
Log:
Scheduler intervals should be now in seconds

Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/AuxiliaryComponents.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/AuxiliaryComponents.java
2009-03-09 12:56:43 UTC (rev 5043)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/AuxiliaryComponents.java
2009-03-09 14:37:12 UTC (rev 5044)
@@ -42,7 +42,7 @@
return ((Component)components.get(name));
}

- public Map getComponents() {
+ public Map<String,Component> getComponents() {
return components;
}


Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/ConfigurationManager.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/ConfigurationManager.java
2009-03-09 12:56:43 UTC (rev 5043)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/configuration/ConfigurationManager.java
2009-03-09 14:37:12 UTC (rev 5044)
@@ -5,17 +5,13 @@
package org.perfsonar.base2.service.configuration;


+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collection;

-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.net.MalformedURLException;
-
-
import org.apache.commons.digester.Digester;
import org.apache.commons.digester.xmlrules.DigesterLoader;
import org.apache.log4j.Logger;
@@ -232,7 +228,7 @@
AuxiliaryComponents ac = configuration.getAuxiliaryComponents();
if (ac == null) return;

- Collection components =
(Collection<Component>)ac.getComponents().values();
+ Collection<Component> components =
(Collection<Component>)ac.getComponents().values();
for (Component c : (Collection<Component>)components) {

try {

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-03-09 12:56:43 UTC (rev 5043)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulerTask.java
2009-03-09 14:37:12 UTC (rev 5044)
@@ -10,9 +10,9 @@
// --------------------------------------------- Variables


- private long MIN_INTERVAL = 1000; //ms
+ private long MIN_INTERVAL = 1; //seconds

- private long interval = MIN_INTERVAL; //minimal interval (in ms)
between actions
+ private long interval = MIN_INTERVAL; //minimal interval (in seconds)
between actions

private long timestamp = 0; // last timestamp when action was
performed; 0 - never

@@ -24,15 +24,16 @@

public SchedulerTask(long interval, SchedulerAction action) {

+ //check whether interval isn't lower than minimal
if (interval<MIN_INTERVAL) {
- logger.debug("Requested interval for action
["+action.getClass()+"] too low. Taking ["+MIN_INTERVAL+"] ms");
+ logger.debug("Requested interval for action
["+action.getClass()+"] too low. Taking ["+MIN_INTERVAL+"] seconds");
this.interval = MIN_INTERVAL;
} else {
- logger.debug("Interval for action ["+action.getClass()+"] set to
["+interval+"] ms");
+ logger.debug("Interval for action ["+action.getClass()+"] set to
["+interval+"] seconds");
this.interval = interval;
}
this.action = action;
- this.timestamp = 0;
+ this.timestamp = 0;

}

@@ -40,16 +41,16 @@
/**
* This constructor is used, when some action should be run in the future
*
- * @param interval interval for running action
+ * @param interval interval for running action in seconds
* @param action action to run
* @param startTimestamp when should we start running action
*/
public SchedulerTask(
long interval, SchedulerAction action, long startTimestamp) {

- this(interval, action);
+ this(interval, action); //interval in seconds

- timestamp = startTimestamp - interval;
+ timestamp = startTimestamp - (interval*1000);

}

@@ -64,10 +65,10 @@

long currentTimestamp = System.currentTimeMillis();

- logger.debug("Scheduler Task ["+this.getClass()+"] - interval
["+interval+"]" );
+ logger.debug("Scheduler Task ["+this.getClass()+"] - interval
["+interval+"] seconds" );

//if timestamp older than current - interval
- if ((timestamp + interval - currentTimestamp) <= 0) {
+ if ((timestamp + (interval*1000) - currentTimestamp) <= 0) {

logger.debug("Scheduler run action ["+action.getClass()+"]" );

@@ -107,7 +108,7 @@


/**
- * Get interval between two subsequence runs of action
+ * Get interval (in seconds) between two subsequence runs of action
* @param interval
*/
public long getInterval() {
@@ -118,8 +119,8 @@


/**
- * Set interval between two subsequence runs of action
- * @param interval
+ * Set interval between two subsequence runs of action,
+ * @param interval in seconds
*/
public void setInterval(long interval) {


Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulingComponent.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulingComponent.java
2009-03-09 12:56:43 UTC (rev 5043)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SchedulingComponent.java
2009-03-09 14:37:12 UTC (rev 5044)
@@ -16,7 +16,7 @@

private int interval;

- public static final int DEFAULT_INTERVAL = 10000; // milliseconds
+ public static final int DEFAULT_INTERVAL = 10; // seconds



@@ -41,8 +41,12 @@

protected void loadSettings() throws PerfSONARException {

+ logger.debug("SchedulingComponenet - loading configuration");
+
+ //get classname
schedulerClassName = getOption("schedulerClassName").getValue();
-
+
+ //get interval in seconds
String intervalStr = getOption("interval").getValue();
try {
interval = Integer.parseInt(intervalStr);
@@ -52,6 +56,8 @@
+ " Default value is taken.");
interval = DEFAULT_INTERVAL;
}
+
+
}


@@ -73,7 +79,7 @@
protected void runScheduler() throws PerfSONARException {

if (scheduler != null) {
- scheduler.setInterval(interval);
+ scheduler.setInterval(interval); //seconds
scheduler.start();
} else
logger
@@ -102,12 +108,19 @@
}


+ /**
+ * Returns interval in seconds
+ * @return
+ */
public int getInterval() {

return this.interval;
}

-
+ /**
+ * Sets interval in seconds
+ * @param interval
+ */
public void setInterval(int interval) {

this.interval = interval;
@@ -116,19 +129,19 @@

public void registerActions() {

- logger.debug("Start of registering schedulling tasks. Default
interval is ["+interval+"] ms");
+ logger.debug("RegisterActions: Start of registering schedulling
tasks. Default interval is ["+interval+"] sec");

if (scheduler != null) {

Collection<Action> actions = getActions().getActions().values();

for (Action action : actions) {
+
int actionInterval = this.interval;
try {
// get option interval from action and try to convert it
to
// int

- logger.debug(action.getOptions());
actionInterval = Integer.parseInt(action.getOption(
"interval").getValue());

@@ -140,7 +153,7 @@
logger.debug("Action [" + action.getName() + "] class ["
+ action.getClass()
+ "] registered to the scheduler with interval ["
- + actionInterval + "]");
+ + actionInterval + "] seconds");
}
}


Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SimpleAction.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SimpleAction.java
2009-03-09 12:56:43 UTC (rev 5043)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SimpleAction.java
2009-03-09 14:37:12 UTC (rev 5044)
@@ -7,7 +7,6 @@
import org.perfsonar.base2.service.configuration.Action;
import org.apache.log4j.Logger;

-
public class SimpleAction extends Action implements SchedulerAction {



Modified:
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SimpleScheduler.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SimpleScheduler.java
2009-03-09 12:56:43 UTC (rev 5043)
+++
branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service/scheduler/SimpleScheduler.java
2009-03-09 14:37:12 UTC (rev 5044)
@@ -24,7 +24,7 @@
protected boolean paused = false;

protected int interval = SchedulingComponent.DEFAULT_INTERVAL;
- protected int startDelayTime = 10000;
+ protected int startDelayTime = 10; //sec

protected static final Logger logger =
Logger.getLogger(SimpleScheduler.class.getName());

@@ -51,8 +51,8 @@
int iteration = 0;
paused = false;
try {
- logger.info("Scheduler run. Waiting ["+startDelayTime+"] ms for
initialization of other components...");
- Thread.sleep(startDelayTime);
+ logger.info("Scheduler run. Waiting ["+startDelayTime+"] sec
for initialization of other components...");
+ Thread.sleep(startDelayTime * 1000); //seconds
} catch (Exception ex) { logger.warn(ex.toString());}

while (working) { //infinite loop until stopScheduler()
@@ -80,7 +80,7 @@

//logger.debug("Scheduler waits ["+interval+"] ms");

- Thread.sleep(interval); //wait
+ Thread.sleep(interval * 1000); //wait seconds

iteration++; //increase iteration counter

@@ -102,27 +102,38 @@

}

-
+ /**
+ * get Interval in seconds
+ */
public int getInterval() {

return interval;
}


- public void setInterval(int interval) {
+ /**
+ * set Interval in seconds
+ */
+ public void setInterval(int intervalSec) {

- this.interval = interval;
+ this.interval = intervalSec;
}


+ /**
+ * Add task to scheduler
+ */
public void addTask(SchedulerTask t) {

tasks.add(t);
}

- public void addTask(int interval, SchedulerAction action) {
+ /**
+ * Add scheduler action and set an interval for it (in seconds)
+ */
+ public void addTask(int intervalSec, SchedulerAction action) {

- tasks.add(new SchedulerTask(interval, action));
+ tasks.add(new SchedulerTask(intervalSec, action));

}

@@ -159,6 +170,5 @@
this.paused = paused;
}

-
} //SimpleScheduler




  • perfsonar: r5044 - in branches/new-structure-with-base2/ps-mdm-base2/src/main/java/org/perfsonar/base2/service: configuration scheduler, svnlog, 03/09/2009

Archive powered by MHonArc 2.6.16.

Top of Page