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.edge.LongNullHashSetEdges.java

License:Apache License

@Override
public NullWritable getEdgeValue(LongWritable targetVertexId) {
    if (neighbors.contains(targetVertexId.get())) {
        return NullWritable.get();
    } else {/*from   w ww . ja va2 s.c  om*/
        return null;
    }
}

From source file:org.apache.giraph.edge.primitives.LongEdgeStore.java

License:Apache License

@Override
protected OutEdges<LongWritable, E> getVertexOutEdges(
        VertexIdEdgeIterator<LongWritable, E> vertexIdEdgeIterator,
        Map<Long, OutEdges<LongWritable, E>> partitionEdgesIn) {
    Long2ObjectMap<OutEdges<LongWritable, E>> partitionEdges = (Long2ObjectMap<OutEdges<LongWritable, E>>) partitionEdgesIn;
    LongWritable vertexId = vertexIdEdgeIterator.getCurrentVertexId();
    OutEdges<LongWritable, E> outEdges = partitionEdges.get(vertexId.get());
    if (outEdges == null) {
        synchronized (partitionEdges) {
            outEdges = partitionEdges.get(vertexId.get());
            if (outEdges == null) {
                outEdges = configuration.createAndInitializeInputOutEdges();
                partitionEdges.put(vertexId.get(), outEdges);
            }//  ww w . j  a v a2  s .  c  om
        }
    }
    return outEdges;
}

From source file:org.apache.giraph.examples.ColoringComputation.java

License:Apache License

@Override
public void compute(Vertex<LongWritable, LongWritable, NullWritable> vertex, Iterable<LongWritable> messages)
        throws IOException {

    // initialization (no serializability in first SS)
    if (getLogicalSuperstep() == 0) {
        vertex.getValue().set(NO_COLOR);
        return;//from w w w.j  ava  2 s.c om
    }

    if (vertex.getValue().get() == NO_COLOR) {
        // get neighbour's colours
        LongOpenHashSet conflicts = new LongOpenHashSet(vertex.getNumEdges());
        for (LongWritable message : messages) {
            conflicts.add(message.get());
        }

        // acquire a new color
        for (long i = 0; i < conflicts.size() + 1; i++) {
            if (!conflicts.contains(i)) {
                vertex.getValue().set(i);
                break;
            }
        }

        if (vertex.getValue().get() == NO_COLOR) {
            LOG.fatal("[[COLOR]] vid=" + vertex.getId() + " no suitable colors!");
            throw new IllegalStateException("No suitable colors!");
        }

        // broadcast change to all neighbours
        for (Edge<LongWritable, NullWritable> e : vertex.getEdges()) {
            // skip self-loops
            if (e.getTargetVertexId().get() == vertex.getId().get()) {
                continue;
            }
            sendMessage(e.getTargetVertexId(), vertex.getValue());
        }
    } else {
        // we should NOT get a conflict any more! (this check is optional)
        for (LongWritable message : messages) {
            if (message.get() == vertex.getValue().get()) {
                LOG.fatal("[[COLOR]] vid=" + vertex.getId() + " unexpected conflict!");
                throw new IllegalStateException("Unexpected conflict!");
            }
        }
    }

    vertex.voteToHalt();
}

From source file:org.apache.giraph.examples.Giraphx.java

License:Apache License

private boolean detectHasAllCleanOrNoRequest() {
    for (LongWritable idlong : allEdgeIndexList) {
        long neighbor_id = idlong.get();
        if (!isLocalMap.get(idlong) || VERSION_OF_JOB.equals("dGiraph_coloring")) {
            if (inReqList.contains(neighbor_id) && myForkMap.get(neighbor_id).equals("DIRTY")) {
                return false;
            }//from  w ww. ja  va  2  s . co m
        }
    }
    return true;
}

From source file:org.apache.giraph.examples.Giraphx.java

License:Apache License

private void requestMissingForks(long my_id) {
    Text m3_msg = new Text("M3:" + my_id);
    for (LongWritable idlong : allEdgeIndexList) {
        long neighbor_id = idlong.get();
        if (!isLocalMap.get(idlong) || VERSION_OF_JOB.equals("dGiraph_coloring")) {
            if (!myForkMap.containsKey(neighbor_id) && !outReqMap.containsKey(idlong)) {
                sendMsg(idlong, m3_msg);
                outReqMap.put(idlong, true);
                //Log.info("SEREF sent fork request "+m3_msg+" to "+neighbor_id);
            }//from   w  w w  .  j  a v a 2  s  .  co m
        }
    }
}

From source file:org.apache.giraph.examples.GlobalClusteringCoefficientVertex.java

License:Apache License

@Override
public void compute(Iterator<LongArrayWritable> msgIterator) {
    DoubleSumAggregator trianglesum = (DoubleSumAggregator) getAggregator("trianglesum");
    DoubleSumAggregator triples = (DoubleSumAggregator) getAggregator("triples");
    if (getSuperstep() == 0) {
        // Each vertex this is connected to

        List<LongWritable> verticesl = new ArrayList<LongWritable>();

        // This is so we know which vertex the messages came from
        verticesl.add(getVertexId());/*from  w w  w . java2 s.  c o m*/

        // Find all connected vertices with ID less than current vertex
        for (LongWritable targetVertexId : this) {
            if (targetVertexId.get() < getVertexId().get()) {
                verticesl.add(targetVertexId);
            }
        }

        // Need to send list to other vertices, must convert to arraywritable
        LongWritable[] verticesa = verticesl.toArray(new LongWritable[0]);
        LongArrayWritable vertices = new LongArrayWritable(verticesa);

        // Sends list of smaller ID vertices to bigger ID vertices
        for (LongWritable targetVertexId : this) {
            if (targetVertexId.get() > getVertexId().get()) {
                sendMsg(targetVertexId, vertices);
            }
        }
    } else if (getSuperstep() == 1) {
        while (msgIterator.hasNext()) {
            LongArrayWritable law = msgIterator.next();
            Writable[] vertices = law.get();
            LongWritable source = (LongWritable) vertices[0];

            for (int i = 1; i < vertices.length; i++) {
                if (hasEdge((LongWritable) vertices[i])) {
                    double num = getVertexValue().get();
                    setVertexValue(new DoubleWritable(1.0 + num));

                    LongWritable[] one = new LongWritable[] { new LongWritable(1) };
                    LongArrayWritable inc = new LongArrayWritable(one);

                    sendMsg(source, inc);
                    sendMsg(((LongWritable) vertices[i]), inc);

                    triangles.add(source.toString());
                    triangles.add(vertices[i].toString());
                }
            }
        }
    } else if (getSuperstep() == 2) {
        while (msgIterator.hasNext()) {
            LongArrayWritable law = msgIterator.next();
            Writable[] msg = law.get();
            LongWritable value = (LongWritable) msg[0];

            double num = getVertexValue().get();
            setVertexValue(new DoubleWritable(num + value.get()));
        }

        trianglesum.aggregate(getVertexValue());

        double sum = 0.0;
        for (LongWritable source : this) {
            for (LongWritable target : this) {
                if (source.get() > target.get()) {
                    sum++;
                }
            }
        }

        triples.aggregate(new DoubleWritable(sum));
    } else {
        setVertexValue(new DoubleWritable(
                trianglesum.getAggregatedValue().get() / triples.getAggregatedValue().get()));

        voteToHalt();
    }
}

From source file:org.apache.giraph.examples.LocalClusteringCoefficientVertex.java

License:Apache License

@Override
public void compute(Iterator<LongArrayWritable> msgIterator) {
    if (getSuperstep() == 0) {
        // Each vertex this is connected to

        List<LongWritable> verticesl = new ArrayList<LongWritable>();

        // This is so we know which vertex the messages came from
        verticesl.add(getVertexId());/*from   w w w  .j  ava  2  s. c o  m*/

        // Find all connected vertices with ID less than current vertex
        for (LongWritable targetVertexId : this) {
            if (targetVertexId.get() < getVertexId().get()) {
                verticesl.add(targetVertexId);
            }
        }

        // Need to send list to other vertices, must convert to arraywritable
        LongWritable[] verticesa = verticesl.toArray(new LongWritable[0]);
        LongArrayWritable vertices = new LongArrayWritable(verticesa);

        // Sends list of smaller ID vertices to bigger ID vertices
        for (LongWritable targetVertexId : this) {
            if (targetVertexId.get() > getVertexId().get()) {
                sendMsg(targetVertexId, vertices);
            }
        }
    } else if (getSuperstep() == 1) {
        while (msgIterator.hasNext()) {
            LongArrayWritable law = msgIterator.next();
            Writable[] vertices = law.get();
            LongWritable source = (LongWritable) vertices[0];

            for (int i = 1; i < vertices.length; i++) {
                if (hasEdge((LongWritable) vertices[i])) {
                    double num = getVertexValue().get();
                    setVertexValue(new DoubleWritable(1.0 + num));

                    LongWritable[] one = new LongWritable[] { new LongWritable(1) };
                    LongArrayWritable inc = new LongArrayWritable(one);

                    sendMsg(source, inc);
                    sendMsg(((LongWritable) vertices[i]), inc);

                    triangles.add(source.toString());
                    triangles.add(vertices[i].toString());
                }
            }
        }
    } else {
        while (msgIterator.hasNext()) {
            LongArrayWritable law = msgIterator.next();
            Writable[] msg = law.get();
            LongWritable value = (LongWritable) msg[0];

            double num = getVertexValue().get();
            setVertexValue(new DoubleWritable(num + value.get()));
        }

        int sum = 0;
        for (LongWritable source : this) {
            for (LongWritable target : this) {
                if (source.get() > target.get()) {
                    sum++;
                }
            }
        }

        if (sum > 0) {
            setVertexValue(new DoubleWritable(getVertexValue().get() / sum));
        }

        voteToHalt();
    }
}

From source file:org.apache.giraph.examples.LongSumAggregator.java

License:Apache License

public void aggregate(LongWritable value) {
    sum += value.get();
}

From source file:org.apache.giraph.examples.LongSumAggregator.java

License:Apache License

public void setAggregatedValue(LongWritable value) {
    sum = value.get();
}

From source file:org.apache.giraph.examples.NetworkLocalClusteringCoefficientVertex.java

License:Apache License

@Override
public void compute(Iterator<LongArrayWritable> msgIterator) {
    DoubleSumAggregator sumAggreg = (DoubleSumAggregator) getAggregator("sum");
    if (getSuperstep() == 0) {
        // Each vertex this is connected to

        List<LongWritable> verticesl = new ArrayList<LongWritable>();

        // This is so we know which vertex the messages came from
        verticesl.add(getVertexId());/*from ww  w  .  j a v  a 2s  . c  o  m*/

        // Find all connected vertices with ID less than current vertex
        for (LongWritable targetVertexId : this) {
            if (targetVertexId.get() < getVertexId().get()) {
                verticesl.add(targetVertexId);
            }
        }

        // Need to send list to other vertices, must convert to arraywritable
        LongWritable[] verticesa = verticesl.toArray(new LongWritable[0]);
        LongArrayWritable vertices = new LongArrayWritable(verticesa);

        // Sends list of smaller ID vertices to bigger ID vertices
        for (LongWritable targetVertexId : this) {
            if (targetVertexId.get() > getVertexId().get()) {
                sendMsg(targetVertexId, vertices);
            }
        }
    } else if (getSuperstep() == 1) {
        while (msgIterator.hasNext()) {
            LongArrayWritable law = msgIterator.next();
            Writable[] vertices = law.get();
            LongWritable source = (LongWritable) vertices[0];

            for (int i = 1; i < vertices.length; i++) {
                if (hasEdge((LongWritable) vertices[i])) {
                    double num = getVertexValue().get();
                    setVertexValue(new DoubleWritable(1.0 + num));

                    LongWritable[] one = new LongWritable[] { new LongWritable(1) };
                    LongArrayWritable inc = new LongArrayWritable(one);

                    sendMsg(source, inc);
                    sendMsg(((LongWritable) vertices[i]), inc);

                    triangles.add(source.toString());
                    triangles.add(vertices[i].toString());
                }
            }
        }
    } else if (getSuperstep() == 2) {
        while (msgIterator.hasNext()) {
            LongArrayWritable law = msgIterator.next();
            Writable[] msg = law.get();
            LongWritable value = (LongWritable) msg[0];

            double num = getVertexValue().get();
            setVertexValue(new DoubleWritable(num + value.get()));
        }

        int sum = 0;
        for (LongWritable source : this) {
            for (LongWritable target : this) {
                if (source.get() > target.get()) {
                    sum++;
                }
            }
        }

        if (sum > 0) {
            setVertexValue(new DoubleWritable(getVertexValue().get() / sum));
        }

        sumAggreg.aggregate(getVertexValue());
    } else {
        setVertexValue(new DoubleWritable(sumAggreg.getAggregatedValue().get() / getNumVertices()));

        voteToHalt();
    }
}