Improved log and configurable interval for eliminate pool thread

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@15219 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2009-09-11 15:38:06 +00:00
parent 4cf1a9f3f4
commit 82f3d44967
2 changed files with 50 additions and 50 deletions

View File

@ -22,7 +22,11 @@
type="java.lang.Long"
override="false" />
<environment
name="temporaryResourceSweeperIntervalInMs"
value="480000"
type="java.lang.Long"
override="false" />
<!--
<environment

View File

@ -5,72 +5,68 @@ import java.util.LinkedList;
import java.util.List;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
/**
*
* Manages the asynchronous deletion of temporary resources
*
*
* @author Lucio Lelii, Manuele Simi (ISTI-CNR)
*
*
*/
public class EliminatePoolingThread extends Thread {
private final long sleepTime = 60000;
private final long sleepTime = (Long) ServiceContext.getContext().getProperty("temporaryResourceSweeperIntervalInMs");;
private List<Pair> stack = Collections.synchronizedList(new LinkedList<Pair>());
private List<Pair> stack = Collections.synchronizedList(new LinkedList<Pair>());
private static GCUBELog logger = new GCUBELog(EliminatePoolingThread.class.getName());
private static GCUBELog logger = new GCUBELog(EliminatePoolingThread.class);
@SuppressWarnings("static-access")
public void run() {
boolean noErrors = true;
while (noErrors) {
try {
this.sleep(sleepTime);
} catch (InterruptedException e) {
}
public void run() {
LinkedList<Pair> tmpStack = new LinkedList<Pair>();
boolean noErrors = true;
try {
long timestamp = System.currentTimeMillis();
while (noErrors) {
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {}
synchronized (stack) {
int numRes = stack.size();
while (stack.size() > 0) {
Pair c = stack.remove(stack.size() - 1);
logger.trace("checking resource for deletion " + c.resource.getID());
logger.trace("timenstamp now: " + timestamp + ", resource lifetime: " + c.lifetime);
if ((timestamp >= c.lifetime)) {
try {
logger.debug("temporary resource " + c.resource.getID() + " is going to be deleted");
ProfileContext.getContext().getWSHome().remove(c.resource.getID());
} catch (Exception e) {
logger.error(e);
tmpStack.offer(c);//re-insert the resource in the list
}
} else {
tmpStack.offer(c); //re-insert the resource in the list
LinkedList<Pair> tmpStack = new LinkedList<Pair>();
try {
long timestamp = System.currentTimeMillis();
synchronized (stack) {
int numRes = stack.size();
while (stack.size() > 0) {
Pair c = stack.remove(stack.size() - 1);
logger.trace("checking resource for deletion " + c.resource.getID());
logger.trace("timenstamp now: " + timestamp + ", resource lifetime: " + c.lifetime);
if (timestamp >= c.lifetime) {
try {
logger.debug("temporary resource " + c.resource.getID() + " is going to be deleted");
ProfileContext.getContext().getWSHome().remove(c.resource.getID());
} catch (Exception e) {
logger.error(e);
tmpStack.offer(c);// re-insert the resource in the list
}
} else {
tmpStack.offer(c); // re-insert the resource in the list
}
}
logger.debug("cannot destroy " + tmpStack.size() + " resources retrying in 30 seconds");
logger.debug("destroyed " + (numRes - tmpStack.size()) + " resources ");
stack.addAll(tmpStack);
} // end synchronized block
} catch (Exception e) {
logger.error("Cannot continue with thread Excecution " + e);
noErrors = false;
}
}
logger.debug("cannot destroy " + tmpStack.size() + " resources retrying in 30 seconds");
logger.debug("destroyed " + (numRes - tmpStack.size()) + " resources ");
stack.addAll(tmpStack);
} //end synchronized block
} catch (Exception e) {
logger.error("Cannot continue with thread Excecution " + e);
noErrors = false;
}
}
}
}
public synchronized List<Pair> getStack() {
return this.stack;
}
public synchronized List<Pair> getStack() {
return this.stack;
}
}