@Override public void write(Kryo kryo, Output output, ListDelegate object) { _serializer.write(kryo, output, object); }
@Override public ListDelegate read(Kryo kryo, Input input, Class<ListDelegate> type) { return (ListDelegate) _serializer.read(kryo, input, type); }
private static void removeField(Kryo kryo, Class type, String fieldName) { FieldSerializer fld = new FieldSerializer(kryo, type); fld.removeField(fieldName); kryo.register(type, fld); }
kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer()); kryo.register(InvocationHandler.class, new JdkProxySerializer()); kryo.register(BigDecimal.class, new DefaultSerializers.BigDecimalSerializer()); kryo.register(BigInteger.class, new DefaultSerializers.BigIntegerSerializer()); kryo.register(Pattern.class, new RegexSerializer()); kryo.register(BitSet.class, new BitSetSerializer());
@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); } }
k.register(HashMap.class, new HashMapSerializer()); k.register(HashSet.class, new HashSetSerializer()); k.register(BigInteger.class, new BigIntegerSerializer()); k.register(TransactionAttempt.class); k.register(Values.class);
public InvokeMethodResult read (Kryo kryo, Input input, Class<InvokeMethodResult> type) { InvokeMethodResult result = super.read(kryo, input, type); result.objectID = input.readInt(true); return result; } };
public void registerClasses(Kryo kryo) { kryo.register(AvgCount.class, new FieldSerializer(kryo, AvgCount.class)); } }
resultSerializer.removeField("objectID"); kryo.register(InvokeMethodResult.class, resultSerializer);
public void write (Kryo kryo, Output output, InvokeMethodResult result) { super.write(kryo, output, result); output.writeInt(result.objectID, true); }
@Override public void write(Kryo kryo, Output output, Map map) { super.write(kryo, output, map); CopyOnFirstWriteProperties p = (CopyOnFirstWriteProperties) map; Properties ip = p.getInterned(); kryo.writeObjectOrNull(output, ip, Properties.class); }
public BlowfishTupleSerializer(Kryo kryo, Map storm_conf) { String encryption_key = null; try { encryption_key = (String) storm_conf.get(SECRET_KEY); LOG.debug("Blowfish serializer being constructed ..."); if (encryption_key == null) { throw new RuntimeException("Blowfish encryption key not specified"); } byte[] bytes = Hex.decodeHex(encryption_key.toCharArray()); _serializer = new BlowfishSerializer(new ListDelegateSerializer(), bytes); } catch (org.apache.commons.codec.DecoderException ex) { throw new RuntimeException("Blowfish encryption key invalid", ex); } }
@Override public Map read(Kryo kryo, Input input, Class<Map> type) { Map map = super.read(kryo, input, type); Properties ip = kryo.readObjectOrNull(input, Properties.class); ((CopyOnFirstWriteProperties) map).setInterned(ip); return map; } }
kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer()); kryo.register(InvocationHandler.class, new JdkProxySerializer()); kryo.register(BigDecimal.class, new DefaultSerializers.BigDecimalSerializer()); kryo.register(BigInteger.class, new DefaultSerializers.BigIntegerSerializer()); kryo.register(Pattern.class, new RegexSerializer()); kryo.register(BitSet.class, new BitSetSerializer());
@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); } }
k.register(HashMap.class, new HashMapSerializer()); k.register(HashSet.class, new HashSetSerializer()); k.register(BigInteger.class, new BigIntegerSerializer()); k.register(TransactionAttempt.class); k.register(Values.class);
@Override public MapWork read(Kryo kryo, Input input, Class<MapWork> type) { MapWork mapWork = super.read(kryo, input, type); // The set methods in MapWork intern the any duplicate strings which is why we call them // during de-serialization mapWork.setPathToPartitionInfo(mapWork.getPathToPartitionInfo()); mapWork.setPathToAliases(mapWork.getPathToAliases()); return mapWork; } }
public BlowfishTupleSerializer(Kryo kryo, Map<String, Object> topoConf) { String encryptionkey; try { encryptionkey = (String) topoConf.get(SECRET_KEY); LOG.debug("Blowfish serializer being constructed ..."); byte[] bytes; if (encryptionkey != null) { bytes = Hex.decodeHex(encryptionkey.toCharArray()); } else { // try to use zookeeper secret String payload = (String) topoConf.get(Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_PAYLOAD); if (payload != null) { LOG.debug("{} is not present. Use {} as Blowfish encryption key", SECRET_KEY, Config.STORM_ZOOKEEPER_TOPOLOGY_AUTH_PAYLOAD); bytes = payload.getBytes(); } else { throw new RuntimeException("Blowfish encryption key not specified"); } } serializer = new BlowfishSerializer(new ListDelegateSerializer(), bytes); } catch (DecoderException ex) { throw new RuntimeException("Blowfish encryption key invalid", ex); } }
kryo.register(BitSet.class, new JavaSerializer());
@Override public PartitionDesc read(Kryo kryo, Input input, Class<PartitionDesc> type) { PartitionDesc partitionDesc = super.read(kryo, input, type); // The set methods in PartitionDesc intern the any duplicate strings which is why we call them // during de-serialization partitionDesc.setBaseFileName(partitionDesc.getBaseFileName()); partitionDesc.setPartSpec(partitionDesc.getPartSpec()); partitionDesc.setInputFileFormatClass(partitionDesc.getInputFileFormatClass()); partitionDesc.setOutputFileFormatClass(partitionDesc.getOutputFileFormatClass()); return partitionDesc; } }