Search in sources :

Example 1 with GraphConfiguration

use of org.vertexium.GraphConfiguration in project vertexium by visallo.

the class KryoVertexiumSerializerTest method before.

@Before
public void before() {
    System.gc();
    Map<String, Object> config = new HashMap<>();
    config.put(QuickKryoVertexiumSerializer.CONFIG_COMPRESS, compress);
    shouldAssertTiming = !compress;
    iterations = compress ? 100 : 100000;
    graphConfiguration = new GraphConfiguration(config);
}
Also used : GraphConfiguration(org.vertexium.GraphConfiguration) HashMap(java.util.HashMap) Before(org.junit.Before)

Example 2 with GraphConfiguration

use of org.vertexium.GraphConfiguration in project vertexium by visallo.

the class ConfigurationUtils method createProvider.

@SuppressWarnings("unchecked")
public static <T> T createProvider(String className, Graph graph, GraphConfiguration config) throws VertexiumException {
    checkNotNull(className, "className is required");
    className = className.trim();
    LOGGER.debug("creating provider '%s'", className);
    Class<Graph> graphClass = Graph.class;
    Class<GraphConfiguration> graphConfigurationClass = GraphConfiguration.class;
    try {
        Class<?> clazz = Class.forName(className);
        try {
            Constructor constructor;
            try {
                constructor = clazz.getConstructor(graphClass);
                return (T) constructor.newInstance(graph);
            } catch (NoSuchMethodException ignore1) {
                try {
                    constructor = clazz.getConstructor(graphClass, graphConfigurationClass);
                    return (T) constructor.newInstance(graph, config);
                } catch (NoSuchMethodException ignore2) {
                    try {
                        constructor = clazz.getConstructor(graphConfigurationClass);
                        return (T) constructor.newInstance(config);
                    } catch (NoSuchMethodException ignore3) {
                        try {
                            constructor = clazz.getConstructor(Map.class);
                            return (T) constructor.newInstance(config.getConfig());
                        } catch (NoSuchMethodException ignoreInner) {
                            constructor = clazz.getConstructor();
                            return (T) constructor.newInstance();
                        }
                    }
                }
            }
        } catch (IllegalArgumentException e) {
            StringBuilder possibleMatches = new StringBuilder();
            for (Constructor<?> s : clazz.getConstructors()) {
                possibleMatches.append(s.toGenericString());
                possibleMatches.append(", ");
            }
            throw new VertexiumException("Invalid constructor for " + className + ". Expected <init>(" + graphConfigurationClass.getName() + "). Found: " + possibleMatches, e);
        }
    } catch (NoSuchMethodException e) {
        throw new VertexiumException("Provider must have a single argument constructor taking a " + graphConfigurationClass.getName(), e);
    } catch (ClassNotFoundException e) {
        throw new VertexiumException("No provider found with class name " + className, e);
    } catch (Exception e) {
        throw new VertexiumException(e);
    }
}
Also used : GraphConfiguration(org.vertexium.GraphConfiguration) Constructor(java.lang.reflect.Constructor) VertexiumException(org.vertexium.VertexiumException) VertexiumException(org.vertexium.VertexiumException) IOException(java.io.IOException) Graph(org.vertexium.Graph)

Aggregations

GraphConfiguration (org.vertexium.GraphConfiguration)2 IOException (java.io.IOException)1 Constructor (java.lang.reflect.Constructor)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 Graph (org.vertexium.Graph)1 VertexiumException (org.vertexium.VertexiumException)1