org.objenesis.strategy.StdInstantiatorStrategy Java Examples
The following examples show how to use
org.objenesis.strategy.StdInstantiatorStrategy.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KryoFactory.java From vertexium with Apache License 2.0 | 6 votes |
public Kryo createKryo() { Kryo kryo = new Kryo(new DefaultClassResolver(), new MapReferenceResolver() { @Override public boolean useReferences(Class type) { // avoid calling System.identityHashCode if (type == String.class || type == Date.class) { return false; } return super.useReferences(type); } }); registerClasses(kryo); kryo.setAutoReset(true); kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); return kryo; }
Example #2
Source File: KryoState.java From beam with Apache License 2.0 | 6 votes |
KryoState getOrCreate(KryoCoder<?> coder) { return kryoStateMap .get() .computeIfAbsent( coder.getInstanceId(), k -> { final Kryo kryo = new Kryo(); // fallback in case serialized class does not have default constructor kryo.setInstantiatorStrategy( new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); kryo.setReferences(coder.getOptions().getReferences()); kryo.setRegistrationRequired(coder.getOptions().getRegistrationRequired()); kryo.setClassLoader(Thread.currentThread().getContextClassLoader()); // first id of user provided class registration final int firstRegistrationId = kryo.getNextRegistrationId(); // register user provided classes for (KryoRegistrar registrar : coder.getRegistrars()) { registrar.registerClasses(kryo); } return new KryoState( kryo, firstRegistrationId, new InputChunked(coder.getOptions().getBufferSize()), new OutputChunked(coder.getOptions().getBufferSize())); }); }
Example #3
Source File: AbstractSerializer.java From jea with Apache License 2.0 | 6 votes |
/** * 根据所注册的Class,初始化Kryo实例 * * @return */ protected Kryo initKryo() { Kryo kryo = new Kryo(); kryo.setReferences(true); kryo.setRegistrationRequired(true); kryo.setInstantiatorStrategy(new StdInstantiatorStrategy()); Set<Class<?>> keys = propertyMap.keySet(); for(Class<?> key : keys){ if(propertyMap.get(key) != null){ kryo.register(key, propertyMap.get(key)); } else { kryo.register(key); } } return kryo; }
Example #4
Source File: DbStoragePlainFile.java From Iron with Apache License 2.0 | 6 votes |
private Kryo createKryoInstance() { Kryo kryo = new Kryo(); kryo.register(IronTable.class); kryo.setDefaultSerializer(CompatibleFieldSerializer.class); kryo.setReferences(false); // Serialize Arrays$ArrayList //noinspection ArraysAsListWithZeroOrOneArgument kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer()); UnmodifiableCollectionsSerializer.registerSerializers(kryo); SynchronizedCollectionsSerializer.registerSerializers(kryo); // Serialize inner AbstractList$SubAbstractListRandomAccess kryo.addDefaultSerializer(new ArrayList<>().subList(0, 0).getClass(), new NoArgCollectionSerializer()); // Serialize AbstractList$SubAbstractList kryo.addDefaultSerializer(new LinkedList<>().subList(0, 0).getClass(), new NoArgCollectionSerializer()); // To keep backward compatibility don't change the order of serializers above kryo.setInstantiatorStrategy( new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); return kryo; }
Example #5
Source File: SerializationTest.java From rtree-3d with Apache License 2.0 | 6 votes |
@Test @Ignore public void testSerializationRoundTrip() throws FileNotFoundException { // this test to see if can use kryo to serialize RTree instance List<Entry<Object, Point>> entries = GreekEarthquakes.entriesList(); int maxChildren = 8; RTree<Object, Point> tree = RTree.maxChildren(maxChildren).<Object, Point> create() .add(entries); File file = new File("target/greek-serialized.kryo"); file.delete(); Kryo kryo = new Kryo(); Output output = new Output(new FileOutputStream(file)); kryo.writeObject(output, tree); output.close(); Input input = new Input(new FileInputStream(file)); kryo.setInstantiatorStrategy(new StdInstantiatorStrategy()); @SuppressWarnings("unchecked") RTree<Object, Point> tree2 = kryo.readObject(input, RTree.class); assertNotNull(tree2); }
Example #6
Source File: TestKryoUpgrade.java From dremio-oss with Apache License 2.0 | 6 votes |
@Test public void testSchemaPathUpgrade() throws Exception { /* Pre-4.2 serialized SchemaPath. Generated by this code: final PathSegment.NameSegment nameSegment = new PathSegment.NameSegment("path"); final SchemaPath schemaPath = new SchemaPath(nameSegment); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final Output output = new Output(outputStream); final Kryo kryo = new Kryo(); kryo.writeObject(output, schemaPath); FileUtils.writeByteArrayToFile(new File("schemapath.kryo"), output.getBuffer()); */ final URL resource = Resources.getResource("kryo/schemapath.kryo"); final byte[] bytes = Files.readAllBytes(Paths.get(resource.getPath())); final Kryo kryo = new Kryo(); kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); final SchemaPath schemaPath = kryo.readObject(new Input(bytes), SchemaPath.class); assertEquals("path", schemaPath.getAsUnescapedPath()); }
Example #7
Source File: KryoSerialization.java From JPPF with Apache License 2.0 | 6 votes |
/** * Create a Kryo instance, with its instantiator strategy and a set of * common serializers (from kryo-serializers project) initialized. * @return an instance of {@link Kryo}. */ private static Kryo createKryo() { final Kryo kryo = new Kryo(new CustomClassResolver(), new MapReferenceResolver()); kryo.setAutoReset(true); kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); kryo.register(ObjectName.class, new ObjectNameSerializer()); kryo.register(OffloadableNotification.class, new GenericObjectSerializer()); kryo.register(TaskExecutionNotification.class, new GenericObjectSerializer()); kryo.register(TaskGraph.class, new JobTaskGraphSerializer()); kryo.register(Collection.class, new CollectionSerializer()); kryo.register(Arrays.asList( "" ).getClass(), new ArraysAsListSerializer() ); kryo.register(Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer() ); kryo.register(Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer() ); kryo.register(Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer() ); kryo.register(Collections.singletonList( "" ).getClass(), new CollectionsSingletonListSerializer() ); kryo.register(Collections.singleton( "" ).getClass(), new CollectionsSingletonSetSerializer() ); kryo.register(Collections.singletonMap( "", "" ).getClass(), new CollectionsSingletonMapSerializer() ); kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer()); kryo.register(InvocationHandler.class, new JdkProxySerializer()); UnmodifiableCollectionsSerializer.registerSerializers(kryo); SynchronizedCollectionsSerializer.registerSerializers(kryo); kryo.register(EnumMap.class, new EnumMapSerializer()); kryo.register(EnumSet.class, new EnumSetSerializer()); return kryo; }
Example #8
Source File: KryoUtils.java From kafka-examples with Apache License 2.0 | 6 votes |
public Kryo create() { Kryo kryo = new Kryo(); try { kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer()); kryo.register(Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer()); kryo.register(Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer()); kryo.register(Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer()); kryo.register(SINGLETON_LIST.getClass(), new CollectionsSingletonListSerializer()); kryo.register(SINGLETON_SET.getClass(), new CollectionsSingletonSetSerializer()); kryo.register(SINGLETON_MAP.getClass(), new CollectionsSingletonMapSerializer()); kryo.setRegistrationRequired(false); UnmodifiableCollectionsSerializer.registerSerializers(kryo); SynchronizedCollectionsSerializer.registerSerializers(kryo); ((Kryo.DefaultInstantiatorStrategy) kryo.getInstantiatorStrategy()).setFallbackInstantiatorStrategy(new StdInstantiatorStrategy()); } catch (Exception e) { logger.error("Exception occurred", e); } return kryo; }
Example #9
Source File: KryoUtils.java From RxCache with Apache License 2.0 | 6 votes |
@Override protected Kryo initialValue() { Kryo kryo = new Kryo(); /** * 不要轻易改变这里的配置!更改之后,序列化的格式就会发生变化, * 上线的同时就必须清除 Redis 里的所有缓存, * 否则那些缓存再回来反序列化的时候,就会报错 */ //支持对象循环引用(否则会栈溢出) kryo.setReferences(true); //默认值就是 true,添加此行的目的是为了提醒维护者,不要改变这个配置 //不强制要求注册类(注册行为无法保证多个 JVM 内同一个类的注册编号相同;而且业务系统中大量的 Class 也难以一一注册) kryo.setRegistrationRequired(false); //默认值就是 false,添加此行的目的是为了提醒维护者,不要改变这个配置 //Fix the NPE bug when deserializing Collections. ((Kryo.DefaultInstantiatorStrategy) kryo.getInstantiatorStrategy()) .setFallbackInstantiatorStrategy(new StdInstantiatorStrategy()); kryo.register(CacheHolder.class, new CacheHolderSerializer()); return kryo; }
Example #10
Source File: SerDeUtils.java From metron with Apache License 2.0 | 5 votes |
@Override protected Kryo initialValue() { Kryo ret = new Kryo(); ret.setReferences(true); ret.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); ret.register(Arrays.asList("").getClass(), new ArraysAsListSerializer()); ret.register(Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer()); ret.register(Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer()); ret.register(Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer()); ret.register(Collections.singletonList("").getClass(), new CollectionsSingletonListSerializer()); ret.register(Collections.singleton("").getClass(), new CollectionsSingletonSetSerializer()); ret.register(Collections.singletonMap("", "").getClass(), new CollectionsSingletonMapSerializer()); ret.register(GregorianCalendar.class, new GregorianCalendarSerializer()); ret.register(InvocationHandler.class, new JdkProxySerializer()); UnmodifiableCollectionsSerializer.registerSerializers(ret); SynchronizedCollectionsSerializer.registerSerializers(ret); // custom serializers for non-jdk libs // register CGLibProxySerializer, works in combination with the appropriate action in handleUnregisteredClass (see below) ret.register(CGLibProxySerializer.CGLibProxyMarker.class, new CGLibProxySerializer()); // joda DateTime, LocalDate and LocalDateTime ret.register(LocalDate.class, new JodaLocalDateSerializer()); ret.register(LocalDateTime.class, new JodaLocalDateTimeSerializer()); // guava ImmutableList, ImmutableSet, ImmutableMap, ImmutableMultimap, UnmodifiableNavigableSet ImmutableListSerializer.registerSerializers(ret); ImmutableSetSerializer.registerSerializers(ret); ImmutableMapSerializer.registerSerializers(ret); ImmutableMultimapSerializer.registerSerializers(ret); return ret; }
Example #11
Source File: KryoSerializer.java From Jupiter with Apache License 2.0 | 5 votes |
@Override protected Kryo initialValue() throws Exception { Kryo kryo = new Kryo(); for (Class<?> type : useJavaSerializerTypes) { kryo.addDefaultSerializer(type, JavaSerializer.class); } kryo.setInstantiatorStrategy(new StdInstantiatorStrategy()); kryo.setRegistrationRequired(false); kryo.setReferences(false); return kryo; }
Example #12
Source File: AbstractConfig.java From trainbenchmark with Eclipse Public License 1.0 | 5 votes |
public static <T extends AbstractConfig<?>> T fromFile(final String path, final Class<T> clazz) throws FileNotFoundException { final Kryo kryo = new Kryo(); kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); try (final Input input = new Input(new FileInputStream(path))) { final T bc = kryo.readObject(input, clazz); return bc; } }
Example #13
Source File: KryoSerializer.java From cqengine with Apache License 2.0 | 5 votes |
/** * Creates a new instance of Kryo serializer, for use with the given object type. * <p/> * Note: this method is public to allow end-users to validate compatibility of their POJOs, * with the Kryo serializer as used by CQEngine. * * @param objectType The type of object which the instance of Kryo will serialize * @return a new instance of Kryo serializer */ @SuppressWarnings({"ArraysAsListWithZeroOrOneArgument", "WeakerAccess"}) protected Kryo createKryo(Class<?> objectType) { Kryo kryo = new Kryo(); // Instantiate serialized objects via a no-arg constructor when possible, falling back to Objenesis... kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); // Register the object which this index will persist... kryo.register(objectType); kryo.setRegistrationRequired(false); // Register additional serializers which are not built-in to Kryo 3.0... kryo.register(Arrays.asList().getClass(), new ArraysAsListSerializer()); UnmodifiableCollectionsSerializer.registerSerializers(kryo); SynchronizedCollectionsSerializer.registerSerializers(kryo); return kryo; }
Example #14
Source File: DbStoragePlainFile.java From Paper with Apache License 2.0 | 5 votes |
private Kryo createKryoInstance(boolean compatibilityMode) { Kryo kryo = new Kryo(); if (compatibilityMode) { kryo.getFieldSerializerConfig().setOptimizedGenerics(true); } kryo.register(PaperTable.class); kryo.setDefaultSerializer(CompatibleFieldSerializer.class); kryo.setReferences(false); // Serialize Arrays$ArrayList //noinspection ArraysAsListWithZeroOrOneArgument kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer()); UnmodifiableCollectionsSerializer.registerSerializers(kryo); SynchronizedCollectionsSerializer.registerSerializers(kryo); // Serialize inner AbstractList$SubAbstractListRandomAccess kryo.addDefaultSerializer(new ArrayList<>().subList(0, 0).getClass(), new NoArgCollectionSerializer()); // Serialize AbstractList$SubAbstractList kryo.addDefaultSerializer(new LinkedList<>().subList(0, 0).getClass(), new NoArgCollectionSerializer()); // To keep backward compatibility don't change the order of serializers above // UUID support kryo.register(UUID.class, new UUIDSerializer()); for (Class<?> clazz : mCustomSerializers.keySet()) kryo.register(clazz, mCustomSerializers.get(clazz)); kryo.setInstantiatorStrategy( new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); return kryo; }
Example #15
Source File: SerDeUtils.java From metron with Apache License 2.0 | 5 votes |
@Override protected Kryo initialValue() { Kryo ret = new Kryo(); ret.setReferences(true); ret.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); ret.register(Arrays.asList("").getClass(), new ArraysAsListSerializer()); ret.register(Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer()); ret.register(Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer()); ret.register(Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer()); ret.register(Collections.singletonList("").getClass(), new CollectionsSingletonListSerializer()); ret.register(Collections.singleton("").getClass(), new CollectionsSingletonSetSerializer()); ret.register(Collections.singletonMap("", "").getClass(), new CollectionsSingletonMapSerializer()); ret.register(GregorianCalendar.class, new GregorianCalendarSerializer()); ret.register(InvocationHandler.class, new JdkProxySerializer()); UnmodifiableCollectionsSerializer.registerSerializers(ret); SynchronizedCollectionsSerializer.registerSerializers(ret); // custom serializers for non-jdk libs // register CGLibProxySerializer, works in combination with the appropriate action in handleUnregisteredClass (see below) ret.register(CGLibProxySerializer.CGLibProxyMarker.class, new CGLibProxySerializer()); // joda DateTime, LocalDate and LocalDateTime ret.register(LocalDate.class, new JodaLocalDateSerializer()); ret.register(LocalDateTime.class, new JodaLocalDateTimeSerializer()); // guava ImmutableList, ImmutableSet, ImmutableMap, ImmutableMultimap, UnmodifiableNavigableSet ImmutableListSerializer.registerSerializers(ret); ImmutableSetSerializer.registerSerializers(ret); ImmutableMapSerializer.registerSerializers(ret); ImmutableMultimapSerializer.registerSerializers(ret); return ret; }
Example #16
Source File: KryoPoolFactory.java From AvatarMQ with Apache License 2.0 | 5 votes |
public Kryo create() { Kryo kryo = new Kryo(); kryo.setReferences(false); kryo.register(RequestMessage.class); kryo.register(ResponseMessage.class); kryo.setInstantiatorStrategy(new StdInstantiatorStrategy()); return kryo; }
Example #17
Source File: KryoUtils.java From kylin with Apache License 2.0 | 5 votes |
public static Kryo getKryo() { if (_Kryo.get() == null) { Kryo kryo = new Kryo(); kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); kryo.register(BitSet.class, new BitSetSerializer()); _Kryo.set(kryo); } return _Kryo.get(); }
Example #18
Source File: Namespace.java From atomix with Apache License 2.0 | 5 votes |
/** * Creates a Kryo instance. * * @return Kryo instance */ @Override public Kryo create() { LOGGER.trace("Creating Kryo instance for {}", this); Kryo kryo = new Kryo(); kryo.setClassLoader(classLoader); kryo.setRegistrationRequired(registrationRequired); // If compatible serialization is enabled, override the default serializer. if (compatible) { kryo.setDefaultSerializer(CompatibleFieldSerializer::new); } // TODO rethink whether we want to use StdInstantiatorStrategy kryo.setInstantiatorStrategy( new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); for (RegistrationBlock block : registeredBlocks) { int id = block.begin(); if (id == FLOATING_ID) { id = kryo.getNextRegistrationId(); } for (Pair<Class<?>[], Serializer<?>> entry : block.types()) { register(kryo, entry.getLeft(), entry.getRight(), id++); } } return kryo; }
Example #19
Source File: WritableComparator.java From flink with Apache License 2.0 | 5 votes |
private void checkKryoInitialized() { if (this.kryo == null) { this.kryo = new Kryo(); Kryo.DefaultInstantiatorStrategy instantiatorStrategy = new Kryo.DefaultInstantiatorStrategy(); instantiatorStrategy.setFallbackInstantiatorStrategy(new StdInstantiatorStrategy()); kryo.setInstantiatorStrategy(instantiatorStrategy); this.kryo.setAsmEnabled(true); this.kryo.register(type); } }
Example #20
Source File: WritableSerializer.java From flink with Apache License 2.0 | 5 votes |
private void checkKryoInitialized() { if (this.kryo == null) { this.kryo = new Kryo(); Kryo.DefaultInstantiatorStrategy instantiatorStrategy = new Kryo.DefaultInstantiatorStrategy(); instantiatorStrategy.setFallbackInstantiatorStrategy(new StdInstantiatorStrategy()); kryo.setInstantiatorStrategy(instantiatorStrategy); this.kryo.setAsmEnabled(true); this.kryo.register(typeClass); } }
Example #21
Source File: ValueComparator.java From flink with Apache License 2.0 | 5 votes |
private void checkKryoInitialized() { if (this.kryo == null) { this.kryo = new Kryo(); Kryo.DefaultInstantiatorStrategy instantiatorStrategy = new Kryo.DefaultInstantiatorStrategy(); instantiatorStrategy.setFallbackInstantiatorStrategy(new StdInstantiatorStrategy()); kryo.setInstantiatorStrategy(instantiatorStrategy); this.kryo.setAsmEnabled(true); this.kryo.register(type); } }
Example #22
Source File: KryoSerializer.java From flink with Apache License 2.0 | 5 votes |
/** * Returns the Chill Kryo Serializer which is implicitly added to the classpath via flink-runtime. * Falls back to the default Kryo serializer if it can't be found. * @return The Kryo serializer instance. */ private Kryo getKryoInstance() { try { // check if ScalaKryoInstantiator is in class path (coming from Twitter's Chill library). // This will be true if Flink's Scala API is used. Class<?> chillInstantiatorClazz = Class.forName("org.apache.flink.runtime.types.FlinkScalaKryoInstantiator"); Object chillInstantiator = chillInstantiatorClazz.newInstance(); // obtain a Kryo instance through Twitter Chill Method m = chillInstantiatorClazz.getMethod("newKryo"); return (Kryo) m.invoke(chillInstantiator); } catch (ClassNotFoundException | InstantiationException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { LOG.warn("Falling back to default Kryo serializer because Chill serializer couldn't be found.", e); Kryo.DefaultInstantiatorStrategy initStrategy = new Kryo.DefaultInstantiatorStrategy(); initStrategy.setFallbackInstantiatorStrategy(new StdInstantiatorStrategy()); Kryo kryo = new Kryo(); kryo.setInstantiatorStrategy(initStrategy); return kryo; } }
Example #23
Source File: ValueSerializer.java From flink with Apache License 2.0 | 5 votes |
private void checkKryoInitialized() { if (this.kryo == null) { this.kryo = new Kryo(); Kryo.DefaultInstantiatorStrategy instantiatorStrategy = new Kryo.DefaultInstantiatorStrategy(); instantiatorStrategy.setFallbackInstantiatorStrategy(new StdInstantiatorStrategy()); kryo.setInstantiatorStrategy(instantiatorStrategy); this.kryo.setAsmEnabled(true); KryoUtils.applyRegistrations(this.kryo, kryoRegistrations.values()); } }
Example #24
Source File: KryoNamespace.java From onos with Apache License 2.0 | 5 votes |
/** * Creates a Kryo instance. * * @return Kryo instance */ @Override public Kryo create() { log.trace("Creating Kryo instance for {}", this); Kryo kryo = new Kryo(); kryo.setRegistrationRequired(registrationRequired); // If compatible serialization is enabled, override the default serializer. if (compatible) { kryo.setDefaultSerializer(CompatibleFieldSerializer::new); } // TODO rethink whether we want to use StdInstantiatorStrategy kryo.setInstantiatorStrategy( new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); for (RegistrationBlock block : registeredBlocks) { int id = block.begin(); if (id == FLOATING_ID) { id = kryo.getNextRegistrationId(); } for (Pair<Class<?>[], Serializer<?>> entry : block.types()) { register(kryo, entry.getLeft(), entry.getRight(), id++); } } return kryo; }
Example #25
Source File: DefaultKryoFactory.java From jstorm with Apache License 2.0 | 5 votes |
@Override public Kryo getKryo(Map conf) { KryoSerializableDefault k = new KryoSerializableDefault(); k.setRegistrationRequired(Boolean.valueOf(conf.get(Config.TOPOLOGY_KRYO_REGISTER_REQUIRED).toString())); k.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); k.setReferences(false); return k; }
Example #26
Source File: ValueSerializer.java From flink with Apache License 2.0 | 5 votes |
private void checkKryoInitialized() { if (this.kryo == null) { this.kryo = new Kryo(); Kryo.DefaultInstantiatorStrategy instantiatorStrategy = new Kryo.DefaultInstantiatorStrategy(); instantiatorStrategy.setFallbackInstantiatorStrategy(new StdInstantiatorStrategy()); kryo.setInstantiatorStrategy(instantiatorStrategy); this.kryo.setAsmEnabled(true); KryoUtils.applyRegistrations(this.kryo, kryoRegistrations.values()); } }
Example #27
Source File: WritableSerializer.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void checkKryoInitialized() { if (this.kryo == null) { this.kryo = new Kryo(); Kryo.DefaultInstantiatorStrategy instantiatorStrategy = new Kryo.DefaultInstantiatorStrategy(); instantiatorStrategy.setFallbackInstantiatorStrategy(new StdInstantiatorStrategy()); kryo.setInstantiatorStrategy(instantiatorStrategy); this.kryo.setAsmEnabled(true); this.kryo.register(typeClass); } }
Example #28
Source File: ValueComparator.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void checkKryoInitialized() { if (this.kryo == null) { this.kryo = new Kryo(); Kryo.DefaultInstantiatorStrategy instantiatorStrategy = new Kryo.DefaultInstantiatorStrategy(); instantiatorStrategy.setFallbackInstantiatorStrategy(new StdInstantiatorStrategy()); kryo.setInstantiatorStrategy(instantiatorStrategy); this.kryo.setAsmEnabled(true); this.kryo.register(type); } }
Example #29
Source File: KryoSerializer.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Returns the Chill Kryo Serializer which is implicitly added to the classpath via flink-runtime. * Falls back to the default Kryo serializer if it can't be found. * @return The Kryo serializer instance. */ private Kryo getKryoInstance() { try { // check if ScalaKryoInstantiator is in class path (coming from Twitter's Chill library). // This will be true if Flink's Scala API is used. Class<?> chillInstantiatorClazz = Class.forName("org.apache.flink.runtime.types.FlinkScalaKryoInstantiator"); Object chillInstantiator = chillInstantiatorClazz.newInstance(); // obtain a Kryo instance through Twitter Chill Method m = chillInstantiatorClazz.getMethod("newKryo"); return (Kryo) m.invoke(chillInstantiator); } catch (ClassNotFoundException | InstantiationException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { LOG.warn("Falling back to default Kryo serializer because Chill serializer couldn't be found.", e); Kryo.DefaultInstantiatorStrategy initStrategy = new Kryo.DefaultInstantiatorStrategy(); initStrategy.setFallbackInstantiatorStrategy(new StdInstantiatorStrategy()); Kryo kryo = new Kryo(); kryo.setInstantiatorStrategy(initStrategy); return kryo; } }
Example #30
Source File: ValueSerializer.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void checkKryoInitialized() { if (this.kryo == null) { this.kryo = new Kryo(); Kryo.DefaultInstantiatorStrategy instantiatorStrategy = new Kryo.DefaultInstantiatorStrategy(); instantiatorStrategy.setFallbackInstantiatorStrategy(new StdInstantiatorStrategy()); kryo.setInstantiatorStrategy(instantiatorStrategy); this.kryo.setAsmEnabled(true); KryoUtils.applyRegistrations(this.kryo, kryoRegistrations.values()); } }