com.esotericsoftware.kryo.Kryo.reset()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(172)

本文整理了Java中com.esotericsoftware.kryo.Kryo.reset()方法的一些代码示例,展示了Kryo.reset()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Kryo.reset()方法的具体详情如下:
包路径:com.esotericsoftware.kryo.Kryo
类名称:Kryo
方法名:reset

Kryo.reset介绍

[英]Resets unregistered class names, references to previously serialized or deserialized objects, and the #getGraphContext(). If #setAutoReset(boolean) is true, this method is called automatically when an object graph has been completely serialized or deserialized. If overridden, the super method must be called.
[中]重置未注册的类名、对以前序列化或反序列化对象的引用以及#getGraphContext()。如果#setAutoReset(boolean)为true,则当对象图已完全序列化或反序列化时,将自动调用此方法。如果被重写,则必须调用super方法。

代码示例

代码示例来源:origin: magro/memcached-session-manager

/**
 * {@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);
  }
}

代码示例来源:origin: magro/memcached-session-manager

/**
 * {@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);
  }
}

代码示例来源:origin: com.esotericsoftware/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();
  }
}

代码示例来源:origin: com.esotericsoftware.kryo/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();
  }
}

代码示例来源:origin: com.esotericsoftware/kryo

/** 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();
  }
}

代码示例来源:origin: com.esotericsoftware.kryo/kryo

/** 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();
  }
}

代码示例来源:origin: com.esotericsoftware/kryo-shaded

/** 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();
  }
}

代码示例来源:origin: com.esotericsoftware/kryo-shaded

/** 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();
  }
}

代码示例来源:origin: svn2github/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();
  }
}

代码示例来源:origin: svn2github/kryo

/** 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();
  }
}

代码示例来源:origin: eu.stratosphere/stratosphere-testutil

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);
}

代码示例来源:origin: vmware/xenon

public static <T> T cloneObject(T t) {
  Kryo k = getKryoThreadLocalForObjects();
  T clone = k.copy(t);
  k.reset();
  return clone;
}

代码示例来源:origin: ome/formats-bsd

@Override
public void close() {
 loadStop();
 saveStop();
 kryo.reset();
}

代码示例来源:origin: com.vmware.dcp/dcp-common

public static <T> T cloneObject(T t) {
  Kryo k = kryoForObjectPerThread.get();
  T clone = k.copy(t);
  k.reset();
  return clone;
}

代码示例来源:origin: openmicroscopy/bioformats

@Override
public void close() {
 loadStop();
 saveStop();
 kryo.reset();
}

代码示例来源:origin: DaanVanYperen/artemis-odb-contrib

/** 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());
  }
}

代码示例来源:origin: com.esotericsoftware.kryo/kryo

/** 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();
  }
}

代码示例来源:origin: com.esotericsoftware/kryo

/** 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();
  }
}

代码示例来源:origin: com.esotericsoftware.kryo/kryo

/** 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();
  }
}

代码示例来源:origin: com.esotericsoftware/kryo

/** 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();
  }
}

相关文章