Michael Blow has uploaded a new change for review. https://asterix-gerrit.ics.uci.edu/3149
Change subject: [NO ISSUE] Compatibility improvements ...................................................................... [NO ISSUE] Compatibility improvements Change-Id: Idde612dace51121f1e5bc91519e9236b7e4f96a4 --- M hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/comm/IJavaSerializationProvider.java M hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/JavaSerializationUtils.java M hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/controllers/NodeRegistration.java M hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityUtil.java 4 files changed, 56 insertions(+), 17 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/49/3149/1 diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/comm/IJavaSerializationProvider.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/comm/IJavaSerializationProvider.java index deaa966..46d68a0 100644 --- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/comm/IJavaSerializationProvider.java +++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/comm/IJavaSerializationProvider.java @@ -36,4 +36,8 @@ default void readObject(ObjectInputStream in, Object object) throws IOException, ClassNotFoundException { in.defaultReadObject(); } + + default void writeObject(ObjectOutputStream out, Object object) throws IOException { + out.defaultWriteObject(); + } } diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/JavaSerializationUtils.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/JavaSerializationUtils.java index 56e15a4..8e24204 100644 --- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/JavaSerializationUtils.java +++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/JavaSerializationUtils.java @@ -101,6 +101,10 @@ serProvider.readObject(in, object); } + public static void writeObject(ObjectOutputStream out, Object object) throws IOException { + serProvider.writeObject(out, object); + } + private static class ClassLoaderObjectInputStream extends ObjectInputStream { private ClassLoader classLoader; diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/controllers/NodeRegistration.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/controllers/NodeRegistration.java index f76d9b8..2817e7d 100644 --- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/controllers/NodeRegistration.java +++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/controllers/NodeRegistration.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.Serializable; import java.net.InetSocketAddress; import java.util.HashMap; @@ -45,10 +46,6 @@ private final InetSocketAddress ncAddress; private final String nodeId; - - @Deprecated // required for binary backward-compatibility when registering with a 0.9.4 CC - @SuppressWarnings("unused") - private final NCConfig ncConfig; private final NetworkAddress dataPort; @@ -115,7 +112,6 @@ for (IOption option : cfg.getOptions()) { config.put(option.toSerializable(), cfg.get(option)); } - this.ncConfig = null; } public InetSocketAddress getNodeControllerAddress() { @@ -206,4 +202,7 @@ JavaSerializationUtils.readObject(in, this); } + private void writeObject(ObjectOutputStream out) throws IOException { + JavaSerializationUtils.writeObject(out, this); + } } \ No newline at end of file diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityUtil.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityUtil.java index 65da9fe..f83a175 100644 --- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityUtil.java +++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/CompatibilityUtil.java @@ -41,28 +41,60 @@ return prevLevel; } - public static Object readField(Object obj, String fieldName) throws IOException { - Class<?> objClass = obj.getClass(); - LOGGER.debug("reading field '{}' on object of type {}", fieldName, objClass); + public static Field getAccessibleField(Class<?> clazz, String fieldName) { + Field f = null; try { - Field f = objClass.getDeclaredField(fieldName); - f.setAccessible(true); + f = clazz.getDeclaredField(fieldName); + } catch (NoSuchFieldException e) { + throw new IllegalStateException(e); + } + f.setAccessible(true); + return f; + } + + public static Field getAccessibleField(Object obj, String fieldName) { + Class<?> cl = obj.getClass(); + while (true) { + Field f = null; + try { + f = getAccessibleField(cl, fieldName); + return f; + } catch (IllegalStateException e) { + cl = cl.getSuperclass(); + if (cl == null) { + throw new IllegalStateException("no such field: '" + fieldName + "' found in " + obj.getClass()); + } + } + } + } + + public static Object readField(Object obj, String fieldName) throws IOException { + return readField(obj, getAccessibleField(obj, fieldName)); + } + + public static Object readField(Object obj, Field f) throws IOException { + Class<?> objClass = obj.getClass(); + LOGGER.debug("reading field '{}' on object of type {}", f::getName, objClass::toString); + try { return f.get(obj); - } catch (NoSuchFieldException | IllegalAccessException e) { - LOGGER.warn("exception reading field '{}' on object of type {}", fieldName, objClass, e); + } catch (IllegalAccessException e) { + LOGGER.warn("exception reading field '{}' on object of type {}", f.getName(), objClass, e); throw new IOException(e); } } public static void writeField(Object obj, String fieldName, Object newValue) throws IOException { + writeField(obj, getAccessibleField(obj, fieldName), newValue); + } + + public static void writeField(Object obj, Field f, Object newValue) throws IOException { Class<?> objClass = obj.getClass(); - LOGGER.debug("updating field '{}' on object of type {} to {}", fieldName, objClass, newValue); + LOGGER.debug("updating field '{}' on object of type {} to {}", f::getName, objClass::toString, + newValue::toString); try { - Field f = objClass.getDeclaredField(fieldName); - f.setAccessible(true); f.set(obj, newValue); - } catch (NoSuchFieldException | IllegalAccessException e) { - LOGGER.warn("exception updating field '{}' object of type {} to {}", fieldName, objClass, newValue, e); + } catch (IllegalAccessException e) { + LOGGER.warn("exception updating field '{}' object of type {} to {}", f.getName(), objClass, newValue, e); throw new IOException(e); } } -- To view, visit https://asterix-gerrit.ics.uci.edu/3149 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idde612dace51121f1e5bc91519e9236b7e4f96a4 Gerrit-PatchSet: 1 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Michael Blow <mb...@apache.org>