Java Code Examples for org.apache.tinkerpop.gremlin.process.computer.VertexProgram

The following are top voted examples for showing how to use org.apache.tinkerpop.gremlin.process.computer.VertexProgram. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: tinkergraph-gremlin   File: TinkerWorkerPool.java   View source code 6 votes vote down vote up
public void executeVertexProgram(final TriConsumer<Iterator<Vertex>, VertexProgram, TinkerWorkerMemory> worker) throws InterruptedException {
    for (int i = 0; i < this.numberOfWorkers; i++) {
        final int index = i;
        this.completionService.submit(() -> {
            final VertexProgram vp = this.vertexProgramPool.take();
            final TinkerWorkerMemory workerMemory = this.workerMemoryPool.poll();
            final List<Vertex> vertices = this.workerVertices.get(index);
            worker.accept(vertices.iterator(), vp, workerMemory);
            this.vertexProgramPool.offer(vp);
            this.workerMemoryPool.offer(workerMemory);
            return null;
        });
    }
    for (int i = 0; i < this.numberOfWorkers; i++) {
        try {
            this.completionService.take().get();
        } catch (InterruptedException ie) {
            throw ie;
        } catch (final Exception e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }
}
 
Example 2
Project: grakn   File: GraknComputerImpl.java   View source code 6 votes vote down vote up
@Override
public ComputerResult compute(@Nullable VertexProgram program, @Nullable MapReduce mapReduce,
                              @Nullable Set<LabelId> types, Boolean includesRolePlayerEdges) {
    try {
        graphComputer = getGraphComputer();
        if (program != null) {
            graphComputer.program(program);
        } else {
            filterAllEdges = true;
        }
        if (mapReduce != null) graphComputer.mapReduce(mapReduce);
        applyFilters(types, includesRolePlayerEdges);
        return graphComputer.submit().get();
    } catch (InterruptedException | ExecutionException e) {
        throw asRuntimeException(e.getCause());
    }
}
 
Example 3
Project: grakn   File: GraknSparkMemory.java   View source code 6 votes vote down vote up
public GraknSparkMemory(final VertexProgram<?> vertexProgram,
                        final Set<MapReduce> mapReducers,
                        final JavaSparkContext sparkContext) {
    if (null != vertexProgram) {
        for (final MemoryComputeKey key : vertexProgram.getMemoryComputeKeys()) {
            this.memoryComputeKeys.put(key.getKey(), key);
        }
    }
    for (final MapReduce mapReduce : mapReducers) {
        this.memoryComputeKeys.put(
                mapReduce.getMemoryKey(),
                MemoryComputeKey.of(mapReduce.getMemoryKey(), Operator.assign, false, false));
    }
    for (final MemoryComputeKey memoryComputeKey : this.memoryComputeKeys.values()) {
        this.sparkMemory.put(
                memoryComputeKey.getKey(),
                sparkContext.accumulator(ObjectWritable.empty(), memoryComputeKey.getKey(),
                        new MemoryAccumulator<>(memoryComputeKey)));
    }
    this.broadcast = sparkContext.broadcast(Collections.emptyMap());
}
 
Example 4
Project: LiteGraph   File: GraphComputerHelper.java   View source code 6 votes vote down vote up
public static void validateProgramOnComputer(final GraphComputer computer, final VertexProgram vertexProgram) {
    if (vertexProgram.getMemoryComputeKeys().contains(null))
        throw Memory.Exceptions.memoryKeyCanNotBeNull();
    if (vertexProgram.getMemoryComputeKeys().contains(""))
        throw Memory.Exceptions.memoryKeyCanNotBeEmpty();

    final GraphComputer.Features graphComputerFeatures = computer.features();
    final VertexProgram.Features vertexProgramFeatures = vertexProgram.getFeatures();

    for (final Method method : VertexProgram.Features.class.getMethods()) {
        if (method.getName().startsWith("requires")) {
            final boolean supports;
            final boolean requires;
            try {
                supports = (boolean) GraphComputer.Features.class.getMethod(method.getName().replace("requires", "supports")).invoke(graphComputerFeatures);
                requires = (boolean) method.invoke(vertexProgramFeatures);
            } catch (final Exception e) {
                throw new IllegalStateException("A reflection exception has occurred: " + e.getMessage(), e);
            }
            if (requires && !supports)
                throw new IllegalStateException("The vertex program can not be executed on the graph computer: " + method.getName());
        }
    }
}
 
Example 5
Project: LiteGraph   File: TinkerWorkerPool.java   View source code 6 votes vote down vote up
public void executeVertexProgram(final Consumer<VertexProgram> worker) throws InterruptedException {
    for (int i = 0; i < this.numberOfWorkers; i++) {
        this.completionService.submit(() -> {
            final VertexProgram vp = this.vertexProgramPool.take();
            worker.accept(vp);
            this.vertexProgramPool.offer(vp);
            return null;
        });
    }
    for (int i = 0; i < this.numberOfWorkers; i++) {
        try {
            this.completionService.take().get();
        } catch (InterruptedException ie) {
            throw ie;
        } catch (final Exception e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }
}
 
Example 6
Project: LiteGraph   File: SparkMemory.java   View source code 6 votes vote down vote up
public SparkMemory(final VertexProgram<?> vertexProgram, final Set<MapReduce> mapReducers, final JavaSparkContext sparkContext) {
    if (null != vertexProgram) {
        for (final MemoryComputeKey key : vertexProgram.getMemoryComputeKeys()) {
            this.memoryComputeKeys.put(key.getKey(), key);
        }
    }
    for (final MapReduce mapReduce : mapReducers) {
        this.memoryComputeKeys.put(mapReduce.getMemoryKey(), MemoryComputeKey.of(mapReduce.getMemoryKey(), Operator.assign, false, false));
    }
    for (final MemoryComputeKey memoryComputeKey : this.memoryComputeKeys.values()) {
        this.sparkMemory.put(
                memoryComputeKey.getKey(),
                sparkContext.accumulator(ObjectWritable.empty(), memoryComputeKey.getKey(), new MemoryAccumulator<>(memoryComputeKey)));
    }
    this.broadcast = sparkContext.broadcast(Collections.emptyMap());
}
 
Example 7
Project: DuctileDB   File: DuctileWorkerPool.java   View source code 6 votes vote down vote up
public void executeVertexProgram(Consumer<VertexProgram<M>> worker) {
for (int i = 0; i < numberOfWorkers; i++) {
    completionService.submit(() -> {
	@SuppressWarnings("unchecked")
	VertexProgram<M> vp = vertexProgramPool.take();
	worker.accept(vp);
	vertexProgramPool.offer(vp);
	return null;
    });
}
for (int i = 0; i < numberOfWorkers; i++) {
    try {
	completionService.take().get();
    } catch (Exception e) {
	throw new IllegalStateException(e.getMessage(), e);
    }
}
   }
 
Example 8
Project: tinkerpop   File: GraphComputerHelper.java   View source code 6 votes vote down vote up
public static void validateProgramOnComputer(final GraphComputer computer, final VertexProgram vertexProgram) {
    if (vertexProgram.getMemoryComputeKeys().contains(null))
        throw Memory.Exceptions.memoryKeyCanNotBeNull();
    if (vertexProgram.getMemoryComputeKeys().contains(""))
        throw Memory.Exceptions.memoryKeyCanNotBeEmpty();

    final GraphComputer.Features graphComputerFeatures = computer.features();
    final VertexProgram.Features vertexProgramFeatures = vertexProgram.getFeatures();

    for (final Method method : VertexProgram.Features.class.getMethods()) {
        if (method.getName().startsWith("requires")) {
            final boolean supports;
            final boolean requires;
            try {
                supports = (boolean) GraphComputer.Features.class.getMethod(method.getName().replace("requires", "supports")).invoke(graphComputerFeatures);
                requires = (boolean) method.invoke(vertexProgramFeatures);
            } catch (final Exception e) {
                throw new IllegalStateException("A reflection exception has occurred: " + e.getMessage(), e);
            }
            if (requires && !supports)
                throw new IllegalStateException("The vertex program can not be executed on the graph computer: " + method.getName());
        }
    }
}
 
Example 9
Project: tinkerpop   File: TinkerWorkerPool.java   View source code 6 votes vote down vote up
public void executeVertexProgram(final TriConsumer<Iterator<Vertex>, VertexProgram, TinkerWorkerMemory> worker) throws InterruptedException {
    for (int i = 0; i < this.numberOfWorkers; i++) {
        final int index = i;
        this.completionService.submit(() -> {
            final VertexProgram vp = this.vertexProgramPool.take();
            final TinkerWorkerMemory workerMemory = this.workerMemoryPool.poll();
            final List<Vertex> vertices = this.workerVertices.get(index);
            worker.accept(vertices.iterator(), vp, workerMemory);
            this.vertexProgramPool.offer(vp);
            this.workerMemoryPool.offer(workerMemory);
            return null;
        });
    }
    for (int i = 0; i < this.numberOfWorkers; i++) {
        try {
            this.completionService.take().get();
        } catch (InterruptedException ie) {
            throw ie;
        } catch (final Exception e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }
}
 
Example 10
Project: tinkerpop   File: SparkMemory.java   View source code 6 votes vote down vote up
public SparkMemory(final VertexProgram<?> vertexProgram, final Set<MapReduce> mapReducers, final JavaSparkContext sparkContext) {
    if (null != vertexProgram) {
        for (final MemoryComputeKey key : vertexProgram.getMemoryComputeKeys()) {
            this.memoryComputeKeys.put(key.getKey(), key);
        }
    }
    for (final MapReduce mapReduce : mapReducers) {
        this.memoryComputeKeys.put(mapReduce.getMemoryKey(), MemoryComputeKey.of(mapReduce.getMemoryKey(), Operator.assign, false, false));
    }
    for (final MemoryComputeKey memoryComputeKey : this.memoryComputeKeys.values()) {
        this.sparkMemory.put(
                memoryComputeKey.getKey(),
                sparkContext.accumulator(ObjectWritable.empty(), memoryComputeKey.getKey(), new MemoryAccumulator<>(memoryComputeKey)));
    }
    this.broadcast = sparkContext.broadcast(Collections.emptyMap());
}
 
Example 11
Project: tinkergraph-gremlin   File: TinkerMemory.java   View source code 5 votes vote down vote up
public TinkerMemory(final VertexProgram<?> vertexProgram, final Set<MapReduce> mapReducers) {
    this.currentMap = new ConcurrentHashMap<>();
    this.previousMap = new ConcurrentHashMap<>();
    if (null != vertexProgram) {
        for (final MemoryComputeKey memoryComputeKey : vertexProgram.getMemoryComputeKeys()) {
            this.memoryKeys.put(memoryComputeKey.getKey(), memoryComputeKey);
        }
    }
    for (final MapReduce mapReduce : mapReducers) {
        this.memoryKeys.put(mapReduce.getMemoryKey(), MemoryComputeKey.of(mapReduce.getMemoryKey(), Operator.assign, false, false));
    }
}
 
Example 12
Project: LiteGraph   File: PageRankVertexProgram.java   View source code 5 votes vote down vote up
@Override
public void storeState(final Configuration configuration) {
    VertexProgram.super.storeState(configuration);
    configuration.setProperty(VERTEX_COUNT, this.vertexCountAsDouble);
    configuration.setProperty(ALPHA, this.alpha);
    configuration.setProperty(TOTAL_ITERATIONS, this.totalIterations);
    configuration.setProperty(PROPERTY, this.property);
    if (null != this.edgeTraversal)
        this.edgeTraversal.storeState(configuration, EDGE_TRAVERSAL);
    if (null != this.initialRankTraversal)
        this.initialRankTraversal.storeState(configuration, INITIAL_RANK_TRAVERSAL);
}
 
Example 13
Project: LiteGraph   File: BulkLoaderVertexProgram.java   View source code 5 votes vote down vote up
@Override
public void storeState(final Configuration config) {
    VertexProgram.super.storeState(config);
    if (configuration != null) {
        ConfigurationUtils.copy(configuration, config);
    }
}
 
Example 14
Project: LiteGraph   File: ProgramVertexProgramStep.java   View source code 5 votes vote down vote up
public ProgramVertexProgramStep(final Traversal.Admin traversal, final VertexProgram vertexProgram) {
    super(traversal);
    this.configuration = new HashMap<>();
    final MapConfiguration base = new MapConfiguration(this.configuration);
    base.setDelimiterParsingDisabled(true);
    vertexProgram.storeState(base);
    this.toStringOfVertexProgram = vertexProgram.toString();
}
 
Example 15
Project: LiteGraph   File: ProgramVertexProgramStep.java   View source code 5 votes vote down vote up
@Override
public VertexProgram generateProgram(final Graph graph, final Memory memory) {
    final MapConfiguration base = new MapConfiguration(this.configuration);
    base.setDelimiterParsingDisabled(true);
    PureTraversal.storeState(base, ROOT_TRAVERSAL, TraversalHelper.getRootTraversal(this.getTraversal()).clone());
    base.setProperty(STEP_ID, this.getId());
    if (memory.exists(TraversalVertexProgram.HALTED_TRAVERSERS))
        TraversalVertexProgram.storeHaltedTraversers(base, memory.get(TraversalVertexProgram.HALTED_TRAVERSERS));
    return VertexProgram.createVertexProgram(graph, base);
}
 
Example 16
Project: LiteGraph   File: VertexProgramPool.java   View source code 5 votes vote down vote up
public VertexProgram take() {
    try {
        return this.pool.poll(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    } catch (final InterruptedException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
Example 17
Project: LiteGraph   File: VertexProgramPool.java   View source code 5 votes vote down vote up
public void offer(final VertexProgram<?> vertexProgram) {
    try {
        this.pool.offer(vertexProgram, TIMEOUT_MS, TimeUnit.MILLISECONDS);
    } catch (final InterruptedException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
Example 18
Project: LiteGraph   File: ProgramTest.java   View source code 5 votes vote down vote up
@Override
public void loadState(final Graph graph, final Configuration configuration) {
    VertexProgram.super.loadState(graph, configuration);
    this.traversal = PureTraversal.loadState(configuration, VertexProgramStep.ROOT_TRAVERSAL, graph);
    this.haltedTraversers = TraversalVertexProgram.loadHaltedTraversers(configuration);
    this.programStep = new TraversalMatrix<>(this.traversal.get()).getStepById(configuration.getString(ProgramVertexProgramStep.STEP_ID));
    this.memoryComputeKeys.addAll(MemoryTraversalSideEffects.getMemoryComputeKeys(this.traversal.get()));
    this.memoryComputeKeys.add(MemoryComputeKey.of(TraversalVertexProgram.HALTED_TRAVERSERS, Operator.addAll, false, false));
    this.memoryComputeKeys.add(MemoryComputeKey.of(TraversalVertexProgram.ACTIVE_TRAVERSERS, Operator.addAll, true, true));
}
 
Example 19
Project: LiteGraph   File: ProgramTest.java   View source code 5 votes vote down vote up
@Override
public void storeState(final Configuration configuration) {
    VertexProgram.super.storeState(configuration);
    this.traversal.storeState(configuration, VertexProgramStep.ROOT_TRAVERSAL);
    TraversalVertexProgram.storeHaltedTraversers(configuration, this.haltedTraversers);
    configuration.setProperty(ProgramVertexProgramStep.STEP_ID, this.programStep.getId());
}
 
Example 20
Project: LiteGraph   File: GiraphVertexWriter.java   View source code 5 votes vote down vote up
@Override
public void initialize(final TaskAttemptContext context) throws IOException, InterruptedException {
    final Configuration configuration = context.getConfiguration();
    this.recordWriter = ReflectionUtils.newInstance(configuration.getClass(Constants.GREMLIN_HADOOP_GRAPH_WRITER, OutputFormat.class, OutputFormat.class), configuration).getRecordWriter(context);
    this.transientComputeKeys = VertexProgramHelper.vertexComputeKeysAsArray(((VertexProgram<?>) VertexProgram.createVertexProgram(EmptyGraph.instance(), ConfUtil.makeApacheConfiguration(configuration))).getVertexComputeKeys().stream().
            filter(VertexComputeKey::isTransient).
            collect(Collectors.toSet()));
}
 
Example 21
Project: LiteGraph   File: GiraphComputation.java   View source code 5 votes vote down vote up
@Override
public void compute(final Vertex<ObjectWritable, VertexWritable, NullWritable> vertex, final Iterable<ObjectWritable> messages) throws IOException {
    final GiraphWorkerContext workerContext = this.getWorkerContext();
    final VertexProgram<?> vertexProgram = workerContext.getVertexProgramPool().take();
    vertexProgram.execute(ComputerGraph.vertexProgram(vertex.getValue().get(), vertexProgram), workerContext.getMessenger((GiraphVertex) vertex, this, messages.iterator()), workerContext.getMemory());
    workerContext.getVertexProgramPool().offer(vertexProgram);
}
 
Example 22
Project: LiteGraph   File: GiraphGraphComputer.java   View source code 5 votes vote down vote up
@Override
public GraphComputer program(final VertexProgram vertexProgram) {
    super.program(vertexProgram);
    this.memory.addVertexProgramMemoryComputeKeys(this.vertexProgram);
    final BaseConfiguration apacheConfiguration = new BaseConfiguration();
    apacheConfiguration.setDelimiterParsingDisabled(true);
    vertexProgram.storeState(apacheConfiguration);
    IteratorUtils.fill(apacheConfiguration.getKeys(), this.vertexProgramConfigurationKeys);
    ConfUtil.mergeApacheIntoHadoopConfiguration(apacheConfiguration, this.giraphConfiguration);
    this.vertexProgram.getMessageCombiner().ifPresent(combiner -> this.giraphConfiguration.setMessageCombinerClass(GiraphMessageCombiner.class));
    return this;
}
 
Example 23
Project: LiteGraph   File: GiraphWorkerContext.java   View source code 5 votes vote down vote up
public void preApplication() throws InstantiationException, IllegalAccessException {
    final Configuration apacheConfiguration = ConfUtil.makeApacheConfiguration(this.getContext().getConfiguration());
    KryoShimServiceLoader.applyConfiguration(apacheConfiguration);
    final VertexProgram vertexProgram = VertexProgram.createVertexProgram(HadoopGraph.open(apacheConfiguration), apacheConfiguration);
    this.vertexProgramPool = new VertexProgramPool(vertexProgram, this.getContext().getConfiguration().getInt(GiraphConstants.NUM_COMPUTE_THREADS.getKey(), 1));
    this.memory = new GiraphMemory(this, vertexProgram);
}
 
Example 24
Project: LiteGraph   File: GiraphMemory.java   View source code 5 votes vote down vote up
public GiraphMemory(final GiraphWorkerContext worker, final VertexProgram<?> vertexProgram) {
    this.worker = worker;
    this.vertexProgram = vertexProgram;
    this.memoryComputeKeys = new HashMap<>();
    this.vertexProgram.getMemoryComputeKeys().forEach(key -> this.memoryComputeKeys.put(key.getKey(), key));
    this.inExecute = true;
}
 
Example 25
Project: LiteGraph   File: TinkerMemory.java   View source code 5 votes vote down vote up
public TinkerMemory(final VertexProgram<?> vertexProgram, final Set<MapReduce> mapReducers) {
    this.currentMap = new ConcurrentHashMap<>();
    this.previousMap = new ConcurrentHashMap<>();
    if (null != vertexProgram) {
        for (final MemoryComputeKey memoryComputeKey : vertexProgram.getMemoryComputeKeys()) {
            this.memoryKeys.put(memoryComputeKey.getKey(), memoryComputeKey);
        }
    }
    for (final MapReduce mapReduce : mapReducers) {
        this.memoryKeys.put(mapReduce.getMemoryKey(), MemoryComputeKey.of(mapReduce.getMemoryKey(), Operator.assign, false, false));
    }
}
 
Example 26
Project: titan1withtp3.1   File: VertexProgramScanJob.java   View source code 5 votes vote down vote up
private VertexProgramScanJob(IDManager idManager, FulgoraMemory memory,
                            FulgoraVertexMemory vertexMemory, VertexProgram<M> vertexProgram) {
    this.idManager = idManager;
    this.memory = memory;
    this.vertexMemory = vertexMemory;
    this.vertexProgram = vertexProgram;
    this.combiner = FulgoraUtil.getMessageCombiner(vertexProgram);
}
 
Example 27
Project: titan1withtp3.1   File: FulgoraVertexMemory.java   View source code 5 votes vote down vote up
public FulgoraVertexMemory(int numVertices, final IDManager idManager, final VertexProgram<M> vertexProgram) {
    Preconditions.checkArgument(numVertices>=0 && vertexProgram!=null && idManager!=null);
    vertexStates = new NonBlockingHashMapLong<>(numVertices);
    partitionVertices = new NonBlockingHashMapLong<>(64);
    this.idManager = idManager;
    this.combiner = FulgoraUtil.getMessageCombiner(vertexProgram);
    this.elementKeyMap = getIdMap(vertexProgram.getElementComputeKeys());
    this.previousScopes = ImmutableMap.of();
}
 
Example 28
Project: titan1withtp3.1   File: FulgoraMemory.java   View source code 5 votes vote down vote up
public FulgoraMemory(final VertexProgram<?> vertexProgram, final Set<MapReduce> mapReducers) {
    this.currentMap = new ConcurrentHashMap<>();
    this.previousMap = new ConcurrentHashMap<>();
    if (null != vertexProgram) {
        for (final String key : vertexProgram.getMemoryComputeKeys()) {
            MemoryHelper.validateKey(key);
            this.memoryKeys.add(key);
        }
    }
    for (final MapReduce mapReduce : mapReducers) {
        this.memoryKeys.add(mapReduce.getMemoryKey());
    }
}
 
Example 29
Project: titan1withtp3.1   File: PartitionedVertexProgramExecutor.java   View source code 5 votes vote down vote up
public PartitionedVertexProgramExecutor(StandardTitanGraph graph, FulgoraMemory memory,
                             FulgoraVertexMemory vertexMemory, VertexProgram<M> vertexProgram) {
    this.graph=graph;
    this.idManager = graph.getIDManager();
    this.memory = memory;
    this.vertexMemory = vertexMemory;
    this.vertexProgram = vertexProgram;
}
 
Example 30
Project: DuctileDB   File: DuctileMemory.java   View source code 5 votes vote down vote up
public DuctileMemory(VertexProgram<M> vertexProgram, Set<MapReduce<?, ?, ?, ?, R>> mapReducers) {
if (null != vertexProgram) {
    for (MemoryComputeKey key : vertexProgram.getMemoryComputeKeys()) {
	// FIXME MemoryHelper.validateKey(key);
	memoryKeys.add(key);
    }
}
for (MapReduce<?, ?, ?, ?, R> mapReduce : mapReducers) {
    // FIXME memoryKeys.add(mapReduce.getMemoryKey());
}
   }
 
Example 31
Project: titan1.0.1.kafka   File: VertexProgramScanJob.java   View source code 5 votes vote down vote up
private VertexProgramScanJob(IDManager idManager, FulgoraMemory memory,
                            FulgoraVertexMemory vertexMemory, VertexProgram<M> vertexProgram) {
    this.idManager = idManager;
    this.memory = memory;
    this.vertexMemory = vertexMemory;
    this.vertexProgram = vertexProgram;
    this.combiner = FulgoraUtil.getMessageCombiner(vertexProgram);
}
 
Example 32
Project: titan1.0.1.kafka   File: FulgoraVertexMemory.java   View source code 5 votes vote down vote up
public FulgoraVertexMemory(int numVertices, final IDManager idManager, final VertexProgram<M> vertexProgram) {
    Preconditions.checkArgument(numVertices>=0 && vertexProgram!=null && idManager!=null);
    vertexStates = new NonBlockingHashMapLong<>(numVertices);
    partitionVertices = new NonBlockingHashMapLong<>(64);
    this.idManager = idManager;
    this.combiner = FulgoraUtil.getMessageCombiner(vertexProgram);
    this.elementKeyMap = getIdMap(vertexProgram.getElementComputeKeys());
    this.previousScopes = ImmutableMap.of();
}
 
Example 33
Project: titan1.0.1.kafka   File: FulgoraMemory.java   View source code 5 votes vote down vote up
public FulgoraMemory(final VertexProgram<?> vertexProgram, final Set<MapReduce> mapReducers) {
    this.currentMap = new ConcurrentHashMap<>();
    this.previousMap = new ConcurrentHashMap<>();
    if (null != vertexProgram) {
        for (final String key : vertexProgram.getMemoryComputeKeys()) {
            MemoryHelper.validateKey(key);
            this.memoryKeys.add(key);
        }
    }
    for (final MapReduce mapReduce : mapReducers) {
        this.memoryKeys.add(mapReduce.getMemoryKey());
    }
}
 
Example 34
Project: titan1.0.1.kafka   File: PartitionedVertexProgramExecutor.java   View source code 5 votes vote down vote up
public PartitionedVertexProgramExecutor(StandardTitanGraph graph, FulgoraMemory memory,
                             FulgoraVertexMemory vertexMemory, VertexProgram<M> vertexProgram) {
    this.graph=graph;
    this.idManager = graph.getIDManager();
    this.memory = memory;
    this.vertexMemory = vertexMemory;
    this.vertexProgram = vertexProgram;
}
 
Example 35
Project: tinkerpop   File: PageRankVertexProgram.java   View source code 5 votes vote down vote up
@Override
public void storeState(final Configuration configuration) {
    VertexProgram.super.storeState(configuration);
    configuration.setProperty(ALPHA, this.alpha);
    configuration.setProperty(EPSILON, this.epsilon);
    configuration.setProperty(PROPERTY, this.property);
    configuration.setProperty(MAX_ITERATIONS, this.maxIterations);
    if (null != this.edgeTraversal)
        this.edgeTraversal.storeState(configuration, EDGE_TRAVERSAL);
    if (null != this.initialRankTraversal)
        this.initialRankTraversal.storeState(configuration, INITIAL_RANK_TRAVERSAL);
}
 
Example 36
Project: tinkerpop   File: BulkLoaderVertexProgram.java   View source code 5 votes vote down vote up
@Override
public void storeState(final Configuration config) {
    VertexProgram.super.storeState(config);
    if (configuration != null) {
        ConfigurationUtils.copy(configuration, config);
    }
}
 
Example 37
Project: tinkerpop   File: ProgramVertexProgramStep.java   View source code 5 votes vote down vote up
public ProgramVertexProgramStep(final Traversal.Admin traversal, final VertexProgram vertexProgram) {
    super(traversal);
    this.configuration = new HashMap<>();
    final MapConfiguration base = new MapConfiguration(this.configuration);
    base.setDelimiterParsingDisabled(true);
    vertexProgram.storeState(base);
    this.toStringOfVertexProgram = vertexProgram.toString();
    this.traverserRequirements = vertexProgram.getTraverserRequirements();
}
 
Example 38
Project: tinkerpop   File: ProgramVertexProgramStep.java   View source code 5 votes vote down vote up
@Override
public VertexProgram generateProgram(final Graph graph, final Memory memory) {
    final MapConfiguration base = new MapConfiguration(this.configuration);
    base.setDelimiterParsingDisabled(true);
    PureTraversal.storeState(base, ROOT_TRAVERSAL, TraversalHelper.getRootTraversal(this.getTraversal()).clone());
    base.setProperty(STEP_ID, this.getId());
    if (memory.exists(TraversalVertexProgram.HALTED_TRAVERSERS))
        TraversalVertexProgram.storeHaltedTraversers(base, memory.get(TraversalVertexProgram.HALTED_TRAVERSERS));
    return VertexProgram.createVertexProgram(graph, base);
}
 
Example 39
Project: tinkerpop   File: VertexProgramPool.java   View source code 5 votes vote down vote up
public VertexProgram take() {
    try {
        return this.pool.poll(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    } catch (final InterruptedException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
Example 40
Project: tinkerpop   File: VertexProgramPool.java   View source code 5 votes vote down vote up
public void offer(final VertexProgram<?> vertexProgram) {
    try {
        this.pool.offer(vertexProgram, TIMEOUT_MS, TimeUnit.MILLISECONDS);
    } catch (final InterruptedException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}