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); }
public synchronized Id nextId(HugeType type) { AtomicLong counter = this.counters.get(type); if (counter == null) { counter = new AtomicLong(0); AtomicLong previous = this.counters.putIfAbsent(type, counter); if (previous != null) { counter = previous; } } return IdGenerator.of(counter.incrementAndGet()); }
@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; }
private BackendEntry getEntryById(Id id, Map<Id, BackendEntry> entries) { // TODO: improve id split Id entryId = IdGenerator.of(EdgeId.split(id)[0]); return entries.get(entryId); }
@Override public PropertyKeyBuilder id(long id) { E.checkArgument(id != 0L, "Not allowed to assign 0 as property key id"); this.id = IdGenerator.of(id); return this; }
@Override protected Id[] toIdArray(Object object) { assert object instanceof String; String value = (String) object; Number[] values = JsonUtil.fromJson(value, Number[].class); Id[] ids = new Id[values.length]; int i = 0; for (Number number : values) { ids[i++] = IdGenerator.of(number.longValue()); } return ids; }
@Override public VertexLabelBuilder id(long id) { E.checkArgument(id != 0L, "Not allowed to assign 0 as vertex label id"); this.id = IdGenerator.of(id); return this; }
@GET @Timed @Path("{id}") @Produces(APPLICATION_JSON_WITH_CHARSET) public Map<String, Object> get(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") long id) { LOG.debug("Graph [{}] get task: {}", graph, id); TaskScheduler scheduler = graph(manager, graph).taskScheduler(); return scheduler.task(IdGenerator.of(id)).asMap(); }
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); }
private static Id generateId(HugeType type, Id id) { // NOTE: it's slower performance to use: // String.format("%x-%s", type.code(), name) return IdGenerator.of(type.string() + "-" + id.asString()); }
@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); } }
@Watched(prefix = "schema") public Id getNextSystemId() { LOG.debug("SchemaTransaction get next system id"); Id id = this.store().nextId(HugeType.SYS_SCHEMA); return IdGenerator.of(-id.asLong()); }