Revision: 1786
http://archive-access.svn.sourceforge.net/archive-access/?rev=1786&view=rev
Author: bradtofel
Date: 2007-07-16 16:19:43 -0700 (Mon, 16 Jul 2007)
Log Message:
-----------
REFACTOR: added getters and setters and created empty constructor for Spring
Modified Paths:
--------------
trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/BDBIndexUpdater.java
Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/BDBIndexUpdater.java
===================================================================
--- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/BDBIndexUpdater.java 2007-07-16 23:16:48 UTC (rev 1785)
+++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/resourceindex/bdb/BDBIndexUpdater.java 2007-07-16 23:19:43 UTC (rev 1786)
@@ -70,8 +70,13 @@
* has already been started -- static, and access to it is synchronized.
*/
private static Thread updateThread = null;
-
/**
+ * Default constructor
+ */
+ public BDBIndexUpdater() {
+
+ }
+ /**
* @param index
* @param incoming
*/
@@ -81,26 +86,19 @@
}
/**
- * @param failed The failed to set.
+ * start the background index merging thread
+ * @throws ConfigurationException
*/
- public void setFailed(File failed) {
- this.failed = failed;
+ public void init() throws ConfigurationException {
+ if(index == null) {
+ throw new ConfigurationException("No index target on bdb updater");
+ }
+ if(incoming == null) {
+ throw new ConfigurationException("No incoming on bdb updater");
+ }
+ startUpdateThread();
}
-
- /**
- * @param merged The merged to set.
- */
- public void setMerged(File merged) {
- this.merged = merged;
- }
-
- /**
- * @param runInterval The runInterval to set.
- */
- public void setRunInterval(int runInterval) {
- this.runInterval = runInterval;
- }
-
+
/** Ensure the argument directory exists
* @param dir
* @throws IOException
@@ -171,6 +169,25 @@
return target;
}
+ private File ensureDir(String path) throws ConfigurationException {
+ if(path.length() < 1) {
+ throw new ConfigurationException("Empty directory path");
+ }
+ File dir = new File(path);
+ if(dir.exists()) {
+ if(!dir.isDirectory()) {
+ throw new ConfigurationException("path " + path + "exists" +
+ "but is not a directory");
+ }
+ } else {
+ if(!dir.mkdirs()) {
+ throw new ConfigurationException("unable to create directory" +
+ " at " + path);
+ }
+ }
+ return dir;
+ }
+
private void handleMerged(File f) {
if (merged == null) {
if (!f.delete()) {
@@ -228,6 +245,104 @@
}
/**
+ * @return the index
+ */
+ public BDBIndex getIndex() {
+ return index;
+ }
+
+ /**
+ * @param index the index to set
+ */
+ public void setIndex(BDBIndex index) {
+ this.index = index;
+ }
+
+ /**
+ * @return the incoming
+ */
+ public String getIncoming() {
+ if(incoming == null) {
+ return null;
+ }
+ return incoming.getAbsolutePath();
+ }
+
+ /**
+ * @param incoming the incoming to set
+ * @throws ConfigurationException
+ */
+ public void setIncoming(String incoming) throws ConfigurationException {
+ this.incoming = ensureDir(incoming);
+ }
+
+
+ /**
+ * @return the merged
+ */
+ public String getMerged() {
+ if(merged == null) {
+ return null;
+ }
+ return merged.getAbsolutePath();
+ }
+
+ /**
+ * @param merged The merged to set.
+ * @throws ConfigurationException
+ */
+ public void setMerged(String merged) throws ConfigurationException {
+ this.merged = ensureDir(merged);
+ }
+ /**
+ * @param merged
+ * @throws IOException
+ */
+ public void setMerged(File merged) throws IOException {
+ ensureDir(merged);
+ this.merged = merged;
+ }
+
+ /**
+ * @return the failed
+ */
+ public String getFailed() {
+ if(failed == null) {
+ return null;
+ }
+ return failed.getAbsolutePath();
+ }
+
+ /**
+ * @param failed The failed to set.
+ * @throws ConfigurationException
+ */
+ public void setFailed(String failed) throws ConfigurationException {
+ this.failed = ensureDir(failed);
+ }
+ /**
+ * @param failed
+ * @throws IOException
+ */
+ public void setFailed(File failed) throws IOException {
+ ensureDir(failed);
+ this.failed = failed;
+ }
+
+ /**
+ * @return the runInterval
+ */
+ public int getRunInterval() {
+ return runInterval;
+ }
+
+ /**
+ * @param runInterval The runInterval to set.
+ */
+ public void setRunInterval(int runInterval) {
+ this.runInterval = runInterval;
+ }
+ /**
* Thread that repeatedly calls mergeAll on the BDBIndexUpdater.
*
* @author Brad Tofel
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|