You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by pluradj <gi...@git.apache.org> on 2017/03/15 16:40:26 UTC

[GitHub] tinkerpop pull request #569: TINKERPOP-1438: GraphManager becomes a customiz...

Github user pluradj commented on a diff in the pull request:

    https://github.com/apache/tinkerpop/pull/569#discussion_r106217616
  
    --- Diff: gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GraphManager.java ---
    @@ -21,139 +21,82 @@
     import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
     import org.apache.tinkerpop.gremlin.structure.Graph;
     import org.apache.tinkerpop.gremlin.structure.Transaction;
    -import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
    -import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
    -import org.slf4j.Logger;
    -import org.slf4j.LoggerFactory;
     
     import javax.script.Bindings;
    -import javax.script.SimpleBindings;
    -import java.util.HashSet;
     import java.util.Map;
     import java.util.Set;
    -import java.util.concurrent.ConcurrentHashMap;
    -import java.util.function.Predicate;
    -
    -/**
    - * Holder for {@link Graph} and {@link TraversalSource} instances configured for the server to be passed to script
    - * engine bindings. The {@link Graph} instances are read from the {@link Settings} for Gremlin Server as defined in
    - * the configuration file. The {@link TraversalSource} instances are rebound to the {@code GraphManager} once
    - * initialization scripts construct them.
    - */
    -public final class GraphManager {
    -    private static final Logger logger = LoggerFactory.getLogger(GremlinServer.class);
    -
    -    private final Map<String, Graph> graphs = new ConcurrentHashMap<>();
    -    private final Map<String, TraversalSource> traversalSources = new ConcurrentHashMap<>();
    +import java.util.function.Supplier;
     
    +public interface GraphManager {
         /**
    -     * Create a new instance using the {@link Settings} from Gremlin Server.
    +     * Get a list of the {@link Graph} instances and their binding names
    +     *
    +     * @return a {@link Map} where the key is the name of the {@link Graph} and the value is the {@link Graph} itself
          */
    -    public GraphManager(final Settings settings) {
    -        settings.graphs.entrySet().forEach(e -> {
    -            try {
    -                final Graph newGraph = GraphFactory.open(e.getValue());
    -                graphs.put(e.getKey(), newGraph);
    -                logger.info("Graph [{}] was successfully configured via [{}].", e.getKey(), e.getValue());
    -            } catch (RuntimeException re) {
    -                logger.warn(String.format("Graph [%s] configured at [%s] could not be instantiated and will not be available in Gremlin Server.  GraphFactory message: %s",
    -                        e.getKey(), e.getValue(), re.getMessage()), re);
    -                if (re.getCause() != null) logger.debug("GraphFactory exception", re.getCause());
    -            }
    -        });
    -    }
    -
    +    public Map<String, Graph> getGraphs();
    +    
         /**
    -     * Get a list of the {@link Graph} instances and their binding names as defined in the Gremlin Server
    -     * configuration file.
    +     * Get {@link Graph} instance whose name matches {@link gName}
          *
    -     * @return a {@link Map} where the key is the name of the {@link Graph} and the value is the {@link Graph} itself
    +     * @return {@link Graph} if exists, else null 
          */
    -    public Map<String, Graph> getGraphs() {
    -        return graphs;
    -    }
    +    public Graph getGraph(String gName);
     
         /**
    -     * Get a list of the {@link TraversalSource} instances and their binding names as defined by Gremlin Server
    -     * initialization scripts.
    +     * Add {@link Graph} g with name {@link String} gName to 
    +     * {@link Map<String, Graph>} returned by call to getGraphs()
    +     */
    +    public void addGraph(String gName, Graph g);
    --- End diff --
    
    seems like `removeGraph(String)` or `removeGraph(Graph)` would be useful


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---