public SessionImpl session ( KeyspaceImpl keyspace ) { JanusGraph graph ; KeyspaceCache cache ; KeyspaceCacheContainer cacheContainer ; ReadWriteLock graphLock ; Lock lock = lockManager . getLock ( getLockingKey ( keyspace ) ) ; lock . lock ( ) ; try { // If keyspace reference already in cache, retrieve open graph and keyspace cache if ( keyspaceCacheMap . containsKey ( keyspace ) ) { cacheContainer = keyspaceCacheMap . get ( keyspace ) ; graph = cacheContainer . graph ( ) ; cache = cacheContainer . cache ( ) ; graphLock = cacheContainer . graphLock ( ) ; } else { // If keyspace reference not cached, put keyspace in keyspace manager, open new graph and instantiate new keyspace cache keyspaceManager . putKeyspace ( keyspace ) ; graph = janusGraphFactory . openGraph ( keyspace . name ( ) ) ; cache = new KeyspaceCache ( ) ; graphLock = new ReentrantReadWriteLock ( ) ; cacheContainer = new KeyspaceCacheContainer ( cache , graph , graphLock ) ; keyspaceCacheMap . put ( keyspace , cacheContainer ) ; } SessionImpl session = new SessionImpl ( keyspace , config , cache , graph , graphLock ) ; session . setOnClose ( this :: onSessionClose ) ; cacheContainer . addSessionReference ( session ) ; return session ; } finally { lock . unlock ( ) ; } }
Retrieves the Session needed to open the Transaction . This will open a new one Session if it hasn t been opened before