use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class SmartCNAnalyzer method segment.
@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;
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class PageInfo method fromBytes.
public static PageInfo fromBytes(byte[] bytes) {
if (bytes.length == 0) {
// The first page
return new PageInfo(0, PAGE_NONE);
}
try {
BytesBuffer buffer = BytesBuffer.wrap(bytes);
int offset = buffer.readInt();
byte[] pageState = buffer.readBytes();
String page = PageState.toString(pageState);
return new PageInfo(offset, page);
} catch (Exception e) {
throw new HugeException("Invalid page: '0x%s'", e, Bytes.toHex(bytes));
}
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class HugeTask method syncWait.
public void syncWait() {
// This method is just called by tests
HugeTask<?> task = null;
try {
task = this.scheduler().waitUntilTaskCompleted(this.id());
} catch (Throwable e) {
if (this.callable() instanceof EphemeralJob && e.getClass() == NotFoundException.class && e.getMessage().contains("Can't find task with id")) {
/*
* The task with EphemeralJob won't saved in backends and
* will be removed from memory when completed
*/
return;
}
throw new HugeException("Failed to wait for task '%s' completed", e, this.id);
}
assert task != null;
/*
* This can be enabled for debug to expose schema-clear errors early,
* but also lead to some negative tests failed,
*/
boolean debugTest = false;
if (debugTest && !task.success()) {
throw new HugeException("Task '%s' is failed with error: %s", task.id(), task.result());
}
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class TaskManager method shutdown.
public void shutdown(long timeout) {
assert this.schedulers.isEmpty() : this.schedulers.size();
Throwable ex = null;
boolean terminated = this.schedulerExecutor.isTerminated();
final TimeUnit unit = TimeUnit.SECONDS;
if (!this.schedulerExecutor.isShutdown()) {
this.schedulerExecutor.shutdown();
try {
terminated = this.schedulerExecutor.awaitTermination(timeout, unit);
} catch (Throwable e) {
ex = e;
}
}
if (terminated && !this.taskExecutor.isShutdown()) {
this.taskExecutor.shutdown();
try {
terminated = this.taskExecutor.awaitTermination(timeout, unit);
} catch (Throwable e) {
ex = e;
}
}
if (terminated && !this.serverInfoDbExecutor.isShutdown()) {
this.serverInfoDbExecutor.shutdown();
try {
terminated = this.serverInfoDbExecutor.awaitTermination(timeout, unit);
} catch (Throwable e) {
ex = e;
}
}
if (terminated && !this.taskDbExecutor.isShutdown()) {
this.taskDbExecutor.shutdown();
try {
terminated = this.taskDbExecutor.awaitTermination(timeout, unit);
} catch (Throwable e) {
ex = e;
}
}
if (!terminated) {
ex = new TimeoutException(timeout + "s");
}
if (ex != null) {
throw new HugeException("Failed to wait for TaskScheduler", ex);
}
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class KoutTraverser method kout.
public Set<Id> kout(Id sourceV, Directions dir, String label, int depth, boolean nearest, long degree, long capacity, long limit) {
E.checkNotNull(sourceV, "source vertex id");
this.checkVertexExist(sourceV, "source vertex");
E.checkNotNull(dir, "direction");
checkPositive(depth, "k-out max_depth");
checkDegree(degree);
checkCapacity(capacity);
checkLimit(limit);
if (capacity != NO_LIMIT) {
// Capacity must > limit because sourceV is counted in capacity
E.checkArgument(capacity >= limit && limit != NO_LIMIT, "Capacity can't be less than limit, " + "but got capacity '%s' and limit '%s'", capacity, limit);
}
Id labelId = this.getEdgeLabelId(label);
Set<Id> latest = newIdSet();
latest.add(sourceV);
Set<Id> all = newIdSet();
all.add(sourceV);
long remaining = capacity == NO_LIMIT ? NO_LIMIT : capacity - latest.size();
while (depth-- > 0) {
// Just get limit nodes in last layer if limit < remaining capacity
if (depth == 0 && limit != NO_LIMIT && (limit < remaining || remaining == NO_LIMIT)) {
remaining = limit;
}
if (nearest) {
latest = this.adjacentVertices(sourceV, latest, dir, labelId, all, degree, remaining);
all.addAll(latest);
} else {
latest = this.adjacentVertices(sourceV, latest, dir, labelId, null, degree, remaining);
}
if (capacity != NO_LIMIT) {
// Update 'remaining' value to record remaining capacity
remaining -= latest.size();
if (remaining <= 0 && depth > 0) {
throw new HugeException("Reach capacity '%s' while remaining depth '%s'", capacity, depth);
}
}
}
return latest;
}
Aggregations