Skip to content
Snippets Groups Projects
Commit ef9233dd authored by tpylak's avatar tpylak
Browse files

LMS-1568 BDS migration: allow to run maintanance plugin only once at the server startup

SVN: 16367
parent 713f7143
No related branches found
No related tags found
No related merge requests found
package ch.systemsx.cisd.etlserver; package ch.systemsx.cisd.etlserver;
import java.util.Date;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
...@@ -31,13 +32,21 @@ public class MaintenancePlugin ...@@ -31,13 +32,21 @@ public class MaintenancePlugin
{ {
final String timerThreadName = parameters.getPluginName() + " - Maintenance Plugin"; final String timerThreadName = parameters.getPluginName() + " - Maintenance Plugin";
final Timer workerTimer = new Timer(timerThreadName); final Timer workerTimer = new Timer(timerThreadName);
workerTimer.schedule(new TimerTask() TimerTask timerTask = new TimerTask()
{ {
@Override @Override
public void run() public void run()
{ {
task.execute(); task.execute();
} }
}, parameters.getStartDate(), parameters.getIntervalSeconds() * 1000); };
Date startDate = parameters.getStartDate();
if (parameters.isExecuteOnlyOnce())
{
workerTimer.schedule(timerTask, startDate);
} else
{
workerTimer.schedule(timerTask, startDate, parameters.getIntervalSeconds() * 1000);
}
} }
} }
\ No newline at end of file
...@@ -44,6 +44,10 @@ public class MaintenanceTaskParameters ...@@ -44,6 +44,10 @@ public class MaintenanceTaskParameters
private static final String START_KEY = "start"; private static final String START_KEY = "start";
// If true the task will be executed exactly one, interval will be ignored. By default set to
// false.
private static final String ONE_TIME_EXECUTION_KEY = "execute-only-once";
private final String pluginName; private final String pluginName;
private final long interval; private final long interval;
...@@ -54,6 +58,8 @@ public class MaintenanceTaskParameters ...@@ -54,6 +58,8 @@ public class MaintenanceTaskParameters
private final Date startDate; private final Date startDate;
private final boolean executeOnlyOnce;
public MaintenanceTaskParameters(Properties properties, String pluginName) public MaintenanceTaskParameters(Properties properties, String pluginName)
{ {
this.properties = properties; this.properties = properties;
...@@ -61,6 +67,7 @@ public class MaintenanceTaskParameters ...@@ -61,6 +67,7 @@ public class MaintenanceTaskParameters
interval = PropertyUtils.getLong(properties, INTERVAL_KEY, ONE_DAY_IN_SEC); interval = PropertyUtils.getLong(properties, INTERVAL_KEY, ONE_DAY_IN_SEC);
className = PropertyUtils.getMandatoryProperty(properties, CLASS_KEY); className = PropertyUtils.getMandatoryProperty(properties, CLASS_KEY);
startDate = extractStartDate(PropertyUtils.getProperty(properties, START_KEY)); startDate = extractStartDate(PropertyUtils.getProperty(properties, START_KEY));
executeOnlyOnce = PropertyUtils.getBoolean(properties, ONE_TIME_EXECUTION_KEY, false);
} }
private static Date extractStartDate(String timeOrNull) private static Date extractStartDate(String timeOrNull)
...@@ -92,6 +99,11 @@ public class MaintenanceTaskParameters ...@@ -92,6 +99,11 @@ public class MaintenanceTaskParameters
} }
} }
public boolean isExecuteOnlyOnce()
{
return executeOnlyOnce;
}
public long getIntervalSeconds() public long getIntervalSeconds()
{ {
return interval; return interval;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment