001 package de.deepamehta.storage.neo4j; 002 003 import de.deepamehta.core.storage.spi.DeepaMehtaStorage; 004 005 import org.osgi.framework.BundleActivator; 006 import org.osgi.framework.BundleContext; 007 008 import java.util.logging.Level; 009 import java.util.logging.Logger; 010 011 012 013 public class Neo4jStorageActivator implements BundleActivator { 014 015 // ------------------------------------------------------------------------------------------------------- Constants 016 017 private static final String DATABASE_PATH = System.getProperty("dm4.database.path", "deepamehta-db"); 018 // Note: the default value is required in case no config file is in effect. This applies when DM is started 019 // via feature:install from Karaf. The default value must match the value defined in global POM. 020 021 // ---------------------------------------------------------------------------------------------- Instance Variables 022 023 private DeepaMehtaStorage storage; 024 025 private final Logger logger = Logger.getLogger(getClass().getName()); 026 027 // -------------------------------------------------------------------------------------------------- Public Methods 028 029 030 031 // ************************************** 032 // *** BundleActivator Implementation *** 033 // ************************************** 034 035 036 037 @Override 038 public void start(BundleContext context) { 039 try { 040 logger.info("========== Starting \"DeepaMehta 4 Storage - Neo4j\" =========="); 041 storage = new Neo4jStorage(DATABASE_PATH); 042 // 043 logger.info("Registering DeepaMehta 4 storage service - Neo4j - at OSGi framework"); 044 context.registerService(DeepaMehtaStorage.class.getName(), storage, null); 045 } catch (Throwable e) { 046 logger.log(Level.SEVERE, "Starting \"DeepaMehta 4 Storage - Neo4j\" failed", e); 047 // Note: here we catch anything, also errors (like NoClassDefFoundError). 048 // If thrown through the OSGi container it would not print out the stacktrace. 049 // File Install would retry to start the bundle endlessly. 050 } 051 } 052 053 @Override 054 public void stop(BundleContext context) { 055 try { 056 logger.info("========== Stopping \"DeepaMehta 4 Storage - Neo4j\" =========="); 057 if (storage != null) { 058 storage.shutdown(); 059 } 060 } catch (Throwable e) { 061 logger.log(Level.SEVERE, "Stopping \"DeepaMehta 4 Storage - Neo4j\" failed", e); 062 // Note: here we catch anything, also errors (like NoClassDefFoundError). 063 // If thrown through the OSGi container it would not print out the stacktrace. 064 } 065 } 066 }