|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmessif.objects.nio.BinarySerializator
messif.objects.nio.MultiClassSerializator<T>
messif.objects.nio.CachingSerializator<T>
T
- default class used when reading serialized objectpublic class CachingSerializator<T>
This class extends the deserializing support of 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.
Field Summary | |
---|---|
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 |
Fields inherited from class messif.objects.nio.MultiClassSerializator |
---|
CLASSNAME_SERIALIZATION, constructor, defaultClass, DEFAULTCLASS_SERIALIZATION, factoryMethod, JAVA_SERIALIZATION |
Fields inherited from class messif.objects.nio.BinarySerializator |
---|
log |
Constructor Summary | |
---|---|
CachingSerializator(java.lang.Class<? extends T> defaultClass,
java.lang.Class... cachedClasses)
Creates a new instance of CachingSerializator. |
Method Summary | |
---|---|
protected int |
addToCache(java.lang.Class<? extends BinarySerializable> classToAdd)
Add the specified class to cache. |
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. |
int |
hashCode()
Returns a hash code value for this serializator. |
Methods inherited from class messif.objects.nio.MultiClassSerializator |
---|
getBinarySize, getDefaultClass, readObject, readObjectImpl, write |
Methods inherited from class messif.objects.nio.BinarySerializator |
---|
getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getNativeSerializableConstructor, getNativeSerializableFactoryMethod, getSerialVersionUID, getSerialVersionUIDHash, readBoolean, readBooleanArray, readByte, readByteArray, readDouble, readDoubleArray, readFloat, readFloatArray, readChar, readCharArray, readInt, readIntArray, readLong, readLongArray, readObject, readObject, readObjectSize, readShort, readShortArray, readString, 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 |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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
Constructor Detail |
---|
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 cached
java.lang.IllegalArgumentException
- if there is an invalid value in cachedClasses
Method Detail |
---|
protected int addToCache(java.lang.Class<? extends BinarySerializable> classToAdd) throws java.lang.IllegalArgumentException
classToAdd
- the class to add
java.lang.IllegalArgumentException
- if the class has invalid constructor/factory method or there is already another class on this positionprotected 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 stream
java.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 stream
java.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 up
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 compare
true
if this serializator is the same as the obj
argument; false
otherwise.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |