Exemplo n.º 1
0
 @Override
 public Event fromBytes(byte[] bytes) {
   Kryo kryo = pool.borrow();
   try (Input in = new Input(bytes)) {
     return (Event) kryo.readClassAndObject(in);
   } finally {
     pool.release(kryo);
   }
 }
Exemplo n.º 2
0
 @Override
 public byte[] toBytes(Event event) {
   Kryo kryo = pool.borrow();
   try (Output out = new Output(new java.io.ByteArrayOutputStream())) {
     kryo.writeClassAndObject(out, event);
     return out.toBytes();
   } finally {
     pool.release(kryo);
   }
 }
 /**
  * Release kryo instance back to the pool.
  *
  * @param kryo - kryo instance to be released
  */
 public static void releaseKryo(Kryo kryo) {
   kryoPool.release(kryo);
 }
 /**
  * By default, kryo pool uses ConcurrentLinkedQueue which is unbounded. To facilitate reuse of
  * kryo object call releaseKryo() after done using the kryo instance. The class loader for the
  * kryo instance will be set to current thread's context class loader.
  *
  * @return kryo instance
  */
 public static Kryo borrowKryo() {
   Kryo kryo = kryoPool.borrow();
   kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
   return kryo;
 }