T
- default class used when reading serialized objectpublic class CachingSerializator<T> extends MultiClassSerializator<T>
MultiClassSerializator
with
caching. The constructors/factory methods of all the cachedClasses
are cached and thus this serializator is quite fast when deserializing from binary stream.
If the class is not predefined, but supports BinarySerializable
interface,
there will be an additional cost of the class name and constructor/factory method lookup.
This serializator checks the serialUIDs of the cached objects for changes.Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.Class<? extends BinarySerializable>,java.lang.Integer> |
cachedClasses
The hash table of cached classes with references to the constructor/factory method lists
|
protected java.util.List<java.lang.reflect.Constructor<?>> |
cachedConstructors
The list of constructors for the cached classes with the exactly the same order as specified by cachedClasses
|
protected java.util.List<java.lang.reflect.Method> |
cachedFactoryMethods
The list of factory methods for the cached classes with the exactly the same order as specified by cachedClasses
|
protected java.util.Set<java.lang.Class<? extends BinarySerializable>> |
notCachedClasses
List of classes that are not cached but were serialized by this serializator.
|
CLASSNAME_SERIALIZATION, constructor, defaultClass, DEFAULTCLASS_SERIALIZATION, factoryMethod, JAVA_SERIALIZATION
log
Constructor and Description |
---|
CachingSerializator(java.lang.Class<? extends T> defaultClass,
java.lang.Class<?>[] cachedClasses)
Creates a new instance of CachingSerializator.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this serializator.
|
protected int |
getClassIndex(BinarySerializable object)
Returns the index of the predefined class for this object.
|
protected java.lang.reflect.Constructor<?> |
getConstructor(byte flag,
java.lang.Class<?> objectClass)
Returns a constructor for the specified flag and object class.
|
protected java.lang.reflect.Method |
getFactoryMethod(byte flag,
java.lang.Class<?> objectClass)
Returns a factory method for the specified flag and object class.
|
java.util.Collection<java.lang.Class<? extends BinarySerializable>> |
getNotCachedClasses()
Returns the unmodifiable list of classes that are not cached but were serialized
by this serializator.
|
int |
hashCode()
Returns a hash code value for this serializator.
|
getBinarySize, getDefaultClass, readObject, readObjectImpl, write
getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getNativeSerializableConstructor, getNativeSerializableFactoryMethod, getSerialVersionUID, getSerialVersionUIDHash, objectToBuffer, readBigInteger, readBoolean, readBooleanArray, readByte, readByteArray, readDouble, readDoubleArray, readEnum, readFloat, readFloatArray, readFromFile, readChar, readCharArray, readInt, readIntArray, readLong, readLongArray, readObject, readObject, readObjectSize, readShort, readShortArray, readString, readStringArray, skipObject, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, writeToFile
protected final java.util.Map<java.lang.Class<? extends BinarySerializable>,java.lang.Integer> cachedClasses
protected transient java.util.List<java.lang.reflect.Constructor<?>> cachedConstructors
protected transient java.util.List<java.lang.reflect.Method> cachedFactoryMethods
protected transient java.util.Set<java.lang.Class<? extends BinarySerializable>> notCachedClasses
public CachingSerializator(java.lang.Class<? extends T> defaultClass, java.lang.Class<?>[] cachedClasses) throws java.lang.IllegalArgumentException
cachedClasses
are cached.
If any of the items of this the list of predefined classes is replaced or deleted, the deserialization of the older binary stream will fail. Appending the list is safe.
defaultClass
- the default class that is used for deserialization when a class is not specifiedcachedClasses
- the classes that are used frequently and should be cachedjava.lang.IllegalArgumentException
- if there is an invalid value in cachedClasses
protected java.lang.reflect.Constructor<?> getConstructor(byte flag, java.lang.Class<?> objectClass) throws java.lang.IllegalArgumentException
DEFAULTCLASS
serialization,
current constructor is returned. If the stored object implements the
BinarySerializable
interface, its constructor is looked up.
Otherwise, null is returned.getConstructor
in class MultiClassSerializator<T>
flag
- the type of deserialization (see constants)objectClass
- the class that is expected to be in the streamjava.lang.IllegalArgumentException
- if there was a problem getting the constructorprotected java.lang.reflect.Method getFactoryMethod(byte flag, java.lang.Class<?> objectClass) throws java.lang.IllegalArgumentException
DEFAULTCLASS
serialization,
current factory method is returned. If the stored object implements the
BinarySerializable
interface, its factory method is looked up.
Otherwise, null is returned.getFactoryMethod
in class MultiClassSerializator<T>
flag
- the type of deserialization (see constants)objectClass
- the class that is expected to be in the streamjava.lang.IllegalArgumentException
- if there was a problem getting the factory methodprotected int getClassIndex(BinarySerializable object)
getClassIndex
in class MultiClassSerializator<T>
object
- the object whose class is looked uppublic java.util.Collection<java.lang.Class<? extends BinarySerializable>> getNotCachedClasses()
public int hashCode()
hashCode
in class MultiClassSerializator<T>
public boolean equals(java.lang.Object obj)
equals
in class MultiClassSerializator<T>
obj
- the reference object with which to comparetrue
if this serializator is the same as the obj
argument; false
otherwise.