Changing service's initialization procedure, more control on activated threads

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Collector@40762 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2011-06-23 14:08:23 +00:00
parent d59cdac63c
commit 5e0baa7201
6 changed files with 39 additions and 43 deletions

View File

@ -8,6 +8,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/EXISTLIBS"/>
<classpathentry kind="lib" path="/Dependencies/ISCollector/org.gcube.informationsystem.collector.stubs.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry combineaccessrules="false" kind="src" path="/GCF.1.1.0"/>
<classpathentry combineaccessrules="false" kind="src" path="/GCF.1.2.0"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -123,7 +123,6 @@ public class XMLStorageAccess extends GCUBEPortType {
logger.info("Connect operation invoked");
try {
State.initialize();
//ICServiceContext.getContext().setStatus(Status.READIED);
} catch (Exception e) {
logger.error("Initialisation failed", e);
XMLStorageNotAvailableFaultType fault = new XMLStorageNotAvailableFaultType();

View File

@ -29,7 +29,6 @@ public abstract class Scheduler implements Runnable {
public void run() {
do {
try {
Thread.sleep(this.intervalInMS);
this.doBackup();
@ -39,10 +38,7 @@ public abstract class Scheduler implements Runnable {
logger.error("Unable to backup", e);
}
} while (! Thread.interrupted());
//logger.info("Backup Scheduler was interrupted");
}
}
/**
* Performs the backup
@ -50,5 +46,12 @@ public abstract class Scheduler implements Runnable {
* @throws Exception if the backup fails
*/
protected abstract void doBackup() throws Exception;
/**
* @return the intervalInMS
*/
public int getIntervalInMS() {
return intervalInMS;
}
}

View File

@ -12,6 +12,8 @@ import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Collections;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/**
* The global state of an IC instance
@ -31,11 +33,6 @@ public class State {
*/
private static QueryManager queryManager;
/** Thread that periodically sweeps the XMLStorage from expired resources */
public static Thread sweeperT = null;
/** Thread that periodically backups the XMLStorage */
public static Thread schedulerT = null;
/**
* List of recently deleted resources. It is used to avoid the storage of RPs of a deleted
@ -44,6 +41,8 @@ public class State {
public static List<GCUBEXMLResource> deletedResources = Collections.synchronizedList(new ArrayList<GCUBEXMLResource>());
private static GCUBELog logger = new GCUBELog(State.class);
private static boolean isInitialized = false;
/**
* Initializes the eXist DB connections using during the service life
@ -55,6 +54,10 @@ public class State {
*/
public static void initialize() throws Exception {
logger.info("Starting IC service initialization...");
if (isInitialized) {
logger.info("Service's state is already initialized");
return;
}
long maxOperations = Long.valueOf((String) ICServiceContext.getContext().getProperty("maxOperationsPerConnection", true));
State.initializeDataManager(maxOperations);
State.initializeQueryManager(maxOperations);
@ -72,25 +75,16 @@ public class State {
logger.info("Initialising the sweeper...");
// start the sweeper to periodically cleanup the storage and some data structures
if (State.sweeperT == null) {
Sweeper sweeper = new Sweeper(Long.valueOf((String) ICServiceContext.getContext().getProperty("sweeperIntervalInMillis", true)),
Long.valueOf((String) ICServiceContext.getContext().getProperty("resourceExpirationTimeInMillis", true)));
State.sweeperT = new Thread(sweeper);
State.sweeperT.setName("ICSweeper");
State.sweeperT.start();
}
Sweeper sweeper = new Sweeper(Long.valueOf((String) ICServiceContext.getContext().getProperty("sweeperIntervalInMillis", true)),
Long.valueOf((String) ICServiceContext.getContext().getProperty("resourceExpirationTimeInMillis", true)));
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(sweeper, sweeper.getIntervalInMS(), sweeper.getIntervalInMS(), TimeUnit.MILLISECONDS);
//start the scheduler for automatic backups (if any)
logger.info("Initialising the scheduled backups...");
org.gcube.informationsystem.collector.impl.xmlstorage.backup.Scheduler scheduler = DataManager.getScheduler();
if (scheduler != null) {
if (State.schedulerT == null)
State.schedulerT = new Thread(scheduler);
State.schedulerT.setName("BackupScheduler");
State.schedulerT.start();
}
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(scheduler, scheduler.getIntervalInMS(), scheduler.getIntervalInMS(), TimeUnit.MILLISECONDS);
logger.info("IC service initialization completed");
isInitialized = true;
}
private static void initializeDataManager(long maxOperations) throws Exception {
@ -118,17 +112,21 @@ public class State {
*/
public static void dispose() throws Exception {
logger.info("Disposing IC service's resources...");
if (State.sweeperT != null) {
if (!isInitialized) {
logger.info("Service's state is already disposed");
return;
}
/*if (State.sweeperT != null) {
State.sweeperT.interrupt();
State.sweeperT = null;
}
if (State.schedulerT == null) {
State.schedulerT.interrupt();
State.schedulerT = null;
}
}*/
State.dataManager.shutdown(true);
State.queryManager.shutdown(true);
isInitialized = false;
}
/**

View File

@ -102,17 +102,6 @@ public class Sweeper implements Runnable {
}
}
/**
* Removes all the properties documents related to the given Running
* Instance ID
*
* @param id
* the ID of the Running Instance whose properties documents have
* to be removed
*/
public static void cleanResourceForRI(String id) {
// TO DO
}
/**
* Deletes the Properties collection from the storage
@ -152,4 +141,11 @@ public class Sweeper implements Runnable {
}
/**
* @return the sweeper interval
*/
public long getIntervalInMS() {
return DELAY;
}
}

View File

@ -48,10 +48,10 @@ public class ConnectTester {
port = new XMLStorageAccessServiceLocator().getXMLStorageAccessPortTypePort(new URL(portTypeURI));
port = GCUBERemotePortTypeContext.getProxy(port, GCUBEScope.getScope(args[2]));
} catch (Exception e) {
logger.error("",e);
logger.error("Unable to create the IC portType",e);
}
logger.info("Submitting shutdown request to " + portTypeURI+ "...");
logger.info("Submitting connect request to " + portTypeURI+ "...");
try {
port.connect(new VOID());