/** * The type Kryo binding. * * @param <K> the type parameter */ publicclassKryoBinding<K> implementsEntryBinding<K> { /** * The Base class. */ private Class<K> baseClass; /** * The Kryo. */ private Kryo kryo;
/** * Instantiates a new Kryo binding. * 因为只会初始化一次,所以获取到kryo之后,不释放 * * @param baseClass the base class */ publicKryoBinding(Class<K> baseClass) { this.baseClass = baseClass; //获取kryo kryo = KryoPoolFactory.INSTANCE.getPool().borrow(); //注册结构 kryo.register(baseClass); }
/** * 反序列化 * * @param entry entry * @return 对象 */ @Override public K entryToObject(DatabaseEntry entry) { K result; try (Inputin=newInput(entry.getData())) { result = kryo.readObjectOrNull(in, baseClass); } return result; }