Java Code Examples for org.apache.tinkerpop.gremlin.structure.io.gryo.GryoMapper#Builder

The following examples show how to use org.apache.tinkerpop.gremlin.structure.io.gryo.GryoMapper#Builder . 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: AbstractGryoMessageSerializerV1d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
private void addClassResolverSupplier(final Map<String, Object> config, final GryoMapper.Builder builder) {
    final String className = (String) config.getOrDefault(TOKEN_CLASS_RESOLVER_SUPPLIER, null);
    if (className != null && !className.isEmpty()) {
        try {
            final Class<?> clazz = Class.forName(className);
            try {
                final Method instanceMethod = tryInstanceMethod(clazz);
                builder.classResolver((Supplier<ClassResolver>) instanceMethod.invoke(null));
            } catch (Exception methodex) {
                // tried instance() and that failed so try newInstance() no-arg constructor
                builder.classResolver((Supplier<ClassResolver>) clazz.newInstance());
            }
        } catch (Exception ex) {
            throw new IllegalStateException(ex);
        }
    }
}
 
Example 2
Source File: AbstractGryoMessageSerializerV3d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
private void addClassResolverSupplier(final Map<String, Object> config, final GryoMapper.Builder builder) {
    final String className = (String) config.getOrDefault(TOKEN_CLASS_RESOLVER_SUPPLIER, null);
    if (className != null && !className.isEmpty()) {
        try {
            final Class<?> clazz = Class.forName(className);
            try {
                final Method instanceMethod = tryInstanceMethod(clazz);
                builder.classResolver((Supplier<ClassResolver>) instanceMethod.invoke(null));
            } catch (Exception methodex) {
                // tried instance() and that failed so try newInstance() no-arg constructor
                builder.classResolver((Supplier<ClassResolver>) clazz.newInstance());
            }
        } catch (Exception ex) {
            throw new IllegalStateException(ex);
        }
    }
}
 
Example 3
Source File: GremlinUtil.java    From janusgraph-visualization with Apache License 2.0 5 votes vote down vote up
public static Cluster cluster(String host, int port, IoRegistry registry) {
    // GryoMapper.Builder builder = GryoMapper.build().addRegistry(JanusGraphIoRegistry.getInstance());
    GryoMapper.Builder builder = GryoMapper.build().addRegistry(registry);
    MessageSerializer serializer = new GryoMessageSerializerV3d0(builder);
    return Cluster.build().
            addContactPoint(host).
            port(port).
            serializer(serializer).
            create();
}
 
Example 4
Source File: QueryTest.java    From janusgraph-visualization with Apache License 2.0 5 votes vote down vote up
public void before() {
    String host = "fenglex.com";
    int port = 8182;
    String remoteTraversalSourceName = "g";
    GryoMapper.Builder builder = GryoMapper.build().addRegistry(JanusGraphIoRegistry.getInstance());
    MessageSerializer serializer = new GryoMessageSerializerV3d0(builder);
    Cluster cluster = Cluster.build().
            addContactPoint(host).
            port(port).
            serializer(serializer).
            create();
    traversal().withRemote(DriverRemoteConnection.using(cluster, remoteTraversalSourceName));
}
 
Example 5
Source File: AbstractGryoMessageSerializerV1d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public final void configure(final Map<String, Object> config, final Map<String, Graph> graphs) {
    final GryoMapper.Builder builder = GryoMapper.build().version(GryoVersion.V1_0);
    addIoRegistries(config, builder);
    addClassResolverSupplier(config, builder);
    addCustomClasses(config, builder);

    this.serializeToString = Boolean.parseBoolean(config.getOrDefault(TOKEN_SERIALIZE_RESULT_TO_STRING, "false").toString());
    this.bufferSize = Integer.parseInt(config.getOrDefault(TOKEN_BUFFER_SIZE, "4096").toString());

    this.gryoMapper = configureBuilder(builder, config, graphs).create();
}
 
Example 6
Source File: GryoLiteMessageSerializerV1d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private static GryoMapper.Builder overrideWithLite(final GryoMapper.Builder builder) {
    // override the core graph Elements so as to serialize with "reference" as opposed to "detached"
    builder.addCustom(Edge.class, new EdgeLiteSerializer());
    builder.addCustom(Vertex.class, new VertexLiteSerializer());
    builder.addCustom(VertexProperty.class, new VertexPropertyLiteSerializer());
    builder.addCustom(Property.class, new PropertyLiteSerializer());
    builder.addCustom(Path.class, new PathLiteSerializer());
    return builder;
}
 
Example 7
Source File: AbstractGryoMessageSerializerV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public final void configure(final Map<String, Object> config, final Map<String, Graph> graphs) {
    final GryoMapper.Builder builder = GryoMapper.build().version(GryoVersion.V3_0);
    addIoRegistries(config, builder);
    addClassResolverSupplier(config, builder);
    addCustomClasses(config, builder);

    this.serializeToString = Boolean.parseBoolean(config.getOrDefault(TOKEN_SERIALIZE_RESULT_TO_STRING, "false").toString());
    this.bufferSize = Integer.parseInt(config.getOrDefault(TOKEN_BUFFER_SIZE, "4096").toString());

    this.gryoMapper = configureBuilder(builder, config, graphs).create();
}
 
Example 8
Source File: AbstractGryoMessageSerializerV1d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
/**
 * Called from the {@link #configure(Map, Map)} method right before the call to create the builder. Sub-classes
 * can choose to alter the builder or completely replace it.
 */
GryoMapper.Builder configureBuilder(final GryoMapper.Builder builder, final Map<String, Object> config,
                                    final Map<String, Graph> graphs) {
    return builder;
}
 
Example 9
Source File: GryoLiteMessageSerializerV1d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
GryoMapper.Builder configureBuilder(final GryoMapper.Builder builder, final Map<String, Object> config,
                                    final Map<String, Graph> graphs) {
    return overrideWithLite(builder);
}
 
Example 10
Source File: AbstractGryoMessageSerializerV3d0.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
/**
 * Called from the {@link #configure(Map, Map)} method right before the call to create the builder. Sub-classes
 * can choose to alter the builder or completely replace it.
 */
GryoMapper.Builder configureBuilder(final GryoMapper.Builder builder, final Map<String, Object> config,
                                    final Map<String, Graph> graphs) {
    return builder;
}
 
Example 11
Source File: GryoMessageSerializerV1d0.java    From tinkerpop with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an instance with a standard {@link GryoMapper} instance. Note that the instance created by the supplied
 * builder will be overridden by {@link #configure} if it is called.
 */
public GryoMessageSerializerV1d0(final GryoMapper.Builder kryo) {
    super(kryo.version(GryoVersion.V1_0).create());
}
 
Example 12
Source File: GryoMessageSerializerV3d0.java    From tinkerpop with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an instance with a standard {@link GryoMapper} instance. Note that the instance created by the supplied
 * builder will be overridden by {@link #configure} if it is called.
 */
public GryoMessageSerializerV3d0(final GryoMapper.Builder kryo) {
    super(kryo.version(GryoVersion.V3_0).create());
}
 
Example 13
Source File: GryoLiteMessageSerializerV1d0.java    From tinkerpop with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an instance with a standard {@link GryoMapper} instance. Note that the instance created by the supplied
 * builder will be overridden by {@link #configure} if it is called.
 */
public GryoLiteMessageSerializerV1d0(final GryoMapper.Builder kryo) {
    super(overrideWithLite(kryo).create());
}