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

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

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

Kryo.getDefaultSerializer介绍

[英]Returns the best matching serializer for a class. This method can be overridden to implement custom logic to choose a serializer.
[中]返回类的最佳匹配序列化程序。可以重写此方法以实现自定义逻辑来选择序列化程序。

代码示例

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

@Override
  public Serializer getDefaultSerializer(Class type) {
    if (_override) {
      return new SerializableSerializer();
    } else {
      return super.getDefaultSerializer(type);
    }
  }
}

代码示例来源:origin: alibaba/jstorm

@Override
  public Serializer getDefaultSerializer(Class type) {
    if (_override) {
      return new SerializableSerializer();
    } else {
      return super.getDefaultSerializer(type);
    }
  }
}

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Serializer getDefaultSerializer(Class type) {
    if (type == null) {
      throw new IllegalArgumentException("type cannot be null.");
    }

    /**
     * Kryo requires every class to provide a zero argument constructor. For any class does not match this condition, kryo have two ways:
     * 1. Use JavaSerializer,
     * 2. Set 'kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));', StdInstantiatorStrategy can generate an instance bypassing the constructor.
     *
     * In practice, it's not possible for Dubbo users to register kryo Serializer for every customized class. So in most cases, customized classes with/without zero argument constructor will
     * default to the default serializer.
     * It is the responsibility of kryo to handle with every standard jdk classes, so we will just escape these classes.
     */
    if (!ReflectionUtils.isJdk(type) && !type.isArray() && !type.isEnum() && !ReflectionUtils.checkZeroArgConstructor(type)) {
      if (logger.isWarnEnabled()) {
        logger.warn(type + " has no zero-arg constructor and this will affect the serialization performance");
      }
      return new JavaSerializer();
    }
    return super.getDefaultSerializer(type);
  }
}

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Serializer getDefaultSerializer(Class type) {
    if (type == null) {
      throw new IllegalArgumentException("type cannot be null.");
    }

    /**
     * Kryo requires every class to provide a zero argument constructor. For any class does not match this condition, kryo have two ways:
     * 1. Use JavaSerializer,
     * 2. Set 'kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));', StdInstantiatorStrategy can generate an instance bypassing the constructor.
     *
     * In practice, it's not possible for Dubbo users to register kryo Serializer for every customized class. So in most cases, customized classes with/without zero argument constructor will
     * default to the default serializer.
     * It is the responsibility of kryo to handle with every standard jdk classes, so we will just escape these classes.
     */
    if (!ReflectionUtils.isJdk(type) && !type.isArray() && !type.isEnum() && !ReflectionUtils.checkZeroArgConstructor(type)) {
      if (logger.isWarnEnabled()) {
        logger.warn(type + " has no zero-arg constructor and this will affect the serialization performance");
      }
      return new JavaSerializer();
    }
    return super.getDefaultSerializer(type);
  }
}

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

@Override
@SuppressWarnings( { "rawtypes" } )
public Serializer<?> getDefaultSerializer(final Class clazz) {
  final Serializer<?> customSerializer = loadCustomSerializer( clazz, serializerFactories );
  if ( customSerializer != null ) {
    return customSerializer;
  }
  if ( copyCollectionsForSerialization ) {
    // could also be installed via addDefaultSerializer
    final Serializer<?> copyCollectionSerializer = loadCopyCollectionSerializer( clazz );
    if ( copyCollectionSerializer != null ) {
      return copyCollectionSerializer;
    }
  }
  return super.getDefaultSerializer( clazz );
}

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

kryo.register(pair.getValue0(), new UnshadedSerializerAdapter(((ShadedSerializerAdapter) pair.getValue1()).getSerializerShim()));
else
  kryo.register(pair.getValue0(), kryo.getDefaultSerializer(pair.getValue0()));

代码示例来源:origin: org.apache.storm/storm-core

@Override
  public Serializer getDefaultSerializer(Class type) {
    if(_override) {
      return new SerializableSerializer();
    } else {
      return super.getDefaultSerializer(type);
    }
  }        
}

代码示例来源:origin: com.twitter.heron/heron-storm

@Override
 @SuppressWarnings("rawtypes") // superclass doesn't use types
 public Serializer getDefaultSerializer(Class type) {
  if (override) {
   return new SerializableSerializer();
  } else {
   return super.getDefaultSerializer(type);
  }
 }
}

代码示例来源:origin: com.n3twork.storm/storm-core

@Override
  public Serializer getDefaultSerializer(Class type) {
    if(_override) {
      return new SerializableSerializer();
    } else {
      return super.getDefaultSerializer(type);
    }
  }        
}

代码示例来源:origin: lmco/streamflow

@Override
  public Serializer getDefaultSerializer(Class type) {
    if (override) {
      return new SerializableSerializer();
    } else {
      return super.getDefaultSerializer(type);
    }
  }
}

代码示例来源:origin: org.apache.apex/apex-engine

public void registerExplicit(ClassIdPair pair) throws ClassNotFoundException
{
 //logger.debug("registering class {} => {}", pair.classname, pair.id);
 //pairs.add(pair);
 Class type = Class.forName(pair.classname, false, Thread.currentThread().getContextClassLoader());
 register(new Registration(type, kryo.getDefaultSerializer(type), pair.id));
 if (nextAvailableRegistrationId <= pair.id) {
  nextAvailableRegistrationId = pair.id + 1;
 }
}

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

/** Registers the class using the lowest, next available integer ID and the {@link Kryo#getDefaultSerializer(Class) default
 * serializer}. If the class is already registered, no change will be made and the existing registration will be returned.
 * Registering a primitive also affects the corresponding primitive wrapper.
 * <p>
 * Because the ID assigned is affected by the IDs registered before it, the order classes are registered is important when
 * using this method. The order must be the same at deserialization as it was for serialization. */
public Registration register (Class type) {
  Registration registration = classResolver.getRegistration(type);
  if (registration != null) return registration;
  return register(type, getDefaultSerializer(type));
}

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

/** Registers the class using the specified ID and the {@link Kryo#getDefaultSerializer(Class) default serializer}. If the
 * class is already registered this has no effect and the existing registration is returned. Registering a primitive also
 * affects the corresponding primitive wrapper.
 * <p>
 * IDs must be the same at deserialization as they were for serialization.
 * @param id Must be >= 0. Smaller IDs are serialized more efficiently. IDs 0-8 are used by default for primitive types and
 *           String, but these IDs can be repurposed. */
public Registration register (Class type, int id) {
  Registration registration = classResolver.getRegistration(type);
  if (registration != null) return registration;
  return register(type, getDefaultSerializer(type), id);
}

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

/** Registers the class using the specified ID and the {@link Kryo#getDefaultSerializer(Class) default serializer}. If the ID is
 * already in use by the same type, the old entry is overwritten. If the ID is already in use by a different type, a
 * {@link KryoException} is thrown. Registering a primitive also affects the corresponding primitive wrapper.
 * <p>
 * IDs must be the same at deserialization as they were for serialization.
 * @param id Must be >= 0. Smaller IDs are serialized more efficiently. IDs 0-8 are used by default for primitive types and
 *           String, but these IDs can be repurposed. */
public Registration register (Class type, int id) {
  Registration registration = classResolver.getRegistration(type);
  if (registration != null) return registration;
  return register(type, getDefaultSerializer(type), id);
}

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

/** Registers the class using the lowest, next available integer ID and the {@link Kryo#getDefaultSerializer(Class) default
 * serializer}. If the class is already registered, the existing entry is updated with the new serializer. Registering a
 * primitive also affects the corresponding primitive wrapper.
 * <p>
 * Because the ID assigned is affected by the IDs registered before it, the order classes are registered is important when
 * using this method. The order must be the same at deserialization as it was for serialization. */
public Registration register (Class type) {
  Registration registration = classResolver.getRegistration(type);
  if (registration != null) return registration;
  return register(type, getDefaultSerializer(type));
}

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

/** Registers the class using the specified ID and the {@link Kryo#getDefaultSerializer(Class) default serializer}. If the
 * class is already registered this has no effect and the existing registration is returned. Registering a primitive also
 * affects the corresponding primitive wrapper.
 * <p>
 * IDs must be the same at deserialization as they were for serialization.
 * @param id Must be >= 0. Smaller IDs are serialized more efficiently. IDs 0-8 are used by default for primitive types and
 *           String, but these IDs can be repurposed. */
public Registration register (Class type, int id) {
  Registration registration = classResolver.getRegistration(type);
  if (registration != null) return registration;
  return register(type, getDefaultSerializer(type), id);
}

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

/** Registers the class using the lowest, next available integer ID and the {@link Kryo#getDefaultSerializer(Class) default
 * serializer}. If the class is already registered, no change will be made and the existing registration will be returned.
 * Registering a primitive also affects the corresponding primitive wrapper.
 * <p>
 * Because the ID assigned is affected by the IDs registered before it, the order classes are registered is important when
 * using this method. The order must be the same at deserialization as it was for serialization. */
public Registration register (Class type) {
  Registration registration = classResolver.getRegistration(type);
  if (registration != null) return registration;
  return register(type, getDefaultSerializer(type));
}

代码示例来源:origin: org.apache.apex/apex-engine

@Override
@SuppressWarnings("rawtypes")
public Registration registerImplicit(Class type)
{
 while (getRegistration(nextAvailableRegistrationId) != null) {
  nextAvailableRegistrationId++;
 }
 //logger.debug("adding new classid pair {} => {}", nextAvailableRegistrationId, type.getName());
 pairs.add(new ClassIdPair(nextAvailableRegistrationId, type.getName()));
 return register(new Registration(type, kryo.getDefaultSerializer(type), nextAvailableRegistrationId++));
}

代码示例来源:origin: de.javakaffee/kryo-serializers

@Override
public Serializer<?> getDefaultSerializer(@SuppressWarnings("rawtypes") final Class type) {
  final Serializer<?> result = super.getDefaultSerializer(type);
  if(result instanceof FieldSerializer && ((FieldSerializer<?>) result).getFieldSerializerConfig().getIgnoreSyntheticFields()) {
    // don't ignore synthetic fields so that inner classes work (see KryoTest.testInnerClass)
    FieldSerializer<?> fieldSerializer = (FieldSerializer<?>) result;
    fieldSerializer.getFieldSerializerConfig().setIgnoreSyntheticFields(false);
    fieldSerializer.updateFields();
  }
  return result;
}

代码示例来源:origin: magro/kryo-serializers

@Override
public Serializer<?> getDefaultSerializer(@SuppressWarnings("rawtypes") final Class type) {
  final Serializer<?> result = super.getDefaultSerializer(type);
  if(result instanceof FieldSerializer && ((FieldSerializer<?>) result).getFieldSerializerConfig().getIgnoreSyntheticFields()) {
    // don't ignore synthetic fields so that inner classes work (see KryoTest.testInnerClass)
    FieldSerializer<?> fieldSerializer = (FieldSerializer<?>) result;
    fieldSerializer.getFieldSerializerConfig().setIgnoreSyntheticFields(false);
    fieldSerializer.updateFields();
  }
  return result;
}

相关文章