Java Code Examples for org.apache.hadoop.util.ReflectionUtils#copy()

The following examples show how to use org.apache.hadoop.util.ReflectionUtils#copy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: RDFS   File: WritableUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Make a copy of a writable object using serialization to a buffer.
 * @param orig The object to copy
 * @return The copied object
 */
public static <T extends Writable> T clone(T orig, Configuration conf) {
  try {
    @SuppressWarnings("unchecked") // Unchecked cast from Class to Class<T>
    T newInst = ReflectionUtils.newInstance((Class<T>) orig.getClass(), conf);
    ReflectionUtils.copy(conf, orig, newInst);
    return newInst;
  } catch (IOException e) {
    throw new RuntimeException("Error writing/reading clone buffer", e);
  }
}
 
Example 2
Source Project: hadoop   File: MultiFilterRecordReader.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public boolean nextKeyValue() throws IOException, InterruptedException {
  if (key == null) {
    key = createKey();
  }
  if (value == null) {
    value = createValue();
  }
  if (jc.flush(ivalue)) {
    ReflectionUtils.copy(conf, jc.key(), key);
    ReflectionUtils.copy(conf, emit(ivalue), value);
    return true;
  }
  if (ivalue == null) {
    ivalue = createTupleWritable();
  }
  jc.clear();
  final PriorityQueue<ComposableRecordReader<K,?>> q = 
          getRecordReaderQueue();
  K iterkey = createKey();
  while (q != null && !q.isEmpty()) {
    fillJoinCollector(iterkey);
    jc.reset(iterkey);
    if (jc.flush(ivalue)) {
      ReflectionUtils.copy(conf, jc.key(), key);
      ReflectionUtils.copy(conf, emit(ivalue), value);
      return true;
    }
    jc.clear();
  }
  return false;
}
 
Example 3
Source Project: hadoop   File: MultiFilterRecordReader.java    License: Apache License 2.0 5 votes vote down vote up
public boolean next(V val) throws IOException {
  boolean ret;
  if (ret = jc.flush(ivalue)) {
    ReflectionUtils.copy(getConf(), emit(ivalue), val);
  }
  return ret;
}
 
Example 4
Source Project: hadoop-gpu   File: MultithreadedMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
  synchronized (outer) {
    if (!outer.nextKeyValue()) {
      return false;
    }
    key = ReflectionUtils.copy(outer.getConfiguration(),
                               outer.getCurrentKey(), key);
    value = ReflectionUtils.copy(conf, outer.getCurrentValue(), value);
    return true;
  }
}
 
Example 5
@SuppressWarnings("unchecked")
@Override
public void map(KEY key, VALUE value, Context context) throws IOException, InterruptedException {
    KEY keyCopy = (KEY) ReflectionUtils.newInstance(key.getClass(), conf);
    ReflectionUtils.copy(conf, key, keyCopy);
    allKeys.add(keyCopy);
}
 
Example 6
Source Project: hadoop   File: Chain.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private boolean readFromQueue() throws IOException, InterruptedException {
  KeyValuePair<KEYIN, VALUEIN> kv = null;

  // wait for input on queue
  kv = inputQueue.dequeue();
  if (kv.endOfInput) {
    return false;
  }
  key = (KEYIN) ReflectionUtils.newInstance(keyClass, conf);
  value = (VALUEIN) ReflectionUtils.newInstance(valueClass, conf);
  ReflectionUtils.copy(conf, kv.key, this.key);
  ReflectionUtils.copy(conf, kv.value, this.value);
  return true;
}
 
Example 7
Source Project: big-c   File: WritableUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Make a copy of a writable object using serialization to a buffer.
 * @param orig The object to copy
 * @return The copied object
 */
public static <T extends Writable> T clone(T orig, Configuration conf) {
  try {
    @SuppressWarnings("unchecked") // Unchecked cast from Class to Class<T>
    T newInst = ReflectionUtils.newInstance((Class<T>) orig.getClass(), conf);
    ReflectionUtils.copy(conf, orig, newInst);
    return newInst;
  } catch (IOException e) {
    throw new RuntimeException("Error writing/reading clone buffer", e);
  }
}
 
Example 8
Source Project: big-c   File: Chain.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void writeToQueue(KEYOUT key, VALUEOUT value) throws IOException,
    InterruptedException {
  this.keyout = (KEYOUT) ReflectionUtils.newInstance(keyClass, conf);
  this.valueout = (VALUEOUT) ReflectionUtils.newInstance(valueClass, conf);
  ReflectionUtils.copy(conf, key, this.keyout);
  ReflectionUtils.copy(conf, value, this.valueout);

  // wait to write output to queuue
  outputQueue.enqueue(new KeyValuePair<KEYOUT, VALUEOUT>(keyout, valueout));
}
 
Example 9
Source Project: hadoop-gpu   File: WritableUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Make a copy of a writable object using serialization to a buffer.
 * @param orig The object to copy
 * @return The copied object
 */
public static <T extends Writable> T clone(T orig, Configuration conf) {
  try {
    @SuppressWarnings("unchecked") // Unchecked cast from Class to Class<T>
    T newInst = ReflectionUtils.newInstance((Class<T>) orig.getClass(), conf);
    ReflectionUtils.copy(conf, orig, newInst);
    return newInst;
  } catch (IOException e) {
    throw new RuntimeException("Error writing/reading clone buffer", e);
  }
}
 
Example 10
Source Project: big-c   File: MultithreadedMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
  synchronized (outer) {
    if (!outer.nextKeyValue()) {
      return false;
    }
    key = ReflectionUtils.copy(outer.getConfiguration(),
                               outer.getCurrentKey(), key);
    value = ReflectionUtils.copy(conf, outer.getCurrentValue(), value);
    return true;
  }
}
 
Example 11
Source Project: hbase   File: MultithreadedTableMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
  synchronized (outer) {
    if (!outer.nextKeyValue()) {
      return false;
    }
    key = ReflectionUtils.copy(outer.getConfiguration(),
        outer.getCurrentKey(), key);
    value = ReflectionUtils.copy(conf, outer.getCurrentValue(), value);
    return true;
  }
}
 
Example 12
Source Project: big-c   File: MultiFilterRecordReader.java    License: Apache License 2.0 5 votes vote down vote up
public boolean next(V val) throws IOException {
  boolean ret;
  if (ret = jc.flush(ivalue)) {
    ReflectionUtils.copy(getConf(), emit(ivalue), val);
  }
  return ret;
}
 
Example 13
Source Project: big-c   File: JoinRecordReader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Emit the next set of key, value pairs as defined by the child
 * RecordReaders and operation associated with this composite RR.
 */
public boolean nextKeyValue() 
    throws IOException, InterruptedException {
  if (key == null) {
    key = createKey();
  }
  if (jc.flush(value)) {
    ReflectionUtils.copy(conf, jc.key(), key);
    return true;
  }
  jc.clear();
  if (value == null) {
    value = createValue();
  }
  final PriorityQueue<ComposableRecordReader<K,?>> q = 
          getRecordReaderQueue();
  K iterkey = createKey();
  while (q != null && !q.isEmpty()) {
    fillJoinCollector(iterkey);
    jc.reset(iterkey);
    if (jc.flush(value)) {
      ReflectionUtils.copy(conf, jc.key(), key);
      return true;
    }
    jc.clear();
  }
  return false;
}
 
Example 14
Source Project: big-c   File: ArrayListBackedIterator.java    License: Apache License 2.0 5 votes vote down vote up
public boolean next(X val) throws IOException {
  if (iter.hasNext()) {
    ReflectionUtils.copy(conf, iter.next(), val);
    if (null == hold) {
      hold = WritableUtils.clone(val, null);
    } else {
      ReflectionUtils.copy(conf, val, hold);
    }
    return true;
  }
  return false;
}
 
Example 15
Source Project: RDFS   File: MultithreadedMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
  synchronized (outer) {
    if (!outer.nextKeyValue()) {
      return false;
    }
    key = ReflectionUtils.copy(outer.getConfiguration(),
                               outer.getCurrentKey(), key);
    value = ReflectionUtils.copy(conf, outer.getCurrentValue(), value);
    return true;
  }
}
 
Example 16
Source Project: big-c   File: Chain.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private boolean readFromQueue() throws IOException, InterruptedException {
  KeyValuePair<KEYIN, VALUEIN> kv = null;

  // wait for input on queue
  kv = inputQueue.dequeue();
  if (kv.endOfInput) {
    return false;
  }
  key = (KEYIN) ReflectionUtils.newInstance(keyClass, conf);
  value = (VALUEIN) ReflectionUtils.newInstance(valueClass, conf);
  ReflectionUtils.copy(conf, kv.key, this.key);
  ReflectionUtils.copy(conf, kv.value, this.value);
  return true;
}
 
Example 17
Source Project: hadoop   File: MultiFilterRecordReader.java    License: Apache License 2.0 4 votes vote down vote up
public boolean replay(V val) throws IOException {
  ReflectionUtils.copy(getConf(), emit(ivalue), val);
  return true;
}
 
Example 18
Source Project: hadoop   File: ArrayListBackedIterator.java    License: Apache License 2.0 4 votes vote down vote up
public boolean replay(X val) throws IOException {
  ReflectionUtils.copy(conf, hold, val);
  return true;
}
 
Example 19
Source Project: hadoop   File: WrappedRecordReader.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Clone the key at the head of this RR into the object supplied.
 */
public void key(K qkey) throws IOException {
  ReflectionUtils.copy(conf, key, qkey);
}
 
Example 20
Source Project: big-c   File: MultiFilterRecordReader.java    License: Apache License 2.0 4 votes vote down vote up
public boolean replay(V val) throws IOException {
  ReflectionUtils.copy(getConf(), emit(ivalue), val);
  return true;
}