Example usage for org.apache.hadoop.io LongWritable get

List of usage examples for org.apache.hadoop.io LongWritable get

Introduction

In this page you can find the example usage for org.apache.hadoop.io LongWritable get.

Prototype

public long get() 

Source Link

Document

Return the value of this LongWritable.

Usage

From source file:org.apache.giraph.conf.TestObjectCreation.java

License:Apache License

@Test
public void testReflectionUtilsNewInstance() throws IllegalAccessException, InstantiationException {
    // Throwaway to put into cache
    org.apache.hadoop.util.ReflectionUtils.newInstance(LongWritable.class, null);
    startNanos = TIME.getNanoseconds();/*from w w  w. j ava  2  s.  c o m*/
    for (int i = 0; i < COUNT; ++i) {
        LongWritable value = (LongWritable) org.apache.hadoop.util.ReflectionUtils
                .newInstance(getLongWritableClass(), null);
        value.set(i);
        total += value.get();
    }
}

From source file:org.apache.giraph.conf.TestObjectCreation.java

License:Apache License

@Test
public void testConstructorNewInstance() throws IllegalAccessException, InstantiationException,
        NoSuchMethodException, InvocationTargetException {
    Constructor<?> constructor = LongWritable.class.getDeclaredConstructor(new Class[] {});
    startNanos = TIME.getNanoseconds();/*from   w w  w .  ja  va2 s  .  co  m*/
    for (int i = 0; i < COUNT; ++i) {
        LongWritable value = (LongWritable) constructor.newInstance();
        value.set(i);
        total += value.get();
    }
}

From source file:org.apache.giraph.conf.TestObjectCreation.java

License:Apache License

@Test
public void testImmutableClassesGiraphConfigurationNewInstance() {
    startNanos = TIME.getNanoseconds();//www .j a  v  a  2s .c  o m
    for (int i = 0; i < COUNT; ++i) {
        LongWritable value = getConfiguration().createVertexValue();
        value.set(i);
        total += value.get();
    }
}

From source file:org.apache.giraph.debugger.examples.graphcoloring.GraphColoringDebugConfig.java

License:Apache License

@Override
public boolean isMessageCorrect(LongWritable srcId, LongWritable dstId, Message message, long superstepNo) {
    // TODO check message type validity based on phase
    // TODO check message type validity based on sender and receiver's state
    return message.getType() != null && srcId.get() != dstId.get();
}

From source file:org.apache.giraph.debugger.examples.instrumented.BuggySimpleShortestPathsDebugComputationModified.java

License:Apache License

@Override
public void compute(Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
        Iterable<DoubleWritable> messages) throws IOException {
    // We do a dummy read of the aggregator below because for now we only
    // intercept an aggregator
    // if at least one vertex reads it.
    LongWritable aggregatedValue = getAggregatedValue(
            SimpleShortestPathsMaster.NV_DISTANCE_LESS_THAN_THREE_AGGREGATOR);
    if (aggregatedValue != null) {
        System.out.print("NV_DISTANCE_LESS_THAN_THREE_AGGREGATOR: " + aggregatedValue.get() + "\n");
    }//from w  ww .  jav  a2  s. c o  m
    if (getSuperstep() == 0) {
        vertex.setValue(new DoubleWritable(isSource(vertex) ? 0d : Double.MAX_VALUE));
    }
    double previousValue = vertex.getValue().get();
    double minDist = previousValue;
    for (DoubleWritable message : messages) {
        minDist = Math.min(minDist, message.get());
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Vertex " + vertex.getId() + " got minDist = " + minDist + " vertex value = "
                + vertex.getValue());
    }
    if (minDist < vertex.getValue().get() || getSuperstep() == 0 && minDist == 0) {
        vertex.setValue(new DoubleWritable(minDist));
        for (Edge<LongWritable, FloatWritable> edge : vertex.getEdges()) {
            double distance = minDist + edge.getValue().get();
            if (LOG.isDebugEnabled()) {
                LOG.debug(
                        "Vertex " + vertex.getId() + " sent to " + edge.getTargetVertexId() + " = " + distance);
            }
            // INTENTIONAL BUG:Instead of sending the distance (i.e. by adding edge
            // values),
            // we send the vertex value.
            sendMessage(edge.getTargetVertexId(), new DoubleWritable(minDist));
        }
    }
    if (previousValue > 3 && minDist <= 3) {
        aggregate(SimpleShortestPathsMaster.NV_DISTANCE_LESS_THAN_THREE_AGGREGATOR, new LongWritable(1));
    }
    vertex.voteToHalt();
}

From source file:org.apache.giraph.debugger.examples.integrity.BuggyConnectedComponentsComputation.java

License:Apache License

/**
 * Propagates the smallest vertex id to all neighbors. Will always choose to
 * halt and only reactivate if a smaller id has been sent to it.
 *
 * @param vertex/*  w ww.  j a  v  a  2  s  .  c o m*/
 *          Vertex
 * @param messages
 *          Iterator of messages from the previous superstep.
 * @throws IOException
 */
@Override
public void compute(Vertex<LongWritable, LongWritable, NullWritable> vertex, Iterable<LongWritable> messages)
        throws IOException {
    long currentComponent = vertex.getValue().get();

    if (getSuperstep() == 0) {
        vertex.setValue(vertex.getId());
        for (Edge<LongWritable, NullWritable> edge : vertex.getEdges()) {
            sendMessage(edge.getTargetVertexId(), vertex.getValue());
        }
        vertex.voteToHalt();
        return;
    }

    boolean changed = false;
    // did we get a smaller id ?
    for (LongWritable message : messages) {
        long candidateComponent = message.get();
        // INTENTIONAL BUG: in the original algorithm the value of the comparison
        // sign should be <.
        // We note that this algorithm will end up finding the components
        // correctly, but the ID of
        // each component will be the minimum vertex ID in the component.
        // In the original
        // org.apache.giraph.examples.ConnectedComponentsComputation, the ID of
        // each
        // component is the maximum vertex ID in the component.
        if (candidateComponent > currentComponent) {
            currentComponent = candidateComponent;
            changed = true;
        }
    }

    // propagate new component id to the neighbors
    if (changed) {
        vertex.setValue(new LongWritable(currentComponent));
        for (Edge<LongWritable, NullWritable> edge : vertex.getEdges()) {
            sendMessage(edge.getTargetVertexId(), vertex.getValue());
        }
    }
    vertex.voteToHalt();
}

From source file:org.apache.giraph.debugger.examples.integrity.CCFindingMissingReverseEdgeMsgIntegrityDebugConfig.java

License:Apache License

@Override
public boolean isMessageCorrect(LongWritable srcId, LongWritable dstId, LongWritable message,
        long superstepNo) {
    if (superstepNo == 1) {
        return message.get() >= dstId.get();
    } else {/*from   w w w. j a  v a 2s.  c  o m*/
        return true;
    }
}

From source file:org.apache.giraph.debugger.examples.integrity.ConnectedComponentsDebugConfig.java

License:Apache License

@Override
public boolean isVertexValueCorrect(LongWritable vertexId, LongWritable value) {
    return value.get() <= vertexId.get();
}

From source file:org.apache.giraph.debugger.examples.integrity.ConnectedComponentsDebugConfig.java

License:Apache License

@Override
public boolean isMessageCorrect(LongWritable srcId, LongWritable dstId, LongWritable message,
        long superstepNo) {
    return message.get() <= srcId.get();
}

From source file:org.apache.giraph.debugger.examples.mwm.MWMComputation.java

License:Apache License

@Override
public void compute(Vertex<LongWritable, VertexValue, DoubleWritable> vertex, Iterable<LongWritable> messages)
        throws IOException {
    if (getSuperstep() > 500) {
        vertex.voteToHalt();//from  w  w  w  .j  a  va2s.c o m
    }
    long phase = getSuperstep() % 2;
    if (vertex.getValue().isMatched() || vertex.getNumEdges() == 0) {
        vertex.voteToHalt();
        return;
    }
    if (phase == 0) {
        removeEdges(vertex, messages);
        if (vertex.getNumEdges() == 0) {
            vertex.voteToHalt();
            return;
        }
        long maxValueVertexID = pickMaxValueVertex(vertex);
        vertex.getValue().setMatchedID(maxValueVertexID);
        vertex.setValue(vertex.getValue());
        sendMessage(new LongWritable(maxValueVertexID), vertex.getId());
    } else if (phase == 1) {
        long matchedID = vertex.getValue().getMatchedID();
        boolean isMatched = false;
        for (LongWritable matchingVertexID : messages) {
            if (matchingVertexID.get() == matchedID) {
                isMatched = true;
                break;
            }
        }
        if (isMatched) {
            vertex.getValue().setMatched(true);
            vertex.setValue(vertex.getValue());
            sendMessageToAllEdges(vertex, vertex.getId());
            vertex.voteToHalt();
        }
    }
}