@Override public boolean equals(Object object) { if (object instanceof HashableMarshalledValue) { HashableMarshalledValue<?> value = (HashableMarshalledValue<?>) object; // Testing hashCode equivalence is just an optimization if (this.hashCode != value.hashCode) return false; } return super.equals(object); }
@Override public <T> SimpleMarshalledValue<T> createMarshalledValue(T object) { return new HashableMarshalledValue<>(object, this.context); } }
@Override public SimpleMarshallingContext createMarshallingContext(MarshallingConfigurationRepository repository, ClassLoader loader) { return new SimpleMarshallingContext(this.factory, repository, loader); } }
@Override public MarshallingContext getMarshallingContext() { return new SimpleMarshallingContextFactory().createMarshallingContext(new SimpleMarshallingConfigurationRepository(MarshallingVersion.class, MarshallingVersion.CURRENT, this), this.getModule().getClassLoader()); }
public HotRodMarshaller(Module module) { super(); super.baseCfg.setClassResolver(ModularClassResolver.getInstance(module.getModuleLoader())); super.baseCfg.setClassTable(new DynamicClassTable(module.getClassLoader())); super.baseCfg.setObjectTable(new ExternalizerObjectTable(module.getClassLoader())); } }
@Override public MarshallingConfigurationRepository get() { return new SimpleMarshallingConfigurationRepository(MarshallingVersion.class, MarshallingVersion.CURRENT, this); }
CommandResponseMarshaller(ChannelCommandDispatcherFactoryConfiguration config) { this.context = config.getMarshallingContext(); this.factory = config.getChannelFactory(); this.versionSerializer = IndexSerializer.select(this.context.getCurrentVersion()); }
@Override public HashableMarshalledValue<T> readObject(ObjectInput input) throws IOException, ClassNotFoundException { SimpleMarshalledValue<T> value = this.externalizer.readObject(input); int hashCode = input.readInt(); return new HashableMarshalledValue<>(value.getBytes(), hashCode); }
@Override public <T> SimpleMarshalledValue<T> createMarshalledValue(T object) { return new SimpleMarshalledValue<>(object, this.context); } }
@Override public int getCurrentVersion() { return this.repository.getCurrentMarshallingVersion(); }
public ExternalizerObjectTable(ClassLoader loader) { this(loadExternalizers(loader)); }
private MarshallingConfiguration getMarshallingConfiguration(int version) { return this.repository.getMarshallingConfiguration(version); }
public SimpleMarshalledValueFactory(MarshallingContextFactory factory, MarshallingConfigurationRepository repository, ClassLoader loader) { this(factory.createMarshallingContext(repository, loader)); }
public DynamicClassTable(ClassLoader loader) { super(findClasses(loader)); }
/** * Create a marshalling configuration repository using the specified enumeration of marshalling configuration suppliers. * @param enumClass an enum class * @param current the supplier of the current marshalling configuration * @param context the context with which to obtain the marshalling configuration */ public <C, E extends Enum<E> & Function<C, MarshallingConfiguration>> SimpleMarshallingConfigurationRepository(Class<E> enumClass, E current, C context) { this(current.ordinal() + 1, createConfigurations(enumClass, context)); }
@Override public Writer getClassWriter(Class<?> targetClass) { Integer index = this.indexes.get(targetClass); return (index != null) ? new ClassTableWriter(index, this.indexSerializer) : null; }
private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); byte[] bytes = this.getBytes(); if (bytes != null) { out.writeInt(bytes.length); out.write(bytes); } else { out.writeInt(0); } }
@Override public Unmarshaller createUnmarshaller(int version) throws IOException { return this.factory.createUnmarshaller(this.getMarshallingConfiguration(version)); }
@Override public MarshallingConfiguration apply(MarshallingConfigurationContext context) { MarshallingConfiguration config = new MarshallingConfiguration(); config.setClassResolver(ModularClassResolver.getInstance(context.getModuleLoader())); config.setClassTable(new DynamicClassTable(context.getModule().getClassLoader())); config.setObjectTable(new ExternalizerObjectTable(context.getModule().getClassLoader())); return config; } },
@Override public SimpleMarshalledValue<T> readObject(ObjectInput input) throws IOException { int size = IndexSerializer.VARIABLE.readInt(input); byte[] bytes = (size > 0) ? new byte[size] : null; if (bytes != null) { input.readFully(bytes); } return new SimpleMarshalledValue<>(bytes); }