is-collector/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/State.java

128 lines
4.1 KiB
Java
Executable File

package org.gcube.informationsystem.collector.impl.xmlstorage.exist;
import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext;
import org.gcube.informationsystem.collector.impl.persistence.AggregatorPersistentResource;
import org.globus.wsrf.config.ContainerConfig;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Collections;
/**
* This class groups the data globally scoped in an active RI
*
* @author manuele simi
*
*/
public class State {
/**
* Connection to eXist used to store data
*/
public static XMLStorageManager storage_manager;
/**
* Connection to eXist used to query the database
*/
public static XMLStorageManager query_manager;
/**
* DIS-IC's JNDI resource name as declared in the JNDI file
*/
public static final String JNDIResourceName = "DISICConfiguration";
/**
* Prefix to prepend to any log message
*/
public static final String logPrefix = "";
/**
* Thread that periodically sweeps the database from expired resources
*/
public static Thread sweeperT;
/**
* 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>());
private static Log logger = LogFactory.getLog(State.class.getName());
/**
* 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...");
State.initializeStorageManager();
State.initializeQueryManager();
if (Boolean.valueOf((String) ICServiceContext.getContext().getProperty("deleteRPsOnStartup", true))) {
// cleanup the RPs collection
logger.info("deleting all RPs...");
State.storage_manager.deleteAllProperties();
} else {
logger.info("all RPs previously stored are keept in the storage");
}
// start the sweeper to periodically cleanup the storage and some data structures
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.start();
logger.info("IC service initialization completed");
}
private static void initializeStorageManager() throws Exception {
// open the connection used to store resources
State.storage_manager = new XMLStorageManager();
storage_manager.initialize();
}
private static void initializeQueryManager() throws Exception {
// open the connection used to query stored resources
State.query_manager = new XMLStorageManager();
query_manager.initialize();
}
/**
*
* @return the container base dir
*/
public static String getBaseDirectory() {
return ContainerConfig.getBaseDirectory();
}
/**
* Releases all the State resources
*
* @throws Exception if the shutdown fails
*/
public static void dispose() throws Exception {
logger.info("Disposing IC service's resources...");
State.storage_manager.shutdown();
State.query_manager.shutdown();
}
/**
* 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"));
logger.debug("Class path: " + System.getProperty("java.class.path"));
}
}