Atavism Version 2018.1AGIS API

atavism.server.marshalling
Class MarshallingGenerator

java.lang.Object
  extended by atavism.server.marshalling.MarshallingRuntime
      extended by atavism.server.marshalling.MarshallingGenerator

public class MarshallingGenerator
extends MarshallingRuntime

This class provides methods to introspect a collection of classes, and generate serialization for the data and supertypes in the class. The process proceeds in two passes; the first pass records the java Class objects associated with each class, and if supplied, the type numbers. The first pass ends by determining that the class DAG is complete, with no classes missing, and assigns type number for any class for which we don't have explicitly assigned number. The second pass has all the class objects for all of the types, and generates marshalling in the form of static delegate methods on a generated class ServerMarshalling in package atavism.server.util. That class contains an encode and decode delegate method for every class, as well as a set of tables that map Class object to type number, and type number to encode/decode delegates. Since this class generates the ServerMarshalling class, there are _two_ compile times required; the first compile time is identical to the current compile time, in that it compiles the non-generated server code. Then we run the Python scripts that name (and enumerate) the classes that must be marshalled, running the first pass of marshalling generation. Once all the classes are enumerated, we run the second pass of marshalling generation, which generates the ServerMarshalling class definition. Finally, the ServerMarshalling class is compiled, and the server is ready to execute. Since this class uses Java introspection to get at the data members, all data members must be declared public. This is a drag, but there is no way around it if we are to use introspection. The on-the-wire representation of a class object that has no lists or property maps contains exactly one type number, and that number is the first short field in the wire representation. For lists and property maps, there is one type number per element, since we won't know the types at compile time. One requirement imposed by the marshalling generation mechanism is that you must be able to create an instance to pass to the introspection routines. This means that there must be _some_ constructor of the type that is does not require the actual server to be running.


Nested Class Summary
static class MarshallingGenerator.MarshallingPair
           
static class MarshallingGenerator.MarshalTestClass1
          A test class with all the cases in it
static class MarshallingGenerator.MarshalTestClass2
           
 
Nested classes/interfaces inherited from class atavism.server.marshalling.MarshallingRuntime
MarshallingRuntime.ClassNameAndTypeNumber, MarshallingRuntime.ClassProperties
 
Field Summary
protected static java.lang.String generatedMarshallingClass
          The package name for the generated marhalling - - can be changed by a call to setGeneratedMarshallingClass
protected static java.lang.Class hashMapClass
           
protected static java.lang.Class hashSetClass
           
protected static java.lang.Class linkedListClass
           
protected static java.util.HashMap<java.lang.Short,java.lang.String> readOps
           
protected static java.util.HashMap<java.lang.Short,java.lang.String> writeOps
           
 
Fields inherited from class atavism.server.marshalling.MarshallingRuntime
builtinStart, classToClassProperties, firstAggregateTypeNum, firstAtomicTypeNum, firstExpansionTypeNum, firstGeneratedValueType, firstNonPrimitiveAtomicTypeNum, firstPrimitiveAtomicTypeNum, initialized, lastAggregateTypeNum, lastAtomicTypeNum, lastBuiltinTypeNum, lastExpansionTypeNum, lastNonPrimitiveAtomicTypeNum, lastPrimitiveAtomicTypeNum, marshallers, nextGeneratedValueType, nonStoredStart, predefinedTypesInstalled, registeredBuiltTypeCount, typeNumArrayList, typeNumBoolean, typeNumBooleanFalse, typeNumBooleanTrue, typeNumByte, typeNumByteArray, typeNumDouble, typeNumFloat, typeNumHashMap, typeNumHashSet, typeNumInteger, typeNumJavaSerializable, typeNumLinkedHashMap, typeNumLinkedHashSet, typeNumLinkedList, typeNumLong, typeNumNull, typeNumPrimitiveBoolean, typeNumPrimitiveByte, typeNumPrimitiveDouble, typeNumPrimitiveFloat, typeNumPrimitiveInteger, typeNumPrimitiveLong, typeNumPrimitiveShort, typeNumShort, typeNumString, typeNumTreeMap, typeNumTreeSet
 
Constructor Summary
MarshallingGenerator()
           
 
Method Summary
protected static java.lang.Class canonicalType(java.lang.Class c)
           
protected static void checkClassPresent(java.lang.Class referringClass, java.lang.Class referredClass, java.util.Map<java.lang.Class,java.util.LinkedList<java.lang.Class>> missingTypes)
           
protected static boolean checkTypeReferences()
           
protected static java.lang.String createReadOp(java.lang.Class c, java.lang.String fieldName, short fieldTypeNum)
           
protected static java.lang.String createWriteOp(java.lang.Class c, java.lang.String getter, java.lang.Short fieldTypeNum)
           
protected static void defineRWCode(java.lang.Short typeNumPrimitive, java.lang.Short typeNumNonPrimitive, java.lang.String readOp, java.lang.String writeOp)
           
protected static void defineRWCode(java.lang.Short typeNum, java.lang.String readOp, java.lang.String writeOp)
           
protected static java.lang.String formatFlagBitReference(int index, int flagBitCount)
           
protected static java.lang.String formatTitle(java.lang.String n)
           
protected static void generateAssignBytesMarshalling(java.lang.Class c, int n, java.io.FileWriter str, int indent, java.util.LinkedList<java.lang.reflect.Field> fields, java.util.LinkedList<java.lang.Integer> nullTestedFields, int flagBitCount)
           
static void generateMarshalling(java.lang.String codeFile)
          Generate the ServerMarshalling class code
protected static void generateParseBytesMarshalling(java.lang.Class c, int n, java.io.FileWriter str, int indent)
           
protected static void generateToBytesMarshalling(java.lang.Class c, int n, java.io.FileWriter str, int indent, java.util.LinkedList<java.lang.reflect.Field> fields, java.util.LinkedList<java.lang.Integer> nullTestedFields, int flagBitCount)
           
protected static java.lang.Class getFieldType(java.lang.reflect.Field f)
           
protected static java.lang.String getSimpleClassName(java.lang.Class c)
           
protected static java.util.LinkedList<java.lang.reflect.Field> getValidClassFields(java.lang.Class c)
           
protected static java.lang.Class getValidSuperclass(java.lang.Class c)
           
protected static void initializeCodeGenerator()
           
protected static boolean isStaticOrTransient(java.lang.reflect.Field f)
           
protected static boolean isStringType(java.lang.Class c)
           
protected static void logGenericClassInfo(java.lang.Object object, java.lang.String what)
           
protected static java.lang.Class lookupClass(java.lang.String className)
           
static void main(java.lang.String[] args)
           
protected static java.lang.String makeOmittedTest(java.lang.reflect.Field f)
           
static void setGeneratedMarshallingClass(java.lang.String className)
          Declares the name of the class that will contain the generated marshalling classes - - defaults to AOMarshalling
protected static boolean supportsMarshallable(java.lang.String className)
           
protected static boolean typeIsPrimitive(java.lang.Class c)
           
protected static void writeLine(java.io.FileWriter str, int indent, java.lang.String s)
           
 
Methods inherited from class atavism.server.marshalling.MarshallingRuntime
addMarshaller, addMarshallingClass, addPrimitiveToTypeMap, builtinAggregateTypeNum, builtinType, builtinType, byteToIntNoSignExtend, checkClassPresent, classRequiresInjection, getClassesToBeMarshalled, getClassForClassName, getClassForTypeNum, getClassNameForObject, getHexString, getNextGeneratedValueType, getSimpleClassName, getTypeNumForClass, getTypeNumForClassName, getTypeNumForClassOrBarf, getTypeNumFromJavaClass, hasMarshallingProperties, hasNoArgConstructor, initialize, initializeBatch, injectAllClasses, injectedClass, installPredefinedTypes, javaClassOrNull, markInjected, marshalArrayList, marshalByteArray, marshalHashMap, marshalHashSet, marshalledTypeNum, marshalLinkedHashMap, marshalLinkedHashSet, marshalLinkedList, marshalMarshallingObject, marshalObject, marshalSerializable, marshalTreeMap, marshalTreeSet, maybeInjectMarshalling, processMarshallers, readTypeNum, registeredClassesAndTypes, registerMarshallingClass, registerMarshallingClass, registerMarshallingClasses, throwError, translateFieldTypeName, unmarshalArrayList, unmarshalByteArray, unmarshalHashMap, unmarshalHashSet, unmarshalLinkedHashMap, unmarshalLinkedHashSet, unmarshalLinkedList, unmarshalMarshallingObject, unmarshalObject, unmarshalSerializable, unmarshalTreeMap, unmarshalTreeSet, valueTypeNum, writeTypeNum
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

generatedMarshallingClass

protected static java.lang.String generatedMarshallingClass
The package name for the generated marhalling - - can be changed by a call to setGeneratedMarshallingClass


readOps

protected static java.util.HashMap<java.lang.Short,java.lang.String> readOps

writeOps

protected static java.util.HashMap<java.lang.Short,java.lang.String> writeOps

linkedListClass

protected static java.lang.Class linkedListClass

hashMapClass

protected static java.lang.Class hashMapClass

hashSetClass

protected static java.lang.Class hashSetClass
Constructor Detail

MarshallingGenerator

public MarshallingGenerator()
Method Detail

setGeneratedMarshallingClass

public static void setGeneratedMarshallingClass(java.lang.String className)
Declares the name of the class that will contain the generated marshalling classes - - defaults to AOMarshalling


generateMarshalling

public static void generateMarshalling(java.lang.String codeFile)
Generate the ServerMarshalling class code


checkTypeReferences

protected static boolean checkTypeReferences()

supportsMarshallable

protected static boolean supportsMarshallable(java.lang.String className)

generateToBytesMarshalling

protected static void generateToBytesMarshalling(java.lang.Class c,
                                                 int n,
                                                 java.io.FileWriter str,
                                                 int indent,
                                                 java.util.LinkedList<java.lang.reflect.Field> fields,
                                                 java.util.LinkedList<java.lang.Integer> nullTestedFields,
                                                 int flagBitCount)

generateParseBytesMarshalling

protected static void generateParseBytesMarshalling(java.lang.Class c,
                                                    int n,
                                                    java.io.FileWriter str,
                                                    int indent)

generateAssignBytesMarshalling

protected static void generateAssignBytesMarshalling(java.lang.Class c,
                                                     int n,
                                                     java.io.FileWriter str,
                                                     int indent,
                                                     java.util.LinkedList<java.lang.reflect.Field> fields,
                                                     java.util.LinkedList<java.lang.Integer> nullTestedFields,
                                                     int flagBitCount)

makeOmittedTest

protected static java.lang.String makeOmittedTest(java.lang.reflect.Field f)

createWriteOp

protected static java.lang.String createWriteOp(java.lang.Class c,
                                                java.lang.String getter,
                                                java.lang.Short fieldTypeNum)

createReadOp

protected static java.lang.String createReadOp(java.lang.Class c,
                                               java.lang.String fieldName,
                                               short fieldTypeNum)

checkClassPresent

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

formatFlagBitReference

protected static java.lang.String formatFlagBitReference(int index,
                                                         int flagBitCount)

formatTitle

protected static java.lang.String formatTitle(java.lang.String n)

writeLine

protected static void writeLine(java.io.FileWriter str,
                                int indent,
                                java.lang.String s)

isStaticOrTransient

protected static boolean isStaticOrTransient(java.lang.reflect.Field f)

getValidSuperclass

protected static java.lang.Class getValidSuperclass(java.lang.Class c)

getValidClassFields

protected static java.util.LinkedList<java.lang.reflect.Field> getValidClassFields(java.lang.Class c)

getFieldType

protected static java.lang.Class getFieldType(java.lang.reflect.Field f)

canonicalType

protected static java.lang.Class canonicalType(java.lang.Class c)

typeIsPrimitive

protected static boolean typeIsPrimitive(java.lang.Class c)

isStringType

protected static boolean isStringType(java.lang.Class c)

getSimpleClassName

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

lookupClass

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

initializeCodeGenerator

protected static void initializeCodeGenerator()

defineRWCode

protected static void defineRWCode(java.lang.Short typeNumPrimitive,
                                   java.lang.Short typeNumNonPrimitive,
                                   java.lang.String readOp,
                                   java.lang.String writeOp)

defineRWCode

protected static void defineRWCode(java.lang.Short typeNum,
                                   java.lang.String readOp,
                                   java.lang.String writeOp)

logGenericClassInfo

protected static void logGenericClassInfo(java.lang.Object object,
                                          java.lang.String what)

main

public static void main(java.lang.String[] args)


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