Reputation: 1187
I want to use neo4j in embedded mode. As I have seen it's not possible to share the GraphDatabase
instance in different processes. Now my idea was to use the neo4j embedded in an OSGi container to share the same db for different components. Is it a good idea to write a BundleActivator
which creates the GraphDB
and exposes it to other OSGi bundles with a service?
Upvotes: 2
Views: 908
Reputation: 6331
Now you can use proper DI to instantiate the DB, like http://docs.neo4j.org/chunked/snapshot/tutorials-java-embedded-osgi.html
//the cache providers
ArrayList<CacheProvider> cacheList = new ArrayList<CacheProvider>();
cacheList.add( new SoftCacheProvider() );
//the index providers
IndexProvider lucene = new LuceneIndexProvider();
ArrayList<IndexProvider> provs = new ArrayList<IndexProvider>();
provs.add( lucene );
ListIndexIterable providers = new ListIndexIterable();
providers.setIndexProviders( provs );
//the database setup
GraphDatabaseFactory gdbf = new GraphDatabaseFactory();
gdbf.setIndexProviders( providers );
gdbf.setCacheProviders( cacheList );
db = gdbf.newEmbeddedDatabase( "target/db" );
Upvotes: 1
Reputation: 6331
there is An example template setup with tests making a super-bundle out of the neo4j-related components. Try and let us know how it goes. See here for a typical Activator.
Upvotes: 2