@Test void shutdownDatabaseOnStop() throws Throwable { DatabaseManager databaseManager = getDatabaseManager(); databaseManager.stop(); assertFalse( database.isAvailable( 0 ) ); }
@Override public boolean isAvailable(long timeout) { return graphDb.isAvailable(timeout); }
/** * Create OGM EmbeddedDriver with provided embedded instance. * * @param graphDatabaseService Preconfigured, embedded instance. * @param customPropertiesSupplier Hook to provide custom configuration properties, i.e. for Cypher modification providers */ public EmbeddedDriver(GraphDatabaseService graphDatabaseService, Supplier<Map<String, Object>> customPropertiesSupplier) { super(customPropertiesSupplier); this.graphDatabaseService = requireNonNull(graphDatabaseService); boolean available = this.graphDatabaseService.isAvailable(TIMEOUT); if (!available) { throw new IllegalArgumentException("Provided GraphDatabaseService is not in usable state"); } }
GraphDatabaseService graphdb=null; if(graphdb.isAvailable()&& graphdb!=null) { return graphdb; } else { graphdb = new GraphDatabaseFactory().newEmbeddedDatabase("D:/GraphDB"); return graphdb; }
/** * Stops the underlying server bootstrapper and, in turn, the Neo4j server. */ public void shutdown() { if (database != null && database.isAvailable(100)) { LOGGER.info("Stopping {} server on: {}", enableBolt ? "BOLT" : "HTTP", port); database.shutdown(); database = null; } controls.close(); }
/** * Create OGM EmbeddedDriver with provided embedded instance. * * @param graphDatabaseService Preconfigured, embedded instance. * @param customPropertiesSupplier Hook to provide custom configuration properties, i.e. for Cypher modification providers */ public EmbeddedDriver(GraphDatabaseService graphDatabaseService, Configuration configuration, Supplier<Map<String, Object>> customPropertiesSupplier ) { super(customPropertiesSupplier); super.configure(configuration); this.graphDatabaseService = requireNonNull(graphDatabaseService); boolean available = this.graphDatabaseService.isAvailable(TIMEOUT); if (!available) { throw new IllegalArgumentException("Provided GraphDatabaseService is not in usable state"); } }
@Override public synchronized void close() throws IOException { closed = true; factory.connectionClosing( workspaceId ); if ( graph != null ) { try { logger.info( "Shutting down graph..." ); printStats(); graph.shutdown(); logger.info( "Waiting for shutdown..." ); if ( graph.isAvailable( 1000 * SHUTDOWN_WAIT ) ) { throw new IOException( "Failed to shutdown graph: " + dbDir ); } graph = null; logger.info( "...graph shutdown complete." ); } catch ( final Exception e ) { throw new IOException( "Failed to shutdown: " + e.getMessage(), e ); } } }
if (graphDatabase.isAvailable(1000)) { if (databasePath.exists()) { return Result.healthy(logMessage.toString());
/** * {@inheritDoc} */ @Override public void start() throws Throwable { if (!config.get(RUNTIME_ENABLED)) { LOG.info("GraphAware Runtime disabled."); return; } LOG.info("GraphAware Runtime enabled, bootstrapping..."); final GraphAwareRuntime runtime = createRuntime(database, new Neo4jConfigBasedRuntimeConfiguration(database, config)); registerModules(runtime); new Thread(() -> { if (database.isAvailable(5 * 60 * 1000)) { runtime.start(); LOG.info("GraphAware Runtime automatically started."); } else { LOG.error("Could not start GraphAware Runtime because the database didn't get to a usable state within 5 minutes."); } }, "GraphAware Starter").start(); LOG.info("GraphAware Runtime bootstrapped, starting the Runtime..."); }
/** * Run the next task. * * @param <C> type of the context passed into the module below. * @param <T> module type of the module that will be delegated to. */ private <C extends TimerDrivenModuleContext, T extends TimerDrivenModule<C>> void runNextTask() { if (!database.isAvailable(0)) { LOG.warn("Database not available, probably shutting down..."); return; } Pair<T, C> moduleAndContext = findNextModuleAndContext(); if (moduleAndContext == null) { return; //no module wishes to run } T module = moduleAndContext.first(); C context = moduleAndContext.second(); try (Transaction tx = database.beginTx()) { C newContext = module.doSomeWork(context, database); repository.persistModuleMetadata(module, new DefaultTimerDrivenModuleMetadata(newContext)); moduleContexts.put(module, newContext); tx.success(); } }