Cleaned up a handful of uglinesses in moving AVM configuration into

Alfresco app configuration, mostly related to getting testing to
work smoothly.  Also reworked OrphanReaper to be better behaved
and nominally more efficient.  


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3419 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-07-27 00:47:56 +00:00
parent 6692c7a979
commit 4ab5a046c2
10 changed files with 113 additions and 59 deletions

View File

@@ -17,6 +17,7 @@
package org.alfresco.repo.avm;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.logging.Log;
@@ -66,6 +67,16 @@ class OrphanReaper implements Runnable
*/
private Thread fThread;
/**
* The maximum length of the queue.
*/
private int fQueueLength;
/**
* The linked list containing ids of nodes that are purgable.
*/
private LinkedList<Long> fPurgeQueue;
/**
* Create one with default parameters.
*/
@@ -74,6 +85,7 @@ class OrphanReaper implements Runnable
fInactiveBaseSleep = 30000;
fActiveBaseSleep = 1000;
fBatchSize = 50;
fQueueLength = 1000;
fActive = false;
fDone = false;
}
@@ -116,6 +128,15 @@ class OrphanReaper implements Runnable
fTransaction = transaction;
}
/**
* Set the maximum size of the queue of purgeable nodes.
* @param queueLength The max length.
*/
public void setMaxQueueLength(int queueLength)
{
fQueueLength = queueLength;
}
/**
* Start things up after configuration is complete.
*/
@@ -131,7 +152,11 @@ class OrphanReaper implements Runnable
*/
void shutDown()
{
fDone = true;
synchronized (this)
{
fDone = true;
notify();
}
try
{
fThread.join();
@@ -150,15 +175,18 @@ class OrphanReaper implements Runnable
{
while (!fDone)
{
try
synchronized (this)
{
Thread.sleep(fActive ? fActiveBaseSleep : fInactiveBaseSleep);
try
{
wait(fActive? fActiveBaseSleep : fInactiveBaseSleep);
}
catch (InterruptedException ie)
{
// Do nothing.
}
doBatch();
}
catch (InterruptedException ie)
{
// Do nothing.
}
doBatch();
}
}
@@ -189,15 +217,29 @@ class OrphanReaper implements Runnable
{
public void perform()
{
List<AVMNode> nodes = AVMContext.fgInstance.fAVMNodeDAO.getOrphans(fBatchSize);
if (nodes.size() == 0)
if (fPurgeQueue == null)
{
fActive = false;
return;
List<AVMNode> nodes = AVMContext.fgInstance.fAVMNodeDAO.getOrphans(fQueueLength);
if (nodes.size() == 0)
{
fActive = false;
return;
}
fPurgeQueue = new LinkedList<Long>();
for (AVMNode node : nodes)
{
fPurgeQueue.add(node.getId());
}
}
fActive = true;
for (AVMNode node : nodes)
for (int i = 0; i < fBatchSize; i++)
{
if (fPurgeQueue.size() == 0)
{
fPurgeQueue = null;
return;
}
AVMNode node = AVMContext.fgInstance.fAVMNodeDAO.getByID(fPurgeQueue.removeFirst());
// Save away the ancestor and merged from fields from this node.
HistoryLink hlink = AVMContext.fgInstance.fHistoryLinkDAO.getByDescendent(node);
AVMNode ancestor = null;