Search in sources :

Example 56 with HugeException

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;
}
Also used : HugeException(com.baidu.hugegraph.HugeException) Lock(java.util.concurrent.locks.Lock) RowLock(com.baidu.hugegraph.concurrent.RowLock) KeyLock(com.baidu.hugegraph.concurrent.KeyLock)

Example 57 with HugeException

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));
    }
}
Also used : NotSupportException(com.baidu.hugegraph.exception.NotSupportException) HugeException(com.baidu.hugegraph.HugeException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 58 with HugeException

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);
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) HugeException(com.baidu.hugegraph.HugeException)

Example 59 with HugeException

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;
}
Also used : ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) Configurations(org.apache.commons.configuration2.builder.fluent.Configurations) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) HugeException(com.baidu.hugegraph.HugeException)

Aggregations

HugeException (com.baidu.hugegraph.HugeException)59 Id (com.baidu.hugegraph.backend.id.Id)11 TimeoutException (java.util.concurrent.TimeoutException)6 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)5 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)5 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)4 File (java.io.File)4 Map (java.util.Map)4 HugeGraph (com.baidu.hugegraph.HugeGraph)3 Condition (com.baidu.hugegraph.backend.query.Condition)3 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)3 ConfigException (com.baidu.hugegraph.config.ConfigException)3 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)3 SchemaElement (com.baidu.hugegraph.schema.SchemaElement)3 StringReader (java.io.StringReader)3 PeerId (com.alipay.sofa.jraft.entity.PeerId)2 BackendException (com.baidu.hugegraph.backend.BackendException)2 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)2 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)2 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)2