本文整理汇总了Java中com.esotericsoftware.kryo.pool.KryoCallback类的典型用法代码示例。如果您正苦于以下问题:Java KryoCallback类的具体用法?Java KryoCallback怎么用?Java KryoCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KryoCallback类属于com.esotericsoftware.kryo.pool包,在下文中一共展示了KryoCallback类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: run
import com.esotericsoftware.kryo.pool.KryoCallback; //导入依赖的package包/类
@Override
public <T> T run(KryoCallback<T> callback) {
Kryo kryo = this.borrowOne();
T t;
try {
t = callback.execute(kryo);
} finally {
this.returnOne(kryo);
}
return t;
}
开发者ID:carryxyh,项目名称:FKC,代码行数:13,代码来源:KryoPoolQueueImpl.java
示例2: run
import com.esotericsoftware.kryo.pool.KryoCallback; //导入依赖的package包/类
@Override
public <T> T run(KryoCallback<T> callback) {
Kryo kryo = null;
try {
kryo = kryoPool.borrowObject();
return callback.execute(kryo);
} catch (Exception e) {
fkcExceptionHandler.dealException(e);
return null;
} finally {
if (kryo != null) {
kryoPool.returnObject(kryo);
}
}
}
开发者ID:carryxyh,项目名称:FKC,代码行数:16,代码来源:KryoPoolCommonsImpl.java
示例3: serialize
import com.esotericsoftware.kryo.pool.KryoCallback; //导入依赖的package包/类
@Override
public <T> byte[] serialize(T obj) {
return getPool().run(new KryoCallback<byte[]>() {
@Override
public byte[] execute(Kryo kryo) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Output output = new Output(baos);
kryo.writeClassAndObject(output, obj);
output.close();
return baos.toByteArray();
}
});
}
开发者ID:apache,项目名称:fluo-recipes,代码行数:14,代码来源:KryoSimplerSerializer.java
示例4: deserialize
import com.esotericsoftware.kryo.pool.KryoCallback; //导入依赖的package包/类
@Override
public <T> T deserialize(byte[] serObj, Class<T> clazz) {
return getPool().run(new KryoCallback<T>() {
@Override
public T execute(Kryo kryo) {
ByteArrayInputStream bais = new ByteArrayInputStream(serObj);
Input input = new Input(bais);
return clazz.cast(kryo.readClassAndObject(input));
}
});
}
开发者ID:apache,项目名称:fluo-recipes,代码行数:12,代码来源:KryoSimplerSerializer.java
示例5: toByteArrayKryo
import com.esotericsoftware.kryo.pool.KryoCallback; //导入依赖的package包/类
/**
* Serialize an object to byte array, with a custom class loader.
*
* <p>
* This method uses Kryo lib.
* </p>
*
* @param obj
* @param classLoader
* @return
*/
public static byte[] toByteArrayKryo(final Object obj, final ClassLoader classLoader) {
if (obj == null) {
return null;
}
return kryoPool.run(new KryoCallback<byte[]>() {
@Override
public byte[] execute(Kryo kryo) {
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
if (classLoader != null) {
Thread.currentThread().setContextClassLoader(classLoader);
}
try {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
try (Output output = new Output(baos)) {
kryo.setClassLoader(classLoader != null ? classLoader : oldClassLoader);
// kryo.writeObject(output, obj);
kryo.writeClassAndObject(output, obj);
output.flush();
return baos.toByteArray();
}
} catch (Exception e) {
throw e instanceof SerializationException ? (SerializationException) e
: new SerializationException(e);
}
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
});
}
开发者ID:DDTH,项目名称:ddth-commons,代码行数:42,代码来源:SerializationUtils.java
示例6: fromByteArrayKryo
import com.esotericsoftware.kryo.pool.KryoCallback; //导入依赖的package包/类
/**
* Deserialize a byte array back to an object, with custom class loader.
*
* <p>
* This method uses Kryo lib.
* </p>
*
* @param data
* @param clazz
* @param classLoader
* @return
*/
public static <T> T fromByteArrayKryo(byte[] data, final Class<T> clazz,
final ClassLoader classLoader) {
if (data == null) {
return null;
}
return kryoPool.run(new KryoCallback<T>() {
@SuppressWarnings("unchecked")
@Override
public T execute(Kryo kryo) {
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
if (classLoader != null) {
Thread.currentThread().setContextClassLoader(classLoader);
}
try {
try (Input input = new Input(new ByteArrayInputStream(data))) {
kryo.setClassLoader(classLoader != null ? classLoader : oldClassLoader);
// return kryo.readObject(input, clazz);
Object result = kryo.readClassAndObject(input);
if (result != null && clazz.isAssignableFrom(result.getClass())) {
return (T) result;
} else {
return null;
}
} catch (Exception e) {
throw e instanceof DeserializationException ? (DeserializationException) e
: new DeserializationException(e);
}
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
});
}
开发者ID:DDTH,项目名称:ddth-commons,代码行数:46,代码来源:SerializationUtils.java
示例7: run
import com.esotericsoftware.kryo.pool.KryoCallback; //导入依赖的package包/类
@Override
public <T> T run(KryoCallback<T> callback) {
return pool.run(callback);
}
开发者ID:shlee89,项目名称:athena,代码行数:5,代码来源:KryoNamespace.java
示例8: run
import com.esotericsoftware.kryo.pool.KryoCallback; //导入依赖的package包/类
@Override
public <T> T run(KryoCallback<T> callback) {
return pool.run(callback);
}
开发者ID:atomix,项目名称:atomix,代码行数:5,代码来源:KryoNamespace.java
示例9: run
import com.esotericsoftware.kryo.pool.KryoCallback; //导入依赖的package包/类
/**
* 从pool中获取一个kryo后马上执行callback
*
* @param callback callback
* @param <T>
* @return 返回值
*/
<T> T run(KryoCallback<T> callback);
开发者ID:carryxyh,项目名称:FKC,代码行数:9,代码来源:KryoPool.java
注:本文中的com.esotericsoftware.kryo.pool.KryoCallback类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论