Examples of FSTClazzInfo


Examples of org.nustaq.serialization.FSTClazzInfo

    public static void main( String arg[] ) {
        System.setProperty("fst.unsafe","true");
        Unsafe un = FSTUtil.getUnsafe();
        FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
        FSTClazzInfo cl = conf.getClassInfo(Sample.class);
        Sample test = new Sample();
        System.out.println("fioff "+cl.getFieldInfo("fastTime",Date.class).getMemOffset() );
        System.out.println("fioff "+cl.getFieldInfo("x",Sample.class).getMemOffset() );

        test.x = 9999;

        Sample other = new Sample();

        long pos = cl.getFieldInfo("x", Sample.class).getMemOffset();
        long siz = cl.getFieldInfo("s", Sample.class).getMemOffset()+8;
        byte b[] = new byte[(int) siz];
        un.copyMemory(test,0, b, 0, siz);

        other = copyObj(un,test, (int) siz);
View Full Code Here

Examples of org.nustaq.serialization.FSTClazzInfo

    public void writeObject(FSTObjectOutput out, Object toWrite, FSTClazzInfo clzInfo, FSTClazzInfo.FSTFieldInfo referencedBy, int streamPosition) throws IOException {
        ArrayList col = (ArrayList)toWrite;
        int size = col.size();
        out.writeInt(size);
        Class lastClz = null;
        FSTClazzInfo lastInfo = null;
        for (int i = 0; i < size; i++) {
            Object o = col.get(i);
            if ( o != null ) {
                lastInfo = out.writeObjectInternal(o, o.getClass() == lastClz ? lastInfo : null, null);
                lastClz = o.getClass();
View Full Code Here

Examples of org.nustaq.serialization.FSTClazzInfo

    @Override
    public void writeObject(FSTObjectOutput out, Object toWrite, FSTClazzInfo clzInfo, FSTClazzInfo.FSTFieldInfo referencedBy, int streamPosition) throws IOException {
        Map col = (Map)toWrite;
        out.writeInt(col.size());
        FSTClazzInfo lastKClzI = null;
        FSTClazzInfo lastVClzI = null;
        Class lastKClz = null;
        Class lastVClz = null;
        for (Iterator iterator = col.entrySet().iterator(); iterator.hasNext(); ) {
            Map.Entry next = (Map.Entry) iterator.next();
            Object key = next.getKey();
View Full Code Here

Examples of org.nustaq.serialization.FSTClazzInfo

    Object lastReadDirectObject; // in case readClass already reads full minbin value
    @Override
    public FSTClazzInfo readClass() throws IOException, ClassNotFoundException {
        if (lastDirectClass != null ) {
            FSTClazzInfo clInfo = conf.getCLInfoRegistry().getCLInfo(lastDirectClass);
            lastDirectClass = null;
            return clInfo;
        }
        Object read = input.readObject();
        String name = (String) read;
View Full Code Here

Examples of org.nustaq.serialization.FSTClazzInfo

    public void writeObject(FSTObjectOutput out, Object toWrite, FSTClazzInfo clzInfo, FSTClazzInfo.FSTFieldInfo referencedBy, int streamPosition) throws IOException {
        Collection col = (Collection)toWrite;
        int size = col.size();
        out.writeInt(size);
        Class lastClz = null;
        FSTClazzInfo lastInfo = null;
        if ( col.getClass() == ArrayList.class ) {
            List l = (List) col;
            for (int i = 0; i < size; i++) {
                Object o = l.get(i);
                if ( o != null ) {
View Full Code Here

Examples of org.nustaq.serialization.FSTClazzInfo

        } else {
            orig = pool.getOrNull(clazz.getName());
        }
        newClz.setSuperclass(orig);

        final FSTClazzInfo clInfo = conf.getClassInfo(clazz);

        CtMethod[] methods = orig.getMethods();
        for (int i = 0; i < methods.length; i++) {
            CtMethod method = methods[i];
            final Class curClz = Class.forName( method.getDeclaringClass().getName() );
            boolean allowed = ((method.getModifiers() & AccessFlag.ABSTRACT) == 0 ) &&
                    (method.getModifiers() & AccessFlag.NATIVE) == 0 &&
                    (method.getModifiers() & AccessFlag.FINAL) == 0 &&
                    (   !method.getDeclaringClass().getName().equals(FSTStruct.class.getName())
                       ||method.getName().equals("getFieldValues")) &&
                    ! method.getDeclaringClass().getName().equals(Object.class.getName());
            allowed &= method.getAnnotation(NoAssist.class) == null;
            allowed &= (method.getModifiers() & AccessFlag.STATIC) == 0;
            if ( allowed && (method.getModifiers() & AccessFlag.FINAL) != 0 && ! method.getDeclaringClass().getName().equals("java.lang.Object") ) {
                throw new RuntimeException("final methods are not allowed for struct classes:"+method.getName());
            }
            if ( allowed && (method.getModifiers() & AccessFlag.PRIVATE) != 0 && ! method.getDeclaringClass().getName().equals("java.lang.Object")) {
                throw new RuntimeException("private methods are not allowed for struct classes:"+method.getName());
            }
            if ( allowed ) {
                ClassMap mp = new ClassMap();
                mp.fix(clazz.getName());
                mp.fix(clazz.getSuperclass().getName()); // ?? only depth 2 ??
                method = new CtMethod(method,newClz,mp);
                String methName = method.getName();
                // array access:
                //      void [name](int, type)
                //      [type] [name](int)
                FSTClazzInfo.FSTFieldInfo arrayFi = checkForSpecialArrayMethod(clInfo, method, "", null, null);
                // array length:
                //      int [name]Len()
                FSTClazzInfo.FSTFieldInfo lenfi = checkForSpecialArrayMethod(clInfo, method, "Len", CtClass.intType, new CtClass[0]);
                // get byte index of array data:
                //      int [name]Index()
                FSTClazzInfo.FSTFieldInfo indexfi = checkForSpecialArrayMethod(clInfo, method, "Index", CtClass.intType, new CtClass[0]);
                // get size of array element:
                //      int [name]ElementSize()
                FSTClazzInfo.FSTFieldInfo elemlen = checkForSpecialArrayMethod(clInfo, method, "ElementSize", CtClass.intType, new CtClass[0]);
                // CREATE non volatile pointer to array[0] element:
                //      type [name]Pointer() OR type [name]Pointer(pointerToSetup) (for reuse)
                FSTClazzInfo.FSTFieldInfo pointerfi = checkForSpecialArrayMethod(clInfo, method, "Pointer", null, null);
                // get byte index to structure or array header element:
                //      type [name]StructIndex()
                FSTClazzInfo.FSTFieldInfo structIndex = checkForSpecialMethod(clInfo, method, "StructIndex", CtClass.intType, new CtClass[0], false);
                // set with CAS
                //      boolean [name]CAS(expectedValue,value)
                FSTClazzInfo.FSTFieldInfo casAcc = checkForSpecialMethod(clInfo, method, "CAS", CtClass.booleanType, null, false);

                if ( casAcc != null ) {
                    structGen.defineStructSetCAS(casAcc, clInfo, method);
                    newClz.addMethod(method);
                } else
                if ( pointerfi != null ) {
                    structGen.defineArrayPointer(pointerfi, clInfo, method);
                    newClz.addMethod(method);
                } else
                if ( structIndex != null ) {
                    structGen.defineFieldStructIndex(structIndex, clInfo, method);
                    newClz.addMethod(method);
                } else
                if ( indexfi != null ) {
                    structGen.defineArrayIndex(indexfi, clInfo, method);
                    newClz.addMethod(method);
                } else
                if ( elemlen != null ) {
                    structGen.defineArrayElementSize(elemlen, clInfo, method);
                    newClz.addMethod(method);
                } else
                if arrayFi != null ) {
                    structGen.defineArrayAccessor(arrayFi, clInfo, method);
                    newClz.addMethod(method);
                } else if ( methName.endsWith("Len") && lenfi != null )
                {
                    structGen.defineArrayLength(lenfi, clInfo, method);
                    newClz.addMethod(method);
                } else {
                    if ( methName.equals("getFieldValues") &&
                            ( (clInfo.getClazz().getSuperclass().getName().equals("de.nustaq.reallive.impl.RLStructRow")) // oops
                            || (curClz != FSTStruct.class) )
                       ) {
                        FSTClazzInfo.FSTFieldInfo[] fieldInfo = clInfo.getFieldInfo();
                        StringBuilder body = new StringBuilder("{  return new Object[] { ");
                        for (int j = 0; j < fieldInfo.length; j++) {
                            FSTClazzInfo.FSTFieldInfo fstFieldInfo = fieldInfo[j];
                            int modifiers = fstFieldInfo.getField().getModifiers();
                            if ( (java.lang.reflect.Modifier.isProtected(modifiers) ||
                                  java.lang.reflect.Modifier.isPublic(modifiers)) &&
                                  !java.lang.reflect.Modifier.isStatic(modifiers)
                                )
                            {
                                body.append( "\""+fstFieldInfo.getField().getName()+"\", " );
                                Class type = fstFieldInfo.getType();
                                if ( FSTStruct.class.isAssignableFrom(type) ) {
                                    body.append(fstFieldInfo.getField().getName()).append(".getFieldValues()");
                                } else {
                                    if ( type.isPrimitive() ) {
                                        if ( long.class == type ) {
                                            body.append("new Long("+fstFieldInfo.getField().getName()+")");
                                        } else if ( float.class == type ||double.class == type ) {
                                            body.append("new Double("+fstFieldInfo.getField().getName()+")");
                                        } else {
                                            body.append("new Integer("+fstFieldInfo.getField().getName()+")");
                                        }
                                    } else {
                                        body.append(fstFieldInfo.getField().getName());
                                    }
                                }
                                if ( j != fieldInfo.length-1 )
                                    body.append(",");
                            }
                        }
                        body.append("}; }");
                        method.setBody(body.toString());
                    }
                    newClz.addMethod(method);
                    method.instrument( new ExprEditor() {
                        @Override
                        public void edit(FieldAccess f) throws CannotCompileException {
                            try {
                                if ( ! f.isStatic() ) {
                                    CtClass type = null;
                                    type = f.getField().getType();
                                    FSTClazzInfo.FSTFieldInfo fieldInfo = clInfo.getFieldInfo(f.getFieldName(), null);
                                    if ( fieldInfo == null ) {
                                        return;
                                    }
                                    if ( f.isReader() ) {
                                        structGen.defineStructReadAccess(f, type, fieldInfo);
View Full Code Here

Examples of org.nustaq.serialization.FSTClazzInfo

                return 0;
            }
            if (onHeapStruct.isOffHeap())
                return onHeapStruct.getByteSize();
            int siz = 8;
            FSTClazzInfo clInfo = conf.getClassInfo(onHeapStruct.getClass());
            FSTClazzInfo.FSTFieldInfo fis[] = clInfo.getFieldInfo();
            for (int i = 0; i < fis.length; i++) {
                FSTClazzInfo.FSTFieldInfo fi = fis[i];
                if ( fi.getField().getDeclaringClass() == FSTStruct.class )
                    continue;
                int modifiers = fi.getField().getModifiers();
View Full Code Here

Examples of org.nustaq.serialization.FSTClazzInfo

        int initialIndex =index;
        Class<? extends FSTStruct> aClass = onHeapStruct.getClass();
        int clzId = getClzId(aClass);
        bytes.putInt(index+4,clzId);
        index+=8;
        FSTClazzInfo clInfo = conf.getClassInfo(aClass);
        FSTClazzInfo.FSTFieldInfo fis[] = clInfo.getFieldInfo();
        for (int i = 0; i < fis.length; i++) {
            FSTClazzInfo.FSTFieldInfo fi = fis[i];
            if ( fi.getField().getDeclaringClass() == FSTStruct.class )
                continue;
            index+=fi.getAlignPad();
View Full Code Here

Examples of org.nustaq.serialization.FSTClazzInfo

            writeIndent(indent);
            writeClazzTag(expectedClass, o);
            writeln();

            FSTClazzInfo clInfo = conf.getCLInfoRegistry().getCLInfo(o.getClass());
            FSTClazzInfo.FSTFieldInfo[] fieldInfo = clInfo.getFieldInfo();

            for (int i = 0; i < fieldInfo.length; i++) {
                FSTClazzInfo.FSTFieldInfo fstFieldInfo = fieldInfo[i];
                Class expectedKey = Kson.fumbleOutGenericKeyType(fstFieldInfo.getField());
                Class expectedValue = Kson.fumbleOutGenericValueType(fstFieldInfo.getField());
View Full Code Here

Examples of org.nustaq.serialization.FSTClazzInfo

            }
            if (mappedClass == List.class || mappedClass == Collection.class)
                mappedClass = ArrayList.class;
            if (mappedClass == Map.class)
                mappedClass = HashMap.class;
            FSTClazzInfo clInfo = Kson.conf.getCLInfoRegistry().getCLInfo(mappedClass);
            if (DEBUG_STACK) {
                if ( clInfo != null ) {
                    stack.push(new ParseStep("try reading type " + clInfo.getClazz().getName(), in));
                } else
                    stack.push(new ParseStep("try reading unknown object type", in));
            }
            int ch = in.readChar();
            if (ch != '{' && ch != '[') {
                throw new KsonParseException("expected '{' or '['", in);
            }
            Object res = null;
            if (Map.class.isAssignableFrom(clInfo.getClazz())) {
                res = clInfo.newInstance(true);
                if (DEBUG_STACK) {
                    stack.push(new ParseStep("read map " + clInfo.getClazz().getName()+"<"+genericKeyType+","+genericValueType+">", in));
                }
                List keyVals = readList(genericKeyType, genericValueType);
                for (int i = 0; i < keyVals.size(); i += 2) {
                    Object fi = keyVals.get(i);
                    Object val = keyVals.get(i + 1);
                    ((Map) res).put(fi, val);
                }
                if (DEBUG_STACK) {
                    stack.pop();
                }
            } else if (Collection.class.isAssignableFrom(clInfo.getClazz())) {
                List keyVals = readList(genericKeyType, genericKeyType);
                if (clInfo.getClazz() == ArrayList.class) { // default constructor fails ...
                    res = new ArrayList<>(keyVals.size());
                } else if (clInfo.getClazz() == HashSet.class) { // default constructor fails ...
                    res = new HashSet<>(keyVals.size());
                } else {
                    res = clInfo.newInstance(true);
                }
                if (DEBUG_STACK) {
                    stack.push(new ParseStep("read list " + clInfo.getClazz().getName()+"<"+genericKeyType+"|"+genericValueType+">", in));
                }
                for (int i = 0; i < keyVals.size(); i++) {
                    Object o = keyVals.get(i);
                    ((Collection) res).add(o);
                }
                if (DEBUG_STACK) {
                    stack.pop();
                }
            } else if (clInfo.getClazz().isArray()) {
                Class componentType = clInfo.getClazz().getComponentType();
                if (componentType.isArray())
                    throw new KsonParseException("nested arrays not supported", in);
                if (DEBUG_STACK) {
                    stack.push(new ParseStep("read array of type " + clInfo.getClazz().getComponentType().getName(), in));
                }
                List keyVals = readList(componentType, componentType);
                res = Array.newInstance(componentType, keyVals.size());
                for (int i = 0; i < keyVals.size(); i++) {
                    Array.set(res, i, keyVals.get(i));
                }
                if (DEBUG_STACK) {
                    stack.pop();
                }
            } else {
                res = clInfo.newInstance(true);
                if (res==null) {
                    throw new RuntimeException(clInfo.getClazz().getName()+" misses a default constructor. Instantiation failed.");
                }
                List keyVals = readObjectFields(clInfo);

                for (int i = 0; i < keyVals.size(); i += 2) {
                    String fi = (String) keyVals.get(i);
                    Object val = keyVals.get(i + 1);
                    Field field = clInfo.getFieldInfo(fi, null).getField();
                    if ( field.getType().isEnum() && val instanceof String) {
                        val = Enum.valueOf( (Class<Enum>)field.getType(), (String) val);
                    }
                    field.set(res, val);
                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.