Atavism Version 2018.1AGIS API

atavism.server.marshalling
Class MarshallingRuntime

java.lang.Object
  extended by atavism.server.marshalling.MarshallingRuntime
Direct Known Subclasses:
MarshallingGenerator

public class MarshallingRuntime
extends java.lang.Object

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

classToClassProperties

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.


marshallers

protected static java.lang.Class[] marshallers
The map from typeNum to the classes of the object for which we've generated marshalling code


predefinedTypesInstalled

protected static boolean predefinedTypesInstalled

initialized

public static boolean initialized
A boolean which is true if MarshallingRuntime has been called.


nonStoredStart

protected static final short nonStoredStart
See Also:
Constant Field Values

typeNumPrimitiveBoolean

protected static final short typeNumPrimitiveBoolean
See Also:
Constant Field Values

firstAtomicTypeNum

protected static final short firstAtomicTypeNum
See Also:
Constant Field Values

firstPrimitiveAtomicTypeNum

protected static final short firstPrimitiveAtomicTypeNum
See Also:
Constant Field Values

typeNumPrimitiveByte

protected static final short typeNumPrimitiveByte
See Also:
Constant Field Values

typeNumPrimitiveDouble

protected static final short typeNumPrimitiveDouble
See Also:
Constant Field Values

typeNumPrimitiveFloat

protected static final short typeNumPrimitiveFloat
See Also:
Constant Field Values

typeNumPrimitiveInteger

protected static final short typeNumPrimitiveInteger
See Also:
Constant Field Values

typeNumPrimitiveLong

protected static final short typeNumPrimitiveLong
See Also:
Constant Field Values

typeNumPrimitiveShort

protected static final short typeNumPrimitiveShort
See Also:
Constant Field Values

lastPrimitiveAtomicTypeNum

protected static final short lastPrimitiveAtomicTypeNum
See Also:
Constant Field Values

builtinStart

protected static final short builtinStart
See Also:
Constant Field Values

typeNumBoolean

protected static final short typeNumBoolean
See Also:
Constant Field Values

firstNonPrimitiveAtomicTypeNum

protected static final short firstNonPrimitiveAtomicTypeNum
See Also:
Constant Field Values

typeNumByte

protected static final short typeNumByte
See Also:
Constant Field Values

typeNumDouble

protected static final short typeNumDouble
See Also:
Constant Field Values

typeNumFloat

protected static final short typeNumFloat
See Also:
Constant Field Values

typeNumInteger

protected static final short typeNumInteger
See Also:
Constant Field Values

typeNumLong

protected static final short typeNumLong
See Also:
Constant Field Values

typeNumShort

protected static final short typeNumShort
See Also:
Constant Field Values

typeNumString

protected static final short typeNumString
See Also:
Constant Field Values

lastNonPrimitiveAtomicTypeNum

protected static final short lastNonPrimitiveAtomicTypeNum
See Also:
Constant Field Values

lastAtomicTypeNum

protected static final short lastAtomicTypeNum
See Also:
Constant Field Values

typeNumLinkedList

protected static final short typeNumLinkedList
See Also:
Constant Field Values

typeNumArrayList

protected static final short typeNumArrayList
See Also:
Constant Field Values

typeNumHashMap

protected static final short typeNumHashMap
See Also:
Constant Field Values

typeNumLinkedHashMap

protected static final short typeNumLinkedHashMap
See Also:
Constant Field Values

typeNumTreeMap

protected static final short typeNumTreeMap
See Also:
Constant Field Values

typeNumHashSet

protected static final short typeNumHashSet
See Also:
Constant Field Values

typeNumLinkedHashSet

protected static final short typeNumLinkedHashSet
See Also:
Constant Field Values

typeNumTreeSet

protected static final short typeNumTreeSet
See Also:
Constant Field Values

typeNumByteArray

protected static final short typeNumByteArray
See Also:
Constant Field Values

registeredBuiltTypeCount

protected static final short registeredBuiltTypeCount
See Also:
Constant Field Values

firstAggregateTypeNum

protected static final short firstAggregateTypeNum
See Also:
Constant Field Values

lastAggregateTypeNum

protected static final short lastAggregateTypeNum
See Also:
Constant Field Values

typeNumJavaSerializable

protected static final short typeNumJavaSerializable
See Also:
Constant Field Values

typeNumBooleanFalse

protected static final short typeNumBooleanFalse
See Also:
Constant Field Values

typeNumBooleanTrue

protected static final short typeNumBooleanTrue
See Also:
Constant Field Values

typeNumNull

protected static final short typeNumNull
See Also:
Constant Field Values

firstExpansionTypeNum

protected static final short firstExpansionTypeNum
See Also:
Constant Field Values

lastExpansionTypeNum

protected static final short lastExpansionTypeNum
See Also:
Constant Field Values

lastBuiltinTypeNum

protected static final short lastBuiltinTypeNum
See Also:
Constant Field Values

firstGeneratedValueType

protected static short firstGeneratedValueType

nextGeneratedValueType

protected static short nextGeneratedValueType
Constructor Detail

MarshallingRuntime

public MarshallingRuntime()
Method Detail

registerMarshallingClass

public 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. There are very cases in which it makes sense to call this method directly; most calls will be to the 1-arg overloading.

Parameters:
className - The fully-elaborated class name, e.g., atavism.server.math.Point
typeNum - The type number.

registerMarshallingClass

public 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.

Parameters:
className - The fully-elaborated class name, e.g., atavism.server.math.Point

getNextGeneratedValueType

protected static short getNextGeneratedValueType()

addMarshallingClass

public static void addMarshallingClass(java.lang.String className,
                                       java.lang.Class c)
Records the fact that this marshalling class has marshalling methods. This is called exclusively by the MarshallingClassLoader


hasMarshallingProperties

public static boolean hasMarshallingProperties(java.lang.String className)
Returns true if the className is a class that marshalling knows about

Parameters:
className - The fully-elaborated class name
Returns:
true if this class has been registered for marshalling, or it is a primitive type

injectedClass

public static boolean injectedClass(java.lang.String className)
Returns true if the className is a class that requires that marshalling be generated. False for primitive types and classes for which marshalling is done by hand.

Parameters:
className - The fully-elaborated class name
Returns:
True if the class required byte-code injection.

maybeInjectMarshalling

public static byte[] maybeInjectMarshalling(java.lang.String className)
                                     throws java.lang.ClassNotFoundException
This method is called by the class loader to inject marshalling methods in a class. If the class doesn't need marshalling methods, it returns null.

Parameters:
className - The fully-elaborated class name
Returns:
The bytes of the updated class definition, or null if it doesn't need marshalling.
Throws:
java.lang.ClassNotFoundException

marshalObject

public static void marshalObject(AOByteBuffer buf,
                                 java.lang.Object object)
This is the top-level method for marshalling an object. It gets the object's Class object; looks up the type number in table of marshallable types; and writes the type code for this object to the byte buffer. If the type number is a primitive or built-in type, it executes switch statement whose index is the type number, and whose cases are the code to marshal the object into the byte buffer. If the type number is not one of a primitive or built-in type, it invokes the objects marshalObject method, passing the byte buffer.

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.

Parameters:
buf - The byte buffer into which the object should be marshalled
object - The object to be marshalled.

unmarshalObject

public static java.lang.Object unmarshalObject(AOByteBuffer buf)
This is the top-level method for unmarshalling an object. It reads the type code for this object from the byte buffer, and uses that type number as the index for a switch statement. If the type number represents one of the primitive or built-in types, it directly calls the code to unmarshal the object. If the type number is the one for Java serialization, it invokes Java serialization to unmarshal the object. Otherwise, it calls the class's newInstance() method to create an empty instance, and invokes the unmarshal method on the new instance, passing the byte buffer argument and returns the result.

Parameters:
buf - The byte buffer from which the object should be unmarshalled
Returns:
The unmarshalled object

marshalMarshallingObject

public 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. This is used by by-hand implementations of the MarshallingInterface to marshal data members. The reason that this method exists is that by-hand implementors of marshalling have data member that are marshalled by byte-code injection. But in the by-hand marshalling code, the compiler doesn't know that the data member will ultimately implement Marshallable. implements Marshallable

Parameters:
buf - The byte buffer
object - The object to be marshalled.

unmarshalMarshallingObject

public 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. This is used by by-hand implementations of the MarshallingInterface to unmarshal data members. The reason that this method exists is that by-hand implementors of marshalling have data member that are marshalled by byte-code injection. But in the by-hand marshalling code, the compiler doesn't know that the data member will ultimately implement Marshallable.

Parameters:
buf - The byte buffer
object - The newly-created instance
Returns:
The newly-created instance, or a substitute instance if the unmarshalObject code does "interning" of objects.

getClassForTypeNum

public static java.lang.String getClassForTypeNum(java.lang.Short typeNum)
Get the class name for a given type number.

Parameters:
typeNum - The type number.
Returns:
The fully-elaborated class name corresponding to the type number.

registeredClassesAndTypes

public static java.lang.String registeredClassesAndTypes()
Get a String containing a comma-separated sequence of the class names known about by the marshalling runtime. Not particularly useful except for testing.

Returns:
The comma-separated sequence of the class names

writeTypeNum

protected static void writeTypeNum(AOByteBuffer buf,
                                   java.lang.Short typeNum)

readTypeNum

protected static java.lang.Short readTypeNum(AOByteBuffer buf)

byteToIntNoSignExtend

protected static int byteToIntNoSignExtend(byte b)

valueTypeNum

protected static boolean valueTypeNum(java.lang.Short typeNum)
Is this typeNum itself represent a value, with no further data required?


builtinType

public static boolean builtinType(java.lang.Short typeNum)
Returns true if the type number represents a built-in type

Parameters:
typeNum - The type number
Returns:
True if it's a built-in type.

builtinType

public static boolean builtinType(java.lang.String className)
Returns true if the class name is a built-in type

Parameters:
className - The name of the class
Returns:
True if it's a built-in type.

builtinAggregateTypeNum

public 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.

Parameters:
className - The name of the class
Returns:
The typeNum of the class if it's an aggregate built-in type.

marshalledTypeNum

protected static boolean marshalledTypeNum(java.lang.Short typeNum)

getTypeNumForClassOrBarf

public 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

Parameters:
c - The Class object
Returns:
The appropriate type number, or typeNumNull

getTypeNumForClass

protected static java.lang.Short getTypeNumForClass(java.lang.Class c)

getTypeNumForClassName

protected static java.lang.Short getTypeNumForClassName(java.lang.String className)

getClassForClassName

protected static java.lang.Class getClassForClassName(java.lang.String className)

getClassNameForObject

protected static java.lang.String getClassNameForObject(java.lang.Object object)

classRequiresInjection

protected static java.lang.Short classRequiresInjection(java.lang.String className)

markInjected

public static void markInjected(java.lang.String className)
Mark this class with the given name as having had byte-code injection performed

Parameters:
className - The fully-elaborated class name

addMarshaller

protected static void addMarshaller(java.lang.Class c,
                                    java.lang.Short typeNum)

marshalSerializable

public static void marshalSerializable(AOByteBuffer buf,
                                       java.lang.Object object)
The static method that does marshalling via Java serialization. Performs serialization on the object, and adds the serialized representation to the byte buffer.

Parameters:
buf - The byte buffer
object - The object to be serialized.

unmarshalSerializable

public static java.lang.Object unmarshalSerializable(AOByteBuffer buf)
The static method that unmarshals an object using Java serialization, getting the bytes from the byte buffer.

Parameters:
buf - The byte buffer.
Returns:
The unserialized object.

throwError

protected static void throwError(java.lang.String msg)

marshalLinkedList

public 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. The element type can be any type.

Parameters:
buf - The byte buffer.
object - A collection object containing the list elements to be marshalled

unmarshalLinkedList

public static java.lang.Object unmarshalLinkedList(AOByteBuffer buf)
The built-in unmarshalling code for a linked list, which unmarshals it from the byte buffer argument. The element type can be any type.

Parameters:
buf - The byte buffer.
Returns:
A LinkedList instance containing ing the unmarshalled list.

marshalArrayList

public 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. The element type can be any type.

Parameters:
buf - The byte buffer
object - An ArrayList instance containing the object to be marshalled.

unmarshalArrayList

public static java.lang.Object unmarshalArrayList(AOByteBuffer buf)
The built-in unmarshalling code for an ArrayList, which unmarshals it from the byte buffer argument. The element type can be any type.

Parameters:
buf - The byte buffer.
Returns:
An ArrayList instance containing ing the unmarshalled array.

marshalHashMap

public 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. The key and value types can be any type.

Parameters:
buf - The byte buffer
object - A Map instance containing the Map to be marshalled.

unmarshalHashMap

public static java.lang.Object unmarshalHashMap(AOByteBuffer buf)
The built-in unmarshalling code for a HashMap, which unmarshals it from the byte buffer argument. The key and value types can be any type.

Parameters:
buf - The byte buffer.
Returns:
A HashMap instance containing ing the unmarshalled map.

marshalLinkedHashMap

public 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. The key and value types can be any type.

Parameters:
buf - The byte buffer
object - A Map instance containing the Map to be marshalled.

unmarshalLinkedHashMap

public static java.lang.Object unmarshalLinkedHashMap(AOByteBuffer buf)
The built-in unmarshalling code for a LinkedHashMap, which unmarshals it from the byte buffer argument. The key and value types can be any type.

Parameters:
buf - The byte buffer.
Returns:
A LinkedHashMap instance containing ing the unmarshalled map.

marshalTreeMap

public 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. The key and value types can be any type.

Parameters:
buf - The byte buffer
object - A Map instance containing the Map to be marshalled.

unmarshalTreeMap

public static java.lang.Object unmarshalTreeMap(AOByteBuffer buf)
The built-in unmarshalling code for a TreeMap, which unmarshals it from the byte buffer argument. The key and value types can be any type.

Parameters:
buf - The byte buffer.
Returns:
A TreeMap instance containing ing the unmarshalled map.

marshalHashSet

public 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. The element type can be any type.

Parameters:
buf - The byte buffer
object - A HashSet instance containing the set to be marshaled.

unmarshalHashSet

public static java.lang.Object unmarshalHashSet(AOByteBuffer buf)
The built-in unmarshalling code for a HashSet, which unmarshals it from the byte buffer argument. The element type can be any type.

Parameters:
buf - The byte buffer.
Returns:
A HashSet instance containing ing the unmarshalled set.

marshalLinkedHashSet

public 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. The element type can be any type.

Parameters:
buf - The byte buffer
object - A LinkedHashSet instance containing the set to be marshaled.

unmarshalLinkedHashSet

public static java.lang.Object unmarshalLinkedHashSet(AOByteBuffer buf)
The built-in unmarshalling code for a LinkedHashSet, which unmarshals it from the byte buffer argument. The element type can be any type.

Parameters:
buf - The byte buffer.
Returns:
A LinkedHashSet instance containing ing the unmarshalled set.

marshalTreeSet

public 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. The element type can be any type.

Parameters:
buf - The byte buffer
object - A TreeSet instance containing the set to be marshaled.

unmarshalTreeSet

public static java.lang.Object unmarshalTreeSet(AOByteBuffer buf)
The built-in unmarshalling code for a TreeSet, which unmarshals it from the byte buffer argument. The element type can be any type.

Parameters:
buf - The byte buffer.
Returns:
A TreeSet instance containing ing the unmarshalled set.

marshalByteArray

public 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.

Parameters:
buf - The byte buffer
object - A byte array.

unmarshalByteArray

public static java.lang.Object unmarshalByteArray(AOByteBuffer buf)
The built-in unmarshalling code for a byte array, which unmarshals it from the byte buffer argument.

Parameters:
buf - The byte buffer.
Returns:
A byte array instance containing ing the unmarshalled bytes.

getClassesToBeMarshalled

public 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)

Returns:
A HashSet of ClassNameAndTypeNumber instances.

addPrimitiveToTypeMap

protected static void addPrimitiveToTypeMap(java.lang.Object object,
                                            java.lang.Short typeNum)

checkTypeReferences

protected static boolean checkTypeReferences()

hasNoArgConstructor

protected static boolean hasNoArgConstructor(JavaClass c)
Any marshalled object must have a public no-args constructor


checkClassPresent

protected static void checkClassPresent(JavaClass referringClass,
                                        JavaClass referredClass,
                                        java.util.Map<JavaClass,java.util.LinkedList<JavaClass>> missingTypes)

getTypeNumFromJavaClass

protected static java.lang.Short getTypeNumFromJavaClass(JavaClass c)

getSimpleClassName

protected static java.lang.String getSimpleClassName(JavaClass c)

translateFieldTypeName

protected static java.lang.String translateFieldTypeName(java.lang.String s)

javaClassOrNull

protected static JavaClass javaClassOrNull(java.lang.String className)

installPredefinedTypes

public static void installPredefinedTypes()
A utility method, called by MarshallingRuntime.initialize(), which registers all built-in types


processMarshallers

protected static void processMarshallers(java.lang.String marshallerFile)

registerMarshallingClasses

protected static void registerMarshallingClasses(java.util.LinkedList<java.lang.String> scripts)

initialize

public 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.

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:

  • Any marshallable class must have a public, no-args constructor
  • The only data members whose type is array of primitive type allowed is array of byte
  • Enum data members of marshallable classes are not allowed
  • All data members of a marshallable class must themselves be marshallable

    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.


  • initializeBatch

    public static void initializeBatch(java.lang.String typeNumFileName)

    injectAllClasses

    public static void injectAllClasses(java.lang.String outputDir,
                                        java.lang.String typeNumFileName)
    Perform byte code injection of marshalling code for all registered classes


    getHexString

    public static java.lang.String getHexString(byte[] raw)


    Copyright © 2018 Dragonsan Studios Sp. z o.o.