Change the condition for what is stored in AMQP object history for object reference logic ()

This commit is contained in:
Rick Parker 2017-09-04 11:23:13 +01:00 committed by GitHub
parent 7ec5bd789e
commit f0b2b0a566
3 changed files with 8 additions and 4 deletions
node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp

@ -142,7 +142,7 @@ class DeserializationInput(internal val serializerFactory: SerializerFactory) {
}
// Store the reference in case we need it later on.
// Skip for primitive types as they are too small and overhead of referencing them will be much higher than their content
if (suitableForObjectReference(type)) objectHistory.add(objectRead)
if (suitableForObjectReference(objectRead.javaClass)) objectHistory.add(objectRead)
objectRead
}

@ -1,5 +1,6 @@
package net.corda.nodeapi.internal.serialization.amqp
import com.google.common.primitives.Primitives
import com.google.common.reflect.TypeToken
import org.apache.qpid.proton.codec.Data
import java.beans.IndexedPropertyDescriptor
@ -221,5 +222,8 @@ internal fun Type.isSubClassOf(type: Type): Boolean {
return TypeToken.of(this).isSubtypeOf(type)
}
internal fun suitableForObjectReference(type: Type) =
type != ByteArray::class.java && type.asClass()?.isPrimitive != true
// ByteArrays, primtives and boxed primitives are not stored in the object history
internal fun suitableForObjectReference(type: Type): Boolean {
val clazz = type.asClass()
return type != ByteArray::class.java && (clazz != null && !clazz.isPrimitive && !Primitives.unwrap(clazz).isPrimitive)
}

@ -87,7 +87,7 @@ open class SerializationOutput(internal val serializerFactory: SerializerFactory
// Important to do it after serialization such that dependent object will have preceding reference numbers
// assigned to them first as they will be first read from the stream on receiving end.
// Skip for primitive types as they are too small and overhead of referencing them will be much higher than their content
if (suitableForObjectReference(type)) objectHistory.put(obj, objectHistory.size)
if (suitableForObjectReference(obj.javaClass)) objectHistory.put(obj, objectHistory.size)
}
else {
data.writeReferencedObject(ReferencedObject(retrievedRefCount))