本文整理了Java中com.esotericsoftware.kryo.Kryo.setInstantiatorStrategy()
方法的一些代码示例,展示了Kryo.setInstantiatorStrategy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Kryo.setInstantiatorStrategy()
方法的具体详情如下:
包路径:com.esotericsoftware.kryo.Kryo
类名称:Kryo
方法名:setInstantiatorStrategy
[英]Sets the strategy used by #newInstantiator(Class) for creating objects. See StdInstantiatorStrategy to create objects via without calling any constructor. See SerializingInstantiatorStrategy to mimic Java's built-in serialization.
[中]设置#newInstantiator(类)用于创建对象的策略。请参阅StdInstantiatorStrategy,通过创建对象而不调用任何构造函数。请参阅SerializingStantiatorStrategy以模拟Java的内置序列化。
代码示例来源:origin: apache/storm
private Object getKryoDeserializedObject (final byte[] ser) {
final Kryo kryo = new Kryo();
final Input input = new Input(new ByteArrayInputStream(ser));
kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
return kryo.readClassAndObject(input);
}
代码示例来源:origin: apache/storm
private byte[] getKryoSerializedBytes (final Object obj) {
final Kryo kryo = new Kryo();
final ByteArrayOutputStream os = new ByteArrayOutputStream();
final Output output = new Output(os);
kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
kryo.writeClassAndObject(output, obj);
output.flush();
return os.toByteArray();
}
代码示例来源:origin: alibaba/jstorm
public KryoSerializer() {
kryo = new Kryo();
kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
output = new Output(200, 2000000000);
input = new Input(1);
}
代码示例来源:origin: apache/flink
/**
* 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;
}
}
代码示例来源:origin: apache/flink
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());
}
}
代码示例来源:origin: apache/kylin
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();
}
}
代码示例来源:origin: apache/flink
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);
}
}
代码示例来源:origin: apache/flink
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);
}
}
代码示例来源:origin: apache/flink
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);
}
}
// --------------------------------------------------------------------------------------------
代码示例来源:origin: fengjiachun/Jupiter
@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;
}
};
代码示例来源:origin: fengjiachun/Jupiter
@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;
}
};
代码示例来源:origin: apache/storm
@Override
protected Kryo initialValue() {
Kryo obj = new Kryo();
if (context != null && topoConf != null) {
KryoTupleSerializer ser = new KryoTupleSerializer(topoConf, context);
KryoTupleDeserializer deser = new KryoTupleDeserializer(topoConf, context);
obj.register(TupleImpl.class, new TupleSerializer(ser, deser));
}
if (!registrations.isEmpty()) {
SerializationFactory.register(obj, registrations);
}
obj.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
return obj;
}
};
代码示例来源:origin: apache/hive
@Override
protected Kryo initialValue() {
Kryo kryo = new Kryo();
int count = 0;
for (Class<?> klass : messages) {
kryo.register(klass, REG_ID_BASE + count);
count++;
}
kryo.register(BaseProtocol.JobResult.class, new JobResultSerializer(), count);
kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
return kryo;
}
};
代码示例来源:origin: atomix/atomix
/**
* 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;
}
代码示例来源:origin: apache/rocketmq-externals
private Wrapper getWrapper() {
Wrapper r = WRAPPERS.get();
if (r != null) return r;
r = new Wrapper();
r.bufferSize = bufferSize;
r.maxBufferSize = maxBufferSize;
r.kryo = new Kryo();
r.kryo.register(ArrayList.class);
r.kryo.register(ByteArrayMap.class);
r.kryo.register(ByteArrayList.class);
r.kryo.register(ByteArraySet.class);
r.kryo.register(LinkedHashSet.class);
r.kryo.register(LinkedHashMap.class);
for (Class<?> clazz : classes) r.kryo.register(clazz);
r.kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
WRAPPERS.set(r);
return r;
}
代码示例来源:origin: orbit/orbit
kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
代码示例来源:origin: opentripplanner/OpenTripPlanner
kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new SerializingInstantiatorStrategy()));
return kryo;
代码示例来源:origin: magro/memcached-session-manager
@Override
public Kryo build() {
Kryo k = this.buildFrom(KryoBuilder.this);
k.setInstantiatorStrategy(instantiatorStrategy);
return k;
}
};
代码示例来源:origin: westnordost/StreetComplete
@Override protected Kryo initialValue()
{
Kryo kryo = new Kryo();
/* Kryo docs say that classes that are registered are serialized more space efficiently
(so it is not necessary that all classes that are serialized are registered here, but
it is better) */
kryo.setRegistrationRequired(true);
kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
for(Class reg : registeredClasses)
{
kryo.register(reg);
}
return kryo;
}
};
代码示例来源:origin: spring-projects/spring-integration
@Override
protected void configureKryoInstance(Kryo kryo) {
kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
if (this.kryoRegistrar != null) {
this.kryoRegistrar.registerTypes(kryo);
}
kryo.setReferences(this.useReferences);
}
内容来源于网络,如有侵权,请联系作者删除!