Search in sources :

Example 1 with FastMap

use of rpc.turbo.util.FastMap in project turbo-rpc by hank-whu.

the class FastClassResolver method readName.

protected Registration readName(Input input) {
    int nameId = input.readVarInt(true);
    if (nameIdToClass == null)
        nameIdToClass = new IntToObjectArrayMap<>();
    Class type = nameIdToClass.get(nameId);
    if (type == null) {
        // Only read the class name the first time encountered in object graph.
        String className = input.readString();
        type = getTypeByName(className);
        if (type == null) {
            try {
                type = Class.forName(className, false, kryo.getClassLoader());
            } catch (ClassNotFoundException ex) {
                if (WARN)
                    warn("kryo", "Unable to load class " + className + " with kryo's ClassLoader. Retrying with current..");
                try {
                    type = Class.forName(className);
                } catch (ClassNotFoundException e) {
                    throw new KryoException("Unable to find class: " + className, ex);
                }
            }
            if (nameToClass == null)
                nameToClass = new FastMap<>(32, 0.5F);
            nameToClass.put(className, type);
        }
        nameIdToClass.put(nameId, type);
        if (TRACE)
            trace("kryo", "Read class name: " + className);
    } else {
        if (TRACE)
            trace("kryo", "Read class name reference " + nameId + ": " + className(type));
    }
    return kryo.getRegistration(type);
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) FastMap(rpc.turbo.util.FastMap) Util.getWrapperClass(com.esotericsoftware.kryo.util.Util.getWrapperClass) IntToObjectArrayMap(rpc.turbo.util.IntToObjectArrayMap)

Aggregations

KryoException (com.esotericsoftware.kryo.KryoException)1 Util.getWrapperClass (com.esotericsoftware.kryo.util.Util.getWrapperClass)1 FastMap (rpc.turbo.util.FastMap)1 IntToObjectArrayMap (rpc.turbo.util.IntToObjectArrayMap)1