Java Code Examples for org.apache.tinkerpop.shaded.kryo.Kryo#readObject()
The following examples show how to use
org.apache.tinkerpop.shaded.kryo.Kryo#readObject() .
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 |
@Override public RequestMessage deserializeRequest(final ByteBuf msg) throws SerializationException { try { final Kryo kryo = kryoThreadLocal.get(); final byte[] payload = new byte[msg.readableBytes()]; msg.readBytes(payload); try (final Input input = new Input(payload)) { // by the time the message gets here, the mime length/type have been already read, so this part just // needs to process the payload. final UUID id = kryo.readObject(input, UUID.class); final String processor = input.readString(); final String op = input.readString(); final RequestMessage.Builder builder = RequestMessage.build(op) .overrideRequestId(id) .processor(processor); final Map<String, Object> args = kryo.readObject(input, HashMap.class); args.forEach(builder::addArg); return builder.create(); } } catch (Exception ex) { logger.warn(String.format("Request [%s] could not be deserialized by %s.", msg, AbstractGryoMessageSerializerV1d0.class.getName()), ex); throw new SerializationException(ex); } }
Example 2
Source File: AbstractGryoMessageSerializerV3d0.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public RequestMessage deserializeRequest(final ByteBuf msg) throws SerializationException { try { final Kryo kryo = kryoThreadLocal.get(); final byte[] payload = new byte[msg.readableBytes()]; msg.readBytes(payload); try (final Input input = new Input(payload)) { // by the time the message gets here, the mime length/type have been already read, so this part just // needs to process the payload. return kryo.readObject(input, RequestMessage.class); } } catch (Exception ex) { logger.warn(String.format("Request [%s] could not be deserialized by %s.", msg, AbstractGryoMessageSerializerV3d0.class.getName()), ex); throw new SerializationException(ex); } }
Example 3
Source File: HugeGryoModule.java From hugegraph with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") private static Map<HugeKeys, Object> readEntry(Kryo kryo, Input input) { int columnSize = input.readInt(); Map<HugeKeys, Object> map = new LinkedHashMap<>(); for (int i = 0; i < columnSize; i++) { HugeKeys key = kryo.readObject(input, HugeKeys.class); Object val = kryo.readClassAndObject(input); map.put(key, val); } return map; }
Example 4
Source File: TinkerGraphTest.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Test public void shouldSerializeWithColorClassResolverToTinkerGraph() throws Exception { final Map<String,Color> colors = new HashMap<>(); colors.put("red", Color.RED); colors.put("green", Color.GREEN); final ArrayList<Color> colorList = new ArrayList<>(Arrays.asList(Color.RED, Color.GREEN)); final Supplier<ClassResolver> classResolver = new CustomClassResolverSupplier(); final GryoMapper mapper = GryoMapper.build().version(GryoVersion.V3_0).addRegistry(TinkerIoRegistryV3d0.instance()).classResolver(classResolver).create(); final Kryo kryo = mapper.createMapper(); try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) { final Output out = new Output(stream); kryo.writeObject(out, colorList); out.flush(); final byte[] b = stream.toByteArray(); try (final InputStream inputStream = new ByteArrayInputStream(b)) { final Input input = new Input(inputStream); final List m = kryo.readObject(input, ArrayList.class); final TinkerGraph readX = (TinkerGraph) m.get(0); assertEquals(104, IteratorUtils.count(readX.vertices())); assertEquals(102, IteratorUtils.count(readX.edges())); } } }
Example 5
Source File: TinkerGraphTest.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Test public void shouldSerializeWithColorClassResolverToTinkerGraphUsingDeprecatedTinkerIoRegistry() throws Exception { final Map<String,Color> colors = new HashMap<>(); colors.put("red", Color.RED); colors.put("green", Color.GREEN); final ArrayList<Color> colorList = new ArrayList<>(Arrays.asList(Color.RED, Color.GREEN)); final Supplier<ClassResolver> classResolver = new CustomClassResolverSupplier(); final GryoMapper mapper = GryoMapper.build().version(GryoVersion.V3_0).addRegistry(TinkerIoRegistryV3d0.instance()).classResolver(classResolver).create(); final Kryo kryo = mapper.createMapper(); try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) { final Output out = new Output(stream); kryo.writeObject(out, colorList); out.flush(); final byte[] b = stream.toByteArray(); try (final InputStream inputStream = new ByteArrayInputStream(b)) { final Input input = new Input(inputStream); final List m = kryo.readObject(input, ArrayList.class); final TinkerGraph readX = (TinkerGraph) m.get(0); assertEquals(104, IteratorUtils.count(readX.vertices())); assertEquals(102, IteratorUtils.count(readX.edges())); } } }
Example 6
Source File: AbstractGryoMessageSerializerV3d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public ResponseMessage deserializeResponse(final ByteBuf msg) throws SerializationException { try { final Kryo kryo = kryoThreadLocal.get(); final byte[] payload = new byte[msg.capacity()]; msg.readBytes(payload); try (final Input input = new Input(payload)) { return kryo.readObject(input, ResponseMessage.class); } } catch (Exception ex) { logger.warn(String.format("Response [%s] could not be deserialized by %s.", msg, AbstractGryoMessageSerializerV3d0.class.getName()), ex); throw new SerializationException(ex); } }
Example 7
Source File: GryoMapperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
public <T> T serializeDeserialize(final Object o, final Class<T> clazz) throws Exception { final Kryo kryo = builder.get().create().createMapper(); try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) { final Output out = new Output(stream); kryo.writeObject(out, o); out.flush(); try (final InputStream inputStream = new ByteArrayInputStream(stream.toByteArray())) { final Input input = new Input(inputStream); return kryo.readObject(input, clazz); } } }
Example 8
Source File: TinkerGraphTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldSerializeWithColorClassResolverToTinkerGraph() throws Exception { final Map<String,Color> colors = new HashMap<>(); colors.put("red", Color.RED); colors.put("green", Color.GREEN); final ArrayList<Color> colorList = new ArrayList<>(Arrays.asList(Color.RED, Color.GREEN)); final Supplier<ClassResolver> classResolver = new CustomClassResolverSupplier(); final GryoMapper mapper = GryoMapper.build().version(GryoVersion.V3_0).addRegistry(TinkerIoRegistryV3d0.instance()).classResolver(classResolver).create(); final Kryo kryo = mapper.createMapper(); try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) { final Output out = new Output(stream); kryo.writeObject(out, colorList); out.flush(); final byte[] b = stream.toByteArray(); try (final InputStream inputStream = new ByteArrayInputStream(b)) { final Input input = new Input(inputStream); final List m = kryo.readObject(input, ArrayList.class); final TinkerGraph readX = (TinkerGraph) m.get(0); assertEquals(104, IteratorUtils.count(readX.vertices())); assertEquals(102, IteratorUtils.count(readX.edges())); } } }
Example 9
Source File: TinkerGraphTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldSerializeWithColorClassResolverToTinkerGraphUsingDeprecatedTinkerIoRegistry() throws Exception { final Map<String,Color> colors = new HashMap<>(); colors.put("red", Color.RED); colors.put("green", Color.GREEN); final ArrayList<Color> colorList = new ArrayList<>(Arrays.asList(Color.RED, Color.GREEN)); final Supplier<ClassResolver> classResolver = new CustomClassResolverSupplier(); final GryoMapper mapper = GryoMapper.build().version(GryoVersion.V3_0).addRegistry(TinkerIoRegistryV3d0.instance()).classResolver(classResolver).create(); final Kryo kryo = mapper.createMapper(); try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) { final Output out = new Output(stream); kryo.writeObject(out, colorList); out.flush(); final byte[] b = stream.toByteArray(); try (final InputStream inputStream = new ByteArrayInputStream(b)) { final Input input = new Input(inputStream); final List m = kryo.readObject(input, ArrayList.class); final TinkerGraph readX = (TinkerGraph) m.get(0); assertEquals(104, IteratorUtils.count(readX.vertices())); assertEquals(102, IteratorUtils.count(readX.edges())); } } }