com.esotericsoftware.kryo.Kryo.setReferences()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(280)

本文整理了Java中com.esotericsoftware.kryo.Kryo.setReferences()方法的一些代码示例,展示了Kryo.setReferences()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Kryo.setReferences()方法的具体详情如下:
包路径:com.esotericsoftware.kryo.Kryo
类名称:Kryo
方法名:setReferences

Kryo.setReferences介绍

[英]If true, each appearance of an object in the graph after the first is stored as an integer ordinal. When set to true, MapReferenceResolver is used. This enables references to the same object and cyclic graphs to be serialized, but typically adds overhead of one byte per object. Default is true.
[中]如果为true,则图形中对象在第一次出现后的每个外观都存储为整数序号。设置为true时,将使用MapReferenceSolver。这使得对同一对象和循环图的引用能够被序列化,但通常会增加每个对象一个字节的开销。默认值为true。

代码示例

代码示例来源:origin: EsotericSoftware/kryonet

public KryoSerialization () {
  this(new Kryo());
  kryo.setReferences(false);
  kryo.setRegistrationRequired(true);
}

代码示例来源: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/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: changmingxie/tcc-transaction

public Kryo create() {
    Kryo kryo = new Kryo();
    kryo.setReferences(true);
    kryo.setRegistrationRequired(false);
    //Fix the NPE bug when deserializing Collections.
    ((Kryo.DefaultInstantiatorStrategy) kryo.getInstantiatorStrategy())
        .setFallbackInstantiatorStrategy(new StdInstantiatorStrategy());
    return kryo;
  }
};

代码示例来源:origin: changmingxie/tcc-transaction

@Override
  protected Kryo initialValue() {
    Kryo kryo = new Kryo();
    kryo.setReferences(true);
    kryo.setRegistrationRequired(false);
    //Fix the NPE bug when deserializing Collections.
    ((Kryo.DefaultInstantiatorStrategy) kryo.getInstantiatorStrategy())
        .setFallbackInstantiatorStrategy(new StdInstantiatorStrategy());
    return kryo;
  }
};

代码示例来源:origin: changmingxie/tcc-transaction

@Override
  protected Kryo initialValue() {
    Kryo kryo = new Kryo();
    kryo.setReferences(true);
    kryo.setRegistrationRequired(false);
    //Fix the NPE bug when deserializing Collections.
    ((Kryo.DefaultInstantiatorStrategy) kryo.getInstantiatorStrategy())
        .setFallbackInstantiatorStrategy(new StdInstantiatorStrategy());
    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: 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: opentripplanner/OpenTripPlanner

kryo.setReferences(true);
kryo.addDefaultSerializer(TPrimitiveHash.class, ExternalizableSerializer.class);
kryo.register(TIntArrayList.class, new TIntArrayListSerializer());

代码示例来源:origin: magro/memcached-session-manager

@Override
  public Kryo build() {
    Kryo k = this.buildFrom(KryoBuilder.this);
    k.setReferences(references);
    return k;
  }
};

代码示例来源:origin: magro/memcached-session-manager

@Override
public void customize(Kryo kryo) {
  kryo.setReferences(true);
  kryo.register( GrailsFlashScope.class, new FieldSerializer( kryo, GrailsFlashScope.class ) );
}

代码示例来源: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);
}

代码示例来源:origin: apache/metron

@Override
 protected Kryo initialValue() {
  Kryo ret = new Kryo();
  ret.setReferences(true);
  ret.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
  ret.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
  ret.register(Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer());
  ret.register(Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer());
  ret.register(Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer());
  ret.register(Collections.singletonList("").getClass(), new CollectionsSingletonListSerializer());
  ret.register(Collections.singleton("").getClass(), new CollectionsSingletonSetSerializer());
  ret.register(Collections.singletonMap("", "").getClass(), new CollectionsSingletonMapSerializer());
  ret.register(GregorianCalendar.class, new GregorianCalendarSerializer());
  ret.register(InvocationHandler.class, new JdkProxySerializer());
  UnmodifiableCollectionsSerializer.registerSerializers(ret);
  SynchronizedCollectionsSerializer.registerSerializers(ret);
  // custom serializers for non-jdk libs
  // register CGLibProxySerializer, works in combination with the appropriate action in handleUnregisteredClass (see below)
  ret.register(CGLibProxySerializer.CGLibProxyMarker.class, new CGLibProxySerializer());
  // joda DateTime, LocalDate and LocalDateTime
  ret.register(LocalDate.class, new JodaLocalDateSerializer());
  ret.register(LocalDateTime.class, new JodaLocalDateTimeSerializer());
  // guava ImmutableList, ImmutableSet, ImmutableMap, ImmutableMultimap, UnmodifiableNavigableSet
  ImmutableListSerializer.registerSerializers(ret);
  ImmutableSetSerializer.registerSerializers(ret);
  ImmutableMapSerializer.registerSerializers(ret);
  ImmutableMultimapSerializer.registerSerializers(ret);
  return ret;
 }
};

代码示例来源:origin: apache/metron

@Override
protected Kryo initialValue() {
 Kryo ret = new Kryo();
 ret.setReferences(true);
 ret.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));

代码示例来源:origin: vakinge/jeesuite-libs

/**
 * create a new kryo object to application use
 * @return KryoHolder instance
 */
public KryoHolder creatInstnce() {
  Kryo kryo = new Kryo();
  kryo.setReferences(false);//
  return new KryoHolder(kryo);
}

代码示例来源:origin: chenleijava/springJredisCache

/**
 * create a new kryo object to application use
 *
 * @return
 */
public KryoHolder creatInstnce() {
  Kryo kryo = new Kryo();
  kryo.setReferences(false);//
  return new KryoHolder(kryo);
}

代码示例来源:origin: org.jupiter-rpc/jupiter-all

@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: spring-cloud/spring-cloud-stream

protected void configureKryoInstance(Kryo kryo) {
  kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
  if (this.kryoRegistrar != null) {
    this.kryoRegistrar.registerTypes(kryo);
  }
  kryo.setReferences(this.useReferences);
}

代码示例来源:origin: org.springframework.integration/spring-integration-core

@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);
}

相关文章