Unmarshaller getUnmarshaller() throws IOException { //as opposing to getMarshaller(int), in this case we don't have a good hint about initial buffer sizing if (availableUnMarshallerIndex == PER_THREAD_REUSABLE_INSTANCES) { //we're above the pool threshold: make a throw-away-after usage Marshaller configuration.setBufferSize(512);//reset to default as it might be changed by getMarshaller return factory.createUnmarshaller(configuration); } else { ExtendedRiverUnmarshaller unMarshaller = reusableUnMarshaller[availableUnMarshallerIndex]; if (unMarshaller != null) { availableUnMarshallerIndex++; return unMarshaller; } else { configuration.setBufferSize(RIVER_INTERNAL_BUFFER);//reset to default as it might be changed by getMarshaller unMarshaller = factory.createUnmarshaller(configuration); unMarshaller.setCloseListener(this); reusableUnMarshaller[availableUnMarshallerIndex] = unMarshaller; availableUnMarshallerIndex++; return unMarshaller; } } }
ExtendedRiverMarshaller getMarshaller(int estimatedSize) throws IOException { if (availableMarshallerIndex == PER_THREAD_REUSABLE_INSTANCES) { //we're above the pool threshold: make a throw-away-after usage Marshaller //setting the buffer as cheap as possible: configuration.setBufferSize(estimatedSize); return factory.createMarshaller(configuration); } else { ExtendedRiverMarshaller marshaller = reusableMarshaller[availableMarshallerIndex]; if (marshaller != null) { availableMarshallerIndex++; return marshaller; } else { //we're going to pool this one, make sure the buffer size is set to a reasonable value //as we might have changed it previously: configuration.setBufferSize(RIVER_INTERNAL_BUFFER); marshaller = factory.createMarshaller(configuration); marshaller.setCloseListener(this); reusableMarshaller[availableMarshallerIndex] = marshaller; availableMarshallerIndex++; return marshaller; } } }
@Override public MarshallingConfiguration getMarshallingConfiguration(int version) { MarshallingConfiguration config = this.passivationManager.getMarshallingConfiguration(version); MarshallingConfiguration result = new MarshallingConfiguration(); result.setBufferSize(config.getBufferSize()); result.setClassCount(config.getClassCount()); result.setClassExternalizerFactory(config.getClassExternalizerFactory()); result.setClassResolver(config.getClassResolver()); result.setClassTable(config.getClassTable()); result.setExceptionListener(config.getExceptionListener()); result.setExternalizerCreator(config.getExternalizerCreator()); result.setInstanceCount(config.getInstanceCount()); result.setObjectResolver(config.getObjectResolver()); result.setObjectTable(config.getObjectTable()); result.setSerializabilityChecker(this.serializabilityChecker); result.setSerializedCreator(config.getSerializedCreator()); result.setStreamHeader(config.getStreamHeader()); result.setVersion(config.getVersion()); return result; }