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:
parent
4cf1a9f3f4
commit
82f3d44967
|
@ -22,7 +22,11 @@
|
|||
type="java.lang.Long"
|
||||
override="false" />
|
||||
|
||||
|
||||
<environment
|
||||
name="temporaryResourceSweeperIntervalInMs"
|
||||
value="480000"
|
||||
type="java.lang.Long"
|
||||
override="false" />
|
||||
|
||||
<!--
|
||||
<environment
|
||||
|
|
|
@ -5,6 +5,7 @@ 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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -15,51 +16,46 @@ import org.gcube.informationsystem.registry.impl.contexts.ProfileContext;
|
|||
*/
|
||||
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 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) {
|
||||
}
|
||||
Thread.sleep(sleepTime);
|
||||
} catch (InterruptedException e) {}
|
||||
|
||||
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)) {
|
||||
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
|
||||
tmpStack.offer(c);// re-insert the resource in the list
|
||||
}
|
||||
} else {
|
||||
tmpStack.offer(c); //re-insert the resource in the list
|
||||
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
|
||||
} // end synchronized block
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Cannot continue with thread Excecution " + e);
|
||||
|
|
Loading…
Reference in New Issue