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" type="java.lang.Long"
override="false" /> override="false" />
<environment
name="temporaryResourceSweeperIntervalInMs"
value="480000"
type="java.lang.Long"
override="false" />
<!-- <!--
<environment <environment

View File

@ -5,72 +5,68 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.registry.impl.contexts.ProfileContext; import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
import org.gcube.informationsystem.registry.impl.contexts.ServiceContext;
/** /**
* *
* Manages the asynchronous deletion of temporary resources * Manages the asynchronous deletion of temporary resources
* *
* @author Lucio Lelii, Manuele Simi (ISTI-CNR) * @author Lucio Lelii, Manuele Simi (ISTI-CNR)
* *
*/ */
public class EliminatePoolingThread extends Thread { 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() {
public void run() {
boolean noErrors = true;
while (noErrors) {
try {
this.sleep(sleepTime);
} catch (InterruptedException e) {
}
LinkedList<Pair> tmpStack = new LinkedList<Pair>(); boolean noErrors = true;
try { while (noErrors) {
long timestamp = System.currentTimeMillis(); try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {}
synchronized (stack) { LinkedList<Pair> tmpStack = new LinkedList<Pair>();
int numRes = stack.size(); try {
while (stack.size() > 0) { long timestamp = System.currentTimeMillis();
Pair c = stack.remove(stack.size() - 1); synchronized (stack) {
logger.trace("checking resource for deletion " + c.resource.getID()); int numRes = stack.size();
logger.trace("timenstamp now: " + timestamp + ", resource lifetime: " + c.lifetime); while (stack.size() > 0) {
if ((timestamp >= c.lifetime)) { Pair c = stack.remove(stack.size() - 1);
try { logger.trace("checking resource for deletion " + c.resource.getID());
logger.debug("temporary resource " + c.resource.getID() + " is going to be deleted"); logger.trace("timenstamp now: " + timestamp + ", resource lifetime: " + c.lifetime);
ProfileContext.getContext().getWSHome().remove(c.resource.getID()); if (timestamp >= c.lifetime) {
} catch (Exception e) { try {
logger.error(e); logger.debug("temporary resource " + c.resource.getID() + " is going to be deleted");
tmpStack.offer(c);//re-insert the resource in the list ProfileContext.getContext().getWSHome().remove(c.resource.getID());
} } catch (Exception e) {
} else { logger.error(e);
tmpStack.offer(c); //re-insert the resource in the list 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() { public synchronized List<Pair> getStack() {
return this.stack; return this.stack;
} }
} }