private static void removeField(Kryo kryo, Class type, String fieldName) { FieldSerializer fld = new FieldSerializer(kryo, type); fld.removeField(fieldName); kryo.register(type, fld); }
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 write (Kryo kryo, Output output, InvokeMethodResult result) { super.write(kryo, output, result); output.writeInt(result.objectID, true); }
@Override public Serializer newDefaultSerializer( final Kryo kryo, final Class<?> type ) { final FieldSerializer result = new FieldSerializer( kryo, type ); result.setIgnoreSyntheticFields( false ); return result; }
public static Kryo createKryo() { kryo = new Kryo(); FieldSerializer<MeasurePointData> someClassSerializer = new FieldSerializer<MeasurePointData>(kryo, MeasurePointData.class); someClassSerializer.getField("measurePointId").setSerializer(new MeasurePointIdSerializer()); kryo.register(MeasurePointData.class, someClassSerializer); return kryo; }
public void registerClasses(Kryo kryo) { kryo.register(AvgCount.class, new FieldSerializer(kryo, AvgCount.class)); } }
@Override public void customize(Kryo kryo) { kryo.setReferences(true); kryo.register( GrailsFlashScope.class, new FieldSerializer( kryo, GrailsFlashScope.class ) ); }
kryo.register(Object[].class); kryo.register(InvokeMethod.class); resultSerializer.removeField("objectID"); kryo.register(InvokeMethodResult.class, resultSerializer); kryo.register(InvocationHandler.class, new Serializer() {
kryo.register(AtomicLong.class, new FieldSerializer<AtomicLong>(kryo, AtomicLong.class)); kryo.register(MutableInt.class, new FieldSerializer<MutableInt>(kryo, MutableInt.class)); kryo.register(RemoteInvocation.class, new FieldSerializer<RemoteInvocation>(kryo, RemoteInvocation.class)); kryo.register(RemoteInvocationResult.class, new FieldSerializer<RemoteInvocationResult>(kryo, RemoteInvocationResult.class) { @Override protected RemoteInvocationResult create(Kryo kryo, Input input, Class<RemoteInvocationResult> type) { kryo.register(CmrStatusData.class, new FieldSerializer<CmrStatusData>(kryo, CmrStatusData.class)); kryo.register(AgentStatusData.class, new FieldSerializer<AgentStatusData>(kryo, AgentStatusData.class)); kryo.register(BusinessException.class, new FieldSerializer<BusinessException>(kryo, BusinessException.class), nextRegistrationId++); kryo.register(TechnicalException.class, new FieldSerializer<TechnicalException>(kryo, TechnicalException.class), nextRegistrationId++); kryo.register(RemoteException.class, new FieldSerializer<RemoteException>(kryo, RemoteException.class), nextRegistrationId++); kryo.register(InvocationTargetException.class, new FieldSerializer<InvocationTargetException>(kryo, InvocationTargetException.class) { @Override protected InvocationTargetException create(Kryo kryo, Input input, Class<InvocationTargetException> type) { kryo.register(AgentConfig.class, new FieldSerializer<AgentConfig>(kryo, AgentConfig.class), nextRegistrationId++); kryo.register(StrategyConfig.class, new FieldSerializer<StrategyConfig>(kryo, StrategyConfig.class), nextRegistrationId++); kryo.register(PlatformSensorTypeConfig.class, new FieldSerializer<PlatformSensorTypeConfig>(kryo, PlatformSensorTypeConfig.class), nextRegistrationId++); kryo.register(MethodSensorTypeConfig.class, new FieldSerializer<MethodSensorTypeConfig>(kryo, MethodSensorTypeConfig.class), nextRegistrationId++); kryo.register(ExceptionSensorTypeConfig.class, new FieldSerializer<ExceptionSensorTypeConfig>(kryo, ExceptionSensorTypeConfig.class), nextRegistrationId++); kryo.register(PropertyPath.class, new FieldSerializer<PropertyPath>(kryo, PropertyPath.class), nextRegistrationId++); kryo.register(PropertyPathStart.class, new FieldSerializer<PropertyPathStart>(kryo, PropertyPathStart.class), nextRegistrationId++); kryo.register(InstrumentationDefinition.class, new FieldSerializer<InstrumentationDefinition>(kryo, InstrumentationDefinition.class), nextRegistrationId++); kryo.register(MethodInstrumentationConfig.class, new FieldSerializer<MethodInstrumentationConfig>(kryo, MethodInstrumentationConfig.class), nextRegistrationId++);
@Override public T read(final Kryo kryo, final Input input, final Class<T> type) { final boolean isKnown = kryo.readObject(input, Boolean.class); if (isKnown) { final Integer ordinal = kryo.readObject(input, Integer.class); final SqlOperator operator = OperatorPopulator.BACKWARD.get(ordinal); if (operator != null) { kryo.reference(operator); return (T)operator; } throw new IllegalStateException(String.format("Unable to locate operator with ordinal [%s]", ordinal)); } return super.read(kryo, input, type); }
@Override public void write(final Kryo kryo, final Output output, final T operator) { final int identity = System.identityHashCode(operator); final Integer ordinal = OperatorPopulator.FORWARD.get(identity); final boolean isKnown = ordinal != null; kryo.writeObject(output, isKnown); if (isKnown) { kryo.writeObject(output, ordinal); return; } super.write(kryo, output, operator); }
if (TRACE && generics != null) trace("kryo", "Generic type parameters: " + Arrays.toString(generics)); if (type.isInterface()) { fields = new CachedField[0]; // No fields to serialize. if (genericsScope != null) kryo.getGenericsResolver().pushScope(type, genericsScope); ObjectMap context = kryo.getContext(); validFields = buildValidFields(false, allFields, context, useAsm); validTransientFields = buildValidFields(true, allFields, context, useAsm); validFields = buildValidFieldsFromCachedFields(fields, useAsm); validTransientFields = buildValidFieldsFromCachedFields(transientFields, useAsm); createCachedFields(useAsm, validFields, cachedFields, 0); createCachedFields(useAsm, validTransientFields, cachedTransientFields, validFields.size()); transientFields = cachedTransientFields.toArray(new CachedField[cachedTransientFields.size()]); initializeCachedFields(); if (genericsScope != null) kryo.getGenericsResolver().popScope(); removeField(field);
/** Sets the default value for {@link CachedField#setCanBeNull(boolean)}. Calling this method resets the {@link #getFields() * cached fields}. * @param fieldsCanBeNull False if none of the fields are null. Saves 0-1 byte per field. True if it is not known (default). */ public void setFieldsCanBeNull (boolean fieldsCanBeNull) { this.fieldsCanBeNull = fieldsCanBeNull; if (TRACE) trace("kryo", "setFieldsCanBeNull: " + fieldsCanBeNull); rebuildCachedFields(); }
private void removeFields() { final CachedField[] cachedFields = getFields(); for (final CachedField cachedField : cachedFields) { final Field field = cachedField.getField(); if (isRemove(field)) { if (TRACE) { trace("kryo", String.format("Ignoring field %s tag: %s", disregarding ? "without" : "with", cachedField)); } super.removeField(field.getName()); } } }
@Override @SuppressWarnings("CallToPrintStackTrace") public Fiber read(Kryo kryo, Input input, Class<Fiber> type) { final Fiber f; final Thread currentThread = Thread.currentThread(); final Object tmpThreadLocals = ThreadAccess.getThreadLocals(currentThread); final Object tmpInheritableThreadLocals = ThreadAccess.getInheritableThreadLocals(currentThread); ThreadAccess.setThreadLocals(currentThread, null); ThreadAccess.setInheritableThreadLocals(currentThread, null); try { final Registration reg = kryo.readClass(input); if (reg == null) return null; f = (Fiber) new FieldSerializer(kryo, reg.getType()).read(kryo, input, reg.getType()); if (!f.noLocals) { f.fiberLocals = ThreadAccess.getThreadLocals(currentThread); f.inheritableFiberLocals = ThreadAccess.getInheritableThreadLocals(currentThread); } return f; } catch (Throwable t) { t.printStackTrace(); throw t; } finally { ThreadAccess.setThreadLocals(currentThread, tmpThreadLocals); ThreadAccess.setInheritableThreadLocals(currentThread, tmpInheritableThreadLocals); } } }
if (TRACE && generics != null) trace("kryo", "Generic type parameters: " + Arrays.toString(generics)); if (type.isInterface()) { fields = new CachedField[0]; // No fields to serialize. if (genericsScope != null) kryo.pushGenericsScope(type, genericsScope); ObjectMap context = kryo.getContext(); validFields = buildValidFields(false, allFields, context, useAsm); validTransientFields = buildValidFields(true, allFields, context, useAsm); validFields = buildValidFieldsFromCachedFields(fields, useAsm); validTransientFields = buildValidFieldsFromCachedFields(transientFields, useAsm); createCachedFields(useAsm, validFields, cachedFields, 0); createCachedFields(useAsm, validTransientFields, cachedTransientFields, validFields.size()); transientFields = cachedTransientFields.toArray(new CachedField[cachedTransientFields.size()]); initializeCachedFields(); if (genericsScope != null) kryo.popGenericsScope(); removeField(field);
try { f.stack.resumeStack(); kryo.writeClass(output, f.getClass()); new FieldSerializer(kryo, f.getClass()).write(kryo, output, f); } finally { f.fiberLocals = tmpFiberLocals; f.stack.resumeStack(); kryo.writeClass(output, f.getClass()); new FieldSerializer(kryo, f.getClass()).write(kryo, output, f); } catch (Throwable t) { t.printStackTrace();
@Override public T read(final Kryo kryo, final Input input, final Class<T> type) { // do not use delegate.read because we do not want it to cache the object. Rather, we will cache the normalized type. final T dataType = kryo.newInstance(type); final FieldSerializer.CachedField[] fields = delegate.getFields(); for (int i = 0, n = fields.length; i < n; i++) { fields[i].read(input, dataType); } // be gentle to calcite and normalize the returned data type. normalization here means to use same type instances. final T result = (T) typeFactory.copyType(dataType); kryo.reference(result); return result; }
public T read (Kryo kryo, Input input, Class<T> type) { try { if (typeParameters != null && generics != null) { // Rebuild fields info. It may result in rebuilding the // genericScope rebuildCachedFields(); } if (genericsScope != null) { // Push a new scope for generics kryo.pushGenericsScope(type, genericsScope); } T object = create(kryo, input, type); kryo.reference(object); CachedField[] fields = this.fields; for (int i = 0, n = fields.length; i < n; i++) fields[i].read(input, object); // De-serialize transient fields if (serializeTransient) { for (int i = 0, n = transientFields.length; i < n; i++) transientFields[i].read(input, object); } return object; } finally { if (genericsScope != null && kryo.getGenericsScope() != null) { // Pop the scope for generics kryo.popGenericsScope(); } } }
rebuildCachedFields(); kryo.getGenericsResolver().pushScope(type, genericsScope); T object = create(kryo, input, type); kryo.reference(object); if (config.isOptimizedGenerics() && genericsScope != null && kryo.getGenericsResolver() != null) { kryo.getGenericsResolver().popScope();