/** * Read a {@link Writable}, {@link String}, primitive type, or an array of * the preceding. * @param in * @param conf * @return the object * @throws IOException */ public static Object readObject(DataInput in, Configuration conf) throws IOException { return readObject(in, null, conf); }
public void write(DataOutput out) throws IOException { writeObject(out, instance, declaredClass, conf); }
public long getWritableSize() { return getWritableSize(instance, declaredClass, conf); }
instance = Array.newInstance(declaredClass.getComponentType(), length); for (int i = 0; i < length; i++) { Array.set(instance, i, readObject(in, conf)); Class<?> componentType = readClass(conf, in); int length = in.readInt(); instance = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Array.set(instance, i, readObject(in, conf)); instance = new ArrayList(length); for (int i = 0; i < length; i++) { ((ArrayList)instance).add(readObject(in, conf)); String className = Text.readString(in); try { declaredClass = getClassByName(conf, className); instance = tryInstantiateProtobuf(declaredClass, in); } catch (ClassNotFoundException e) { LOG.error("Can't find class " + className, e); String className = Text.readString(in); try { instanceClass = getClassByName(conf, className); } catch (ClassNotFoundException e) { LOG.error("Can't find class " + className, e);
declClass = Writable.class; writeClassCode(out, declClass); if (declClass.isArray()) { // array } else { if (getClassCode(declaredClass) == GENERIC_ARRAY_CODE) { Class<?> componentType = declaredClass.getComponentType(); writeClass(out, componentType); for (int i = 0; i < length; i++) { Object item = Array.get(instanceObj, i); writeObject(out, item, item.getClass(), conf); for (int i = 0; i < length; i++) { Object elem = list.get(i); writeObject(out, elem, elem == null ? Writable.class : elem.getClass(), conf); Text.writeString(out, c.getName()); } else { writeClassCode(out, c); Text.writeString(out, c.getName()); } else { writeClassCode(out, c);
HbaseObjectWritable objectWritable = new HbaseObjectWritable(); for (int i = 0; i < parameters.length; i++) { parameters[i] = HbaseObjectWritable.readObject(in, objectWritable, this.conf); parameterClasses[i] = objectWritable.getDeclaredClass();
@Override public void readFields(DataInput in) throws IOException { // fields for Invocation methodName = in.readUTF(); parameters = new Object[in.readInt()]; parameterClasses = new Class[parameters.length]; HbaseObjectWritable objectWritable = new HbaseObjectWritable(); for (int i = 0; i < parameters.length; i++) { parameters[i] = HbaseObjectWritable.readObject(in, objectWritable, this.conf); String parameterClassName = in.readUTF(); try { parameterClasses[i] = Classes.extendedForName(parameterClassName); } catch (ClassNotFoundException e) { throw new IOException("Couldn't find class: " + parameterClassName); } } // fields for Exec referenceRow = Bytes.readByteArray(in); protocolName = in.readUTF(); } }
new HbaseObjectWritable(method.getReturnType(), value); long responseSize = retVal.getWritableSize();
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { final boolean logDebug = LOG.isDebugEnabled(); long startTime = 0; if (logDebug) { startTime = System.currentTimeMillis(); } HbaseObjectWritable value = (HbaseObjectWritable) client.call(new Invocation(method, protocol, args), address, protocol, ticket, rpcTimeout); if (logDebug) { // FIGURE HOW TO TURN THIS OFF! long callTime = System.currentTimeMillis() - startTime; LOG.debug("Call: " + method.getName() + " " + callTime); } return value.get(); } }
/** * Write out the code for passed Class. * @param out * @param c * @throws IOException */ static void writeClassCode(final DataOutput out, final Class<?> c) throws IOException { Integer code = getClassCode(c); if (code == null) { LOG.error("Unsupported type " + c); StackTraceElement[] els = new Exception().getStackTrace(); for(StackTraceElement elem : els) { LOG.error(elem.getMethodName()); } throw new UnsupportedOperationException("No code for unexpected " + c); } WritableUtils.writeVInt(out, code); }
/** Reads and returns the class as written by {@link #writeClass(DataOutput, Class)} */ static Class<?> readClass(Configuration conf, DataInput in) throws IOException { Class<?> instanceClass = null; int b = (byte)WritableUtils.readVInt(in); if (b == NOT_ENCODED) { String className = Text.readString(in); try { instanceClass = getClassByName(conf, className); } catch (ClassNotFoundException e) { LOG.error("Can't find class " + className, e); throw new IOException("Can't find class " + className, e); } } else { instanceClass = CODE_TO_CLASS.get(b); } return instanceClass; }
Method parseMethod = getStaticProtobufMethod(protoClass, "parseDelimitedFrom", InputStream.class); return (Message)parseMethod.invoke(null, (InputStream)dataIn); Method parseMethod = getStaticProtobufMethod(protoClass, "parseFrom", byte[].class); return (Message)parseMethod.invoke(null, data);
result = new HbaseObjectWritable(value);
/** Expert: Make multiple, parallel calls to a set of servers. */ @Override public Object[] call(Method method, Object[][] params, InetSocketAddress[] addrs, Class<? extends VersionedProtocol> protocol, User ticket, Configuration conf) throws IOException, InterruptedException { if (this.client == null) { throw new IOException("Client must be initialized by calling setConf(Configuration)"); } Invocation[] invocations = new Invocation[params.length]; for (int i = 0; i < params.length; i++) { invocations[i] = new Invocation(method, protocol, params[i]); } Writable[] wrappedValues = client.call(invocations, addrs, protocol, ticket); if (method.getReturnType() == Void.TYPE) { return null; } Object[] values = (Object[])Array.newInstance(method.getReturnType(), wrappedValues.length); for (int i = 0; i < values.length; i++) { if (wrappedValues[i] != null) { values[i] = ((HbaseObjectWritable)wrappedValues[i]).get(); } } return values; }
public void write(final DataOutput out) throws IOException { HbaseObjectWritable.writeObject(out, action, Row.class, null); out.writeInt(originalIndex); HbaseObjectWritable.writeObject(out, result, result != null ? result.getClass() : Writable.class, null); }
public void readFields(DataInput in) throws IOException { readObject(in, this, this.conf); }
public void write(DataOutput out) throws IOException { out.writeUTF(compareOp.name()); HbaseObjectWritable.writeObject(out, comparator, WritableByteArrayComparable.class, null); }
public void readFields(final DataInput in) throws IOException { this.action = (Row) HbaseObjectWritable.readObject(in, null); this.originalIndex = in.readInt(); this.result = (R) HbaseObjectWritable.readObject(in, null); }
@Override public void write(DataOutput out) throws IOException { Bytes.writeByteArray(out, regionName); HbaseObjectWritable.writeObject(out, value, value != null ? value.getClass() : Writable.class, null); }
public void readFields(DataInput in) throws IOException { compareOp = CompareOp.valueOf(in.readUTF()); comparator = (WritableByteArrayComparable) HbaseObjectWritable.readObject(in, null); }