|
|||||||||
Atavism Version 2018.1 | AGIS API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectatavism.server.marshalling.MarshallingRuntime
public class MarshallingRuntime
This class keeps a registry of the set of classes to be marshalled, and provides static methods to perform registration, and to marshal and unmarshal builtin types.
Nested Class Summary | |
---|---|
static class |
MarshallingRuntime.ClassNameAndTypeNumber
A utility class containing a fully-elaborated class name, paired with a type number |
static class |
MarshallingRuntime.ClassProperties
A data structure to hold the properties of a class registered for marshalling. |
Field Summary | |
---|---|
protected static short |
builtinStart
|
protected static java.util.HashMap<java.lang.String,MarshallingRuntime.ClassProperties> |
classToClassProperties
This is the mapping from class to properties of the class, including type number, injection status and so on. |
protected static short |
firstAggregateTypeNum
|
protected static short |
firstAtomicTypeNum
|
protected static short |
firstExpansionTypeNum
|
protected static short |
firstGeneratedValueType
|
protected static short |
firstNonPrimitiveAtomicTypeNum
|
protected static short |
firstPrimitiveAtomicTypeNum
|
static boolean |
initialized
A boolean which is true if MarshallingRuntime has been called. |
protected static short |
lastAggregateTypeNum
|
protected static short |
lastAtomicTypeNum
|
protected static short |
lastBuiltinTypeNum
|
protected static short |
lastExpansionTypeNum
|
protected static short |
lastNonPrimitiveAtomicTypeNum
|
protected static short |
lastPrimitiveAtomicTypeNum
|
protected static java.lang.Class[] |
marshallers
The map from typeNum to the classes of the object for which we've generated marshalling code |
protected static short |
nextGeneratedValueType
|
protected static short |
nonStoredStart
|
protected static boolean |
predefinedTypesInstalled
|
protected static short |
registeredBuiltTypeCount
|
protected static short |
typeNumArrayList
|
protected static short |
typeNumBoolean
|
protected static short |
typeNumBooleanFalse
|
protected static short |
typeNumBooleanTrue
|
protected static short |
typeNumByte
|
protected static short |
typeNumByteArray
|
protected static short |
typeNumDouble
|
protected static short |
typeNumFloat
|
protected static short |
typeNumHashMap
|
protected static short |
typeNumHashSet
|
protected static short |
typeNumInteger
|
protected static short |
typeNumJavaSerializable
|
protected static short |
typeNumLinkedHashMap
|
protected static short |
typeNumLinkedHashSet
|
protected static short |
typeNumLinkedList
|
protected static short |
typeNumLong
|
protected static short |
typeNumNull
|
protected static short |
typeNumPrimitiveBoolean
|
protected static short |
typeNumPrimitiveByte
|
protected static short |
typeNumPrimitiveDouble
|
protected static short |
typeNumPrimitiveFloat
|
protected static short |
typeNumPrimitiveInteger
|
protected static short |
typeNumPrimitiveLong
|
protected static short |
typeNumPrimitiveShort
|
protected static short |
typeNumShort
|
protected static short |
typeNumString
|
protected static short |
typeNumTreeMap
|
protected static short |
typeNumTreeSet
|
Constructor Summary | |
---|---|
MarshallingRuntime()
|
Method Summary | |
---|---|
protected static void |
addMarshaller(java.lang.Class c,
java.lang.Short typeNum)
|
static void |
addMarshallingClass(java.lang.String className,
java.lang.Class c)
Records the fact that this marshalling class has marshalling methods. |
protected static void |
addPrimitiveToTypeMap(java.lang.Object object,
java.lang.Short typeNum)
|
static java.lang.Short |
builtinAggregateTypeNum(java.lang.String className)
Returns the typeNum of the class name if it is a built-in type and one of the aggregate types. |
static boolean |
builtinType(java.lang.Short typeNum)
Returns true if the type number represents a built-in type |
static boolean |
builtinType(java.lang.String className)
Returns true if the class name is a built-in type |
protected static int |
byteToIntNoSignExtend(byte b)
|
protected static void |
checkClassPresent(JavaClass referringClass,
JavaClass referredClass,
java.util.Map<JavaClass,java.util.LinkedList<JavaClass>> missingTypes)
|
protected static boolean |
checkTypeReferences()
|
protected static java.lang.Short |
classRequiresInjection(java.lang.String className)
|
static java.util.HashSet<MarshallingRuntime.ClassNameAndTypeNumber> |
getClassesToBeMarshalled()
Returns the set of all the class names and type numbers that are subject to marshalling (including those that already support marshalling) |
protected static java.lang.Class |
getClassForClassName(java.lang.String className)
|
static java.lang.String |
getClassForTypeNum(java.lang.Short typeNum)
Get the class name for a given type number. |
protected static java.lang.String |
getClassNameForObject(java.lang.Object object)
|
static java.lang.String |
getHexString(byte[] raw)
|
protected static short |
getNextGeneratedValueType()
|
protected static java.lang.String |
getSimpleClassName(JavaClass c)
|
protected static java.lang.Short |
getTypeNumForClass(java.lang.Class c)
|
protected static java.lang.Short |
getTypeNumForClassName(java.lang.String className)
|
static java.lang.Short |
getTypeNumForClassOrBarf(java.lang.Class c)
Get the type number associated with a Class object, or log an error if it can't be found |
protected static java.lang.Short |
getTypeNumFromJavaClass(JavaClass c)
|
static boolean |
hasMarshallingProperties(java.lang.String className)
Returns true if the className is a class that marshalling knows about |
protected static boolean |
hasNoArgConstructor(JavaClass c)
Any marshalled object must have a public no-args constructor |
static boolean |
initialize(java.lang.String[] argv)
The main MarshallingRuntime entrypoint called by Trampoline to byte-code inject all classes before calling the server process's main class. |
static void |
initializeBatch(java.lang.String typeNumFileName)
|
static void |
injectAllClasses(java.lang.String outputDir,
java.lang.String typeNumFileName)
Perform byte code injection of marshalling code for all registered classes |
static boolean |
injectedClass(java.lang.String className)
Returns true if the className is a class that requires that marshalling be generated. |
static void |
installPredefinedTypes()
A utility method, called by MarshallingRuntime.initialize(), which registers all built-in types |
protected static JavaClass |
javaClassOrNull(java.lang.String className)
|
static void |
markInjected(java.lang.String className)
Mark this class with the given name as having had byte-code injection performed |
static void |
marshalArrayList(AOByteBuffer buf,
java.lang.Object object)
The built-in marshalling code for an ArrayList object, which marshals it into the byte buffer argument. |
static void |
marshalByteArray(AOByteBuffer buf,
java.lang.Object object)
The built-in marshalling code for a byte array object, which marshals it into the byte buffer argument. |
static void |
marshalHashMap(AOByteBuffer buf,
java.lang.Object object)
The built-in marshalling code for a HashMap object, which marshals it into the byte buffer argument. |
static void |
marshalHashSet(AOByteBuffer buf,
java.lang.Object object)
The built-in marshalling code for a HashSet object, which marshals it into the byte buffer argument. |
protected static boolean |
marshalledTypeNum(java.lang.Short typeNum)
|
static void |
marshalLinkedHashMap(AOByteBuffer buf,
java.lang.Object object)
The built-in marshalling code for a LinkedHashMap object, which marshals it into the byte buffer argument. |
static void |
marshalLinkedHashSet(AOByteBuffer buf,
java.lang.Object object)
The built-in marshalling code for a LinkedHashSet object, which marshals it into the byte buffer argument. |
static void |
marshalLinkedList(AOByteBuffer buf,
java.lang.Object object)
The built-in marshalling code for a linked list, which marshals it into the byte buffer argument. |
static void |
marshalMarshallingObject(AOByteBuffer buf,
java.lang.Object object)
Marshal an object that implements Marshallable, but don't preceed the output with a type number. |
static void |
marshalObject(AOByteBuffer buf,
java.lang.Object object)
This is the top-level method for marshalling an object. |
static void |
marshalSerializable(AOByteBuffer buf,
java.lang.Object object)
The static method that does marshalling via Java serialization. |
static void |
marshalTreeMap(AOByteBuffer buf,
java.lang.Object object)
The built-in marshalling code for a TreeMap object, which marshals it into the byte buffer argument. |
static void |
marshalTreeSet(AOByteBuffer buf,
java.lang.Object object)
The built-in marshalling code for a TreeSet object, which marshals it into the byte buffer argument. |
static byte[] |
maybeInjectMarshalling(java.lang.String className)
This method is called by the class loader to inject marshalling methods in a class. |
protected static void |
processMarshallers(java.lang.String marshallerFile)
|
protected static java.lang.Short |
readTypeNum(AOByteBuffer buf)
|
static java.lang.String |
registeredClassesAndTypes()
Get a String containing a comma-separated sequence of the class names known about by the marshalling runtime. |
static void |
registerMarshallingClass(java.lang.String className)
Registers the class with the given name as a marshalling class, with type number equal to the next available type number. |
static void |
registerMarshallingClass(java.lang.String className,
java.lang.Short typeNum)
Registers the class with the given name as a marshalling class, with type number equal to the specified type number. |
protected static void |
registerMarshallingClasses(java.util.LinkedList<java.lang.String> scripts)
|
protected static void |
throwError(java.lang.String msg)
|
protected static java.lang.String |
translateFieldTypeName(java.lang.String s)
|
static java.lang.Object |
unmarshalArrayList(AOByteBuffer buf)
The built-in unmarshalling code for an ArrayList, which unmarshals it from the byte buffer argument. |
static java.lang.Object |
unmarshalByteArray(AOByteBuffer buf)
The built-in unmarshalling code for a byte array, which unmarshals it from the byte buffer argument. |
static java.lang.Object |
unmarshalHashMap(AOByteBuffer buf)
The built-in unmarshalling code for a HashMap, which unmarshals it from the byte buffer argument. |
static java.lang.Object |
unmarshalHashSet(AOByteBuffer buf)
The built-in unmarshalling code for a HashSet, which unmarshals it from the byte buffer argument. |
static java.lang.Object |
unmarshalLinkedHashMap(AOByteBuffer buf)
The built-in unmarshalling code for a LinkedHashMap, which unmarshals it from the byte buffer argument. |
static java.lang.Object |
unmarshalLinkedHashSet(AOByteBuffer buf)
The built-in unmarshalling code for a LinkedHashSet, which unmarshals it from the byte buffer argument. |
static java.lang.Object |
unmarshalLinkedList(AOByteBuffer buf)
The built-in unmarshalling code for a linked list, which unmarshals it from the byte buffer argument. |
static java.lang.Object |
unmarshalMarshallingObject(AOByteBuffer buf,
java.lang.Object object)
Unmarshal an object, but don't assume that the object is preceeded by a type number. |
static java.lang.Object |
unmarshalObject(AOByteBuffer buf)
This is the top-level method for unmarshalling an object. |
static java.lang.Object |
unmarshalSerializable(AOByteBuffer buf)
The static method that unmarshals an object using Java serialization, getting the bytes from the byte buffer. |
static java.lang.Object |
unmarshalTreeMap(AOByteBuffer buf)
The built-in unmarshalling code for a TreeMap, which unmarshals it from the byte buffer argument. |
static java.lang.Object |
unmarshalTreeSet(AOByteBuffer buf)
The built-in unmarshalling code for a TreeSet, which unmarshals it from the byte buffer argument. |
protected static boolean |
valueTypeNum(java.lang.Short typeNum)
Is this typeNum itself represent a value, with no further data required? |
protected static void |
writeTypeNum(AOByteBuffer buf,
java.lang.Short typeNum)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static java.util.HashMap<java.lang.String,MarshallingRuntime.ClassProperties> classToClassProperties
protected static java.lang.Class[] marshallers
protected static boolean predefinedTypesInstalled
public static boolean initialized
protected static final short nonStoredStart
protected static final short typeNumPrimitiveBoolean
protected static final short firstAtomicTypeNum
protected static final short firstPrimitiveAtomicTypeNum
protected static final short typeNumPrimitiveByte
protected static final short typeNumPrimitiveDouble
protected static final short typeNumPrimitiveFloat
protected static final short typeNumPrimitiveInteger
protected static final short typeNumPrimitiveLong
protected static final short typeNumPrimitiveShort
protected static final short lastPrimitiveAtomicTypeNum
protected static final short builtinStart
protected static final short typeNumBoolean
protected static final short firstNonPrimitiveAtomicTypeNum
protected static final short typeNumByte
protected static final short typeNumDouble
protected static final short typeNumFloat
protected static final short typeNumInteger
protected static final short typeNumLong
protected static final short typeNumShort
protected static final short typeNumString
protected static final short lastNonPrimitiveAtomicTypeNum
protected static final short lastAtomicTypeNum
protected static final short typeNumLinkedList
protected static final short typeNumArrayList
protected static final short typeNumHashMap
protected static final short typeNumLinkedHashMap
protected static final short typeNumTreeMap
protected static final short typeNumHashSet
protected static final short typeNumLinkedHashSet
protected static final short typeNumTreeSet
protected static final short typeNumByteArray
protected static final short registeredBuiltTypeCount
protected static final short firstAggregateTypeNum
protected static final short lastAggregateTypeNum
protected static final short typeNumJavaSerializable
protected static final short typeNumBooleanFalse
protected static final short typeNumBooleanTrue
protected static final short typeNumNull
protected static final short firstExpansionTypeNum
protected static final short lastExpansionTypeNum
protected static final short lastBuiltinTypeNum
protected static short firstGeneratedValueType
protected static short nextGeneratedValueType
Constructor Detail |
---|
public MarshallingRuntime()
Method Detail |
---|
public static void registerMarshallingClass(java.lang.String className, java.lang.Short typeNum)
className
- The fully-elaborated class name, e.g., atavism.server.math.PointtypeNum
- The type number.public static void registerMarshallingClass(java.lang.String className)
className
- The fully-elaborated class name, e.g., atavism.server.math.Pointprotected static short getNextGeneratedValueType()
public static void addMarshallingClass(java.lang.String className, java.lang.Class c)
public static boolean hasMarshallingProperties(java.lang.String className)
className
- The fully-elaborated class name
public static boolean injectedClass(java.lang.String className)
className
- The fully-elaborated class name
public static byte[] maybeInjectMarshalling(java.lang.String className) throws java.lang.ClassNotFoundException
className
- The fully-elaborated class name
java.lang.ClassNotFoundException
public static void marshalObject(AOByteBuffer buf, java.lang.Object object)
If it doesn't find the type number in the table of marshallable classes, it falls back to Java serialization to output the class state.
buf
- The byte buffer into which the object should be marshalledobject
- The object to be marshalled.public static java.lang.Object unmarshalObject(AOByteBuffer buf)
buf
- The byte buffer from which the object should be unmarshalled
public static void marshalMarshallingObject(AOByteBuffer buf, java.lang.Object object)
buf
- The byte bufferobject
- The object to be marshalled.public static java.lang.Object unmarshalMarshallingObject(AOByteBuffer buf, java.lang.Object object)
buf
- The byte bufferobject
- The newly-created instance
public static java.lang.String getClassForTypeNum(java.lang.Short typeNum)
typeNum
- The type number.
public static java.lang.String registeredClassesAndTypes()
protected static void writeTypeNum(AOByteBuffer buf, java.lang.Short typeNum)
protected static java.lang.Short readTypeNum(AOByteBuffer buf)
protected static int byteToIntNoSignExtend(byte b)
protected static boolean valueTypeNum(java.lang.Short typeNum)
public static boolean builtinType(java.lang.Short typeNum)
typeNum
- The type number
public static boolean builtinType(java.lang.String className)
className
- The name of the class
public static java.lang.Short builtinAggregateTypeNum(java.lang.String className)
className
- The name of the class
protected static boolean marshalledTypeNum(java.lang.Short typeNum)
public static java.lang.Short getTypeNumForClassOrBarf(java.lang.Class c)
c
- The Class object
protected static java.lang.Short getTypeNumForClass(java.lang.Class c)
protected static java.lang.Short getTypeNumForClassName(java.lang.String className)
protected static java.lang.Class getClassForClassName(java.lang.String className)
protected static java.lang.String getClassNameForObject(java.lang.Object object)
protected static java.lang.Short classRequiresInjection(java.lang.String className)
public static void markInjected(java.lang.String className)
className
- The fully-elaborated class nameprotected static void addMarshaller(java.lang.Class c, java.lang.Short typeNum)
public static void marshalSerializable(AOByteBuffer buf, java.lang.Object object)
buf
- The byte bufferobject
- The object to be serialized.public static java.lang.Object unmarshalSerializable(AOByteBuffer buf)
buf
- The byte buffer.
protected static void throwError(java.lang.String msg)
public static void marshalLinkedList(AOByteBuffer buf, java.lang.Object object)
buf
- The byte buffer.object
- A collection object containing the list elements to be marshalledpublic static java.lang.Object unmarshalLinkedList(AOByteBuffer buf)
buf
- The byte buffer.
public static void marshalArrayList(AOByteBuffer buf, java.lang.Object object)
buf
- The byte bufferobject
- An ArrayList instance containing the object to be marshalled.public static java.lang.Object unmarshalArrayList(AOByteBuffer buf)
buf
- The byte buffer.
public static void marshalHashMap(AOByteBuffer buf, java.lang.Object object)
buf
- The byte bufferobject
- A Map instance containing the Map to be marshalled.public static java.lang.Object unmarshalHashMap(AOByteBuffer buf)
buf
- The byte buffer.
public static void marshalLinkedHashMap(AOByteBuffer buf, java.lang.Object object)
buf
- The byte bufferobject
- A Map instance containing the Map to be marshalled.public static java.lang.Object unmarshalLinkedHashMap(AOByteBuffer buf)
buf
- The byte buffer.
public static void marshalTreeMap(AOByteBuffer buf, java.lang.Object object)
buf
- The byte bufferobject
- A Map instance containing the Map to be marshalled.public static java.lang.Object unmarshalTreeMap(AOByteBuffer buf)
buf
- The byte buffer.
public static void marshalHashSet(AOByteBuffer buf, java.lang.Object object)
buf
- The byte bufferobject
- A HashSet instance containing the set to be marshaled.public static java.lang.Object unmarshalHashSet(AOByteBuffer buf)
buf
- The byte buffer.
public static void marshalLinkedHashSet(AOByteBuffer buf, java.lang.Object object)
buf
- The byte bufferobject
- A LinkedHashSet instance containing the set to be marshaled.public static java.lang.Object unmarshalLinkedHashSet(AOByteBuffer buf)
buf
- The byte buffer.
public static void marshalTreeSet(AOByteBuffer buf, java.lang.Object object)
buf
- The byte bufferobject
- A TreeSet instance containing the set to be marshaled.public static java.lang.Object unmarshalTreeSet(AOByteBuffer buf)
buf
- The byte buffer.
public static void marshalByteArray(AOByteBuffer buf, java.lang.Object object)
buf
- The byte bufferobject
- A byte array.public static java.lang.Object unmarshalByteArray(AOByteBuffer buf)
buf
- The byte buffer.
public static java.util.HashSet<MarshallingRuntime.ClassNameAndTypeNumber> getClassesToBeMarshalled()
protected static void addPrimitiveToTypeMap(java.lang.Object object, java.lang.Short typeNum)
protected static boolean checkTypeReferences()
protected static boolean hasNoArgConstructor(JavaClass c)
protected static void checkClassPresent(JavaClass referringClass, JavaClass referredClass, java.util.Map<JavaClass,java.util.LinkedList<JavaClass>> missingTypes)
protected static java.lang.Short getTypeNumFromJavaClass(JavaClass c)
protected static java.lang.String getSimpleClassName(JavaClass c)
protected static java.lang.String translateFieldTypeName(java.lang.String s)
protected static JavaClass javaClassOrNull(java.lang.String className)
public static void installPredefinedTypes()
protected static void processMarshallers(java.lang.String marshallerFile)
protected static void registerMarshallingClasses(java.util.LinkedList<java.lang.String> scripts)
public static boolean initialize(java.lang.String[] argv)
It's argument is the String array of command-line args; from those args it looks for the values of the -m args; those values will be the file names of text files, each line of which is the name of a class to be registered for marshalling.
initialize() begins by registering all built-in types. It then reads the -m files, registering the classes they contain for marshalling.
initialize() then performs an analysis of the classes that must support marshalling, to see that none are missing, and that they follow the rules for classes that can be marshalled. The rules are:
If any of these rules are violated, a detailed error message spelling out the problem is logged, and the initialize() returns false, indicating that byte-code injection did not happen. If the error checks didn't find any problems, injectAllClass() is called to perform byte-code injection of marshalling code for all registered classes.
public static void initializeBatch(java.lang.String typeNumFileName)
public static void injectAllClasses(java.lang.String outputDir, java.lang.String typeNumFileName)
public static java.lang.String getHexString(byte[] raw)
|
Copyright © 2018 Dragonsan Studios Sp. z o.o. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |