public ByteBuf serialize(Registry registry, ByteBufAllocator bufAllocator, Object value) throws Exception { Objects.requireNonNull(value); KryoPool kryoPool = registry.get(KryoPool.class); Kryo kryo = kryoPool.borrow(); try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Output output = new Output(stream); kryo.writeClassAndObject(output, value); output.close(); byte[] bytes = stream.toByteArray(); String encoded = ENCODER.encodeToString(bytes); return ByteBufUtil.encodeString(bufAllocator, CharBuffer.wrap(encoded), CharsetUtil.UTF_8); } catch (Exception ex) { throw ex; } finally { kryoPool.release(kryo); } }
public Object deserialize(Registry registry, String value) throws Exception { if (value == null || value.isEmpty()) { return null; } KryoPool kryoPool = registry.get(KryoPool.class); Kryo kryo = kryoPool.borrow(); try { byte[] bytes = DECODER.decode(value); ByteArrayInputStream stream = new ByteArrayInputStream(bytes); Input input = new Input(stream); Object obj = kryo.readClassAndObject(input); input.close(); return obj; } catch (Exception ex) { throw ex; } finally { kryoPool.release(kryo); } }
public static KryoPool getKryoPoolInstance() { if (poolFactory == null) { synchronized (KryoPoolFactory.class) { if (poolFactory == null) { poolFactory = new KryoPoolFactory(); } } } return poolFactory.getPool(); }
public KryoMessageSerialization() { KryoFactory factory = new KryoFactory() { public Kryo create() { Kryo kryo = new Kryo(); kryo.addDefaultSerializer(UUID.class, UUIDSerializer.class); kryo.addDefaultSerializer(Instant.class, InstantSerializer.class); // configure kryo instance, customize settings return kryo; } }; // Build pool with SoftReferences enabled (optional) pool = new KryoPool.Builder(factory).softReferences().build(); }
@Override public void onCreate() { super.onCreate(); mRequestQueue = Volley.newRequestQueue(this); onSharedPreferenceKeyChangedListeners = new LinkedList<>(); pauseableListeners = new LinkedList<>(); keyModificationCounts = new HashMap<>(); kryoPool = new KryoPool.Builder(new KryoUtil.KryoRegistrationFactory()).softReferences().build(); calendarEvents = new TreeSet<>(); loadedCalendarDataSources = EnumSet.noneOf(DataSource.class); runningCalendarAsyncTasks = Collections.synchronizedSet(new HashSet<RetrieveCalendarDataAsyncTask>()); directoryData = new ConcurrentHashMap<>(); runningDirectoryAsyncTasks = Collections.synchronizedSet(new HashSet<DirectoryAsyncTask>()); newsData = new ConcurrentHashMap<>(); runningNewsAsyncTasks = Collections.synchronizedSet(new HashSet<NewsParsingAsyncTask>()); SharedPreferences sharedPreferences = PreferenceUtils.getSharedPreferences(this); sharedPreferences.registerOnSharedPreferenceChangeListener(this); setupFirebaseTopics(); setUpCalendarParsing(); setUpNewsParsing(); setUpDirectoryParsing(); enableHttpResponseCache(); }
private KryoPool getPool() { Preconditions.checkState(factory != null || factoryType != null, "KryFactory not initialized"); if (factory == null) { return pools.computeIfAbsent(factoryType, ft -> new KryoPool.Builder(getFactory(ft)).softReferences().build()); } else { return pools.computeIfAbsent(factory.getClass().getName(), ft -> new KryoPool.Builder(factory).softReferences().build()); } }
public KryoMessageConverter(List<KryoRegistrar> kryoRegistrars, boolean useReferences) { this.useReferences = useReferences; this.kryoRegistrar = CollectionUtils.isEmpty(kryoRegistrars) ? null : new CompositeKryoRegistrar(kryoRegistrars); KryoFactory factory = () -> { Kryo kryo = new Kryo(); configureKryoInstance(kryo); return kryo; }; this.pool = new KryoPool.Builder(factory).softReferences().build(); this.supportedMimeTypes = Collections.singletonList(MimeType.valueOf(KRYO_MIME_TYPE)); }
@Provides @Singleton KryoPool provideKryoPool() { KryoFactory kryoFactory = new KryoFactory() { @Override public Kryo create() { Kryo kryo = new Kryo(); // configuration comes here return kryo; } }; // build pool with soft references KryoPool kryoPool = new KryoPool.Builder(kryoFactory).softReferences().build(); return kryoPool; }
@Inject private KryoUtils() { final KryoFactory factory = new KryoFactory() { @Override public Kryo create() { final Kryo kryo = new Kryo(); UnmodifiableCollectionsSerializer.registerSerializers(kryo); // Required to serialize/deserialize Throwable return kryo; } }; kryoPool = new KryoPool.Builder(factory).softReferences().build(); }
public KryoPool getPool() { return pool; }
public KryoCodecServiceImpl(KryoPool pool) { this.pool = pool; }
public KryoSerialize(final KryoPool pool) { this.pool = pool; }
public MessageDecoder(Class<?> clazz){ this.clazz = clazz; pool = new KryoPool.Builder(new MyKryoFactory()).build(); }
public MessageEncoder(Class<?> clazz){ this.clazz = clazz; pool = new KryoPool.Builder(new MyKryoFactory()).build(); }
public KryoCodecUtil(KryoPool pool) { this.pool = pool; }
public static byte[] serialize(KryoPool pool, Object obj) { return checkNotNull(pool, "pool").run(kryo -> serialize(kryo, obj)); }
public static Object unserialize(KryoPool pool, byte[] data) { return checkNotNull(pool, "pool").run(kryo -> unserialize(kryo, data)); }
public static <T> T unserialize(KryoPool pool, byte[] data, Class<T> clazz) { return checkNotNull(clazz, "clazz").cast(unserialize(pool, data)); }
private void init() { if (this.pool == null) { this.pool = new KryoPool.Builder(Kryo::new).build(); this.kryoSerDeserializer = new KryoSerDeserializer<>(pool); } }
KryoSerDeserializer(KryoPool kryoPool) { this.kryoPool = kryoPool; }
public static KryoPool getKryoPoolInstance() { return poolFactory.getPool(); }
public static KryoPool getPool() { return pool; }
public StorageManager() { super(); this.pool = new KryoPool.Builder(factory).softReferences().build(); }
public MapDbObjectSerializer(Class<T> clazz, KryoFactory kryoFactory) { this(clazz, new KryoPool.Builder(kryoFactory).softReferences().build(), 256); }
public MapDbObjectSerializer(Class<T> clazz, KryoPool pool, int bufferSize) { this.pool = pool; this.clazz = clazz; this.bufferSize = bufferSize; }