本文整理了Java中com.esotericsoftware.kryo.Kryo.setClassLoader()
方法的一些代码示例,展示了Kryo.setClassLoader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Kryo.setClassLoader()
方法的具体详情如下:
包路径:com.esotericsoftware.kryo.Kryo
类名称:Kryo
方法名:setClassLoader
[英]Sets the classloader to resolve unregistered class names to classes. The default is the loader that loaded the Kryo class.
[中]设置类加载器以将未注册的类名解析为类。默认值是加载Kryo类的加载程序。
代码示例来源:origin: apache/hive
/**
* By default, kryo pool uses ConcurrentLinkedQueue which is unbounded. To facilitate reuse of
* kryo object call releaseKryo() after done using the kryo instance. The class loader for the
* kryo instance will be set to current thread's context class loader.
*
* @return kryo instance
*/
public static Kryo borrowKryo() {
Kryo kryo = kryoPool.borrow();
kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
return kryo;
}
代码示例来源:origin: alibaba/jetcache
@Override
public Object doApply(byte[] buffer) {
ByteArrayInputStream in;
if (useIdentityNumber) {
in = new ByteArrayInputStream(buffer, 4, buffer.length - 4);
} else {
in = new ByteArrayInputStream(buffer);
}
Input input = new Input(in);
Kryo kryo = (Kryo) KryoValueEncoder.kryoThreadLocal.get()[0];
kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
return kryo.readClassAndObject(input);
}
}
代码示例来源:origin: redisson/redisson
/**
* Sub classes can customize the Kryo instance by overriding this method
*
* @return create Kryo instance
*/
protected Kryo createInstance() {
Kryo kryo = new Kryo();
if (classLoader != null) {
kryo.setClassLoader(classLoader);
}
kryo.setReferences(false);
for (Class<?> clazz : classes) {
kryo.register(clazz);
}
return kryo;
}
代码示例来源:origin: redisson/redisson
/**
* Sub classes can customize the Kryo instance by overriding this method
*
* @return create Kryo instance
*/
protected Kryo createInstance() {
Kryo kryo = new Kryo();
if (classLoader != null) {
kryo.setClassLoader(classLoader);
}
kryo.setReferences(false);
for (Class<?> clazz : classes) {
kryo.register(clazz);
}
return kryo;
}
代码示例来源:origin: apache/hive
public static <T> T deserialize(byte[] buffer, Class<T> clazz) {
Kryo kryo = SerializationUtilities.borrowKryo();
kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
T result = null;
try {
result = kryo.readObject(new Input(new ByteArrayInputStream(buffer)), clazz);
} finally {
SerializationUtilities.releaseKryo(kryo);
}
return result;
}
代码示例来源:origin: apache/hive
public static byte[] serialize(Object object) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Output output = new Output(stream);
Kryo kryo = SerializationUtilities.borrowKryo();
kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
try {
kryo.writeObject(output, object);
} finally {
SerializationUtilities.releaseKryo(kryo);
}
output.close(); // close() also calls flush()
return stream.toByteArray();
}
代码示例来源:origin: apache/hive
/**
* @param plan Usually of type MapredWork, MapredLocalWork etc.
* @param out stream in which serialized plan is written into
*/
private static void serializeObjectByKryo(Kryo kryo, Object plan, OutputStream out) {
Output output = new Output(out);
kryo.setClassLoader(Utilities.getSessionSpecifiedClassLoader());
kryo.writeObject(output, plan);
output.close();
}
代码示例来源:origin: apache/hive
private static <T> T deserializeObjectByKryo(Kryo kryo, InputStream in, Class<T> clazz ) {
Input inp = new Input(in);
kryo.setClassLoader(Utilities.getSessionSpecifiedClassLoader());
T t = kryo.readObject(inp,clazz);
inp.close();
return t;
}
代码示例来源:origin: apache/flink
private void checkKryoInitialized() {
if (this.kryo == null) {
this.kryo = getKryoInstance();
// Enable reference tracking.
kryo.setReferences(true);
// Throwable and all subclasses should be serialized via java serialization
// Note: the registered JavaSerializer is Flink's own implementation, and not Kryo's.
// This is due to a know issue with Kryo's JavaSerializer. See FLINK-6025 for details.
kryo.addDefaultSerializer(Throwable.class, new JavaSerializer());
// Add default serializers first, so that the type registrations without a serializer
// are registered with a default serializer
for (Map.Entry<Class<?>, ExecutionConfig.SerializableSerializer<?>> entry: defaultSerializers.entrySet()) {
kryo.addDefaultSerializer(entry.getKey(), entry.getValue().getSerializer());
}
for (Map.Entry<Class<?>, Class<? extends Serializer<?>>> entry: defaultSerializerClasses.entrySet()) {
kryo.addDefaultSerializer(entry.getKey(), entry.getValue());
}
KryoUtils.applyRegistrations(this.kryo, kryoRegistrations.values());
kryo.setRegistrationRequired(false);
kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
}
}
代码示例来源:origin: apache/hive
ClassLoader newLoader = addToClassPath(loader, addedJars.split(";"));
Thread.currentThread().setContextClassLoader(newLoader);
kryo.setClassLoader(newLoader);
代码示例来源: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: alibaba/jstorm
Kryo k = kryoFactory.getKryo(conf);
if (WorkerClassLoader.getInstance() != null)
k.setClassLoader(WorkerClassLoader.getInstance());
k.register(byte[].class);
代码示例来源:origin: magro/memcached-session-manager
kryo.setClassLoader( classLoader );
代码示例来源:origin: org.apache.apex/malhar-library
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
in.defaultReadObject();
this.kryo = new Kryo();
this.kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
}
代码示例来源:origin: org.apache.apex/malhar-library
public KryoSerializableStreamCodec()
{
this.kryo = new Kryo();
this.kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
}
代码示例来源:origin: org.apache.apex/apex-engine
public DefaultKryoStreamCodec()
{
this.kryo = new Kryo();
this.kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
}
代码示例来源:origin: org.apache.apex/apex-common
public static Object retrieve(InputStream stream)
{
synchronized (kryo) {
kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
Input input = new Input(stream);
return kryo.readClassAndObject(input);
}
}
代码示例来源:origin: com.twitter/chill-java
public Kryo newKryo() {
Kryo k = KryoInstantiator.this.newKryo();
k.setClassLoader(Thread.currentThread().getContextClassLoader());
return k;
}
};
代码示例来源:origin: yyuu/jetty-nosql-memcached
@Override
protected Kryo initialValue() {
Kryo kryo = new Kryo();
kryo.setRegistrationRequired(false);
kryo.setClassLoader( Thread.currentThread().getContextClassLoader() );
return kryo;
};
};
代码示例来源:origin: com.twitter/chill-java
public Kryo newKryo() {
Kryo k = KryoInstantiator.this.newKryo();
k.setClassLoader(cl);
return k;
}
};
内容来源于网络,如有侵权,请联系作者删除!