com.baidu.hugegraph.util.InsertionOrderUtil Java Examples
The following examples show how to use
com.baidu.hugegraph.util.InsertionOrderUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricsAPI.java From hugegraph with Apache License 2.0 | 6 votes |
@GET @Timed @Path("backend") @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed("admin") public String backend(@Context GraphManager manager) { Map<String, Map<String, Object>> results = InsertionOrderUtil.newMap(); for (String graph : manager.graphs()) { HugeGraph g = manager.graph(graph); Map<String, Object> metrics = InsertionOrderUtil.newMap(); metrics.put(BackendMetrics.BACKEND, g.backend()); try { metrics.putAll(g.metadata(null, "metrics")); } catch (Throwable e) { metrics.put(BackendMetrics.EXCEPTION, e.toString()); LOG.debug("Failed to get backend metrics", e); } results.put(graph, metrics); } return JsonUtil.toJson(results); }
Example #2
Source File: HugeTraverser.java From hugegraph with Apache License 2.0 | 6 votes |
public static <K, V extends Comparable<? super V>> Map<K, V> topN( Map<K, V> map, boolean sorted, long limit) { if (sorted) { map = CollectionUtil.sortByValue(map, false); } if (limit == NO_LIMIT || map.size() <= limit) { return map; } Map<K, V> results = InsertionOrderUtil.newMap(); long count = 0L; for (Map.Entry<K, V> entry : map.entrySet()) { results.put(entry.getKey(), entry.getValue()); if (++count >= limit) { break; } } return results; }
Example #3
Source File: InsertionOrderUtilTest.java From hugegraph-common with Apache License 2.0 | 6 votes |
@Test public void testSetCopy() { Set<Integer> set = InsertionOrderUtil.newSet(); set.add(4); set.add(2); set.add(5); set.add(1); set.add(3); Assert.assertEquals(ImmutableList.of(4, 2, 5, 1, 3), ImmutableList.copyOf(set)); Set<Integer> set2 = InsertionOrderUtil.newSet(set); set2.add(6); set2.add(1); Assert.assertEquals(ImmutableList.of(4, 2, 5, 1, 3, 6), ImmutableList.copyOf(set2)); Assert.assertEquals(ImmutableList.of(4, 2, 5, 1, 3), ImmutableList.copyOf(set)); }
Example #4
Source File: ConditionQueryFlatten.java From hugegraph with Apache License 2.0 | 6 votes |
private static Set<Relations> flattenAndOr(Condition condition) { Set<Relations> result = InsertionOrderUtil.newSet(); switch (condition.type()) { case RELATION: Relation relation = (Relation) condition; result.add(Relations.of(relation)); break; case AND: Condition.And and = (Condition.And) condition; result = and(flattenAndOr(and.left()), flattenAndOr(and.right())); break; case OR: Condition.Or or = (Condition.Or) condition; result = or(flattenAndOr(or.left()), flattenAndOr(or.right())); break; default: throw new AssertionError(String.format( "Wrong condition type: '%s'", condition.type())); } return result; }
Example #5
Source File: RocksDBMetrics.java From hugegraph with Apache License 2.0 | 6 votes |
@Override public Map<String, Object> getMetrics() { Map<String, Object> metrics = InsertionOrderUtil.newMap(); metrics.put(NODES, 1); // NOTE: the unit of rocksdb mem property is bytes metrics.put(MEM_USED, this.getMemUsed() / Bytes.MB); metrics.put(MEM_UNIT, "MB"); putMetrics(metrics, BLOCK_CACHE); putMetrics(metrics, BLOCK_CACHE_PINNED); putMetrics(metrics, BLOCK_CACHE_CAPACITY); putMetrics(metrics, INDEX_FILTER); putMetrics(metrics, ALL_MEM_TABLE); putMetrics(metrics, MEM_TABLE); putMetrics(metrics, MEM_TABLE_FLUSH_PENDINF); String size = FileUtils.byteCountToDisplaySize(this.getDataSize()); metrics.put(DATA_SIZE, size); return metrics; }
Example #6
Source File: InsertionOrderUtilTest.java From hugegraph-common with Apache License 2.0 | 6 votes |
@Test public void testListCopy() { List<Integer> list = InsertionOrderUtil.newList(); list.add(4); list.add(2); list.add(5); list.add(1); list.add(3); Assert.assertEquals(ImmutableList.of(4, 2, 5, 1, 3), ImmutableList.copyOf(list)); List<Integer> list2 = InsertionOrderUtil.newList(list); list2.add(6); list2.add(1); Assert.assertEquals(ImmutableList.of(4, 2, 5, 1, 3, 6, 1), ImmutableList.copyOf(list2)); Assert.assertEquals(ImmutableList.of(4, 2, 5, 1, 3), ImmutableList.copyOf(list)); }
Example #7
Source File: IKAnalyzer.java From hugegraph with Apache License 2.0 | 6 votes |
@Override public Set<String> segment(String text) { Set<String> result = InsertionOrderUtil.newSet(); IKSegmenter ik = new IKSegmenter(new StringReader(text), this.smartSegMode); try { Lexeme word = null; while ((word = ik.next()) != null) { result.add(word.getLexemeText()); } } catch (Exception e) { throw new HugeException("IKAnalyzer segment text '%s' failed", e, text); } return result; }
Example #8
Source File: InsertionOrderUtilTest.java From hugegraph-common with Apache License 2.0 | 6 votes |
@Test public void testMapCopy() { Map<Integer, Integer> map = InsertionOrderUtil.newMap(3); map.put(4, 4); map.put(2, 2); map.put(5, 5); map.put(1, 1); map.put(3, 3); Assert.assertEquals(ImmutableList.of(4, 2, 5, 1, 3), ImmutableList.copyOf(map.keySet())); Map<Integer, Integer> map2 = InsertionOrderUtil.newMap(map); map2.put(6, 6); map2.put(1, 7); Assert.assertEquals(ImmutableList.of(4, 2, 5, 1, 3, 6), ImmutableList.copyOf(map2.keySet())); Assert.assertEquals(ImmutableList.of(4, 2, 5, 1, 3), ImmutableList.copyOf(map.keySet())); }
Example #9
Source File: SmartCNAnalyzer.java From hugegraph with Apache License 2.0 | 6 votes |
@Override public Set<String> segment(String text) { Set<String> result = InsertionOrderUtil.newSet(); Reader reader = new StringReader(text); try (TokenStream tokenStream = ANALYZER.tokenStream("text", reader)) { tokenStream.reset(); CharTermAttribute term = null; while (tokenStream.incrementToken()) { term = tokenStream.getAttribute(CharTermAttribute.class); result.add(term.toString()); } } catch (Exception e) { throw new HugeException("SmartCN segment text '%s' failed", e, text); } return result; }
Example #10
Source File: DataTypeUtil.java From hugegraph-loader with Apache License 2.0 | 5 votes |
/** * collection format: "obj1,obj2,...,objn" or "[obj1,obj2,...,objn]" ..etc * TODO: After parsing to json, the order of the collection changed * in some cases (such as list<date>) **/ private static Object parseMultiValues(String key, Object values, DataType dataType, Cardinality cardinality, InputSource source) { // JSON file should not parse again if (values instanceof Collection && checkCollectionDataType(key, (Collection<?>) values, dataType)) { return values; } E.checkState(values instanceof String, "The value(key='%s') must be String type, but got '%s'(%s)", key, values); String rawValue = (String) values; List<Object> valueColl = split(key, rawValue, source); Collection<Object> results = cardinality == Cardinality.LIST ? InsertionOrderUtil.newList() : InsertionOrderUtil.newSet(); valueColl.forEach(value -> { results.add(parseSingleValue(key, value, dataType, source)); }); E.checkArgument(checkCollectionDataType(key, results, dataType), "Not all collection elems %s match with data type %s", results, dataType); return results; }
Example #11
Source File: HbaseTable.java From hugegraph with Apache License 2.0 | 5 votes |
protected <R> R queryByIds(HbaseSession<R> session, Set<Id> ids) { Set<byte[]> rowkeys = InsertionOrderUtil.newSet(); for (Id id : ids) { rowkeys.add(id.asBytes()); } return session.get(this.table(), null, rowkeys); }
Example #12
Source File: InputProgress.java From hugegraph-loader with Apache License 2.0 | 5 votes |
@JsonCreator public InputProgress(@JsonProperty("type") SourceType type, @JsonProperty("loaded_items") Set<InputItemProgress> loadedItems, @JsonProperty("loading_item") InputItemProgress loadingItem) { this.type = type; this.loadedItems = loadedItems; this.loadingItem = loadingItem; this.loadingItems = InsertionOrderUtil.newSet(); }
Example #13
Source File: Line.java From hugegraph-loader with Apache License 2.0 | 5 votes |
public Line(String rawLine, String[] names, Object[] values) { E.checkArgumentNotNull(rawLine, "The rawLine can't be null"); E.checkArgumentNotNull(names, "The names can't be null"); E.checkArgumentNotNull(values, "The values can't be null"); E.checkArgument(names.length == values.length, "The length of names %s should be same as values %s"); this.rawLine = rawLine; this.names = names; this.values = values; this.keyValues = InsertionOrderUtil.newMap(); for (int i = 0; i < this.names.length; i++) { this.keyValues.put(this.names[i], this.values[i]); } }
Example #14
Source File: RocksDBStore.java From hugegraph with Apache License 2.0 | 5 votes |
protected Map<String, RocksDBSessions> tableDBMapping() { Map<String, RocksDBSessions> tableDBMap = InsertionOrderUtil.newMap(); for (Entry<HugeType, String> e : this.tableDiskMapping.entrySet()) { String table = this.table(e.getKey()).table(); RocksDBSessions db = db(e.getValue()); tableDBMap.put(table, db); } return tableDBMap; }
Example #15
Source File: CassandraMetrics.java From hugegraph with Apache License 2.0 | 5 votes |
private Map<String, Object> getMetricsByHost(String host) { Map<String, Object> metrics = InsertionOrderUtil.newMap(); // JMX client operations for Cassandra. try (NodeProbe probe = this.newNodeProbe(host)) { MemoryUsage heapUsage = probe.getHeapMemoryUsage(); metrics.put(MEM_USED, heapUsage.getUsed() / Bytes.MB); metrics.put(MEM_COMMITED, heapUsage.getCommitted() / Bytes.MB); metrics.put(MEM_MAX, heapUsage.getMax() / Bytes.MB); metrics.put(MEM_UNIT, "MB"); metrics.put(DATA_SIZE, probe.getLoadString()); } catch (Throwable e) { metrics.put(EXCEPTION, e.toString()); } return metrics; }
Example #16
Source File: HbaseMetrics.java From hugegraph with Apache License 2.0 | 5 votes |
private static Map<String, Object> formatMetrics(RegionMetrics region) { Map<String, Object> metrics = InsertionOrderUtil.newMap(); metrics.put("mem_store_size", region.getMemStoreSize().get(Size.Unit.MEGABYTE)); metrics.put("file_store_size", region.getStoreFileSize().get(Size.Unit.MEGABYTE)); metrics.put("store_size_unit", "MB"); return metrics; }
Example #17
Source File: Query.java From hugegraph with Apache License 2.0 | 5 votes |
protected Map<HugeKeys, Order> getOrNewOrders() { if (this.orders != null) { return this.orders; } this.orders = InsertionOrderUtil.newMap(); return this.orders; }
Example #18
Source File: HbaseMetrics.java From hugegraph with Apache License 2.0 | 5 votes |
private static Map<String, Object> formatMetrics( List<RegionMetrics> regions) { Map<String, Object> metrics = InsertionOrderUtil.newMap(); for (RegionMetrics region : regions) { metrics.put(region.getNameAsString(), formatMetrics(region)); } return metrics; }
Example #19
Source File: ProfileAPI.java From hugegraph with Apache License 2.0 | 5 votes |
@GET @Timed @Produces(MediaType.APPLICATION_JSON) public String getProfile(@Context Application application) { // May init multi times by multi threads, but no effect on the results if (SERVER_PROFILES != null) { return SERVER_PROFILES; } Map<String, Object> profiles = InsertionOrderUtil.newMap(); profiles.put("service", SERVICE); profiles.put("version", CoreVersion.VERSION.toString()); profiles.put("doc", DOC); profiles.put("api_doc", API_DOC); Set<String> apis = new TreeSet<>(); for (Class<?> clazz : application.getClasses()) { if (!isAnnotatedPathClass(clazz)) { continue; } Resource resource = Resource.from(clazz); APICategory apiCategory = APICategory.parse(resource.getName()); apis.add(apiCategory.dir); } profiles.put("apis", apis); SERVER_PROFILES = JsonUtil.toJson(profiles); return SERVER_PROFILES; }
Example #20
Source File: HbaseMetrics.java From hugegraph with Apache License 2.0 | 5 votes |
private static Map<String, Object> formatMetrics( ServerMetrics serverMetrics, List<RegionMetrics> regions) { Map<String, Object> metrics = InsertionOrderUtil.newMap(); metrics.put("max_heap_size", serverMetrics.getMaxHeapSize().get(Size.Unit.MEGABYTE)); metrics.put("used_heap_size", serverMetrics.getUsedHeapSize().get(Size.Unit.MEGABYTE)); metrics.put("heap_size_unit", "MB"); metrics.put("request_count", serverMetrics.getRequestCount()); metrics.put("request_count_per_second", serverMetrics.getRequestCountPerSecond()); metrics.put("regions", formatMetrics(regions)); return metrics; }
Example #21
Source File: CassandraMetrics.java From hugegraph with Apache License 2.0 | 5 votes |
@Override public Map<String, Object> getMetrics() { Map<String, Object> results = InsertionOrderUtil.newMap(); Set<Host> hosts = this.cluster.getMetadata().getAllHosts(); results.put(NODES, hosts.size()); for (Host host : hosts) { String address = host.getAddress().getHostAddress(); results.put(address, this.getMetricsByHost(address)); } return results; }
Example #22
Source File: MysqlSerializer.java From hugegraph with Apache License 2.0 | 5 votes |
@Override protected Set<Object> parseIndexElemIds(TableBackendEntry entry) { Set<Object> elemIds = InsertionOrderUtil.newSet(); elemIds.add(entry.column(HugeKeys.ELEMENT_IDS)); for (TableBackendEntry.Row row : entry.subRows()) { elemIds.add(row.column(HugeKeys.ELEMENT_IDS)); } return elemIds; }
Example #23
Source File: BackendMutation.java From hugegraph with Apache License 2.0 | 5 votes |
public void put(HugeType type, Id id, BackendAction mutation) { Map<Id, List<BackendAction>> table = this.mutations.get(type); if (table == null) { table = InsertionOrderUtil.newMap(); this.mutations.put(type, table); } List<BackendAction> items = table.get(id); if (items == null) { items = new ArrayList<>(); table.put(id, items); } items.add(mutation); }
Example #24
Source File: InMemoryDBTables.java From hugegraph with Apache License 2.0 | 5 votes |
@Override protected Map<Id, BackendEntry> queryByIdRange( Id start, boolean inclusiveStart, Id end, boolean inclusiveEnd, Map<Id, BackendEntry> entries) { BackendEntry value = this.getEntryById(start, entries); if (value == null) { return Collections.emptyMap(); } Map<Id, BackendEntry> rs = InsertionOrderUtil.newMap(); // TODO: Compatible with BackendEntry TextBackendEntry entry = (TextBackendEntry) value; // Range edges in the vertex String startColumn = columnOfEdge(start); String endColumn = columnOfEdge(end); BackendEntry edges = new TextBackendEntry(HugeType.VERTEX, entry.id()); edges.columns(entry.columnsWithRange(startColumn, inclusiveStart, endColumn, inclusiveEnd)); BackendEntry result = rs.get(entry.id()); if (result == null) { rs.put(entry.id(), edges); } else { result.merge(edges); } return rs; }
Example #25
Source File: InMemoryDBTables.java From hugegraph with Apache License 2.0 | 5 votes |
@Override protected Map<Id, BackendEntry> queryByIdPrefix( Id start, boolean inclusiveStart, Id prefix, Map<Id, BackendEntry> entries) { // Query edge(in a vertex) by v-id + column-name-prefix BackendEntry value = this.getEntryById(start, entries); if (value == null) { return Collections.emptyMap(); } Map<Id, BackendEntry> rs = InsertionOrderUtil.newMap(); // TODO: Compatible with BackendEntry TextBackendEntry entry = (TextBackendEntry) value; // Prefix edges in the vertex String startColumn = columnOfEdge(start); String prefixColumn = columnOfEdge(prefix); BackendEntry edges = new TextBackendEntry(HugeType.VERTEX, entry.id()); edges.columns(entry.columnsWithPrefix(startColumn, inclusiveStart, prefixColumn)); BackendEntry result = rs.get(entry.id()); if (result == null) { rs.put(entry.id(), edges); } else { result.merge(edges); } return rs; }
Example #26
Source File: OffheapCache.java From hugegraph with Apache License 2.0 | 5 votes |
private List<Object> deserializeList(BytesBuffer buffer) { // Read list int length = buffer.readVInt(); List<Object> list = InsertionOrderUtil.newList(); for (int i = 0; i < length; i++) { list.add(this.deserialize(buffer)); } return list; }
Example #27
Source File: ConditionQueryFlatten.java From hugegraph with Apache License 2.0 | 5 votes |
private static Set<Relations> and(Set<Relations> left, Set<Relations> right) { Set<Relations> result = InsertionOrderUtil.newSet(); for (Relations leftRelations : left) { for (Relations rightRelations : right) { Relations relations = new Relations(); relations.addAll(leftRelations); relations.addAll(rightRelations); result.add(relations); } } return result; }
Example #28
Source File: ListIterator.java From hugegraph-common with Apache License 2.0 | 5 votes |
public ListIterator(long capacity, Iterator<T> origin) { List<T> results = InsertionOrderUtil.newList(); while (origin.hasNext()) { if (capacity >= 0L && results.size() >= capacity) { throw new IllegalArgumentException( "The iterator exceeded capacity " + capacity); } results.add(origin.next()); } this.originIterator = origin; this.results = Collections.unmodifiableList(results); this.resultsIterator = this.results.iterator(); }
Example #29
Source File: GraphTransaction.java From hugegraph with Apache License 2.0 | 5 votes |
@Override protected void reset() { super.reset(); // Clear mutation if (this.addedVertices == null || !this.addedVertices.isEmpty()) { this.addedVertices = InsertionOrderUtil.newMap(); } if (this.removedVertices == null || !this.removedVertices.isEmpty()) { this.removedVertices = InsertionOrderUtil.newMap(); } if (this.updatedVertices == null || !this.updatedVertices.isEmpty()) { this.updatedVertices = InsertionOrderUtil.newMap(); } if (this.addedEdges == null || !this.addedEdges.isEmpty()) { this.addedEdges = InsertionOrderUtil.newMap(); } if (this.removedEdges == null || !this.removedEdges.isEmpty()) { this.removedEdges = InsertionOrderUtil.newMap(); } if (this.updatedEdges == null || !this.updatedEdges.isEmpty()) { this.updatedEdges = InsertionOrderUtil.newMap(); } if (this.addedProps == null || !this.addedProps.isEmpty()) { this.addedProps = InsertionOrderUtil.newSet(); } if (this.removedProps == null || !this.removedProps.isEmpty()) { this.removedProps = InsertionOrderUtil.newSet(); } if (this.updatedOldestProps == null || !this.updatedOldestProps.isEmpty()) { this.updatedOldestProps = InsertionOrderUtil.newSet(); } }
Example #30
Source File: GraphIndexTransaction.java From hugegraph with Apache License 2.0 | 5 votes |
private static Set<IndexLabel> relatedIndexLabels(HugeElement element) { Set<IndexLabel> indexLabels = InsertionOrderUtil.newSet(); Set<Id> indexLabelIds = element.schemaLabel().indexLabels(); for (Id id : indexLabelIds) { IndexLabel indexLabel = element.graph().indexLabel(id); indexLabels.add(indexLabel); } return indexLabels; }