private Id genTaskId() { if (ephemeralTaskId >= 0) { ephemeralTaskId = -1; } return IdGenerator.of(ephemeralTaskId--); } }
/** * Generate a string id * @param id original string id value * @return wrapped id object */ public Id generate(String id) { return of(id); }
/** * Generate a long id * @param id original long id value * @return wrapped id object */ public Id generate(long id) { return of(id); }
@Override public EdgeLabelBuilder id(long id) { E.checkArgument(id != 0L, "Not allowed to assign 0 as edge label id"); this.id = IdGenerator.of(id); return this; }
/** * Concat multiple parts into a single id with ID_SPLITOR * @param parts the string id values to be spliced * @return spliced id object */ public static Id splicing(String... parts) { String escaped = StringUtil.escape(ID_SPLITOR, ESCAPE, parts); return IdGenerator.of(escaped); }
@Override public IndexLabelBuilder id(long id) { E.checkArgument(id != 0L, "Not allowed to assign 0 as index label id"); this.id = IdGenerator.of(id); return this; }
protected Id schemaId() { String name = this.task().name(); String[] parts = name.split(SPLITOR, 3); E.checkState(parts.length == 3 && parts[1] != null, "Task name should be formatted to String " + "'TYPE:ID:NAME', but got '%s'", name); return IdGenerator.of(Long.valueOf(parts[1])); }
@DELETE @Timed @Path("{id}") public void delete(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") long id) { LOG.debug("Graph [{}] delete task: {}", graph, id); TaskScheduler scheduler = graph(manager, graph).taskScheduler(); HugeTask<?> task = scheduler.deleteTask(IdGenerator.of(id)); E.checkArgument(task != null, "There is no task with id '%s'", id); }
@Override public Id read(Kryo kryo, Input input, Class<Id> clazz) { boolean number = input.readBoolean(); int length = input.read(); byte[] idBytes = input.readBytes(length); return IdGenerator.of(idBytes, number); } }
@Test public void testMutiThreadsUpdateWithGtCapacity() { RamCache cache = new RamCache(10); runWithThreads(THREADS_NUM, () -> { for (int i = 0; i < 10000 * 100; i++) { Id id = IdGenerator.of( Thread.currentThread().getName() + "-" + i); cache.update(id, "value-" + i); } }); Assert.assertEquals(10, cache.size()); }
@Test public void testUpdateGet() { RamCache cache = new RamCache(); Id id = IdGenerator.of("1"); cache.update(id, "value-1"); Assert.assertEquals("value-1", cache.get(id)); }
@Test public void testUpdateIfAbsent() { RamCache cache = new RamCache(); Id id = IdGenerator.of("1"); cache.updateIfAbsent(id, "value-1"); Assert.assertEquals("value-1", cache.get(id)); }
@Override public BackendEntry writeVertexProperty(HugeVertexProperty<?> prop) { BinaryBackendEntry entry = newBackendEntry(prop.element()); entry.column(this.formatProperty(prop)); entry.subId(IdGenerator.of(prop.key())); return entry; }
@Test public void testUpdateIfAbsentWithExistKey() { RamCache cache = new RamCache(); Id id = IdGenerator.of("1"); cache.update(id, "value-1"); cache.updateIfAbsent(id, "value-2"); Assert.assertEquals("value-1", cache.get(id)); }
private CassandraBackendEntry wrapByVertex(CassandraBackendEntry edge) { assert edge.type().isEdge(); String ownerVertex = edge.column(HugeKeys.OWNER_VERTEX); E.checkState(ownerVertex != null, "Invalid backend entry"); Id vertexId = IdGenerator.of(ownerVertex); CassandraBackendEntry vertex = new CassandraBackendEntry( HugeType.VERTEX, vertexId); vertex.column(HugeKeys.ID, ownerVertex); vertex.column(HugeKeys.PROPERTIES, ImmutableMap.of()); vertex.subRow(edge.row()); return vertex; }
@Override public BackendEntry writeEdge(HugeEdge edge) { Id id = IdGenerator.of(edge.idWithDirection().asString()); TextBackendEntry entry = newBackendEntry(edge.type(), id); entry.column(this.formatEdgeName(edge), this.formatEdgeValue(edge)); return entry; }
private MysqlBackendEntry wrapByVertex(MysqlBackendEntry edge) { assert edge.type().isEdge(); String ownerVertex = edge.column(HugeKeys.OWNER_VERTEX); E.checkState(ownerVertex != null, "Invalid backend entry"); Id vertexId = IdGenerator.of(ownerVertex); MysqlBackendEntry vertex = new MysqlBackendEntry(HugeType.VERTEX, vertexId); vertex.column(HugeKeys.ID, ownerVertex); vertex.column(HugeKeys.PROPERTIES, ""); vertex.subRow(edge.row()); return vertex; }