/* * (non-Javadoc) * @see com.esotericsoftware.kryo.KryoSerializable#read(com.esotericsoftware.kryo.Kryo, * com.esotericsoftware.kryo.io.Input) */ @SuppressWarnings("unchecked") @Override public void read(final Kryo kryo, final Input input) { this.mode = kryo.readObject(input, ExecutionMode.class); final ArrayList<String> requiredPackages = kryo.readObject(input, ArrayList.class); final JobID dummId = JobID.generate(); final ClassLoader oldClassLoader = kryo.getClassLoader(); try { LibraryCacheManager.register( dummId, requiredPackages.toArray(new String[requiredPackages.size()])); kryo.setClassLoader(LibraryCacheManager.getClassLoader(dummId)); this.query = kryo.readObject(input, SopremoPlan.class); } catch (final Exception e) { SopremoUtil.LOG.error(e.getMessage()); throw new KryoException(e); } finally { kryo.setClassLoader(oldClassLoader); try { LibraryCacheManager.unregister(dummId); } catch (final Throwable e) { SopremoUtil.LOG.error(e.getMessage()); } } }
private static <T> T deserializeObjectByKryo(Kryo kryo, InputStream in, Class<T> clazz) { Input inp = new Input(in); kryo.setClassLoader(Utilities.getSessionSpecifiedClassLoader()); T t = kryo.readObject(inp, clazz); inp.close(); return t; }
/** * @param plan Usually of type MapredWork, MapredLocalWork etc. * @param out stream in which serialized plan is written into */ private static void serializeObjectByKryo(Kryo kryo, Object plan, OutputStream out) { Output output = new Output(out); kryo.setClassLoader(Utilities.getSessionSpecifiedClassLoader()); kryo.writeObject(output, plan); output.close(); }
/** * 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; }