Example usage for org.apache.hadoop.util ReflectionUtils copy

List of usage examples for org.apache.hadoop.util ReflectionUtils copy

Introduction

In this page you can find the example usage for org.apache.hadoop.util ReflectionUtils copy.

Prototype

@SuppressWarnings("unchecked")
public static <T> T copy(Configuration conf, T src, T dst) throws IOException 

Source Link

Document

Make a copy of the writable object using serialization to a buffer

Usage

From source file:com.kylinolap.job.hadoop.invertedindex.RandomKeyDistributionMapper.java

License:Apache License

@SuppressWarnings("unchecked")
@Override/*w w w  .  j a  va2s . c  o  m*/
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);
}

From source file:com.kylinolap.job.hadoop.invertedindex.RandomKeyDistributionReducer.java

License:Apache License

@SuppressWarnings("unchecked")
@Override/*  w w w  . j a  v  a2  s  .  co m*/
public void reduce(KEY key, Iterable<NullWritable> values, Context context)
        throws IOException, InterruptedException {
    KEY keyCopy = (KEY) ReflectionUtils.newInstance(key.getClass(), conf);
    ReflectionUtils.copy(conf, key, keyCopy);
    allSplits.add(keyCopy);
}

From source file:main.okapi.common.computation.ReverseEdges.java

License:Apache License

@Override
public void compute(Vertex<I, V, E> vertex, Iterable<MessageWrapper<I, M1>> messages) throws IOException {
    for (MessageWrapper<I, M1> msg : messages) {
        E edgeValue = vertex.getEdgeValue(msg.getSourceId());

        if (edgeValue == null) {
            I clonedId = null;/*from   w w w.ja v  a 2  s. c  o m*/
            E clonedEdgeValue = null;

            try {
                clonedId = (I) msg.getSourceId().getClass().newInstance();
                clonedEdgeValue = (E) msg.getMessage().getClass().newInstance();
            } catch (InstantiationException e) {
                throw new IOException(e);
            } catch (IllegalAccessException e) {
                throw new IOException(e);
            }

            ReflectionUtils.copy(getContext().getConfiguration(), msg.getSourceId(), clonedId);
            ReflectionUtils.copy(getContext().getConfiguration(), msg.getMessage(), clonedEdgeValue);

            Edge<I, E> edge = EdgeFactory.create(clonedId, clonedEdgeValue);
            vertex.addEdge(edge);
        }
    }
}

From source file:org.apache.accumulo.server.data.ServerMutationTest.java

License:Apache License

@Test
public void test() throws Exception {
    ServerMutation m = new ServerMutation(new Text("r1"));
    m.put(new Text("cf1"), new Text("cq1"), new Value("v1".getBytes()));
    m.put(new Text("cf2"), new Text("cq2"), 56, new Value("v2".getBytes()));
    m.setSystemTimestamp(42);/*from   w  w w  .  j  av a2s .  c o  m*/

    List<ColumnUpdate> updates = m.getUpdates();

    assertEquals(2, updates.size());

    assertEquals("r1", new String(m.getRow()));
    ColumnUpdate cu = updates.get(0);

    assertEquals("cf1", new String(cu.getColumnFamily()));
    assertEquals("cq1", new String(cu.getColumnQualifier()));
    assertEquals("", new String(cu.getColumnVisibility()));
    assertFalse(cu.hasTimestamp());
    assertEquals(42l, cu.getTimestamp());

    ServerMutation m2 = new ServerMutation();
    ReflectionUtils.copy(CachedConfiguration.getInstance(), m, m2);

    updates = m2.getUpdates();

    assertEquals(2, updates.size());
    assertEquals("r1", new String(m2.getRow()));

    cu = updates.get(0);
    assertEquals("cf1", new String(cu.getColumnFamily()));
    assertEquals("cq1", new String(cu.getColumnQualifier()));
    assertFalse(cu.hasTimestamp());
    assertEquals(42l, cu.getTimestamp());

    cu = updates.get(1);

    assertEquals("r1", new String(m2.getRow()));
    assertEquals("cf2", new String(cu.getColumnFamily()));
    assertEquals("cq2", new String(cu.getColumnQualifier()));
    assertTrue(cu.hasTimestamp());
    assertEquals(56, cu.getTimestamp());

}