/** * {@inheritDoc} */ @SuppressWarnings( "unchecked" ) @Override public ConcurrentMap<String, Object> deserializeAttributes(final byte[] data ) { final Kryo kryo = _kryoPool.borrow(); Input in = null; try { in = kryo.getStreamFactory().getInput(data); return kryo.readObject(in, ConcurrentHashMap.class); } catch ( final RuntimeException e ) { throw new TranscoderDeserializationException( e ); } finally { closeSilently(in); kryo.reset(); // to be safe _kryoPool.release(kryo); } }
/** * {@inheritDoc} */ @Override public byte[] serializeAttributes( final MemcachedBackupSession session, final ConcurrentMap<String, Object> attributes ) { final Kryo kryo = _kryoPool.borrow(); Output out = null; try { /** * Creates an ObjectStream with an initial buffer size of 50KB and a maximum size of 1000KB. */ out = kryo.getStreamFactory().getOutput(_initialBufferSize, _maxBufferSize); kryo.writeObject(out, attributes); return out.toBytes(); } catch ( final RuntimeException e ) { throw new TranscoderDeserializationException( e ); } finally { closeSilently(out); kryo.reset(); // to be safe _kryoPool.release(kryo); } }
/** Reads a class and returns its registration. * @return May be null. * @see ClassResolver#readClass(Input) */ public Registration readClass (Input input) { if (input == null) throw new IllegalArgumentException("input cannot be null."); try { return classResolver.readClass(input); } finally { if (depth == 0 && autoReset) reset(); } }
/** Reads a class and returns its registration. * @return May be null. * @see ClassResolver#readClass(Input) */ public Registration readClass (Input input) { if (input == null) throw new IllegalArgumentException("input cannot be null."); try { return classResolver.readClass(input); } finally { if (depth == 0 && autoReset) reset(); } }
/** Writes a class and returns its registration. * @param type May be null. * @return Will be null if type is null. * @see ClassResolver#writeClass(Output, Class) */ public Registration writeClass (Output output, Class type) { if (output == null) throw new IllegalArgumentException("output cannot be null."); try { return classResolver.writeClass(output, type); } finally { if (depth == 0 && autoReset) reset(); } }
/** Writes a class and returns its registration. * @param type May be null. * @return Will be null if type is null. * @see ClassResolver#writeClass(Output, Class) */ public Registration writeClass (Output output, Class type) { if (output == null) throw new IllegalArgumentException("output cannot be null."); try { return classResolver.writeClass(output, type); } finally { if (depth == 0 && autoReset) reset(); } }
/** Reads a class and returns its registration. * @return May be null. * @see ClassResolver#readClass(Input) */ public Registration readClass (Input input) { if (input == null) throw new IllegalArgumentException("input cannot be null."); try { return classResolver.readClass(input); } finally { if (depth == 0 && autoReset) reset(); } }
/** Writes a class and returns its registration. * @param type May be null. * @return Will be null if type is null. * @see ClassResolver#writeClass(Output, Class) */ public Registration writeClass (Output output, Class type) { if (output == null) throw new IllegalArgumentException("output cannot be null."); try { return classResolver.writeClass(output, type); } finally { if (depth == 0 && autoReset) reset(); } }
/** Reads a class and returns its registration. * @return May be null. * @see ClassResolver#readClass(Input) */ public Registration readClass (Input input) { if (input == null) throw new IllegalArgumentException("input cannot be null."); try { return classResolver.readClass(input); } finally { if (depth == 0 && autoReset) reset(); } }
/** Writes a class and returns its registration. * @param type May be null. * @return Will be null if type is null. * @see ClassResolver#writeClass(Output, Class) */ public Registration writeClass (Output output, Class type) { if (output == null) throw new IllegalArgumentException("output cannot be null."); try { return classResolver.writeClass(output, type); } finally { if (depth == 0 && autoReset) reset(); } }
protected void testKryoSerialization(final Object original) { final Kryo kryo = KryoUtil.getKryo(); kryo.reset(); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final Output output = new Output(baos); kryo.writeClassAndObject(output, original); output.close(); kryo.reset(); final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); final Object deserialized = kryo.readClassAndObject(new Input(bais)); Assert.assertEquals(original, deserialized); }
public static <T> T cloneObject(T t) { Kryo k = getKryoThreadLocalForObjects(); T clone = k.copy(t); k.reset(); return clone; }
@Override public void close() { loadStop(); saveStop(); kryo.reset(); }
public static <T> T cloneObject(T t) { Kryo k = kryoForObjectPerThread.get(); T clone = k.copy(t); k.reset(); return clone; }
@Override public void close() { loadStop(); saveStop(); kryo.reset(); }
/** Register all classes from dictionary with kryonet. */ protected void registerDictionary( ) { endpoint.getKryo().reset(); for (Map.Entry<Integer, Class> entry : dictionary.getItems().entrySet()) { endpoint.getKryo().register(entry.getValue(), entry.getKey()); } }
/** Writes an object using the specified serializer. The registered serializer is ignored. */ public void writeObject (Output output, Object object, Serializer serializer) { if (output == null) throw new IllegalArgumentException("output cannot be null."); if (object == null) throw new IllegalArgumentException("object cannot be null."); if (serializer == null) throw new IllegalArgumentException("serializer cannot be null."); beginObject(); try { if (references && writeReferenceOrNull(output, object, false)) { serializer.setGenerics(this, null); return; } if (TRACE || (DEBUG && depth == 1)) log("Write", object); serializer.write(this, output, object); } finally { if (--depth == 0 && autoReset) reset(); } }
/** Writes an object using the specified serializer. The registered serializer is ignored. */ public void writeObject (Output output, Object object, Serializer serializer) { if (output == null) throw new IllegalArgumentException("output cannot be null."); if (object == null) throw new IllegalArgumentException("object cannot be null."); if (serializer == null) throw new IllegalArgumentException("serializer cannot be null."); beginObject(); try { if (references && writeReferenceOrNull(output, object, false)) { serializer.setGenerics(this, null); return; } if (TRACE || (DEBUG && depth == 1)) log("Write", object); serializer.write(this, output, object); } finally { if (--depth == 0 && autoReset) reset(); } }
/** Writes an object using the registered serializer. */ public void writeObject (Output output, Object object) { if (output == null) throw new IllegalArgumentException("output cannot be null."); if (object == null) throw new IllegalArgumentException("object cannot be null."); beginObject(); try { if (references && writeReferenceOrNull(output, object, false)) { getRegistration(object.getClass()).getSerializer().setGenerics(this, null); return; } if (TRACE || (DEBUG && depth == 1)) log("Write", object); getRegistration(object.getClass()).getSerializer().write(this, output, object); } finally { if (--depth == 0 && autoReset) reset(); } }
/** Writes an object using the registered serializer. */ public void writeObject (Output output, Object object) { if (output == null) throw new IllegalArgumentException("output cannot be null."); if (object == null) throw new IllegalArgumentException("object cannot be null."); beginObject(); try { if (references && writeReferenceOrNull(output, object, false)) { getRegistration(object.getClass()).getSerializer().setGenerics(this, null); return; } if (TRACE || (DEBUG && depth == 1)) log("Write", object); getRegistration(object.getClass()).getSerializer().write(this, output, object); } finally { if (--depth == 0 && autoReset) reset(); } }