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");
018    
019        // ---------------------------------------------------------------------------------------------- Instance Variables
020    
021        private DeepaMehtaStorage storage;
022    
023        private final Logger logger = Logger.getLogger(getClass().getName());
024    
025        // -------------------------------------------------------------------------------------------------- Public Methods
026    
027    
028    
029        // **************************************
030        // *** BundleActivator Implementation ***
031        // **************************************
032    
033    
034    
035        @Override
036        public void start(BundleContext context) {
037            try {
038                logger.info("========== Starting \"DeepaMehta 4 Storage - Neo4j\" ==========");
039                storage = new Neo4jStorage(DATABASE_PATH);
040                //
041                logger.info("Registering DeepaMehta 4 storage service - Neo4j - at OSGi framework");
042                context.registerService(DeepaMehtaStorage.class.getName(), storage, null);
043            } catch (Throwable e) {
044                logger.log(Level.SEVERE, "Starting \"DeepaMehta 4 Storage - Neo4j\" failed", e);
045                // Note: here we catch anything, also errors (like NoClassDefFoundError).
046                // If thrown through the OSGi container it would not print out the stacktrace.
047                // File Install would retry to start the bundle endlessly.
048            }
049        }
050    
051        @Override
052        public void stop(BundleContext context) {
053            try {
054                logger.info("========== Stopping \"DeepaMehta 4 Storage - Neo4j\" ==========");
055                if (storage != null) {
056                    storage.shutdown();
057                }
058            } catch (Throwable e) {
059                logger.log(Level.SEVERE, "Stopping \"DeepaMehta 4 Storage - Neo4j\" failed", e);
060                // Note: here we catch anything, also errors (like NoClassDefFoundError).
061                // If thrown through the OSGi container it would not print out the stacktrace.
062            }
063        }
064    }