Skip to content

Commit

Permalink
Continued bugfixing.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroecheler committed Jan 15, 2015
1 parent 1856ae7 commit 1db4ba8
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 46 deletions.
Expand Up @@ -76,14 +76,14 @@ public TitanGraphComputer isolation(final Isolation isolation) {
}

@Override
public TitanGraphComputer setResultMode(ResultMode mode) {
public TitanGraphComputer resultMode(ResultMode mode) {
Preconditions.checkArgument(mode!=null,"Need to specify mode");
this.resultMode = mode;
return this;
}

@Override
public TitanGraphComputer setNumProcessingThreads(int threads) {
public TitanGraphComputer workers(int threads) {
Preconditions.checkArgument(threads>0,"Invalid number of threads: %s",threads);
numThreads = threads;
return this;
Expand Down
Expand Up @@ -122,43 +122,7 @@ public String toString() {

@Override
public Variables variables() {
final WriteConfiguration config = ((StandardTitanGraph)this).getBackend().getUserConfiguration();
return new Variables() {

@Override
public Set<String> keys() {
return Sets.newHashSet(config.getKeys(""));
}

@Override
public <R> Optional<R> get(String s) {
if (s==null) throw Exceptions.variableKeyCanNotBeNull();
if (StringUtils.isEmpty(s)) throw Exceptions.variableKeyCanNotBeEmpty();
Object value = config.get(s,Object.class);
if (value==null) return Optional.empty();
else return Optional.of((R)value);
}

@Override
public void set(String s, Object o) {
if (s==null) throw Exceptions.variableKeyCanNotBeNull();
if (StringUtils.isEmpty(s)) throw Exceptions.variableKeyCanNotBeEmpty();
if (o==null) throw Exceptions.variableValueCanNotBeNull();
config.set(s,o);
}

@Override
public void remove(String s) {
if (s==null) throw Exceptions.variableKeyCanNotBeNull();
if (StringUtils.isEmpty(s)) throw Exceptions.variableKeyCanNotBeEmpty();
config.remove(s);
}

@Override
public String toString() {
return StringFactory.graphVariablesString(this);
}
};
return new TitanGraphVariables(((StandardTitanGraph)this).getBackend().getUserConfiguration());
}

@Override
Expand Down
@@ -0,0 +1,56 @@
package com.thinkaurelius.titan.graphdb.tinkerpop;

import com.google.common.collect.Sets;
import com.thinkaurelius.titan.diskstorage.configuration.WriteConfiguration;
import com.tinkerpop.gremlin.structure.Graph;
import com.tinkerpop.gremlin.structure.util.StringFactory;
import org.apache.commons.lang3.StringUtils;

import java.util.Optional;
import java.util.Set;

/**
* @author Matthias Broecheler (me@matthiasb.com)
*/
public class TitanGraphVariables implements Graph.Variables {

private final WriteConfiguration config;

public TitanGraphVariables(WriteConfiguration config) {
this.config = config;
}

@Override
public Set<String> keys() {
return Sets.newHashSet(config.getKeys(""));
}

@Override
public <R> Optional<R> get(String s) {
if (s==null) throw Graph.Variables.Exceptions.variableKeyCanNotBeNull();
if (StringUtils.isEmpty(s)) throw Graph.Variables.Exceptions.variableKeyCanNotBeEmpty();
Object value = config.get(s,Object.class);
if (value==null) return Optional.empty();
else return Optional.of((R)value);
}

@Override
public void set(String s, Object o) {
if (s==null) throw Graph.Variables.Exceptions.variableKeyCanNotBeNull();
if (StringUtils.isEmpty(s)) throw Graph.Variables.Exceptions.variableKeyCanNotBeEmpty();
if (o==null) throw Graph.Variables.Exceptions.variableValueCanNotBeNull();
config.set(s,o);
}

@Override
public void remove(String s) {
if (s==null) throw Graph.Variables.Exceptions.variableKeyCanNotBeNull();
if (StringUtils.isEmpty(s)) throw Graph.Variables.Exceptions.variableKeyCanNotBeEmpty();
config.remove(s);
}

@Override
public String toString() {
return StringFactory.graphVariablesString(this);
}
}
Expand Up @@ -11,6 +11,8 @@
import com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration;
import com.thinkaurelius.titan.graphdb.database.StandardTitanGraph;
import com.thinkaurelius.titan.graphdb.relations.*;
import com.thinkaurelius.titan.graphdb.tinkerpop.TitanGraphVariables;
import com.thinkaurelius.titan.graphdb.tinkerpop.TitanIo;
import com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx;
import com.thinkaurelius.titan.graphdb.types.VertexLabelVertex;
import com.thinkaurelius.titan.graphdb.types.vertices.EdgeLabelVertex;
Expand Down Expand Up @@ -58,7 +60,8 @@ public abstract class AbstractTitanGraphProvider extends AbstractGraphProvider {
add(CacheVertexProperty.class);
add(SimpleTitanProperty.class);

add(StandardVertex.class);
add(TitanIo.class);
add(TitanGraphVariables.class);
}};

@Override
Expand Down Expand Up @@ -110,7 +113,7 @@ public Map<String, Object> getBaseConfiguration(String graphName, Class<?> test,

@Override
public void loadGraphData(final Graph g, final LoadGraphWith loadGraphWith, final Class testClass, final String testName) {
this.createIndices((TitanGraph) g, loadGraphWith.value());
if (loadGraphWith!=null) this.createIndices((TitanGraph) g, loadGraphWith.value());
super.loadGraphData(g, loadGraphWith, testClass, testName);
}

Expand Down
Expand Up @@ -19,7 +19,6 @@
import com.tinkerpop.gremlin.process.computer.util.StaticMapReduce;
import com.tinkerpop.gremlin.process.computer.util.StaticVertexProgram;
import com.tinkerpop.gremlin.process.graph.AnonymousGraphTraversal;
import com.tinkerpop.gremlin.process.graph.GraphTraversal;
import com.tinkerpop.gremlin.structure.Direction;
import com.tinkerpop.gremlin.structure.Graph;
import com.tinkerpop.gremlin.structure.Vertex;
Expand Down Expand Up @@ -191,8 +190,8 @@ public void degreeCounting() throws Exception {
clopen();

final TitanGraphComputer computer = graph.compute();
computer.setResultMode(TitanGraphComputer.ResultMode.NONE);
computer.setNumProcessingThreads(4);
computer.resultMode(TitanGraphComputer.ResultMode.NONE);
computer.workers(4);
computer.program(new DegreeCounter());
computer.mapReduce(new DegreeMapper());
ComputerResult result = computer.submit().get();
Expand Down Expand Up @@ -221,8 +220,8 @@ public void degreeCountingDistance() throws Exception {

for (TitanGraphComputer.ResultMode mode : TitanGraphComputer.ResultMode.values()) {
final TitanGraphComputer computer = graph.compute();
computer.setResultMode(mode);
computer.setNumProcessingThreads(1);
computer.resultMode(mode);
computer.workers(1);
computer.program(new DegreeCounter(2));
ComputerResult result = computer.submit().get();
System.out.println("Execution time (ms) ["+numV+"|"+numE+"]: " + result.memory().getRuntime());
Expand Down

0 comments on commit 1db4ba8

Please sign in to comment.