/** * Uses the initialized Kryo instance from the JobConf to test if Kryo will accept the class * * @param aClass * @return */ public boolean accept(Class<?> aClass) { try { return (testKryo.getRegistration(aClass) != null); } catch (IllegalArgumentException e) { return false; } }
@Override public void write(Kryo kryo, Output output) { output.writeInt(objectID, true); int methodClassID = kryo.getRegistration(method.getDeclaringClass()).getId(); output.writeInt(methodClassID, true); CachedMethod[] cachedMethods = getMethods(kryo, method.getDeclaringClass()); CachedMethod cachedMethod = null; for (int i = 0, n = cachedMethods.length; i < n; i++) { cachedMethod = cachedMethods[i]; if (cachedMethod.method.equals(method)) { output.writeByte(i); break; } } for (int i = 0, n = cachedMethod.serializers.length; i < n; i++) { Serializer serializer = cachedMethod.serializers[i]; if (serializer != null) { kryo.writeObjectOrNull(output, args[i], serializer); } else { kryo.writeClassAndObject(output, args[i]); } } output.writeByte(responseID); }
@Override public void read(Kryo kryo, Input input) { objectID = input.readInt(true); int methodClassID = input.readInt(true); Class methodClass = kryo.getRegistration(methodClassID).getType(); byte methodIndex = input.readByte(); CachedMethod cachedMethod; try { cachedMethod = getMethods(kryo, methodClass)[methodIndex]; } catch (IndexOutOfBoundsException ex) { throw new KryoException( "Invalid method index " + methodIndex + " for class: " + methodClass.getName()); } method = cachedMethod.method; args = new Object[cachedMethod.serializers.length]; for (int i = 0, n = args.length; i < n; i++) { Serializer serializer = cachedMethod.serializers[i]; if (serializer != null) { args[i] = kryo.readObjectOrNull(input, method.getParameterTypes()[i], serializer); } else { args[i] = kryo.readClassAndObject(input); } } responseID = input.readByte(); }
/** * Checks if the given class is registered with the RPC service. * * @param throwableType the class to check * @return <code>true</code> if the given class is registered with the RPC service, <code>false * </code> otherwise */ private boolean isThrowableRegistered(final Class<? extends Throwable> throwableType) { final Kryo kryo = KryoUtil.getKryo(); try { kryo.getRegistration(throwableType); } catch (final IllegalArgumentException e) { return false; } return true; }