Threshold failure detector issue
[voldemort/jeffpc.git] / src / java / voldemort / cluster / failuredetector / NodeStatus.java
blobd62520095686962393c9fb110cac048a3380f030
1 /*
2 * Copyright 2008-2009 LinkedIn, Inc
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
17 package voldemort.cluster.failuredetector;
19 import java.util.concurrent.atomic.AtomicInteger;
21 /**
22 * Holds the status of a node--either available or unavailable as well as the
23 * last date the status was checked.
25 * Operations on this class are not atomic, but that is okay.
29 class NodeStatus {
31 private long lastChecked;
33 private boolean isAvailable;
35 private long startMillis;
37 private long success;
39 private long failure;
41 private long total;
43 private final AtomicInteger numConsecutiveCatastrophicErrors;
45 public NodeStatus() {
46 numConsecutiveCatastrophicErrors = new AtomicInteger(0);
49 public long getLastChecked() {
50 return lastChecked;
53 public void setLastChecked(long lastChecked) {
54 this.lastChecked = lastChecked;
57 public boolean isAvailable() {
58 return isAvailable;
61 public void setAvailable(boolean isAvailable) {
62 this.isAvailable = isAvailable;
65 public long getStartMillis() {
66 return startMillis;
69 public void setStartMillis(long startMillis) {
70 this.startMillis = startMillis;
73 public long getSuccess() {
74 return success;
77 public long getFailure() {
78 return failure;
81 public long getTotal() {
82 return total;
85 public int getNumConsecutiveCatastrophicErrors() {
86 return numConsecutiveCatastrophicErrors.get();
89 public void resetNumConsecutiveCatastrophicErrors() {
90 this.numConsecutiveCatastrophicErrors.set(0);
93 public int incrementConsecutiveCatastrophicErrors() {
94 return this.numConsecutiveCatastrophicErrors.incrementAndGet();
97 public void resetCounters(long currentTime) {
98 setStartMillis(currentTime);
99 // Not resetting the catastrophic errors, as they will be reset
100 // whenever a success is received.
101 success = 0;
102 failure = 0;
103 total = 0;
106 public void recordOperation(boolean isSuccess) {
107 if(isSuccess) {
108 success++;
109 } else {
110 failure++;
112 total++;