@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(); }
public void readFields(final DataInput in) throws IOException { this.columnFamily = Bytes.readByteArray(in); if(this.columnFamily.length == 0) { this.columnFamily = null; } this.columnQualifier = Bytes.readByteArray(in); if(this.columnQualifier.length == 0) { this.columnQualifier = null; } this.compareOp = CompareOp.valueOf(in.readUTF()); this.comparator = (WritableByteArrayComparable)HbaseObjectWritable.readObject(in, null); this.foundColumn = in.readBoolean(); this.matchedColumn = in.readBoolean(); this.filterIfMissing = in.readBoolean(); this.latestVersionOnly = in.readBoolean(); }
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(); }
@Test public void testExecDeserialization() throws IOException { DataOutputBuffer dob = new DataOutputBuffer(); dob.writeUTF(methodName); dob.writeInt(1); Scan scan = new Scan(); HbaseObjectWritable.writeObject(dob, scan, Scan.class, new Configuration()); dob.writeUTF("org.apache.hadoop.hbase.client.Scan"); Bytes.writeByteArray(dob, new byte[]{'a'}); // this is the dynamic protocol name dob.writeUTF(protocolName); DataInputBuffer dib = new DataInputBuffer(); dib.reset(dob.getData(), dob.getLength()); Exec after = new Exec(); after.setConf(HBaseConfiguration.create()); after.readFields(dib); // no error thrown assertEquals(after.getProtocolName(), protocolName); assertEquals(after.getMethodName(), methodName); }
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) { long callTime = System.currentTimeMillis() - startTime; LOG.debug("Call: " + method.getName() + " " + callTime); } return value.get(); }
/** * Construct & cache an IPC client with the user-provided SocketFactory * if no cached client exists. * * @param conf Configuration * @param factory socket factory * @return an IPC client */ protected synchronized HBaseClient getClient(Configuration conf, SocketFactory factory) { // Construct & cache client. The configuration is only used for timeout, // and Clients have connection pools. So we can either (a) lose some // connection pooling and leak sockets, or (b) use the same timeout for // all configurations. Since the IPC is usually intended globally, not // per-job, we choose (a). HBaseClient client = clients.get(factory); if (client == null) { // Make an hbase client instead of hadoop Client. client = new HBaseClient(HbaseObjectWritable.class, conf, factory); clients.put(factory, client); } else { client.incCount(); } return client; }
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, 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(); }
@Override public void write(DataOutput out) throws IOException { out.writeInt(actions.size()); for (Map.Entry<byte[], List<Action<R>>> e : actions.entrySet()) { Bytes.writeByteArray(out, e.getKey()); List<Action<R>> lst = e.getValue(); out.writeInt(lst.size()); for (Action a : lst) { HbaseObjectWritable.writeObject(out, a, a.getClass(), null); } } }
@Override public void readFields(DataInput in) throws IOException { actions.clear(); int mapSize = in.readInt(); for (int i = 0; i < mapSize; i++) { byte[] key = Bytes.readByteArray(in); int listSize = in.readInt(); List<Action<R>> lst = new ArrayList<Action<R>>(listSize); for (int j = 0; j < listSize; j++) { lst.add((Action) HbaseObjectWritable.readObject(in, null)); } actions.put(key, lst); } }
@Override public void write(DataOutput out) throws IOException { out.writeInt(results.size()); for (Map.Entry<byte[], List<Pair<Integer, Object>>> e : results.entrySet()) { Bytes.writeByteArray(out, e.getKey()); List<Pair<Integer, Object>> lst = e.getValue(); out.writeInt(lst.size()); for (Pair<Integer, Object> r : lst) { if (r == null) { out.writeInt(-1); // Cant have index -1; on other side we recognize -1 as 'null' } else { out.writeInt(r.getFirst()); // Can this can npe!?! Object obj = r.getSecond(); if (obj instanceof Throwable) { out.writeBoolean(true); // true, Throwable/exception. Throwable t = (Throwable) obj; // serialize exception WritableUtils.writeString(out, t.getClass().getName()); WritableUtils.writeString(out, StringUtils.stringifyException(t)); } else { out.writeBoolean(false); // no exception if (! (obj instanceof Writable)) obj = null; // squash all non-writables to null. HbaseObjectWritable.writeObject(out, r.getSecond(), obj != null ? obj.getClass() : Writable.class, null); } } } } }
@Override public void write(DataOutput out) throws IOException { // fields for Invocation out.writeUTF(this.methodName); out.writeInt(parameterClasses.length); for (int i = 0; i < parameterClasses.length; i++) { HbaseObjectWritable.writeObject(out, parameters[i], parameters[i] != null ? parameters[i].getClass() : parameterClasses[i], conf); out.writeUTF(parameterClasses[i].getName()); } // fields for Exec Bytes.writeByteArray(out, referenceRow); out.writeUTF(protocol.getName()); }
@Override public void readFields(final DataInput in) throws IOException { int version = in.readByte(); if (version > VERSION) { throw new IOException("version not supported"); } this.row = Bytes.readByteArray(in); int numMutations = in.readInt(); mutations.clear(); for(int i = 0; i < numMutations; i++) { mutations.add((Mutation) HbaseObjectWritable.readObject(in, null)); } }
@Override public void write(final DataOutput out) throws IOException { out.writeByte(VERSION); Bytes.writeByteArray(out, this.row); out.writeInt(mutations.size()); for (Mutation m : mutations) { HbaseObjectWritable.writeObject(out, m, m.getClass(), null); } }
public void readFields(final DataInput in) throws IOException { byte opByte = in.readByte(); operator = Operator.values()[opByte]; int size = in.readInt(); if (size > 0) { filters = new ArrayList<Filter>(size); for (int i = 0; i < size; i++) { Filter filter = HbaseObjectWritable.readFilter(in, conf); filters.add(filter); } } }
public void write(final DataOutput out) throws IOException { out.writeByte(operator.ordinal()); out.writeInt(filters.size()); for (Filter filter : filters) { HbaseObjectWritable.writeObject(out, filter, Writable.class, conf); } }