You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by dk...@apache.org on 2015/09/01 16:26:22 UTC

[06/19] incubator-tinkerpop git commit: close Graph instance in case the initialization failed

close Graph instance in case the initialization failed


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/8b7f2b97
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/8b7f2b97
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/8b7f2b97

Branch: refs/heads/tp30
Commit: 8b7f2b97cd9e3d64d444dea5846dc98cf62e4c36
Parents: 08b57f8
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Mon Aug 24 18:09:41 2015 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Mon Aug 24 18:09:41 2015 +0200

----------------------------------------------------------------------
 .../bulkloading/BulkLoaderVertexProgram.java    | 45 ++++++++++++--------
 1 file changed, 27 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8b7f2b97/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java
index 8ff404b..2aa86f2 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java
@@ -105,27 +105,36 @@ public class BulkLoaderVertexProgram implements VertexProgram<Tuple> {
         if (null == graph) {
             graph = GraphFactory.open(configuration);
             LOGGER.info("Opened Graph instance: {}", graph);
-            if (!graph.features().graph().supportsConcurrentAccess()) {
-                throw new IllegalStateException("The given graph instance does not allow concurrent access.");
-            }
-            if (graph.features().graph().supportsTransactions()) {
-                if (!graph.features().graph().supportsThreadedTransactions()) {
-                    throw new IllegalStateException("The given graph instance does not support threaded transactions.");
-                }
-            }
-            g = graph.traversal();
-            final String bulkLoaderClassName = configuration.getString(BULK_LOADER_CLASS, DefaultBulkLoader.class.getCanonicalName());
             try {
-                final Class<?> bulkLoaderClass = Class.forName(bulkLoaderClassName);
-                bulkLoader = (BulkLoader) bulkLoaderClass.getConstructor().newInstance();
-            } catch (ClassNotFoundException e) {
-                LOGGER.error("Unable to find custom bulk loader class: {}", bulkLoaderClassName);
-                throw new IllegalStateException(e);
+                if (!graph.features().graph().supportsConcurrentAccess()) {
+                    throw new IllegalStateException("The given graph instance does not allow concurrent access.");
+                }
+                if (graph.features().graph().supportsTransactions()) {
+                    if (!graph.features().graph().supportsThreadedTransactions()) {
+                        throw new IllegalStateException("The given graph instance does not support threaded transactions.");
+                    }
+                }
+                g = graph.traversal();
+                final String bulkLoaderClassName = configuration.getString(BULK_LOADER_CLASS, DefaultBulkLoader.class.getCanonicalName());
+                try {
+                    final Class<?> bulkLoaderClass = Class.forName(bulkLoaderClassName);
+                    bulkLoader = (BulkLoader) bulkLoaderClass.getConstructor().newInstance();
+                } catch (ClassNotFoundException e) {
+                    LOGGER.error("Unable to find custom bulk loader class: {}", bulkLoaderClassName);
+                    throw new IllegalStateException(e);
+                } catch (Exception e) {
+                    LOGGER.error("Unable to create an instance of the given bulk loader class: {}", bulkLoaderClassName);
+                    throw new IllegalStateException(e);
+                }
+                bulkLoader.configure(configuration.subset(BULK_LOADER_CFG_PREFIX));
             } catch (Exception e) {
-                LOGGER.error("Unable to create an instance of the given bulk loader class: {}", bulkLoaderClassName);
-                throw new IllegalStateException(e);
+                try {
+                    graph.close();
+                } catch (Exception e2) {
+                    LOGGER.warn("Failed to close Graph instance", e2);
+                }
+                throw e;
             }
-            bulkLoader.configure(configuration.subset(BULK_LOADER_CFG_PREFIX));
         } else {
             LOGGER.warn("Leaked Graph instance: {}", graph);
         }