use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class LockUtil method lockWrite.
private static Lock lockWrite(String group, String lock, long time) {
Lock writeLock = LockManager.instance().get(group).readWriteLock(lock).writeLock();
LOG.debug("Trying to get the write lock '{}' of LockGroup '{}'", lock, group);
while (true) {
try {
if (!writeLock.tryLock(time, TimeUnit.SECONDS)) {
throw new HugeException("Lock [%s:%s] is locked by other operation", group, lock);
}
break;
} catch (InterruptedException ignore) {
LOG.info("Trying to lock write of {} is interrupted!", lock);
}
}
LOG.debug("Got the write lock '{}' of LockGroup '{}'", lock, group);
return writeLock;
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class Reflection method registerMethodsToFilter.
public static void registerMethodsToFilter(Class<?> containingClass, String... methodNames) {
if (REGISTER_METHODS_TO_FILTER_MOTHOD == null) {
throw new NotSupportException("Reflection.registerMethodsToFilterMethod()");
}
try {
REGISTER_METHODS_TO_FILTER_MOTHOD.setAccessible(true);
REGISTER_METHODS_TO_FILTER_MOTHOD.invoke(REFLECTION_CLAZZ, containingClass, methodNames);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new HugeException("Failed to register class '%s' methods to filter: %s", containingClass, Arrays.toString(methodNames));
}
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class BaseApiTest method readList.
protected static <T> List<T> readList(String content, String key, Class<T> clazz) {
try {
JsonNode root = MAPPER.readTree(content);
JsonNode element = root.get(key);
if (element == null) {
throw new HugeException(String.format("Can't find value of the key: %s in json.", key));
}
JavaType type = MAPPER.getTypeFactory().constructParametricType(List.class, clazz);
return MAPPER.readValue(element.toString(), type);
} catch (IOException e) {
throw new HugeException(String.format("Failed to deserialize %s", content), e);
}
}
use of com.baidu.hugegraph.HugeException in project incubator-hugegraph by apache.
the class Utils method getConf.
public static PropertiesConfiguration getConf() {
String confFile = Utils.class.getClassLoader().getResource(CONF_PATH).getPath();
File file = new File(confFile);
E.checkArgument(file.exists() && file.isFile() && file.canRead(), "Need to specify a readable config file rather than:" + " %s", file.toString());
PropertiesConfiguration config;
try {
config = new Configurations().properties(file);
} catch (ConfigurationException e) {
throw new HugeException("Unable to load config file: %s", e, confFile);
}
return config;
}
Aggregations