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

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

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

Kryo.getSerializer介绍

[英]Returns the serializer for the registration for the specified class.
[中]返回指定类的注册的序列化程序。

代码示例

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

if (kryo.isFinal(parameterTypes[ii])) cachedMethod.serializers[ii] = kryo.getSerializer(parameterTypes[ii]);

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

@Test
public void test_registers_when_valid_class_name() {
  Class arbitraryClass = BlowfishTupleSerializer.class;
  String secretKey = "0123456789abcdef";
  Map<String, Object> conf = Utils.readDefaultConfig();
  conf.put(Config.TOPOLOGY_TUPLE_SERIALIZER, arbitraryClass.getName());
  conf.put(BlowfishTupleSerializer.SECRET_KEY, secretKey);
  Kryo kryo = SerializationFactory.getKryo(conf);
  Assert.assertEquals(arbitraryClass, kryo.getSerializer(ListDelegate.class).getClass());
}

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

@Test
public void test_registers_default_when_not_in_conf() throws ClassNotFoundException {
  Map<String, Object> conf = Utils.readDefaultConfig();
  String className = (String) conf.get(Config.TOPOLOGY_TUPLE_SERIALIZER);
  Class configuredClass = Class.forName(className);
  Kryo kryo = SerializationFactory.getKryo(conf);
  Assert.assertEquals(configuredClass, kryo.getSerializer(ListDelegate.class).getClass());
}

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

private void validateStateDescriptorConfigured(SingleOutputStreamOperator<?> result) {
  OneInputTransformation<?, ?> transform = (OneInputTransformation<?, ?>) result.getTransformation();
  WindowOperator<?, ?, ?, ?, ?> op = (WindowOperator<?, ?, ?, ?, ?>) transform.getOperator();
  StateDescriptor<?, ?> descr = op.getStateDescriptor();
  // this would be the first statement to fail if state descriptors were not properly initialized
  TypeSerializer<?> serializer = descr.getSerializer();
  assertTrue(serializer instanceof KryoSerializer);
  Kryo kryo = ((KryoSerializer<?>) serializer).getKryo();
  assertTrue("serializer registration was not properly passed on",
      kryo.getSerializer(File.class) instanceof JavaSerializer);
}

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

private void validateListStateDescriptorConfigured(SingleOutputStreamOperator<?> result) {
    OneInputTransformation<?, ?> transform = (OneInputTransformation<?, ?>) result.getTransformation();
    WindowOperator<?, ?, ?, ?, ?> op = (WindowOperator<?, ?, ?, ?, ?>) transform.getOperator();
    StateDescriptor<?, ?> descr = op.getStateDescriptor();

    assertTrue(descr instanceof ListStateDescriptor);

    ListStateDescriptor<?> listDescr = (ListStateDescriptor<?>) descr;

    // this would be the first statement to fail if state descriptors were not properly initialized
    TypeSerializer<?> serializer = listDescr.getSerializer();
    assertTrue(serializer instanceof ListSerializer);

    TypeSerializer<?> elementSerializer = listDescr.getElementSerializer();
    assertTrue(elementSerializer instanceof KryoSerializer);

    Kryo kryo = ((KryoSerializer<?>) elementSerializer).getKryo();

    assertTrue("serializer registration was not properly passed on",
        kryo.getSerializer(File.class) instanceof JavaSerializer);
  }
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public List<Registration> getRegistrations() {
  List<Registration> registrations = new ArrayList<Registration>();
  if (!CollectionUtils.isEmpty(this.registeredClasses)) {
    for (Map.Entry<Integer, Class<?>> entry : this.registeredClasses.entrySet()) {
      registrations.add(
          new Registration(entry.getValue(), kryo.getSerializer(entry.getValue()), entry.getKey()));
    }
  }
  return registrations;
}

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

@Override
public Serializer newSerializer(Class<?> type) {
  if ( CGLibProxySerializer.canSerialize( type ) ) {
    return kryo.getSerializer(CGLibProxySerializer.CGLibProxyMarker.class);
  }
  return null;
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public List<Registration> getRegistrations() {
  List<Registration> registrations = new ArrayList<Registration>();
  if (!CollectionUtils.isEmpty(this.registeredClasses)) {
    for (int i = 0; i < this.registeredClasses.size(); i++) {
      registrations.add(new Registration(this.registeredClasses.get(i),
          kryo.getSerializer(this.registeredClasses.get(i)), i + this.initialValue));
    }
  }
  return registrations;
}

代码示例来源:origin: usc-cloud/goffish

protected void popSerializerAndValueClass(Kryo kryo) {
  _currentValueClass = _valueConcreteType;
  _currentSerializer = _valueSerializer;
  if (_currentValueClass == null && _valueConcreteGenericType != null) {
    _currentValueClass = _valueConcreteGenericType;
    _currentSerializer = kryo.getSerializer(_currentValueClass);
  }
  
  _valueConcreteGenericType = null;
}

代码示例来源:origin: com.esotericsoftware/kryo

public EnumNameSerializer (Kryo kryo, Class<? extends Enum> type) {
  this.enumType = type;
  stringSerializer = kryo.getSerializer(String.class);
  setImmutable(true);
}

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

@Override
public List<Registration> getRegistrations() {
  List<Registration> registrations = new ArrayList<Registration>();
  if (!CollectionUtils.isEmpty(this.registeredClasses)) {
    for (Map.Entry<Integer, Class<?>> entry : this.registeredClasses.entrySet()) {
      registrations.add(
          new Registration(entry.getValue(), kryo.getSerializer(entry.getValue()), entry.getKey()));
    }
  }
  return registrations;
}

代码示例来源:origin: com.esotericsoftware/kryo-shaded

public EnumNameSerializer (Kryo kryo, Class<? extends Enum> type) {
  this.enumType = type;
  stringSerializer = kryo.getSerializer(String.class);
  setImmutable(true);
}

代码示例来源:origin: org.springframework.xd/spring-xd-codec

@Override
  public List<Registration> getRegistrations() {
    List<Registration> registrations = new ArrayList<>();
    if (!CollectionUtils.isEmpty(registeredClasses)) {
      for (Map.Entry<Integer, Class<?>> entry : registeredClasses.entrySet()) {
        registrations.add(new Registration(entry.getValue(), kryo.getSerializer(entry.getValue()), entry.getKey()));
      }
    }
    return registrations;
  }
}

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

@Override
public List<Registration> getRegistrations() {
  List<Registration> registrations = new ArrayList<Registration>();
  if (!CollectionUtils.isEmpty(this.registeredClasses)) {
    for (int i = 0; i < this.registeredClasses.size(); i++) {
      registrations.add(new Registration(this.registeredClasses.get(i),
          kryo.getSerializer(this.registeredClasses.get(i)), i + this.initialValue));
    }
  }
  return registrations;
}

代码示例来源:origin: org.springframework.xd/spring-xd-codec

@Override
public List<Registration> getRegistrations() {
  List<Registration> registrations = new ArrayList<>();
  if (!CollectionUtils.isEmpty(registeredClasses)) {
    for (int i = 0; i < registeredClasses.size(); i++) {
      registrations.add(new Registration(registeredClasses.get(i), kryo.getSerializer(registeredClasses.get
          (i)), i + initialValue));
    }
  }
  return registrations;
}

代码示例来源:origin: junkdog/artemis-odb

private Serializer serializer (Kryo kryo, Class<? extends Component> type, EntityEdit edit) {
  Serializer serializer = serializers.get(type);
  if (serializer == null) {
    serializer = kryo.getSerializer(type);
    if (serializer.getClass() == FieldSerializer.class) {
      serializer = new ComponentFieldSerializer(kryo, type);
    }
    serializers.put(type, serializer);
  }
  if (serializer instanceof ComponentFieldSerializer) {
    ((ComponentFieldSerializer)serializer).init(edit);
  } else {
    throw new RuntimeException("Custom serializer for " + type + " must extend ComponentFieldSerializer.");
  }
  return serializer;
}

代码示例来源:origin: com.esotericsoftware/kryo-shaded

public String[] read (Kryo kryo, Input input, Class<String[]> type) {
  int length = input.readVarInt(true);
  if (length == NULL) return null;
  String[] array = new String[--length];
  if (kryo.getReferences() && kryo.getReferenceResolver().useReferences(String.class)) {
    Serializer serializer = kryo.getSerializer(String.class);
    for (int i = 0; i < length; i++) {
      array[i] = kryo.readObjectOrNull(input, String.class, serializer);
    }
  } else {
    for (int i = 0; i < length; i++)
      array[i] = input.readString();
  }
  return array;
}

代码示例来源:origin: com.esotericsoftware/kryo

public String[] read (Kryo kryo, Input input, Class<String[]> type) {
  int length = input.readVarInt(true);
  if (length == NULL) return null;
  String[] array = new String[--length];
  if (kryo.getReferences() && kryo.getReferenceResolver().useReferences(String.class)) {
    Serializer serializer = kryo.getSerializer(String.class);
    for (int i = 0; i < length; i++) {
      array[i] = kryo.readObjectOrNull(input, String.class, serializer);
    }
  } else {
    for (int i = 0; i < length; i++)
      array[i] = input.readString();
  }
  return array;
}

代码示例来源:origin: com.esotericsoftware.kryo/kryo

public void write (Kryo kryo, Output output, String[] object) {
  if (object == null) {
    output.writeVarInt(NULL, true);
    return;
  }
  output.writeVarInt(object.length + 1, true);
  if (kryo.getReferences() && kryo.getReferenceResolver().useReferences(String.class)) {
    Serializer serializer = kryo.getSerializer(String.class);
    for (int i = 0, n = object.length; i < n; i++)
      kryo.writeObjectOrNull(output, object[i], serializer);
  } else {
    for (int i = 0, n = object.length; i < n; i++)
      output.writeString(object[i]);
  }
}

代码示例来源:origin: com.esotericsoftware/kryo

public void write (Kryo kryo, Output output, String[] object) {
  if (object == null) {
    output.writeVarInt(NULL, true);
    return;
  }
  output.writeVarInt(object.length + 1, true);
  if (kryo.getReferences() && kryo.getReferenceResolver().useReferences(String.class)) {
    Serializer serializer = kryo.getSerializer(String.class);
    for (int i = 0, n = object.length; i < n; i++)
      kryo.writeObjectOrNull(output, object[i], serializer);
  } else {
    for (int i = 0, n = object.length; i < n; i++)
      output.writeString(object[i]);
  }
}

相关文章