2009-08-17 19:32:15 +02:00
|
|
|
package org.gcube.informationsystem.collector.impl.xmlstorage.exist;
|
|
|
|
|
2009-08-26 03:25:38 +02:00
|
|
|
import org.gcube.common.core.utils.logging.GCUBELog;
|
2009-08-17 19:32:15 +02:00
|
|
|
import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext;
|
|
|
|
import org.gcube.informationsystem.collector.impl.persistence.AggregatorPersistentResource;
|
2009-08-27 19:10:46 +02:00
|
|
|
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XMLStorageManager.STATUS;
|
2009-08-17 19:32:15 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Enumeration;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
/**
|
2009-08-25 03:33:19 +02:00
|
|
|
* The global state of an IC instance
|
2009-08-17 19:32:15 +02:00
|
|
|
*
|
2009-08-25 03:33:19 +02:00
|
|
|
* @author Manuele Simi (ISTI-CNR)
|
2009-08-17 19:32:15 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class State {
|
|
|
|
|
|
|
|
/**
|
2009-08-26 03:25:38 +02:00
|
|
|
* Connection to XMLStorage for data management
|
2009-08-17 19:32:15 +02:00
|
|
|
*/
|
2009-08-26 03:25:38 +02:00
|
|
|
private static DataManager dataManager;
|
2009-08-17 19:32:15 +02:00
|
|
|
|
|
|
|
/**
|
2009-08-26 03:25:38 +02:00
|
|
|
* Connection to XMLStorage for querying the data
|
2009-08-17 19:32:15 +02:00
|
|
|
*/
|
2009-08-25 03:33:19 +02:00
|
|
|
private static QueryManager queryManager;
|
2009-08-17 19:32:15 +02:00
|
|
|
|
2009-08-26 03:25:38 +02:00
|
|
|
/** Thread that periodically sweeps the XMLStorage from expired resources */
|
2009-08-27 19:10:46 +02:00
|
|
|
public static Thread sweeperT = null;
|
2009-08-26 03:25:38 +02:00
|
|
|
|
|
|
|
/** Thread that periodically backups the XMLStorage */
|
2009-08-27 19:10:46 +02:00
|
|
|
public static Thread schedulerT = null;
|
2009-08-17 19:32:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of recently deleted resources. It is used to avoid the storage of RPs of a deleted
|
|
|
|
* resource
|
|
|
|
*/
|
|
|
|
public static List<AggregatorPersistentResource> deletedResources = Collections.synchronizedList(new ArrayList<AggregatorPersistentResource>());
|
|
|
|
|
2009-08-26 03:25:38 +02:00
|
|
|
private static GCUBELog logger = new GCUBELog(State.class);
|
2009-08-17 19:32:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the eXist DB connections using during the service life
|
|
|
|
*
|
|
|
|
* @param configuration
|
|
|
|
* the RI configuration loaded from the JNDI resource
|
|
|
|
* @throws Exception
|
|
|
|
* if the intialization fails
|
|
|
|
*/
|
|
|
|
public static void initialize() throws Exception {
|
|
|
|
logger.info("starting IC service initialization...");
|
2009-08-25 03:33:19 +02:00
|
|
|
State.initializeDataManager();
|
2009-08-17 19:32:15 +02:00
|
|
|
State.initializeQueryManager();
|
|
|
|
if (Boolean.valueOf((String) ICServiceContext.getContext().getProperty("deleteRPsOnStartup", true))) {
|
|
|
|
// cleanup the RPs collection
|
|
|
|
logger.info("deleting all RPs...");
|
2009-08-26 03:25:38 +02:00
|
|
|
State.dataManager.deleteAllProperties();
|
2009-08-17 19:32:15 +02:00
|
|
|
} else {
|
|
|
|
logger.info("all RPs previously stored are keept in the storage");
|
|
|
|
}
|
|
|
|
|
2009-08-27 00:57:18 +02:00
|
|
|
logger.info("Initialising the sweeper...");
|
2009-08-17 19:32:15 +02:00
|
|
|
// start the sweeper to periodically cleanup the storage and some data structures
|
2009-08-27 19:10:46 +02:00
|
|
|
if (State.sweeperT == null) {
|
2009-08-28 19:58:13 +02:00
|
|
|
Sweeper sweeper = new Sweeper(Long.valueOf((String) ICServiceContext.getContext().getProperty("sweeperIntervalInMillis", true)), Long.valueOf((String) ICServiceContext.getContext()
|
2009-08-27 19:10:46 +02:00
|
|
|
.getProperty("resourceExpirationTimeInMillis", true)));
|
|
|
|
State.sweeperT = new Thread(sweeper);
|
|
|
|
State.sweeperT.start();
|
|
|
|
}
|
|
|
|
|
2009-08-26 03:25:38 +02:00
|
|
|
|
|
|
|
//start the scheduler for automatic backups (if any)
|
2009-08-27 00:57:18 +02:00
|
|
|
logger.info("Initialising the scheduled backups...");
|
2009-08-26 03:25:38 +02:00
|
|
|
org.gcube.informationsystem.collector.impl.xmlstorage.backup.Scheduler scheduler = DataManager.getScheduler();
|
|
|
|
if (scheduler != null) {
|
2009-08-27 19:10:46 +02:00
|
|
|
if (State.schedulerT == null)
|
|
|
|
State.schedulerT = new Thread(scheduler);
|
|
|
|
State.schedulerT.start();
|
2009-08-26 03:25:38 +02:00
|
|
|
}
|
2009-08-17 19:32:15 +02:00
|
|
|
logger.info("IC service initialization completed");
|
|
|
|
}
|
|
|
|
|
2009-08-25 03:33:19 +02:00
|
|
|
private static void initializeDataManager() throws Exception {
|
2009-08-27 19:10:46 +02:00
|
|
|
if (State.dataManager == null)
|
|
|
|
State.dataManager = new DataManager();
|
|
|
|
if (State.dataManager.getStatus() != STATUS.INITIALISED)
|
|
|
|
dataManager.initialize();
|
|
|
|
else
|
|
|
|
logger.info("DataManager already initalized");
|
2009-08-17 19:32:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void initializeQueryManager() throws Exception {
|
2009-08-27 19:10:46 +02:00
|
|
|
if (State.queryManager == null)
|
|
|
|
State.queryManager = new QueryManager();
|
|
|
|
if (State.queryManager.getStatus() != STATUS.INITIALISED)
|
|
|
|
queryManager.initialize();
|
|
|
|
else
|
|
|
|
logger.info("QueryManager already initalized");
|
2009-08-17 19:32:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Releases all the State resources
|
|
|
|
*
|
|
|
|
* @throws Exception if the shutdown fails
|
|
|
|
*/
|
|
|
|
public static void dispose() throws Exception {
|
|
|
|
logger.info("Disposing IC service's resources...");
|
2009-08-26 03:25:38 +02:00
|
|
|
State.sweeperT.interrupt();
|
2009-08-27 19:10:46 +02:00
|
|
|
State.sweeperT = null;
|
2009-08-26 03:25:38 +02:00
|
|
|
State.schedulerT.interrupt();
|
2009-08-27 19:10:46 +02:00
|
|
|
State.schedulerT = null;
|
2009-08-26 03:25:38 +02:00
|
|
|
State.dataManager.shutdown();
|
2009-08-25 03:33:19 +02:00
|
|
|
State.queryManager.shutdown();
|
2009-08-26 03:25:38 +02:00
|
|
|
|
2009-08-25 03:33:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-26 03:25:38 +02:00
|
|
|
* @return the dataManager
|
2009-08-25 03:33:19 +02:00
|
|
|
*/
|
|
|
|
public static DataManager getDataManager() {
|
2009-08-26 03:25:38 +02:00
|
|
|
return dataManager;
|
2009-08-25 03:33:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the queryManager
|
|
|
|
*/
|
|
|
|
public static QueryManager getQueryManager() {
|
|
|
|
return queryManager;
|
2009-08-17 19:32:15 +02:00
|
|
|
}
|
|
|
|
|
2009-08-25 03:33:19 +02:00
|
|
|
|
2009-08-17 19:32:15 +02:00
|
|
|
/**
|
|
|
|
* Prints the enviromnet variables
|
|
|
|
*/
|
|
|
|
public void printEnv() {
|
|
|
|
java.util.Properties p = System.getProperties();
|
|
|
|
Enumeration<Object> keys = p.keys();
|
|
|
|
while (keys.hasMoreElements()) {
|
|
|
|
logger.debug(keys.nextElement());
|
|
|
|
}
|
|
|
|
logger.debug("Exist home: " + System.getProperty("exist.home"));
|
|
|
|
}
|
|
|
|
}
|