48 |
|
|
49 |
private CircuitBreakerState currentState; |
private CircuitBreakerState currentState; |
50 |
|
|
51 |
private OpenState open = new OpenState(); |
private final OpenState open = new OpenState(); |
52 |
private HalfOpenState halfOpen = new HalfOpenState(); |
private final HalfOpenState halfOpen = new HalfOpenState(); |
53 |
private ClosedState closed = new ClosedState(); |
private final ClosedState closed = new ClosedState(); |
54 |
|
|
55 |
private String name; |
private String name; |
56 |
|
|
85 |
|
|
86 |
public void tripBreaker() { |
public void tripBreaker() { |
87 |
synchronized(this) { |
synchronized(this) { |
88 |
open.trip(); |
if (currentState != open) { // TODO:Is this conditional necessary ?? |
89 |
currentState = open; |
open.trip(); |
90 |
|
currentState = open; |
91 |
|
|
92 |
notifier.sendNotification(name, Notifier.Event.BreakerTripped); |
notifier.sendNotification(name, Notifier.Event.BreakerTripped); |
93 |
|
} |
94 |
} |
} |
95 |
} |
} |
96 |
|
|
97 |
public void attemptReset() { |
public void attemptReset() { |
98 |
synchronized(this) { |
synchronized(this) { |
99 |
currentState = halfOpen; |
if (currentState != halfOpen) { // TODO:Is this conditional necessary ?? |
100 |
notifier.sendNotification(name, Notifier.Event.BreakerAttemptReset); |
currentState = halfOpen; |
101 |
|
notifier.sendNotification(name, Notifier.Event.BreakerAttemptReset); |
102 |
|
} |
103 |
} |
} |
104 |
|
|
105 |
} |
} |
106 |
|
|
107 |
public void reset() { |
public void reset() { |
108 |
synchronized(this) { |
synchronized(this) { |
109 |
currentState = closed; |
if (currentState != closed) { // TODO: Is this conditional necessary ?? |
110 |
notifier.sendNotification(name, Notifier.Event.BreakerReset); |
currentState = closed; |
111 |
|
notifier.sendNotification(name, Notifier.Event.BreakerReset); |
112 |
|
} |
113 |
} |
} |
114 |
} |
} |
115 |
|
|
132 |
return closed.getThreshold(); |
return closed.getThreshold(); |
133 |
} |
} |
134 |
|
|
135 |
|
public int getTimeout() { |
136 |
|
return (int)open.getTimeout(); |
137 |
|
} |
138 |
|
|
139 |
public int getFailureCount() { |
public int getFailureCount() { |
140 |
if (getState() == closed) { |
if (getState() == closed) { |
141 |
return closed.getFailureCount(); |
return closed.getFailureCount(); |
157 |
} |
} |
158 |
|
|
159 |
public String getNotifierName() { |
public String getNotifierName() { |
160 |
return notifier.toString(); |
return notifier.getClass().getName(); |
161 |
} |
} |
162 |
|
|
163 |
} |
} |