/** {@inheritDoc} */ @SuppressWarnings("unchecked") public Object read(Connection connection, InputStream inputStream) { Input input = new Input(inputStream); IKryoProvider kryoProvider = serializerQueue.poll(); // if nothing is available in queue don't wait, create new one if (null == kryoProvider) { kryoProvider = createKryoProvider(); } try { Kryo kryo = kryoProvider.getKryo(); kryo.getContext().put("connection", connection); return kryo.readClassAndObject(input); } finally { serializerQueue.offer(kryoProvider); } }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") public void write(Connection connection, OutputStream outputStream, Object object) { Output output = new Output(outputStream); IKryoProvider kryoProvider = serializerQueue.poll(); // if nothing is available in queue don't wait, create new one if (null == kryoProvider) { kryoProvider = createKryoProvider(); } try { Kryo kryo = kryoProvider.getKryo(); kryo.getContext().put("connection", connection); kryo.writeClassAndObject(output, object); output.flush(); } finally { serializerQueue.offer(kryoProvider); } }