Package org.ldaptive
Class AbstractConnectionValidator
- java.lang.Object
-
- org.ldaptive.AbstractFreezable
-
- org.ldaptive.AbstractConnectionValidator
-
- All Implemented Interfaces:
Function<Connection,Boolean>
,ConnectionValidator
,Freezable
- Direct Known Subclasses:
AbstractOperationConnectionValidator
public abstract class AbstractConnectionValidator extends AbstractFreezable implements ConnectionValidator
Base class for connection validator implementations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractConnectionValidator.AbstractBuilder<B,T extends AbstractConnectionValidator>
Base class for validator builders.
-
Field Summary
Fields Modifier and Type Field Description static Duration
DEFAULT_VALIDATE_PERIOD
Default validation period, value is 30 minutes.static Duration
DEFAULT_VALIDATE_TIMEOUT
Default per connection validate timeout, value is 5 seconds.protected Logger
logger
Logger for this class.private Consumer<Connection>
onFailure
Consumer to execute on a failed validation.private Consumer<Connection>
onSuccess
Consumer to execute on a successful validation.private boolean
timeoutIsFailure
Whether the occurrence of a timeout should result in a validation failure.private Duration
validatePeriod
Validation period.private Duration
validateTimeout
Maximum length of time a connection validation should block.
-
Constructor Summary
Constructors Constructor Description AbstractConnectionValidator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Boolean
apply(Connection conn)
Supplier<Boolean>
applyAsync(Connection conn)
Provides an asynchronous implementation ofFunction.apply(Object)
.Consumer<Connection>
getOnFailure()
Returns a consumer to handle a connection that has failed validation.Consumer<Connection>
getOnSuccess()
Returns a consumer to handle a connection that has been successfully validated.boolean
getTimeoutIsFailure()
Returns whether a timeout should be considered a validation failure.Duration
getValidatePeriod()
Returns the interval at which the validation task will be executed.Duration
getValidateTimeout()
Returns the duration at which a validate operation should be abandoned.void
setOnFailure(Consumer<Connection> consumer)
Sets a consumer to handle a connection that has failed validation.void
setOnSuccess(Consumer<Connection> consumer)
Sets a consumer to handle a connection that has been successfully validated.void
setTimeoutIsFailure(boolean failure)
Sets whether a timeout should be considered a validation failure.void
setValidatePeriod(Duration period)
void
setValidateTimeout(Duration timeout)
Sets the validate timeout.String
toString()
-
Methods inherited from class org.ldaptive.AbstractFreezable
assertMutable, freeze, freeze, freeze, isFrozen
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.ldaptive.ConnectionValidator
applyAsync
-
-
-
-
Field Detail
-
DEFAULT_VALIDATE_PERIOD
public static final Duration DEFAULT_VALIDATE_PERIOD
Default validation period, value is 30 minutes.
-
DEFAULT_VALIDATE_TIMEOUT
public static final Duration DEFAULT_VALIDATE_TIMEOUT
Default per connection validate timeout, value is 5 seconds.
-
logger
protected final Logger logger
Logger for this class.
-
validatePeriod
private Duration validatePeriod
Validation period.
-
validateTimeout
private Duration validateTimeout
Maximum length of time a connection validation should block.
-
onSuccess
private Consumer<Connection> onSuccess
Consumer to execute on a successful validation.
-
onFailure
private Consumer<Connection> onFailure
Consumer to execute on a failed validation.
-
timeoutIsFailure
private boolean timeoutIsFailure
Whether the occurrence of a timeout should result in a validation failure.
-
-
Method Detail
-
getValidatePeriod
public Duration getValidatePeriod()
Description copied from interface:ConnectionValidator
Returns the interval at which the validation task will be executed.- Specified by:
getValidatePeriod
in interfaceConnectionValidator
- Returns:
- validation period
-
setValidatePeriod
public void setValidatePeriod(Duration period)
-
getValidateTimeout
public Duration getValidateTimeout()
Description copied from interface:ConnectionValidator
Returns the duration at which a validate operation should be abandoned.- Specified by:
getValidateTimeout
in interfaceConnectionValidator
- Returns:
- validation timeout
-
setValidateTimeout
public void setValidateTimeout(Duration timeout)
Sets the validate timeout.- Parameters:
timeout
- to set
-
getOnSuccess
public Consumer<Connection> getOnSuccess()
Returns a consumer to handle a connection that has been successfully validated.- Returns:
- success consumer
-
setOnSuccess
public void setOnSuccess(Consumer<Connection> consumer)
Sets a consumer to handle a connection that has been successfully validated.- Parameters:
consumer
- to invoke on success
-
getOnFailure
public Consumer<Connection> getOnFailure()
Returns a consumer to handle a connection that has failed validation.- Returns:
- failure consumer
-
setOnFailure
public void setOnFailure(Consumer<Connection> consumer)
Sets a consumer to handle a connection that has failed validation.- Parameters:
consumer
- to invoke on failure
-
getTimeoutIsFailure
public boolean getTimeoutIsFailure()
Returns whether a timeout should be considered a validation failure.- Returns:
- whether a timeout should be considered a validation failure
-
setTimeoutIsFailure
public void setTimeoutIsFailure(boolean failure)
Sets whether a timeout should be considered a validation failure.- Parameters:
failure
- whether a timeout should be considered a validation failure
-
apply
public Boolean apply(Connection conn)
- Specified by:
apply
in interfaceFunction<Connection,Boolean>
-
applyAsync
public Supplier<Boolean> applyAsync(Connection conn)
Description copied from interface:ConnectionValidator
Provides an asynchronous implementation ofFunction.apply(Object)
. The returned supplier will block until a validation result is received respectingConnectionValidator.getValidateTimeout()
.- Specified by:
applyAsync
in interfaceConnectionValidator
- Parameters:
conn
- to validate- Returns:
- supplier to retrieve the validation result
-
-