Converted OrphanReaper thread into quartz job, as requested. Fixes AR-1450.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5661 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park 2007-05-10 18:23:12 +00:00
parent 3d47482757
commit 01ade4da9e
4 changed files with 139 additions and 67 deletions

View File

@ -160,10 +160,7 @@
<bean id="rawServices" class="org.alfresco.repo.avm.util.RawServices"/> <bean id="rawServices" class="org.alfresco.repo.avm.util.RawServices"/>
<bean id="orphanReaper" class="org.alfresco.repo.avm.OrphanReaper" <bean id="orphanReaper" class="org.alfresco.repo.avm.OrphanReaper"
init-method="init" destroy-method="shutDown" depends-on="AVMService"> depends-on="AVMService" destroy-method="shutDown">
<property name="inactiveBaseSleep">
<value>60000</value>
</property>
<property name="activeBaseSleep"> <property name="activeBaseSleep">
<value>1000</value> <value>1000</value>
</property> </property>

View File

@ -181,4 +181,29 @@
</property> </property>
</bean> </bean>
<bean id="avmOrphanReaperJob" class="org.alfresco.util.TriggerBean">
<property name="jobDetail">
<bean id="avmOrphanReaperJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>org.alfresco.repo.avm.OrphanReaperJob</value>
</property>
<property name="jobDataAsMap">
<map>
<entry key="orphanReaper">
<ref bean="orphanReaper"/>
</entry>
</map>
</property>
</bean>
</property>
<property name="scheduler">
<ref bean="schedulerFactory"/>
</property>
<property name="startDelayMinutes">
<value>1</value>
</property>
<property name="repeatIntervalMinutes">
<value>1</value>
</property>
</bean>
</beans> </beans>

View File

@ -38,8 +38,46 @@ import org.springframework.orm.hibernate3.HibernateTemplate;
* in the AVM repository. These orphans arise from purge operations. * in the AVM repository. These orphans arise from purge operations.
* @author britt * @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); private Logger fgLogger = Logger.getLogger(OrphanReaper.class);
/** /**
@ -52,11 +90,6 @@ public class OrphanReaper implements Runnable
*/ */
private SessionFactory fSessionFactory; private SessionFactory fSessionFactory;
/**
* Inactive base sleep interval.
*/
private long fInactiveBaseSleep;
/** /**
* Active base sleep interval. * Active base sleep interval.
*/ */
@ -73,16 +106,6 @@ public class OrphanReaper implements Runnable
*/ */
private boolean fActive; private boolean fActive;
/**
* Flag for shutting down this.
*/
private boolean fDone;
/**
* The thread for this.
*/
private Thread fThread;
/** /**
* The maximum length of the queue. * The maximum length of the queue.
*/ */
@ -93,30 +116,23 @@ public class OrphanReaper implements Runnable
*/ */
private LinkedList<Long> fPurgeQueue; private LinkedList<Long> fPurgeQueue;
private boolean fDone = false;
private boolean fRunning = false;
/** /**
* Create one with default parameters. * Create one with default parameters.
*/ */
public OrphanReaper() public OrphanReaper()
{ {
fInactiveBaseSleep = 30000;
fActiveBaseSleep = 1000; fActiveBaseSleep = 1000;
fBatchSize = 50; fBatchSize = 50;
fQueueLength = 1000; fQueueLength = 1000;
fActive = false; fActive = false;
fDone = false;
} }
// Setters for configuration. // 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. * Set the active base sleep interval.
* @param interval The interval to set in ms. * @param interval The interval to set in ms.
@ -165,55 +181,43 @@ public class OrphanReaper implements Runnable
/** /**
* Start things up after configuration is complete. * Start things up after configuration is complete.
*/ */
public void init() // public void init()
{ // {
fThread = new Thread(this); // fThread = new Thread(this);
fThread.start(); // fThread.start();
} // }
/** /**
* Shutdown the reaper. This needs to be called when * Shutdown the reaper. This needs to be called when
* the application shuts down. * the application shuts down.
*/ */
public void shutDown() public void shutDown()
{
synchronized (this)
{ {
fDone = true; fDone = true;
notify();
}
try
{
fThread.join();
}
catch (InterruptedException ie)
{
// Do nothing.
}
} }
/** /**
* Sit in a loop, periodically querying for orphans. When orphans * Sit in a loop, periodically querying for orphans. When orphans
* are found, unhook them in bite sized batches. * are found, unhook them in bite sized batches.
*/ */
public void run() // public void run()
{ // {
while (!fDone) // while (!fDone)
{ // {
synchronized (this) // synchronized (this)
{ // {
try // try
{ // {
wait(fActive? fActiveBaseSleep : fInactiveBaseSleep); // wait(fActive? fActiveBaseSleep : fInactiveBaseSleep);
} // }
catch (InterruptedException ie) // catch (InterruptedException ie)
{ // {
// Do nothing. // // Do nothing.
} // }
doBatch(); // doBatch();
} // }
} // }
} // }
/** /**
* This is really for debugging and testing. Allows another thread to * This is really for debugging and testing. Allows another thread to

View File

@ -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();
}
}