com.esotericsoftware.kryo.util.MapReferenceResolver Java Examples

The following examples show how to use com.esotericsoftware.kryo.util.MapReferenceResolver. 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: KryoSerialization.java    From JPPF with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #2
Source File: KryoFactory.java    From vertexium with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: DefaultStatefulStreamCodec.java    From Bats with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("OverridableMethodCallInConstructor")
public DefaultStatefulStreamCodec()
{
  super(new ClassResolver(), new MapReferenceResolver());
  data = new Output(4096, Integer.MAX_VALUE);
  state = new Output(4096, Integer.MAX_VALUE);
  input = new Input();

  register(Class.class);
  register(ClassIdPair.class);
  classResolver = (ClassResolver)getClassResolver();
  this.pairs = classResolver.pairs;
  classResolver.init();
  dataStatePair = new DataStatePair();
}
 
Example #4
Source File: DefaultStatefulStreamCodec.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("OverridableMethodCallInConstructor")
public DefaultStatefulStreamCodec()
{
  super(new ClassResolver(), new MapReferenceResolver());
  data = new Output(4096, Integer.MAX_VALUE);
  state = new Output(4096, Integer.MAX_VALUE);
  input = new Input();

  register(Class.class);
  register(ClassIdPair.class);
  classResolver = (ClassResolver)getClassResolver();
  this.pairs = classResolver.pairs;
  classResolver.init();
  dataStatePair = new DataStatePair();
}
 
Example #5
Source File: KryoPool.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Kryo newInstance() {
    Kryo next = new Kryo(new DefaultClassResolver(),new MapReferenceResolver());
    if(kryoRegistry!=null)
        kryoRegistry.register(next);
    return next;
}
 
Example #6
Source File: KryoContext.java    From turbo-rpc with Apache License 2.0 4 votes vote down vote up
public KryoContext() {
	kryo = new Kryo(new FastClassResolver(), new MapReferenceResolver(), new DefaultStreamFactory());
	kryo.setDefaultSerializer(FastSerializer.class);
	kryo.setReferences(false);

	kryo.register(ArrayList.class);
	kryo.register(LinkedList.class);
	kryo.register(CopyOnWriteArrayList.class);
	kryo.register(HashMap.class);
	kryo.register(ConcurrentHashMap.class);
	kryo.register(TreeMap.class);
	kryo.register(TreeSet.class);
	kryo.register(HashSet.class);
	kryo.register(java.util.Date.class);
	kryo.register(java.sql.Date.class);
	kryo.register(LocalDate.class);
	kryo.register(LocalDateTime.class);
	kryo.register(byte[].class);
	kryo.register(char[].class);
	kryo.register(short[].class);
	kryo.register(int[].class);
	kryo.register(long[].class);
	kryo.register(float[].class);
	kryo.register(double[].class);
	kryo.register(boolean[].class);
	kryo.register(String[].class);
	kryo.register(Object[].class);
	kryo.register(BigInteger.class);
	kryo.register(BigDecimal.class);
	kryo.register(Class.class);
	kryo.register(Enum.class);
	kryo.register(EnumSet.class);
	kryo.register(Currency.class);
	kryo.register(StringBuffer.class);
	kryo.register(StringBuilder.class);
	kryo.register(Collections.EMPTY_LIST.getClass());
	kryo.register(Collections.EMPTY_MAP.getClass());
	kryo.register(Collections.EMPTY_SET.getClass());
	kryo.register(Collections.singletonList(null).getClass());
	kryo.register(Collections.singletonMap(null, null).getClass());
	kryo.register(Collections.singleton(null).getClass());
	kryo.register(Collection.class);
	kryo.register(Map.class);
	kryo.register(TimeZone.class);
	kryo.register(Calendar.class);
	kryo.register(Locale.class);
	kryo.register(Charset.class);
	kryo.register(URL.class);
}