com.esotericsoftware.kryo.Kryo.getClassLoader()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中com.esotericsoftware.kryo.Kryo.getClassLoader()方法的一些代码示例,展示了Kryo.getClassLoader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Kryo.getClassLoader()方法的具体详情如下:
包路径:com.esotericsoftware.kryo.Kryo
类名称:Kryo
方法名:getClassLoader

Kryo.getClassLoader介绍

暂无

代码示例

代码示例来源:origin: alibaba/jstorm

@Override
  public Object read(Kryo kryo, Input input, Class c) {
    int len = input.readInt();
    byte[] ser = new byte[len];
    input.readBytes(ser);
    ByteArrayInputStream bis = new ByteArrayInputStream(ser);
    try {
      ClassLoaderObjectInputStream ois = new ClassLoaderObjectInputStream(kryo.getClassLoader(), bis);
      return ois.readObject();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: apache/flink

@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public T read(Kryo kryo, Input input, Class aClass) {
  try {
    ObjectMap graphContext = kryo.getGraphContext();
    ObjectInputStream objectStream = (ObjectInputStream)graphContext.get(this);
    if (objectStream == null) {
      // make sure we use Kryo's classloader
      objectStream = new InstantiationUtil.ClassLoaderObjectInputStream(input, kryo.getClassLoader());
      graphContext.put(this, objectStream);
    }
    return (T) objectStream.readObject();
  } catch (Exception ex) {
    throw new KryoException("Error during Java deserialization.", ex);
  }
}

代码示例来源:origin: alibaba/jstorm

Class serializerClass = Class.forName(payloadSerializerName, true, k.getClassLoader());
Serializer serializer = resolveSerializerInstance(k, ListDelegate.class, serializerClass, conf);
k.register(ListDelegate.class, serializer);
String serializerClassName = registrations.get(klassName);
try {
  Class klass = Class.forName(klassName, true, k.getClassLoader());
    serializerClass = Class.forName(serializerClassName, true, k.getClassLoader());
  if (serializerClass == null) {
    k.register(klass);
for (String klassName : (List<String>) conf.get(Config.TOPOLOGY_KRYO_DECORATORS)) {
  try {
    Class klass = Class.forName(klassName, true, k.getClassLoader());
    IKryoDecorator decorator = (IKryoDecorator) klass.newInstance();
    decorator.decorate(k);

代码示例来源:origin: org.apache.apex/malhar-library

ObjectInputStreamWithKryoClassLoader(InputStream in, Kryo kryo) throws IOException
{
 super(in);
 this.loader = kryo.getClassLoader();
}

代码示例来源:origin: com.esotericsoftware/kryo

ObjectInputStreamWithKryoClassLoader(InputStream in, Kryo kryo) throws IOException {
  super(in);
  this.loader = kryo.getClassLoader();
}

代码示例来源:origin: com.esotericsoftware/kryo-shaded

ObjectInputStreamWithKryoClassLoader(InputStream in, Kryo kryo) throws IOException {
  super(in);
  this.loader = kryo.getClassLoader();
}

代码示例来源:origin: magro/kryo-serializers

@Override
  public Object copy(final Kryo kryo, final Object original) {
    return Proxy.newProxyInstance( kryo.getClassLoader(), original.getClass().getInterfaces(),
        Proxy.getInvocationHandler(original) );
  }
}

代码示例来源:origin: de.javakaffee/kryo-serializers

@Override
  public Object copy(final Kryo kryo, final Object original) {
    return Proxy.newProxyInstance( kryo.getClassLoader(), original.getClass().getInterfaces(),
        Proxy.getInvocationHandler(original) );
  }
}

代码示例来源:origin: de.javakaffee/kryo-serializers

@Override
public Object read(final Kryo kryo, final Input input, final Class<? extends Object> type) {
  final InvocationHandler invocationHandler = (InvocationHandler) kryo.readClassAndObject( input );
  final Class<?>[] interfaces = kryo.readObject( input, Class[].class );
  final ClassLoader classLoader = kryo.getClassLoader();
  try {
    return Proxy.newProxyInstance( classLoader, interfaces, invocationHandler );
  } catch( final RuntimeException e ) {
    System.err.println( getClass().getName()+ ".read:\n" +
        "Could not create proxy using classLoader " + classLoader + "," +
        " have invocationhandler.classloader: " + invocationHandler.getClass().getClassLoader() +
        " have contextclassloader: " + Thread.currentThread().getContextClassLoader() );
    throw e;
  }
}

代码示例来源:origin: magro/kryo-serializers

@Override
public Object read(final Kryo kryo, final Input input, final Class<? extends Object> type) {
  final InvocationHandler invocationHandler = (InvocationHandler) kryo.readClassAndObject( input );
  final Class<?>[] interfaces = kryo.readObject( input, Class[].class );
  final ClassLoader classLoader = kryo.getClassLoader();
  try {
    return Proxy.newProxyInstance( classLoader, interfaces, invocationHandler );
  } catch( final RuntimeException e ) {
    System.err.println( getClass().getName()+ ".read:\n" +
        "Could not create proxy using classLoader " + classLoader + "," +
        " have invocationhandler.classloader: " + invocationHandler.getClass().getClassLoader() +
        " have contextclassloader: " + Thread.currentThread().getContextClassLoader() );
    throw e;
  }
}

代码示例来源:origin: seznam/euphoria

@Override
 @SuppressWarnings("unchecked")
 public T read(Kryo kryo, Input input, Class<T> type) {
  try {
   synchronized (lock) {
    if (instance == null) {
     final Method method =
       kryo.getClassLoader().loadClass(type.getName()).getMethod(methodName);
     if (!Modifier.isStatic(method.getModifiers())) {
      throw new KryoException(
        "Method " + type.getName() + "#" + methodName + " is not static.");
     }
     instance = (T) method.invoke(null);
    }
    return instance;
   }
  } catch (IllegalAccessException
    | ClassNotFoundException
    | NoSuchMethodException
    | InvocationTargetException e) {
   throw new KryoException(e);
  }
 }
}

代码示例来源:origin: org.apache.beam/beam-runners-spark

@Override
public Object read(Kryo kryo, Input input, Class type) {
 try {
  return new ObjectInputStreamWithClassLoader(input, kryo.getClassLoader()).readObject();
 } catch (Exception e) {
  throw new KryoException("Error during Java deserialization.", e);
 }
}

代码示例来源:origin: seznam/euphoria

@SuppressWarnings("unchecked")
public Object read (Kryo kryo, Input input, Class type) {
 try {
  // ~ InputStream is not closed on purpose because
  // that would also cause a closing of the underling Kryo input
  return new ObjectInputStreamWithClassLoader(input, kryo.getClassLoader()).readObject();
 } catch (Exception e) {
  throw new KryoException("Error during Java deserialization.", e);
 }
}

代码示例来源:origin: org.apache.flink/flink-core

@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public T read(Kryo kryo, Input input, Class aClass) {
  try {
    ObjectMap graphContext = kryo.getGraphContext();
    ObjectInputStream objectStream = (ObjectInputStream)graphContext.get(this);
    if (objectStream == null) {
      // make sure we use Kryo's classloader
      objectStream = new InstantiationUtil.ClassLoaderObjectInputStream(input, kryo.getClassLoader());
      graphContext.put(this, objectStream);
    }
    return (T) objectStream.readObject();
  } catch (Exception ex) {
    throw new KryoException("Error during Java deserialization.", ex);
  }
}

代码示例来源:origin: com.alibaba.blink/flink-core

@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public T read(Kryo kryo, Input input, Class aClass) {
  try {
    ObjectMap graphContext = kryo.getGraphContext();
    ObjectInputStream objectStream = (ObjectInputStream)graphContext.get(this);
    if (objectStream == null) {
      // make sure we use Kryo's classloader
      objectStream = new InstantiationUtil.ClassLoaderObjectInputStream(input, kryo.getClassLoader());
      graphContext.put(this, objectStream);
    }
    return (T) objectStream.readObject();
  } catch (Exception ex) {
    throw new KryoException("Error during Java deserialization.", ex);
  }
}

代码示例来源:origin: com.tinkerpop/gremlin-core

protected Registration readName(final Input input) {
  final int nameId = input.readVarInt(true);
  if (nameIdToClass == null) nameIdToClass = new IntMap<>();
  Class type = nameIdToClass.get(nameId);
  if (type == null) {
    // Only read the class name the first time encountered in object graph.
    final String className = input.readString();
    type = getTypeByName(className);
    if (type == null) {
      try {
        type = Class.forName(className, false, kryo.getClassLoader());
      } catch (ClassNotFoundException ex) {
        throw new KryoException("Unable to find class: " + className, ex);
      }
      if (nameToClass == null) nameToClass = new ObjectMap<>();
      nameToClass.put(className, type);
    }
    nameIdToClass.put(nameId, type);
  }
  return kryo.getRegistration(type);
}

代码示例来源:origin: com.esotericsoftware/kryo

protected Registration readName (Input input) {
  int nameId = input.readVarInt(true);
  if (nameIdToClass == null) nameIdToClass = new IntMap();
  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 ObjectMap();
      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);
}

代码示例来源:origin: com.esotericsoftware/kryo-shaded

protected Registration readName (Input input) {
  int nameId = input.readVarInt(true);
  if (nameIdToClass == null) nameIdToClass = new IntMap();
  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 ObjectMap();
      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);
}

代码示例来源:origin: com.esotericsoftware.kryo/kryo

protected Registration readName (Input input) {
  int nameId = input.readVarInt(true);
  if (nameIdToClass == null) nameIdToClass = new IntMap();
  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) {
        throw new KryoException("Unable to find class: " + className, ex);
      }
      if (nameToClass == null) nameToClass = new ObjectMap();
      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);
}

代码示例来源:origin: svn2github/kryo

protected Registration readName (Input input) {
  int nameId = input.readVarInt(true);
  if (nameIdToClass == null) nameIdToClass = new IntMap();
  Class type = nameIdToClass.get(nameId);
  if (type == null) {
    // Only read the class name the first time encountered in object graph.
    String className = input.readString();
    if (nameToClass != null) type = nameToClass.get(className);
    if (type == null) {
      try {
        type = Class.forName(className, false, kryo.getClassLoader());
      } catch (ClassNotFoundException ex) {
        throw new KryoException("Unable to find class: " + className, ex);
      }
      if (nameToClass == null) nameToClass = new ObjectMap();
      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);
}

相关文章