Skip to content
Browse files

Started created ChecksumModule commands and started implementing more

of the actual ChecksumModule.
  • Loading branch information...
1 parent f595970 commit 93451a633cf889bcf8d401ff42b7eba7c7a751f1 Matthew Oliver committed May 18, 2011
View
36 src/au/gov/naa/digipres/spyd/module/checksum/ChecksumModule.java
@@ -2,7 +2,9 @@
import java.util.List;
import java.util.Vector;
+import java.util.logging.Logger;
+import au.gov.naa.digipres.spyd.core.SpydPreferences;
import au.gov.naa.digipres.spyd.dao.DataAccessManager;
import au.gov.naa.digipres.spyd.dao.ItemRecordDAO;
import au.gov.naa.digipres.spyd.module.ModuleExecutionException;
@@ -14,15 +16,39 @@
public static final String PREFERENCE_PERIOD_UNITS = "checksum.period.units";
public static final String PREFERENCE_PERIOD = "checksum.period";
public static final String PREFERENCE_CHECKSUM_ALGORITHM = "checksum.algorithm";
+ public static final String PREFERENCE_NUMBER_OF_CHECKER_THREADS = "checksum.num.threads";
+
+ public static final int DEFAULT_NUMBER_OF_CHECKER_THREADS = 2;
private ItemRecordDAO recordDAO;
private DataAccessManager dataAccessManager;
+ private int numberOfCheckerThreads;
+
+ private Logger logger;
+
+ // Preferences
+ private SpydPreferences preferences;
public ChecksumModule(ModuleManager moduleManager) {
super(moduleManager);
dataAccessManager = moduleManager.getPluginManager().getSpyd().getDataAccessManager();
recordDAO = dataAccessManager.getItemRecordDAO();
+
+ // Get the number of threads.. that is if the user has specified one in the config file
+ preferences = moduleManager.getPluginManager().getSpyd().getPreferences();
+ String tmpNumThreads = preferences.getPreference(PREFERENCE_NUMBER_OF_CHECKER_THREADS);
+ if (tmpNumThreads == null) {
+ // not set so use default.
+ numberOfCheckerThreads = DEFAULT_NUMBER_OF_CHECKER_THREADS;
+ } else {
+ try {
+ numberOfCheckerThreads = Integer.parseInt(tmpNumThreads);
+ } catch (NumberFormatException ex) {
+ logger.warning("checksum.num.threads value is not an int, using default number (" + DEFAULT_NUMBER_OF_CHECKER_THREADS + ")");
+ numberOfCheckerThreads = DEFAULT_NUMBER_OF_CHECKER_THREADS;
+ }
+ }
}
@Override
@@ -47,8 +73,16 @@ public void unloadEvent() {
List<String> prefs = new Vector<String>();
prefs.add(PREFERENCE_CHECKSUM_ALGORITHM);
prefs.add(PREFERENCE_PERIOD);
-
+ prefs.add(PREFERENCE_PERIOD_UNITS);
return prefs;
}
+ public synchronized void setNumberOfCheckerThreads(int numberOfCheckerThreads) {
+ this.numberOfCheckerThreads = numberOfCheckerThreads;
+ }
+
+ public synchronized int getNumberOfCheckerThreads() {
+ return numberOfCheckerThreads;
+ }
+
}
View
35 src/au/gov/naa/digipres/spyd/module/checksum/command/NumberOfCheckerThreadsCommand.java
@@ -0,0 +1,35 @@
+package au.gov.naa.digipres.spyd.module.checksum.command;
+
+import au.gov.naa.digipres.spyd.command.Command;
+import au.gov.naa.digipres.spyd.command.CommandException;
+
+public class NumberOfCheckerThreadsCommand extends Command {
+
+ public static final String NUMBER_OF_THREADS_TRIGGER = "numcheckerthreads";
+
+ public NumberOfCheckerThreadsCommand() {
+ super();
+ trigger = NUMBER_OF_THREADS_TRIGGER;
+ }
+
+ @Override
+ public String getHelp() {
+ return getTrigger() + " - Show/Set the number of checker threads.";
+ }
+
+ @Override
+ public String getUsage() {
+ return getTrigger() + " [<number of threads]";
+ }
+
+ @Override
+ public void runCommand() throws CommandException {
+ fireStartCommandEvent();
+ if (getParamiterList().size() == 0) {
+ // Display the number of threads
+ //TODO get the current value of the numberOfCheckerThreads from the checker module.
+ }
+ fireEndCommandEvent();
+ }
+
+}

0 comments on commit 93451a6

Please sign in to comment.
Something went wrong with that request. Please try again.