Java Code Examples for com.thinkaurelius.titan.core.TitanEdge

The following are top voted examples for showing how to use com.thinkaurelius.titan.core.TitanEdge. 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: titan1withtp3.1   File: EdgeSerializerTest.java   View source code 6 votes vote down vote up
@Test
public void testValueOrdering() {
    StandardTitanGraph graph = (StandardTitanGraph) StorageSetup.getInMemoryGraph();
    TitanManagement mgmt = graph.openManagement();
    EdgeLabel father = mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
    for (int i=1;i<=5;i++) mgmt.makePropertyKey("key" + i).dataType(Integer.class).make();
    mgmt.commit();

    TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex();
    TitanEdge e1 = v1.addEdge("father",v2);
    for (int i=1;i<=5;i++) e1.property("key"+i,i);

    graph.tx().commit();

    e1.remove();
    graph.tx().commit();

}
 
Example 2
Project: titan1withtp3.1   File: VertexMemoryHandler.java   View source code 6 votes vote down vote up
public Stream<M> receiveMessages(MessageScope messageScope) {
    if (messageScope instanceof MessageScope.Global) {
        M message = vertexMemory.getMessage(vertexId,messageScope);
        if (message == null) return Stream.empty();
        else return Stream.of(message);
    } else {
        final MessageScope.Local<M> localMessageScope = (MessageScope.Local) messageScope;
        final Traversal<Vertex, Edge> reverseIncident = FulgoraUtil.getReverseElementTraversal(localMessageScope,vertex,vertex.tx());
        final BiFunction<M,Edge,M> edgeFct = localMessageScope.getEdgeFunction();

        return IteratorUtils.stream(reverseIncident)
                .map(e -> {
                    M msg = vertexMemory.getMessage(vertexMemory.getCanonicalId(((TitanEdge) e).otherVertex(vertex).longId()), localMessageScope);
                    return msg == null ? null : edgeFct.apply(msg, e);
                })
                .filter(m -> m != null);
    }
}
 
Example 3
Project: titan1.0.1.kafka   File: EdgeSerializerTest.java   View source code 6 votes vote down vote up
@Test
public void testValueOrdering() {
    StandardTitanGraph graph = (StandardTitanGraph) StorageSetup.getInMemoryGraph();
    TitanManagement mgmt = graph.openManagement();
    EdgeLabel father = mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
    for (int i=1;i<=5;i++) mgmt.makePropertyKey("key" + i).dataType(Integer.class).make();
    mgmt.commit();

    TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex();
    TitanEdge e1 = v1.addEdge("father",v2);
    for (int i=1;i<=5;i++) e1.property("key"+i,i);

    graph.tx().commit();

    e1.remove();
    graph.tx().commit();

}
 
Example 4
Project: titan1.0.1.kafka   File: VertexMemoryHandler.java   View source code 6 votes vote down vote up
public Stream<M> receiveMessages(MessageScope messageScope) {
    if (messageScope instanceof MessageScope.Global) {
        M message = vertexMemory.getMessage(vertexId,messageScope);
        if (message == null) return Stream.empty();
        else return Stream.of(message);
    } else {
        final MessageScope.Local<M> localMessageScope = (MessageScope.Local) messageScope;
        final Traversal<Vertex, Edge> reverseIncident = FulgoraUtil.getReverseElementTraversal(localMessageScope,vertex,vertex.tx());
        final BiFunction<M,Edge,M> edgeFct = localMessageScope.getEdgeFunction();

        return IteratorUtils.stream(reverseIncident)
                .map(e -> {
                    M msg = vertexMemory.getMessage(vertexMemory.getCanonicalId(((TitanEdge) e).otherVertex(vertex).longId()), localMessageScope);
                    return msg == null ? null : edgeFct.apply(msg, e);
                })
                .filter(m -> m != null);
    }
}
 
Example 5
Project: titan0.5.4-hbase1.1.1-custom   File: EdgeSerializerTest.java   View source code 6 votes vote down vote up
@Test
public void testValueOrdering() {
    StandardTitanGraph graph = (StandardTitanGraph) StorageSetup.getInMemoryGraph();
    TitanManagement mgmt = graph.getManagementSystem();
    EdgeLabel father = mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
    for (int i=1;i<=5;i++) mgmt.makePropertyKey("key" + i).dataType(Integer.class).make();
    mgmt.commit();

    TitanVertex v1 = graph.addVertex(null), v2 = graph.addVertex(null);
    TitanEdge e1 = v1.addEdge("father",v2);
    for (int i=1;i<=5;i++) e1.setProperty("key"+i,i);

    graph.commit();

    e1.remove();
    graph.commit();

}
 
Example 6
Project: titan0.5.4-hbase1.1.1-custom   File: LoaderScriptWrapper.java   View source code 6 votes vote down vote up
public TitanEdge getEdge(FaunusEdge faunusEdge, TitanVertex in, TitanVertex out, TitanGraph graph, Mapper.Context context) {
    Bindings bindings = new SimpleBindings();
    bindings.put("faunusEdge", faunusEdge);
    bindings.put("inVertex", in);
    bindings.put("outVertex", out);
    bindings.put("graph", graph);
    bindings.put("context", context);
    bindings.put("log", LOGGER);
    DEFAULT_COMPAT.incrementContextCounter(context, Counters.EDGE_LOADER_SCRIPT_CALLS, 1L);
    try {
        TitanEdge edge = (TitanEdge)edgeMethod.eval(bindings);
        LOGGER.debug("Compiled edge method returned {}", edge);
        DEFAULT_COMPAT.incrementContextCounter(context, Counters.EDGE_LOADER_SCRIPT_RETURNS, 1L);
        return edge;
    } catch (ScriptException e) {
        DEFAULT_COMPAT.incrementContextCounter(context, Counters.EDGE_LOADER_SCRIPT_EXCEPTIONS, 1L);
        throw new RuntimeException(e);
    }
}
 
Example 7
Project: titan1withtp3.1   File: DirectionCondition.java   View source code 5 votes vote down vote up
@Override
public boolean evaluate(E element) {
    if (direction==Direction.BOTH) return true;
    if (element instanceof CacheEdge) {
        return direction==((CacheEdge)element).getVertexCentricDirection();
    } else if (element instanceof TitanEdge) {
        return ((TitanEdge)element).vertex(direction).equals(baseVertex);
    } else if (element instanceof TitanVertexProperty) {
        return direction==Direction.OUT;
    }
    return false;
}
 
Example 8
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 5 votes vote down vote up
private TitanEdge addSchemaEdge(TitanVertex out, TitanVertex in, TypeDefinitionCategory def, Object modifier) {
    assert def.isEdge();
    TitanEdge edge = transaction.addEdge(out, in, BaseLabel.SchemaDefinitionEdge);
    TypeDefinitionDescription desc = new TypeDefinitionDescription(def, modifier);
    edge.property(BaseKey.SchemaDefinitionDesc.name(), desc);
    return edge;
}
 
Example 9
Project: titan1withtp3.1   File: TitanSchemaVertex.java   View source code 5 votes vote down vote up
public Iterable<TitanEdge> getEdges(final TypeDefinitionCategory def, final Direction dir, TitanSchemaVertex other) {
    TitanVertexQuery query = query().type(BaseLabel.SchemaDefinitionEdge).direction(dir);
    if (other!=null) query.adjacent(other);
    return Iterables.filter(query.edges(),new Predicate<TitanEdge>() {
        @Override
        public boolean apply(@Nullable TitanEdge edge) {
            TypeDefinitionDescription desc = edge.valueOrNull(BaseKey.SchemaDefinitionDesc);
            return desc.getCategory()==def;
        }
    });
}
 
Example 10
Project: titan1withtp3.1   File: ElementUtils.java   View source code 5 votes vote down vote up
public static RelationIdentifier getEdgeId(Object id) {
    if (null == id) return null;

    try {
        if (id instanceof TitanEdge) return (RelationIdentifier) ((TitanEdge) id).id();
        else if (id instanceof RelationIdentifier) return (RelationIdentifier) id;
        else if (id instanceof String) return RelationIdentifier.parse((String) id);
        else if (id instanceof long[]) return RelationIdentifier.get((long[]) id);
        else if (id instanceof int[]) return RelationIdentifier.get((int[]) id);
    } catch (IllegalArgumentException e) {
        //swallow since null will be returned below
    }
    return null;
}
 
Example 11
Project: titan1.0.1.kafka   File: DirectionCondition.java   View source code 5 votes vote down vote up
@Override
public boolean evaluate(E element) {
    if (direction==Direction.BOTH) return true;
    if (element instanceof CacheEdge) {
        return direction==((CacheEdge)element).getVertexCentricDirection();
    } else if (element instanceof TitanEdge) {
        return ((TitanEdge)element).vertex(direction).equals(baseVertex);
    } else if (element instanceof TitanVertexProperty) {
        return direction==Direction.OUT;
    }
    return false;
}
 
Example 12
Project: titan1.0.1.kafka   File: ManagementSystem.java   View source code 5 votes vote down vote up
private TitanEdge addSchemaEdge(TitanVertex out, TitanVertex in, TypeDefinitionCategory def, Object modifier) {
    assert def.isEdge();
    TitanEdge edge = transaction.addEdge(out, in, BaseLabel.SchemaDefinitionEdge);
    TypeDefinitionDescription desc = new TypeDefinitionDescription(def, modifier);
    edge.property(BaseKey.SchemaDefinitionDesc.name(), desc);
    return edge;
}
 
Example 13
Project: titan1.0.1.kafka   File: TitanSchemaVertex.java   View source code 5 votes vote down vote up
public Iterable<TitanEdge> getEdges(final TypeDefinitionCategory def, final Direction dir, TitanSchemaVertex other) {
    TitanVertexQuery query = query().type(BaseLabel.SchemaDefinitionEdge).direction(dir);
    if (other!=null) query.adjacent(other);
    return Iterables.filter(query.edges(),new Predicate<TitanEdge>() {
        @Override
        public boolean apply(@Nullable TitanEdge edge) {
            TypeDefinitionDescription desc = edge.valueOrNull(BaseKey.SchemaDefinitionDesc);
            return desc.getCategory()==def;
        }
    });
}
 
Example 14
Project: titan1.0.1.kafka   File: ElementUtils.java   View source code 5 votes vote down vote up
public static RelationIdentifier getEdgeId(Object id) {
    if (null == id) return null;

    try {
        if (id instanceof TitanEdge) return (RelationIdentifier) ((TitanEdge) id).id();
        else if (id instanceof RelationIdentifier) return (RelationIdentifier) id;
        else if (id instanceof String) return RelationIdentifier.parse((String) id);
        else if (id instanceof long[]) return RelationIdentifier.get((long[]) id);
        else if (id instanceof int[]) return RelationIdentifier.get((int[]) id);
    } catch (IllegalArgumentException e) {
        //swallow since null will be returned below
    }
    return null;
}
 
Example 15
Project: titan0.5.4-hbase1.1.1-custom   File: StandardFaunusEdge.java   View source code 5 votes vote down vote up
@Override
public boolean equals(Object oth) {
    if (this == oth) return true;
    else if (oth == null || !(oth instanceof TitanEdge)) return false;
    TitanEdge e = (TitanEdge) oth;
    if (hasId() || e.hasId()) return getLongId()==e.getLongId();
    return getType().equals(e.getEdgeLabel()) && outVertex==e.getVertex(Direction.OUT).getLongId() &&
            inVertex==e.getVertex(Direction.IN).getLongId();
}
 
Example 16
Project: titan0.5.4-hbase1.1.1-custom   File: DirectionCondition.java   View source code 5 votes vote down vote up
@Override
public boolean evaluate(E element) {
    if (direction==Direction.BOTH) return true;
    if (element instanceof CacheEdge) {
        return direction==((CacheEdge)element).getVertexCentricDirection();
    } else if (element instanceof TitanEdge) {
        return ((TitanEdge)element).getVertex(direction).equals(baseVertex);
    } else if (element instanceof TitanProperty) {
        return direction==Direction.OUT;
    }
    return false;
}
 
Example 17
Project: titan0.5.4-hbase1.1.1-custom   File: TitanSchemaVertex.java   View source code 5 votes vote down vote up
public Iterable<TitanEdge> getEdges(final TypeDefinitionCategory def, final Direction dir, TitanSchemaVertex other) {
    TitanVertexQuery query = query().type(BaseLabel.SchemaDefinitionEdge).direction(dir);
    if (other!=null) query.adjacent(other);
    return Iterables.filter(query.titanEdges(),new Predicate<TitanEdge>() {
        @Override
        public boolean apply(@Nullable TitanEdge edge) {
            TypeDefinitionDescription desc = edge.getProperty(BaseKey.SchemaDefinitionDesc);
            return desc.getCategory()==def;
        }
    });
}
 
Example 18
Project: titan1withtp3.1   File: TitanGraphPerformanceMemoryTest.java   View source code 4 votes vote down vote up
@Test
    public void testTransactionalMemory() throws Exception {
        makeVertexIndexedUniqueKey("uid",Long.class);
        makeKey("name",String.class);

        PropertyKey time = makeKey("time",Integer.class);
        mgmt.makeEdgeLabel("friend").signature(time).directed().make();
        finishSchema();

        final Random random = new Random();
        final int rounds = 100;
        final int commitSize = 1500;
        final AtomicInteger uidCounter = new AtomicInteger(0);
        Thread[] writeThreads = new Thread[4];
        long start = System.currentTimeMillis();
        for (int t = 0; t < writeThreads.length; t++) {
            writeThreads[t] = new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int r = 0; r < rounds; r++) {
                        TitanTransaction tx = graph.newTransaction();
                        TitanVertex previous = null;
                        for (int c = 0; c < commitSize; c++) {
                            TitanVertex v = tx.addVertex();
                            long uid = uidCounter.incrementAndGet();
                            v.property(VertexProperty.Cardinality.single, "uid",  uid);
                            v.property(VertexProperty.Cardinality.single, "name",  "user" + uid);
                            if (previous != null) {
                                v.addEdge("friend", previous, "time", Math.abs(random.nextInt()));
                            }
                            previous = v;
                        }
                        tx.commit();
                    }
                }
            });
            writeThreads[t].start();
        }
        for (int t = 0; t < writeThreads.length; t++) {
            writeThreads[t].join();
        }
        System.out.println("Write time for " + (rounds * commitSize * writeThreads.length) + " vertices & edges: " + (System.currentTimeMillis() - start));

        final int maxUID = uidCounter.get();
        final int trials = 1000;
        final String fixedName = "john";
        Thread[] readThreads = new Thread[Runtime.getRuntime().availableProcessors() * 2];
        start = System.currentTimeMillis();
        for (int t = 0; t < readThreads.length; t++) {
            readThreads[t] = new Thread(new Runnable() {
                @Override
                public void run() {
                    TitanTransaction tx = graph.newTransaction();
                    long ruid = random.nextInt(maxUID) + 1;
                    getVertex(tx,"uid", ruid).property(VertexProperty.Cardinality.single, "name",  fixedName);
                    for (int t = 1; t <= trials; t++) {
                        TitanVertex v = getVertex(tx,"uid", random.nextInt(maxUID) + 1);
                        assertCount(2, v.properties());
                        int count = 0;
                        for (TitanEdge e : v.query().direction(Direction.BOTH).edges()) {
                            count++;
                            assertTrue(e.<Integer>value("time") >= 0);
                        }
                        assertTrue(count <= 2);
//                        if (t%(trials/10)==0) System.out.println(t);
                    }
                    assertEquals(fixedName, getVertex(tx,"uid", ruid).value("name"));
                    tx.commit();
                }
            });
            readThreads[t].start();
        }
        for (int t = 0; t < readThreads.length; t++) {
            readThreads[t].join();
        }
        System.out.println("Read time for " + (trials * readThreads.length) + " vertex lookups: " + (System.currentTimeMillis() - start));

    }
 
Example 19
Project: titan1withtp3.1   File: EdgeSerializerTest.java   View source code 4 votes vote down vote up
private Entry serialize(StandardTitanGraph graph, TitanEdge e, int pos) {
    EdgeSerializer edgeSerializer = graph.getEdgeSerializer();
    InternalRelation r = (InternalRelation)e;
    return edgeSerializer.writeRelation(r,pos,r.tx());
}
 
Example 20
Project: titan1withtp3.1   File: IncidenceDirectionCondition.java   View source code 4 votes vote down vote up
@Override
public boolean evaluate(E relation) {
    return relation.isEdge() && ((TitanEdge) relation).vertex(direction).equals(otherVertex);
}
 
Example 21
Project: titan1withtp3.1   File: IncidenceCondition.java   View source code 4 votes vote down vote up
@Override
public boolean evaluate(E relation) {
    return relation.isEdge() && ((TitanEdge) relation).otherVertex(baseVertex).equals(otherVertex);
}
 
Example 22
Project: titan1withtp3.1   File: TitanSchemaVertex.java   View source code 4 votes vote down vote up
public Iterable<TitanEdge> getEdges(final TypeDefinitionCategory def, final Direction dir) {
    return getEdges(def,dir,null);
}
 
Example 23
Project: titan1withtp3.1   File: PreloadedVertex.java   View source code 4 votes vote down vote up
@Override
public TitanEdge addEdge(String s, Vertex vertex, Object... keyValues) {
    throw GraphComputer.Exceptions.adjacentVertexEdgesAndVerticesCanNotBeReadOrUpdated();
}
 
Example 24
Project: titan1withtp3.1   File: RelationIdentifier.java   View source code 4 votes vote down vote up
public TitanEdge findEdge(TitanTransaction tx) {
    TitanRelation r = findRelation(tx);
    if (r == null) return null;
    else if (r instanceof TitanEdge) return (TitanEdge) r;
    else throw new UnsupportedOperationException("Referenced relation is a property not an edge");
}
 
Example 25
Project: incubator-atlas   File: NativeTitan1GraphQuery.java   View source code 4 votes vote down vote up
@Override
public Iterable<AtlasEdge<Titan1Vertex, Titan1Edge>> edges() {
    Iterable<TitanEdge> it = query.edges();
    return graph.wrapEdges(it);
}
 
Example 26
Project: titan1.0.1.kafka   File: TitanGraphPerformanceMemoryTest.java   View source code 4 votes vote down vote up
@Test
    public void testTransactionalMemory() throws Exception {
        makeVertexIndexedUniqueKey("uid",Long.class);
        makeKey("name",String.class);

        PropertyKey time = makeKey("time",Integer.class);
        mgmt.makeEdgeLabel("friend").signature(time).directed().make();
        finishSchema();

        final Random random = new Random();
        final int rounds = 100;
        final int commitSize = 1500;
        final AtomicInteger uidCounter = new AtomicInteger(0);
        Thread[] writeThreads = new Thread[4];
        long start = System.currentTimeMillis();
        for (int t = 0; t < writeThreads.length; t++) {
            writeThreads[t] = new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int r = 0; r < rounds; r++) {
                        TitanTransaction tx = graph.newTransaction();
                        TitanVertex previous = null;
                        for (int c = 0; c < commitSize; c++) {
                            TitanVertex v = tx.addVertex();
                            long uid = uidCounter.incrementAndGet();
                            v.property(VertexProperty.Cardinality.single, "uid",  uid);
                            v.property(VertexProperty.Cardinality.single, "name",  "user" + uid);
                            if (previous != null) {
                                v.addEdge("friend", previous, "time", Math.abs(random.nextInt()));
                            }
                            previous = v;
                        }
                        tx.commit();
                    }
                }
            });
            writeThreads[t].start();
        }
        for (int t = 0; t < writeThreads.length; t++) {
            writeThreads[t].join();
        }
        System.out.println("Write time for " + (rounds * commitSize * writeThreads.length) + " vertices & edges: " + (System.currentTimeMillis() - start));

        final int maxUID = uidCounter.get();
        final int trials = 1000;
        final String fixedName = "john";
        Thread[] readThreads = new Thread[Runtime.getRuntime().availableProcessors() * 2];
        start = System.currentTimeMillis();
        for (int t = 0; t < readThreads.length; t++) {
            readThreads[t] = new Thread(new Runnable() {
                @Override
                public void run() {
                    TitanTransaction tx = graph.newTransaction();
                    long ruid = random.nextInt(maxUID) + 1;
                    getVertex(tx,"uid", ruid).property(VertexProperty.Cardinality.single, "name",  fixedName);
                    for (int t = 1; t <= trials; t++) {
                        TitanVertex v = getVertex(tx,"uid", random.nextInt(maxUID) + 1);
                        assertCount(2, v.properties());
                        int count = 0;
                        for (TitanEdge e : v.query().direction(Direction.BOTH).edges()) {
                            count++;
                            assertTrue(e.<Integer>value("time") >= 0);
                        }
                        assertTrue(count <= 2);
//                        if (t%(trials/10)==0) System.out.println(t);
                    }
                    assertEquals(fixedName, getVertex(tx,"uid", ruid).value("name"));
                    tx.commit();
                }
            });
            readThreads[t].start();
        }
        for (int t = 0; t < readThreads.length; t++) {
            readThreads[t].join();
        }
        System.out.println("Read time for " + (trials * readThreads.length) + " vertex lookups: " + (System.currentTimeMillis() - start));

    }
 
Example 27
Project: titan1.0.1.kafka   File: EdgeSerializerTest.java   View source code 4 votes vote down vote up
private Entry serialize(StandardTitanGraph graph, TitanEdge e, int pos) {
    EdgeSerializer edgeSerializer = graph.getEdgeSerializer();
    InternalRelation r = (InternalRelation)e;
    return edgeSerializer.writeRelation(r,pos,r.tx());
}
 
Example 28
Project: titan1.0.1.kafka   File: IncidenceDirectionCondition.java   View source code 4 votes vote down vote up
@Override
public boolean evaluate(E relation) {
    return relation.isEdge() && ((TitanEdge) relation).vertex(direction).equals(otherVertex);
}
 
Example 29
Project: titan1.0.1.kafka   File: IncidenceCondition.java   View source code 4 votes vote down vote up
@Override
public boolean evaluate(E relation) {
    return relation.isEdge() && ((TitanEdge) relation).otherVertex(baseVertex).equals(otherVertex);
}
 
Example 30
Project: titan1.0.1.kafka   File: TitanSchemaVertex.java   View source code 4 votes vote down vote up
public Iterable<TitanEdge> getEdges(final TypeDefinitionCategory def, final Direction dir) {
    return getEdges(def,dir,null);
}
 
Example 31
Project: titan1.0.1.kafka   File: PreloadedVertex.java   View source code 4 votes vote down vote up
@Override
public TitanEdge addEdge(String s, Vertex vertex, Object... keyValues) {
    throw GraphComputer.Exceptions.adjacentVertexEdgesAndVerticesCanNotBeReadOrUpdated();
}
 
Example 32
Project: titan1.0.1.kafka   File: RelationIdentifier.java   View source code 4 votes vote down vote up
public TitanEdge findEdge(TitanTransaction tx) {
    TitanRelation r = findRelation(tx);
    if (r == null) return null;
    else if (r instanceof TitanEdge) return (TitanEdge) r;
    else throw new UnsupportedOperationException("Referenced relation is a property not an edge");
}
 
Example 33
Project: titan0.5.4-hbase1.1.1-custom   File: TitanGraphPerformanceMemoryTest.java   View source code 4 votes vote down vote up
@Test
    public void testTransactionalMemory() throws Exception {
        makeVertexIndexedUniqueKey("uid",Long.class);
        makeKey("name",String.class);

        PropertyKey time = makeKey("time",Integer.class);
        mgmt.makeEdgeLabel("friend").signature(time).directed().make();
        finishSchema();

        final Random random = new Random();
        final int rounds = 100;
        final int commitSize = 1500;
        final AtomicInteger uidCounter = new AtomicInteger(0);
        Thread[] writeThreads = new Thread[4];
        long start = System.currentTimeMillis();
        for (int t = 0; t < writeThreads.length; t++) {
            writeThreads[t] = new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int r = 0; r < rounds; r++) {
                        TitanTransaction tx = graph.newTransaction();
                        TitanVertex previous = null;
                        for (int c = 0; c < commitSize; c++) {
                            TitanVertex v = tx.addVertex();
                            long uid = uidCounter.incrementAndGet();
                            v.setProperty("uid", uid);
                            v.setProperty("name", "user" + uid);
                            if (previous != null) {
                                v.addEdge("friend", previous).setProperty("time", Math.abs(random.nextInt()));
                            }
                            previous = v;
                        }
                        tx.commit();
                    }
                }
            });
            writeThreads[t].start();
        }
        for (int t = 0; t < writeThreads.length; t++) {
            writeThreads[t].join();
        }
        System.out.println("Write time for " + (rounds * commitSize * writeThreads.length) + " vertices & edges: " + (System.currentTimeMillis() - start));

        final int maxUID = uidCounter.get();
        final int trials = 1000;
        final String fixedName = "john";
        Thread[] readThreads = new Thread[Runtime.getRuntime().availableProcessors() * 2];
        start = System.currentTimeMillis();
        for (int t = 0; t < readThreads.length; t++) {
            readThreads[t] = new Thread(new Runnable() {
                @Override
                public void run() {
                    TitanTransaction tx = graph.newTransaction();
                    long ruid = random.nextInt(maxUID) + 1;
                    getVertex(tx,"uid", ruid).setProperty("name", fixedName);
                    for (int t = 1; t <= trials; t++) {
                        TitanVertex v = getVertex(tx,"uid", random.nextInt(maxUID) + 1);
                        assertEquals(2, Iterables.size(v.getProperties()));
                        int count = 0;
                        for (TitanEdge e : v.getEdges()) {
                            count++;
                            assertTrue(((Number) e.getProperty("time")).longValue() >= 0);
                        }
                        assertTrue(count <= 2);
//                        if (t%(trials/10)==0) System.out.println(t);
                    }
                    assertEquals(fixedName, getVertex(tx,"uid", ruid).getProperty("name"));
                    tx.commit();
                }
            });
            readThreads[t].start();
        }
        for (int t = 0; t < readThreads.length; t++) {
            readThreads[t].join();
        }
        System.out.println("Read time for " + (trials * readThreads.length) + " vertex lookups: " + (System.currentTimeMillis() - start));

    }
 
Example 34
Project: titan0.5.4-hbase1.1.1-custom   File: EdgeSerializerTest.java   View source code 4 votes vote down vote up
private Entry serialize(StandardTitanGraph graph, TitanEdge e, int pos) {
    EdgeSerializer edgeSerializer = graph.getEdgeSerializer();
    InternalRelation r = (InternalRelation)e;
    return edgeSerializer.writeRelation(r,pos,r.tx());
}
 
Example 35
Project: titan0.5.4-hbase1.1.1-custom   File: FulgoraRelationQuery.java   View source code 4 votes vote down vote up
M process(TitanEdge e, Direction dir, S state, @Nullable M previous) {
    M result = gather.apply(state,e, dir);
    if (previous==null) return result;
    else return combiner.combine(previous,result);
}
 
Example 36
Project: titan0.5.4-hbase1.1.1-custom   File: FulgoraRelationQuery.java   View source code 4 votes vote down vote up
@Override
public Object apply(Object state, TitanEdge edge, Direction dir) {
    return state;
}
 
Example 37
Project: titan0.5.4-hbase1.1.1-custom   File: IncidenceDirectionCondition.java   View source code 4 votes vote down vote up
@Override
public boolean evaluate(E relation) {
    return relation.isEdge() && ((TitanEdge) relation).getVertex(direction).equals(otherVertex);
}
 
Example 38
Project: titan0.5.4-hbase1.1.1-custom   File: IncidenceCondition.java   View source code 4 votes vote down vote up
@Override
public boolean evaluate(E relation) {
    return relation.isEdge() && ((TitanEdge) relation).getOtherVertex(baseVertex).equals(otherVertex);
}
 
Example 39
Project: titan0.5.4-hbase1.1.1-custom   File: TitanSchemaVertex.java   View source code 4 votes vote down vote up
public Iterable<TitanEdge> getEdges(final TypeDefinitionCategory def, final Direction dir) {
    return getEdges(def,dir,null);
}
 
Example 40
Project: titan0.5.4-hbase1.1.1-custom   File: Gather.java   View source code 2 votes vote down vote up
/**
 * Gathers the adjacent vertex's state and the connecting edge's properties into a single object
 * to be combined by a corresponding {@link Combiner} as configured in {@link OLAPQueryBuilder#edges(Gather, Combiner)}.
 *
 * @param state State of the adjacent vertex
 * @param edge Edge connecting to the adjacent vertex
 * @param dir Direction of the edge from the perspective of the current/central vertex
 * @return An object of type M which gathers the state and edge properties
 */
public M apply(S state, TitanEdge edge, Direction dir);