From 30d08687ea07115f607872e754739c5ac282d323 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Thu, 23 Jun 2011 14:09:51 +0000 Subject: [PATCH] Removing sleep() from the sweeper (use an executor, instead) git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Collector@40763 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../impl/xmlstorage/exist/sweep/Sweeper.java | 61 +++++++++---------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/sweep/Sweeper.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/sweep/Sweeper.java index 89ceb54..5a195ec 100755 --- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/sweep/Sweeper.java +++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/sweep/Sweeper.java @@ -18,11 +18,11 @@ import org.gcube.informationsystem.collector.impl.resources.GCUBEInstanceStateRe import org.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource; /** - * This class provides some cleanup procedures to use to maintain a consistent - * content in the XML storage. One of them is a thread, activated at RI startup - * time, that periodically drops the out to date resources from the storage + * This class provides some cleanup procedures to use to maintain a consistent content in the XML + * storage. One of them is a thread, activated at RI startup time, that periodically drops the out + * to date resources from the storage * - * @author Manuele Simi (ISTI-CNR) + * @author Manuele Simi (ISTI-CNR) * */ public class Sweeper implements Runnable { @@ -33,38 +33,34 @@ public class Sweeper implements Runnable { private static GCUBELog logger = new GCUBELog(Sweeper.class); - //private static XMLStorage storage = null; + // private static XMLStorage storage = null; /** * Initializes a new Sweeper * - * @param delay the sweeper delay - * @param resourceExpirationTime the time after that a resource is classified as exipired - * @throws Exception if the eXist connection fails + * @param delay + * the sweeper delay + * @param resourceExpirationTime + * the time after that a resource is classified as exipired + * @throws Exception + * if the eXist connection fails */ public Sweeper(long delay, long resourceExpirationTime) throws Exception { Sweeper.DELAY = delay; Sweeper.resourceExpirationTime = resourceExpirationTime; logger.info("Starting sweeper thread with an interval of " + Sweeper.DELAY + " ms"); - + } /** * {@inheritDoc} */ public void run() { - if (Sweeper.DELAY == -1) return; - try { - while (!Thread.interrupted()) { - Thread.sleep(Sweeper.DELAY); - logger.info("Starting IC sweeper..."); - this.cleanDeletedResourcesList(); - this.cleanExpiredResources(); - } - } catch (InterruptedException ie) { - logger.error("Unable to sleep (yawn)", ie); - // thread was interrupted - } + if (Sweeper.DELAY == -1) + return; + logger.info("Starting IC sweeper..."); + this.cleanDeletedResourcesList(); + this.cleanExpiredResources(); } /** @@ -77,14 +73,14 @@ public class Sweeper implements Runnable { now.setTimeZone(TimeZone.getTimeZone("GMT")); try { GCUBEInstanceStateResource fakeresource = new GCUBEInstanceStateResource(); - //get all IDs for Instance States' collection + // get all IDs for Instance States' collection String[] ids = State.getDataManager().listAllCollectionResourceIDs(fakeresource.getCollectionName()); for (String id : ids) { try { GCUBEInstanceStateResource tempresource = new GCUBEInstanceStateResource(); tempresource.setResourceName(id); - GCUBEXMLResource xmlresource = new GCUBEXMLResource(tempresource); - State.getDataManager().retrieveResourceContent(xmlresource); + GCUBEXMLResource xmlresource = new GCUBEXMLResource(tempresource); + State.getDataManager().retrieveResourceContent(xmlresource); logger.trace("Checking resource " + id); if (ResourceFilter.isExpired(xmlresource)) { // removes the resources from the database @@ -93,29 +89,28 @@ public class Sweeper implements Runnable { } // break; } catch (Exception e) { - logger.debug("IC sweeper - the resource " + id + " is no longer available in the storage"); + logger.debug("IC sweeper - the resource " + id + " is no longer available in the storage"); } } } catch (Exception e2) { - logger.warn("IC sweeper - an exception was rised when trying to cleanup the storage ", e2); + logger.warn("IC sweeper - an exception was rised when trying to cleanup the storage ", e2); } } - /** * Deletes the Properties collection from the storage - * @throws XMLStorageNotAvailableException + * + * @throws XMLStorageNotAvailableException * */ public static void cleanRPs() throws XMLStorageNotAvailableException { - // cleanup the RPs collection + // cleanup the RPs collection State.getDataManager().deleteCollection(new GCUBEInstanceStateResource().getCollectionName()); } /** - * Deletes the expired resources from the list of deleted resources as - * notified by the AF + * Deletes the expired resources from the list of deleted resources as notified by the AF * */ @@ -123,7 +118,7 @@ public class Sweeper implements Runnable { Calendar now = new GregorianCalendar(); now.setTimeZone(TimeZone.getTimeZone("GMT")); - List toRemove = new ArrayList(); + List toRemove = new ArrayList(); for (GCUBEXMLResource res : State.deletedResources) { try { if (now.getTimeInMillis() - res.getLastUpdateTimeinMills() > Sweeper.resourceExpirationTime) { @@ -145,7 +140,7 @@ public class Sweeper implements Runnable { * @return the sweeper interval */ public long getIntervalInMS() { - return DELAY; + return DELAY; } }