@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; } }
/** * Read a {@link Vertex} from output generated by any of the {@link GryoWriter} {@code writeVertex} or * {@code writeVertices} methods or by {@link GryoWriter#writeGraph(OutputStream, Graph)}. * * @param inputStream a stream containing at least a single vertex as defined by the accompanying * {@link GraphWriter#writeVertex(OutputStream, Vertex)}. * @param vertexAttachMethod a function that creates re-attaches a {@link Vertex} to a {@link Host} object. */ @Override public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexAttachMethod) throws IOException { return readVertex(inputStream, vertexAttachMethod, null, null); }
public GryoReader create() { return new GryoReader(batchSize, this.gryoMapper); }
public GryoReader takeReader() { final GryoReader reader = this.gryoReaders.poll(); return null == reader ? GryoReader.build().mapper(mapper).create() : reader; }
/** * {@inheritDoc} */ @Override public void readGraph(final String file) throws IOException { try (final InputStream in = new FileInputStream(file)) { reader().create().readGraph(in, graph); } }
private Pair<StarGraph, Integer> serializeDeserialize(final StarGraph starGraph) { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { graph.io(IoCore.gryo()).writer().create().writeObject(outputStream, starGraph); return Pair.with(graph.io(IoCore.gryo()).reader().create().readObject(new ByteArrayInputStream(outputStream.toByteArray()), StarGraph.class), outputStream.size()); } catch (IOException ioe) { throw new RuntimeException(ioe); } } }
/** * Read an {@link Edge} from output generated by {@link GryoWriter#writeEdge(OutputStream, Edge)} or via * an {@link Edge} passed to {@link GryoWriter#writeObject(OutputStream, Object)}. * * @param inputStream a stream containing at least one {@link Edge} as defined by the accompanying * {@link GraphWriter#writeEdge(OutputStream, Edge)} method. * @param edgeAttachMethod a function that creates re-attaches a {@link Edge} to a {@link Host} object. */ @Override public Edge readEdge(final InputStream inputStream, final Function<Attachable<Edge>, Edge> edgeAttachMethod) throws IOException { final Input input = new Input(inputStream); readHeader(input); final Attachable<Edge> attachable = kryo.readObject(input, DetachedEdge.class); return edgeAttachMethod.apply(attachable); }
/** * {@inheritDoc} */ @Override public GryoReader.Builder reader() { return GryoReader.build().mapper(mapper().create()); }
/** * Generate the graph in {@link #createGratefulDead()} into an existing graph. */ public static void generateGratefulDead(final TinkerGraph graph) { final InputStream stream = TinkerFactory.class.getResourceAsStream("grateful-dead.kryo"); try { graph.io(gryo()).reader().create().readGraph(stream, graph); } catch (Exception ex) { throw new IllegalStateException(ex); } }
private Pair<StarGraph, Integer> serializeDeserialize(final StarGraph starGraph) { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { graph.io(IoCore.gryo()).writer().create().writeObject(outputStream, starGraph); return Pair.with(graph.io(IoCore.gryo()).reader().create().readObject(new ByteArrayInputStream(outputStream.toByteArray()), StarGraph.class), outputStream.size()); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
/** * Read a {@link Property} from output generated by {@link GryoWriter#writeProperty(OutputStream, Property)} or * via an {@link Property} passed to {@link GryoWriter#writeObject(OutputStream, Object)}. * * @param inputStream a stream containing at least one {@link Property} as written by the accompanying * {@link GraphWriter#writeProperty(OutputStream, Property)} method. * @param propertyAttachMethod a function that creates re-attaches a {@link Property} to a {@link Host} object. */ @Override public Property readProperty(final InputStream inputStream, final Function<Attachable<Property>, Property> propertyAttachMethod) throws IOException { final Input input = new Input(inputStream); readHeader(input); final Attachable<Property> attachable = kryo.readObject(input, DetachedProperty.class); return propertyAttachMethod.apply(attachable); }
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; } }
private void createPool(final int poolSize, final Type type, final GryoMapper gryoMapper) { this.mapper = gryoMapper; if (type.equals(Type.READER) || type.equals(Type.READER_WRITER)) { gryoReaders = new LinkedBlockingQueue<>(poolSize); for (int i = 0; i < poolSize; i++) { gryoReaders.add(GryoReader.build().mapper(gryoMapper).create()); } } if (type.equals(Type.WRITER) || type.equals(Type.READER_WRITER)) { gryoWriters = new LinkedBlockingQueue<>(poolSize); for (int i = 0; i < poolSize; i++) { gryoWriters.add(GryoWriter.build().mapper(gryoMapper).create()); } } kryos = new LinkedBlockingQueue<>(poolSize); for (int i = 0; i < poolSize; i++) { kryos.add(gryoMapper.createMapper()); } }
@Test @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = FEATURE_STRING_VALUES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) public void shouldReadWriteSelfLoopingEdges() { final Graph source = graph; final Vertex v1 = source.addVertex(); final Vertex v2 = source.addVertex(); v1.addEdge("CONTROL", v2); v1.addEdge("SELFLOOP", v1); final Configuration targetConf = graphProvider.newGraphConfiguration("target", this.getClass(), name.getMethodName(), null); final Graph target = graphProvider.openTestGraph(targetConf); ; try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { source.io(IoCore.gryo()).writer().create().writeGraph(os, source); try (ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) { target.io(IoCore.gryo()).reader().create().readGraph(is, target); } } catch (IOException ioe) { throw new RuntimeException(ioe); } assertEquals(IteratorUtils.count(source.vertices()), IteratorUtils.count(target.vertices())); assertEquals(IteratorUtils.count(source.edges()), IteratorUtils.count(target.edges())); } }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeTraversalMetrics() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V3_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final TraversalMetrics before = (TraversalMetrics) g.V().both().profile().next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, before); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final TraversalMetrics after = gryoReader.readObject(inputStream, TraversalMetrics.class); assertNotNull(after); assertEquals(before.getMetrics().size(), after.getMetrics().size()); assertEquals(before.getDuration(TimeUnit.MILLISECONDS), after.getDuration(TimeUnit.MILLISECONDS)); assertEquals(before.getMetrics(0).getCounts(), after.getMetrics().stream().findFirst().get().getCounts()); }
if (terminatorLocation >= TERMINATOR.length) { try (InputStream in = new ByteArrayInputStream(output.toByteArray())) { final Optional<Vertex> vertex = this.gryoReader.readVertex(in, this.graphFilter); if (vertex.isPresent()) { this.vertexWritable.set(vertex.get());
/** * Read a {@link VertexProperty} from output generated by * {@link GryoWriter#writeVertexProperty(OutputStream, VertexProperty)} or via an {@link VertexProperty} passed * to {@link GryoWriter#writeObject(OutputStream, Object)}. * * @param inputStream a stream containing at least one {@link VertexProperty} as written by the accompanying * {@link GraphWriter#writeVertexProperty(OutputStream, VertexProperty)} method. * @param vertexPropertyAttachMethod a function that creates re-attaches a {@link VertexProperty} to a * {@link Host} object. */ @Override public VertexProperty readVertexProperty(final InputStream inputStream, final Function<Attachable<VertexProperty>, VertexProperty> vertexPropertyAttachMethod) throws IOException { final Input input = new Input(inputStream); readHeader(input); final Attachable<VertexProperty> attachable = kryo.readObject(input, DetachedVertexProperty.class); return vertexPropertyAttachMethod.apply(attachable); }
public GryoReader create() { return new GryoReader(batchSize, this.gryoMapper); }
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; } }
final GryoMapper.Builder builder = GryoMapper.build(); detectRegistries().forEach(builder::addRegistry); return GryoReader.build().mapper(builder.create()).create(); } else if (objectOrClass.equals(IO.graphml)) return GraphMLReader.build().create();