/** Initialize and register classes with kryo. */ public void initialize() { // Register types we know about and do not require external configuration kryo.register(ArrayList.class); kryo.register(BasicCredentialMetaData.class); kryo.register(Class.class, new DefaultSerializers.ClassSerializer()); kryo.register(ZonedDateTime.class, new ZonedDateTimeTranscoder()); kryo.register(HardTimeoutExpirationPolicy.class); kryo.register(HashMap.class); kryo.register(LinkedHashMap.class); kryo.register(HashSet.class); kryo.register(DefaultHandlerResult.class); kryo.register(ImmutableAuthentication.class); kryo.register(MultiTimeUseOrTimeoutExpirationPolicy.class); kryo.register(NeverExpiresExpirationPolicy.class); kryo.register(RememberMeDelegatingExpirationPolicy.class); kryo.register(ServiceTicketImpl.class); kryo.register( SimpleWebApplicationServiceImpl.class, new SimpleWebApplicationServiceSerializer()); kryo.register(ThrottledUseAndTimeoutExpirationPolicy.class); kryo.register(TicketGrantingTicketExpirationPolicy.class); kryo.register(TicketGrantingTicketImpl.class); kryo.register(TimeoutExpirationPolicy.class); kryo.register(UsernamePasswordCredential.class); kryo.register(SimplePrincipal.class); kryo.register(URL.class, new URLSerializer()); kryo.register(URI.class, new URISerializer()); kryo.register(Pattern.class, new RegexSerializer()); kryo.register(UUID.class, new UUIDSerializer()); kryo.register(EnumMap.class, new EnumMapSerializer()); kryo.register(EnumSet.class, new EnumSetSerializer()); // we add these ones for tests only kryo.register(RegisteredServiceImpl.class, new RegisteredServiceSerializer()); kryo.register(RegexRegisteredService.class, new RegisteredServiceSerializer()); kryo.register(CasDelegatingLogger.class, new DefaultSerializers.VoidSerializer()); // from the kryo-serializers library (https://github.com/magro/kryo-serializers) UnmodifiableCollectionsSerializer.registerSerializers(kryo); ImmutableListSerializer.registerSerializers(kryo); ImmutableSetSerializer.registerSerializers(kryo); ImmutableMapSerializer.registerSerializers(kryo); ImmutableMultimapSerializer.registerSerializers(kryo); kryo.register(Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer()); kryo.register(Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer()); kryo.register(Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer()); // Register other types if (serializerMap != null) { serializerMap.forEach(kryo::register); } // don't reinit the registered classes after every write or read kryo.setAutoReset(false); // don't replace objects by references kryo.setReferences(false); // Catchall for any classes not explicitly registered kryo.setRegistrationRequired(false); }
public BinaryQueueImpl( long waitOnEmptyImMs, String path, String name, final Class<? extends Event>[] clazzes) throws IOException { this.directory = path; this.name = name; this.waitOnEmtpyInMs = waitOnEmptyImMs; queue = new BigQueueImpl(directory, name); backOff = waitOnEmptyImMs; final AtomicInteger ids = new AtomicInteger(11); KryoFactory factory = () -> { Kryo kryo = new Kryo(); kryo.setRegistrationRequired(true); for (Class<? extends Event> c : clazzes) { kryo.register(c, ids.incrementAndGet()); } return kryo; }; pool = new KryoPool.Builder(factory).softReferences().build(); }