diff --git a/config/alfresco/avm-services-context.xml b/config/alfresco/avm-services-context.xml
index 073810ddfa..e102dee36f 100644
--- a/config/alfresco/avm-services-context.xml
+++ b/config/alfresco/avm-services-context.xml
@@ -160,10 +160,7 @@
-
- 60000
-
+ depends-on="AVMService" destroy-method="shutDown">
1000
diff --git a/config/alfresco/scheduled-jobs-context.xml b/config/alfresco/scheduled-jobs-context.xml
index db0a97221f..ae6ae52cc8 100644
--- a/config/alfresco/scheduled-jobs-context.xml
+++ b/config/alfresco/scheduled-jobs-context.xml
@@ -181,4 +181,29 @@
+
+
+
+
+ org.alfresco.repo.avm.OrphanReaperJob
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+ 1
+
+
\ No newline at end of file
diff --git a/source/java/org/alfresco/repo/avm/OrphanReaper.java b/source/java/org/alfresco/repo/avm/OrphanReaper.java
index 473c1b4a77..c457e15c2d 100644
--- a/source/java/org/alfresco/repo/avm/OrphanReaper.java
+++ b/source/java/org/alfresco/repo/avm/OrphanReaper.java
@@ -38,8 +38,46 @@ import org.springframework.orm.hibernate3.HibernateTemplate;
* in the AVM repository. These orphans arise from purge operations.
* @author britt
*/
-public class OrphanReaper implements Runnable
+public class OrphanReaper
{
+ public void execute()
+ {
+ synchronized (this)
+ {
+ if (fRunning)
+ {
+ return;
+ }
+ fRunning = true;
+ }
+ try
+ {
+ do
+ {
+ doBatch();
+ if (fDone)
+ {
+ return;
+ }
+ try
+ {
+ Thread.sleep(fActiveBaseSleep);
+ }
+ catch (InterruptedException e)
+ {
+ // Do nothing.
+ }
+ } while (fActive);
+ }
+ finally
+ {
+ synchronized (this)
+ {
+ fRunning = false;
+ }
+ }
+ }
+
private Logger fgLogger = Logger.getLogger(OrphanReaper.class);
/**
@@ -52,11 +90,6 @@ public class OrphanReaper implements Runnable
*/
private SessionFactory fSessionFactory;
- /**
- * Inactive base sleep interval.
- */
- private long fInactiveBaseSleep;
-
/**
* Active base sleep interval.
*/
@@ -73,16 +106,6 @@ public class OrphanReaper implements Runnable
*/
private boolean fActive;
- /**
- * Flag for shutting down this.
- */
- private boolean fDone;
-
- /**
- * The thread for this.
- */
- private Thread fThread;
-
/**
* The maximum length of the queue.
*/
@@ -93,30 +116,23 @@ public class OrphanReaper implements Runnable
*/
private LinkedList fPurgeQueue;
+ private boolean fDone = false;
+
+ private boolean fRunning = false;
+
/**
* Create one with default parameters.
*/
public OrphanReaper()
{
- fInactiveBaseSleep = 30000;
fActiveBaseSleep = 1000;
fBatchSize = 50;
fQueueLength = 1000;
fActive = false;
- fDone = false;
}
// Setters for configuration.
- /**
- * Set the Inactive Base Sleep interval.
- * @param interval The interval to set in ms.
- */
- public void setInactiveBaseSleep(long interval)
- {
- fInactiveBaseSleep = interval;
- }
-
/**
* Set the active base sleep interval.
* @param interval The interval to set in ms.
@@ -165,11 +181,11 @@ public class OrphanReaper implements Runnable
/**
* Start things up after configuration is complete.
*/
- public void init()
- {
- fThread = new Thread(this);
- fThread.start();
- }
+// public void init()
+// {
+// fThread = new Thread(this);
+// fThread.start();
+// }
/**
* Shutdown the reaper. This needs to be called when
@@ -177,43 +193,31 @@ public class OrphanReaper implements Runnable
*/
public void shutDown()
{
- synchronized (this)
- {
- fDone = true;
- notify();
- }
- try
- {
- fThread.join();
- }
- catch (InterruptedException ie)
- {
- // Do nothing.
- }
+ fDone = true;
}
/**
* Sit in a loop, periodically querying for orphans. When orphans
* are found, unhook them in bite sized batches.
*/
- public void run()
- {
- while (!fDone)
- {
- synchronized (this)
- {
- try
- {
- wait(fActive? fActiveBaseSleep : fInactiveBaseSleep);
- }
- catch (InterruptedException ie)
- {
- // Do nothing.
- }
- doBatch();
- }
- }
- }
+// public void run()
+// {
+// while (!fDone)
+// {
+// synchronized (this)
+// {
+// try
+// {
+// wait(fActive? fActiveBaseSleep : fInactiveBaseSleep);
+// }
+// catch (InterruptedException ie)
+// {
+// // Do nothing.
+// }
+// doBatch();
+// }
+// }
+// }
/**
* This is really for debugging and testing. Allows another thread to
diff --git a/source/java/org/alfresco/repo/avm/OrphanReaperJob.java b/source/java/org/alfresco/repo/avm/OrphanReaperJob.java
new file mode 100644
index 0000000000..be2b85b460
--- /dev/null
+++ b/source/java/org/alfresco/repo/avm/OrphanReaperJob.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2005-2007 Alfresco Software Limited.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing
+ */
+
+package org.alfresco.repo.avm;
+
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+/**
+ * Quartz wrapper for OrphanReaper.
+ * @author britt
+ */
+public class OrphanReaperJob implements Job
+{
+ /* (non-Javadoc)
+ * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
+ */
+ public void execute(JobExecutionContext context) throws JobExecutionException
+ {
+ OrphanReaper reaper = (OrphanReaper)context.getJobDetail().getJobDataMap().get("orphanReaper");
+ reaper.execute();
+ }
+}