Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
GiraphHadoopCounter |
|
| 1.3333333333333333;1.333 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, software | |
13 | * distributed under the License is distributed on an "AS IS" BASIS, | |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 | * See the License for the specific language governing permissions and | |
16 | * limitations under the License. | |
17 | */ | |
18 | ||
19 | package org.apache.giraph.counters; | |
20 | ||
21 | import com.google.common.base.Objects; | |
22 | import org.apache.hadoop.mapreduce.Counter; | |
23 | ||
24 | import java.io.DataInput; | |
25 | import java.io.DataOutput; | |
26 | import java.io.IOException; | |
27 | ||
28 | /** | |
29 | * Wrapper around Hadoop Counter to make it easier to use. | |
30 | */ | |
31 | public class GiraphHadoopCounter { | |
32 | /** Hadoop Counter we're wrapping. */ | |
33 | private Counter counter; | |
34 | ||
35 | /** | |
36 | * Create wrapping a Hadoop Counter. | |
37 | * | |
38 | * @param counter Hadoop Counter to wrap. | |
39 | */ | |
40 | 0 | public GiraphHadoopCounter(Counter counter) { |
41 | 0 | this.counter = counter; |
42 | 0 | } |
43 | ||
44 | /** | |
45 | * Get underlying Hadoop Counter we're wrapping. | |
46 | * | |
47 | * @return Hadoop Counter being wrapped. | |
48 | */ | |
49 | public Counter getHadoopCounter() { | |
50 | 0 | return counter; |
51 | } | |
52 | ||
53 | @Override | |
54 | public int hashCode() { | |
55 | 0 | return counter.hashCode(); |
56 | } | |
57 | ||
58 | @Override | |
59 | public boolean equals(Object genericRight) { | |
60 | 0 | if (genericRight == null) { |
61 | 0 | return false; |
62 | } | |
63 | 0 | if (getClass() != genericRight.getClass()) { |
64 | 0 | return false; |
65 | } | |
66 | 0 | GiraphHadoopCounter right = (GiraphHadoopCounter) genericRight; |
67 | 0 | return Objects.equal(counter, right.counter); |
68 | } | |
69 | ||
70 | /** | |
71 | * Set counter to value. Should be greater than current value. | |
72 | * | |
73 | * @param value long value to set to. | |
74 | */ | |
75 | public void setValue(long value) { | |
76 | 0 | increment(value - getValue()); |
77 | 0 | } |
78 | ||
79 | /** | |
80 | * Increment counter value by 1. | |
81 | */ | |
82 | public void increment() { | |
83 | 0 | increment(1); |
84 | 0 | } |
85 | ||
86 | /** | |
87 | * Increment counter value. | |
88 | * | |
89 | * @param incr amount to increment by. | |
90 | */ | |
91 | public void increment(long incr) { | |
92 | 0 | counter.increment(incr); |
93 | 0 | } |
94 | ||
95 | /** | |
96 | * Get counter value | |
97 | * | |
98 | * @return long value of counter | |
99 | */ | |
100 | public long getValue() { | |
101 | 0 | return counter.getValue(); |
102 | } | |
103 | ||
104 | /** | |
105 | * Get counter display name. | |
106 | * | |
107 | * @return String Hadoop counter display name. | |
108 | */ | |
109 | public String getDisplayName() { | |
110 | 0 | return counter.getDisplayName(); |
111 | } | |
112 | ||
113 | /** | |
114 | * Get counter name. | |
115 | * | |
116 | * @return String Hadoop counter name. | |
117 | */ | |
118 | public String getName() { | |
119 | 0 | return counter.getName(); |
120 | } | |
121 | ||
122 | /** | |
123 | * Write to Hadoop output. | |
124 | * | |
125 | * @param out DataOutput to write to. | |
126 | * @throws IOException if something goes wrong. | |
127 | */ | |
128 | public void write(DataOutput out) throws IOException { | |
129 | 0 | counter.write(out); |
130 | 0 | } |
131 | ||
132 | /** | |
133 | * Read from Hadoop input. | |
134 | * | |
135 | * @param in DataInput to read from. | |
136 | * @throws IOException if something goes wrong reading. | |
137 | */ | |
138 | public void readFields(DataInput in) throws IOException { | |
139 | 0 | counter.readFields(in); |
140 | 0 | } |
141 | } |