public class Balancer<T>
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
Balancer.ServiceHandler<T> |
| Constructor and Description |
|---|
Balancer() |
| Modifier and Type | Method and Description |
|---|---|
void |
addService(T service) |
<R> R |
execute(FunctionWithException<T,R,java.lang.Exception> submit) |
void |
forEach(java.util.function.Consumer<T> consumer) |
int |
getAvailable() |
long |
getRecoveryPeriod() |
T |
getService() |
Balancer.ServiceHandler<T> |
getStarter() |
Balancer.ServiceHandler<T> |
getStopper() |
long |
getTimeout() |
boolean |
isThreadSafe() |
protected void |
recover(T service) |
Balancer<T> |
recoveryPeriod(long recoveryPeriod) |
void |
setRecoveryPeriod(long recoveryPeriod) |
void |
setStarter(Balancer.ServiceHandler<T> starter) |
void |
setStopper(Balancer.ServiceHandler<T> stopper) |
void |
setThreadSafe(boolean threadSafe) |
void |
setTimeout(long timeout) |
protected boolean |
shouldRecover(java.lang.Exception exception) |
void |
start() |
protected void |
start(T service) |
Balancer<T> |
starter(Balancer.ServiceHandler<T> starter) |
void |
stop() |
protected void |
stop(T service) |
Balancer<T> |
stopper(Balancer.ServiceHandler<T> stopper) |
Balancer<T> |
threadSafe(boolean threadSafe) |
Balancer<T> |
timeout(long timeout) |
Balancer<T> |
timeout(T service) |
public T getService()
public long getTimeout()
public void setTimeout(long timeout)
public long getRecoveryPeriod()
public void setRecoveryPeriod(long recoveryPeriod)
public boolean isThreadSafe()
public void setThreadSafe(boolean threadSafe)
public void addService(T service)
public void forEach(java.util.function.Consumer<T> consumer)
public int getAvailable()
public Balancer.ServiceHandler<T> getStarter()
public void setStarter(Balancer.ServiceHandler<T> starter)
public Balancer<T> starter(Balancer.ServiceHandler<T> starter)
public Balancer.ServiceHandler<T> getStopper()
public void setStopper(Balancer.ServiceHandler<T> stopper)
public Balancer<T> stopper(Balancer.ServiceHandler<T> stopper)
public void start()
public void stop()
protected void start(T service) throws java.io.IOException
java.io.IOExceptionprotected void stop(T service) throws java.io.IOException
java.io.IOExceptionprotected void recover(T service)
public <R> R execute(FunctionWithException<T,R,java.lang.Exception> submit) throws java.io.IOException
java.io.IOExceptionprotected boolean shouldRecover(java.lang.Exception exception)