本文整理汇总了Java中com.esotericsoftware.kryo.Serializer类的典型用法代码示例。如果您正苦于以下问题:Java Serializer类的具体用法?Java Serializer怎么用?Java Serializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Serializer类属于com.esotericsoftware.kryo包,在下文中一共展示了Serializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: KryoTranscoderTests
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
public KryoTranscoderTests(final int bufferSize) {
this.principalAttributes = new HashMap<String, Object>();
this.principalAttributes.put(ST_ID, TGT_ID);
transcoder = new KryoTranscoder(bufferSize);
final Map<Class<?>, Serializer> serializerMap = new HashMap<Class<?>, Serializer>();
serializerMap.put(
MockServiceTicket.class,
new FieldSerializer(transcoder.getKryo(), MockServiceTicket.class));
serializerMap.put(
MockTicketGrantingTicket.class,
new FieldSerializer(transcoder.getKryo(), MockTicketGrantingTicket.class));
serializerMap.put(
TicketGrantingTicketImpl.class,
new FieldSerializer(transcoder.getKryo(), TicketGrantingTicketImpl.class));
serializerMap.put(
ServiceTicketImpl.class,
new FieldSerializer(transcoder.getKryo(), ServiceTicketImpl.class));
transcoder.setSerializerMap(serializerMap);
transcoder.initialize();
}
示例2: read
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
@Override
public Queue read(Kryo kryo, Input input, Class<Queue> type) {
int length = input.readVarInt(true);
Registration registration = kryo.readClass(input);
Class cls = registration == null ? Object.class : registration.getType();
Queue queue = new Queue(length, cls);
kryo.reference(queue);
Class elementClass = null;
Serializer serializer = null;
if (genericType != null) {
elementClass = genericType;
serializer = kryo.getSerializer(genericType);
genericType = null;
}
if (serializer != null) {
for (int i = 0; i < length; i++)
queue.addLast(kryo.readObjectOrNull(input, elementClass, serializer));
} else {
for (int i = 0; i < length; i++)
queue.addLast(kryo.readClassAndObject(input));
}
return queue;
}
示例3: write
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
public void write (Kryo kryo, Output output, ObjectFloatMap map) {
int length = map.size;
output.writeVarInt(length, true);
output.writeBoolean(false); // whether type is written (in case future version of ObjectFloatMap supports type awareness)
Serializer keySerializer = null;
if (keyGenericType != null) {
if (keySerializer == null) keySerializer = kryo.getSerializer(keyGenericType);
keyGenericType = null;
}
for (Iterator iter = map.iterator(); iter.hasNext();) {
ObjectFloatMap.Entry entry = (ObjectFloatMap.Entry)iter.next();
if (keySerializer != null) {
kryo.writeObject(output, entry.key, keySerializer);
} else
kryo.writeClassAndObject(output, entry.key);
output.writeFloat(entry.value);
}
}
示例4: write
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
@Override
public void write(Kryo kryo, Output output, SortedIntList list) {
output.writeVarInt(list.size(), true);
Serializer serializer = null;
if (genericType != null) {
if (serializer == null) serializer = kryo.getSerializer(genericType);
genericType = null;
}
for (Iterator<SortedIntList.Node> iter = list.iterator(); iter.hasNext();){
SortedIntList.Node node = iter.next();
output.writeInt(node.index);
if (serializer != null) {
kryo.writeObjectOrNull(output, node.value, serializer);
} else {
kryo.writeClassAndObject(output, node.value);
}
}
}
示例5: read
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
@Override
public SortedIntList read(Kryo kryo, Input input, Class<SortedIntList> type) {
int length = input.readVarInt(true);
SortedIntList list = new SortedIntList();
kryo.reference(list);
Class elementClass = null;
Serializer serializer = null;
if (genericType != null) {
elementClass = genericType;
serializer = kryo.getSerializer(genericType);
genericType = null;
}
for (int i = 0; i < length; i++) {
int index = input.readInt();
Object value = serializer != null ?
kryo.readObjectOrNull(input, elementClass, serializer) : kryo.readClassAndObject(input);
list.insert(index, value);
}
return list;
}
示例6: read
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
@Override
public T read(Kryo kryo, Input input, Class<T> type) {
int length = input.readVarInt(true);
boolean ordered = input.readBoolean();
Class cls = kryo.readClass(input).getType();
T array = create(ordered, length, cls);
kryo.reference(array);
Class elementClass = null;
Serializer serializer = null;
if (genericType != null) {
elementClass = genericType;
serializer = kryo.getSerializer(genericType);
genericType = null;
}
if (serializer != null) {
for (int i = 0; i < length; i++)
array.add(kryo.readObjectOrNull(input, elementClass, serializer));
} else {
for (int i = 0; i < length; i++)
array.add(kryo.readClassAndObject(input));
}
return array;
}
示例7: read
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
@Override
public T read(Kryo kryo, Input input, Class<T> type) {
int length = input.readVarInt(true);
input.readBoolean(); // currently unused
T objectSet = create(length);
kryo.reference(objectSet);
Class elementClass = null;
Serializer serializer = null;
if (genericType != null) {
elementClass = genericType;
serializer = kryo.getSerializer(genericType);
genericType = null;
}
if (serializer != null) {
for (int i = 0; i < length; i++)
objectSet.add(kryo.readObject(input, elementClass, serializer));
} else {
for (int i = 0; i < length; i++)
objectSet.add(kryo.readClassAndObject(input));
}
return objectSet;
}
示例8: write
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
public void write (Kryo kryo, Output output, LongMap map) {
int length = map.size;
output.writeVarInt(length, true);
output.writeBoolean(false); // whether type is written (in case future version of LongMap supports type awareness)
Serializer valueSerializer = null;
if (valueGenericType != null) {
if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueGenericType);
valueGenericType = null;
}
for (Iterator iter = map.iterator(); iter.hasNext();) {
LongMap.Entry entry = (LongMap.Entry)iter.next();
output.writeLong(entry.key);
if (valueSerializer != null) {
kryo.writeObjectOrNull(output, entry.value, valueSerializer);
} else
kryo.writeClassAndObject(output, entry.value);
}
}
示例9: write
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
public void write (Kryo kryo, Output output, IntMap map) {
int length = map.size;
output.writeVarInt(length, true);
output.writeBoolean(false); // whether type is written (in case future version of IntMap supports type awareness)
Serializer valueSerializer = null;
if (valueGenericType != null) {
if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueGenericType);
valueGenericType = null;
}
for (Iterator iter = map.iterator(); iter.hasNext();) {
IntMap.Entry entry = (IntMap.Entry)iter.next();
output.writeInt(entry.key);
if (valueSerializer != null) {
kryo.writeObjectOrNull(output, entry.value, valueSerializer);
} else
kryo.writeClassAndObject(output, entry.value);
}
}
示例10: write
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
public void write (Kryo kryo, Output output, ObjectIntMap map) {
int length = map.size;
output.writeVarInt(length, true);
output.writeBoolean(false); // whether type is written (in case future version of ObjectIntMap supports type awareness)
Serializer keySerializer = null;
if (keyGenericType != null) {
if (keySerializer == null) keySerializer = kryo.getSerializer(keyGenericType);
keyGenericType = null;
}
for (Iterator iter = map.iterator(); iter.hasNext();) {
ObjectIntMap.Entry entry = (ObjectIntMap.Entry)iter.next();
if (keySerializer != null) {
kryo.writeObject(output, entry.key, keySerializer);
} else
kryo.writeClassAndObject(output, entry.key);
output.writeInt(entry.value);
}
}
示例11: create
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
/**
* 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);
// 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;
}
示例12: createKryo
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
private Kryo createKryo() {
Kryo result = new KryoReflectionFactorySupport() {
@Override
public Serializer<?> getDefaultSerializer(@SuppressWarnings("rawtypes") final Class clazz) {
if (EnumMap.class.isAssignableFrom(clazz)) {
return new EnumMapSerializer();
}
if (SubListSerializers.ArrayListSubListSerializer.canSerialize(clazz) || SubListSerializers.JavaUtilSubListSerializer.canSerialize(clazz)) {
return SubListSerializers.createFor(clazz);
}
return super.getDefaultSerializer(clazz);
}
};
result.register(Collections.singletonList("").getClass(), new ArraysAsListSerializer());
UnmodifiableCollectionsSerializer.registerSerializers(result);
return result;
}
示例13: reduceMapSetUnion
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
/**
* Set union, the set with the same key will be reduced(union) together in the root process.
* @param mapData map set data
* @param rootRank root rank
* @param elementSerializer element object Kryo serializer
* @param elementType element obejct class
* @return if this process is root, the set with the same key will be reduced together,
* otherwise, invalid map or null is returned.
* @throws Mp4jException
*/
public <T> Map<String, Set<T>> reduceMapSetUnion(Map<String, Set<T>> mapData, int rootRank, Serializer<T> elementSerializer, Class<T> elementType) throws Mp4jException {
Operand operand = Operands.OBJECT_OPERAND(new Mp4jSetSerializer<>(elementSerializer, elementType), elementType);
IOperator operator = new IObjectOperator<Set<T>>() {
@Override
public Set<T> apply(Set<T> o1, Set<T> o2) {
for (T val : o2) {
o1.add(val);
}
return o1;
}
};
return reduceMap(mapData, operand, operator, rootRank);
}
示例14: allreduceMapSetUnion
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
/**
* Set union, the set with the same key will be reduced(union) together.
* @param mapData map set data
* @param elementSerializer element object Kryo serializer
* @param elementType element object class
* @return the set with the same key will be reduced together.
* @throws Mp4jException
*/
public <T> Map<String, Set<T>> allreduceMapSetUnion(Map<String, Set<T>> mapData, Serializer<T> elementSerializer, Class<T> elementType) throws Mp4jException {
Operand operand = Operands.OBJECT_OPERAND(new Mp4jSetSerializer<>(elementSerializer, elementType), elementType);
IOperator operator = new IObjectOperator<Set<T>>() {
@Override
public Set<T> apply(Set<T> o1, Set<T> o2) {
for (T val : o2) {
o1.add(val);
}
return o1;
}
};
return allreduceMap(mapData, operand, operator);
}
示例15: reduceMapSetUnion
import com.esotericsoftware.kryo.Serializer; //导入依赖的package包/类
/**
* Set union, the set with the same key will be reduced(union) together in the root process and thread.
* @param mapData map set data
* @param rootRank root rank
* @param elementSerializer element object Kryo serializer
* @param elementType element object class
* @return if this process and thread is root, the set with the same key will be reduced together,
* otherwise, invalid map or null is returned.
* @throws Mp4jException
*/
public <T> Map<String, Set<T>> reduceMapSetUnion(Map<String, Set<T>> mapData, int rootRank, int rootThreadId, Serializer<T> elementSerializer, Class<T> elementType) throws Mp4jException {
Operand operand = Operands.OBJECT_OPERAND(new ProcessCommSlave.Mp4jSetSerializer<>(elementSerializer, elementType), elementType);
IOperator operator = new IObjectOperator<Set<T>>() {
@Override
public Set<T> apply(Set<T> o1, Set<T> o2) {
for (T val : o2) {
o1.add(val);
}
return o1;
}
};
return reduceMap(mapData, operand, operator, rootRank, rootThreadId);
}