- java.lang.Object
-
- com.github.robtimus.pool.PoolLogger
-
public class PoolLogger extends Object
A logger for events triggered by aPool
orPoolableObject
.Instances of this class are thread-safe.
This class needs SLF4J to be present on the class path to work. If it isn't nothing will be logged at all.
- Author:
- Rob Spoor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PoolLogger.Builder
A builder forPoolLogger
objects.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
acquiredObject(PoolableObject<?> object, int idleCount, int poolSize)
Called when aPoolableObject
is acquired from aPool
.void
createdNonPooledObject(PoolableObject<?> object)
Called when a newPoolableObject
has been created that will not be returned to the pool it was acquired from.void
createdObject(PoolableObject<?> object)
Called when a newPoolableObject
has been created.void
createdPool(PoolConfig config)
Called when aPool
has been created.void
creatingPool(PoolConfig config)
Called when aPool
is being created.static PoolLogger.Builder
custom()
Returns a new builder for creatingPoolLogger
objects.void
decreasedObjectRefCount(PoolableObject<?> object, int refCount)
Called when a reference was removed from aPoolableObject
.static PoolLogger
defaultLogger()
Returns a defaultPoolLogger
object.void
drainedPool(int poolSize)
Called when aPool
is drained.void
failedToCreatePool(Exception exception)
Called when aPool
could not be created.void
increasedObjectRefCount(PoolableObject<?> object, int refCount)
Called when an additional reference was added to aPoolableObject
.boolean
isEnabled(LogLevel level)
Returns whether or not logging at a specific level is enabled.static PoolLogger
noopLogger()
Returns aPoolLogger
object that does not perform any actual logging.void
objectEvent(LogLevel level, PoolableObject<?> object, String message)
Called whenPoolableObject.logEvent(LogLevel, String)
is called.void
objectEvent(LogLevel level, PoolableObject<?> object, Supplier<String> messageSupplier)
Called whenPoolableObject.logEvent(LogLevel, Supplier)
is called.void
objectIdleTooLong(PoolableObject<?> object, int idleCount, int poolSize)
Called when aPoolableObject
has been idle for too long.void
objectInvalidated(PoolableObject<?> object, int idleCount, int poolSize)
Called when aPoolableObject
is no longer valid and has been removed from itsPool
.void
releasedObjectResources(PoolableObject<?> object)
Called when the resources of aPoolableObject
have been released.void
releaseObjectResourcesFailed(PoolableObject<?> object, Exception exception)
Called when an error occurs when quietly releasing the resources of aPoolableObject
.void
releasingObjectResources(PoolableObject<?> object)
Called before the resources of aPoolableObject
will be released.void
returnedObject(PoolableObject<?> object, int idleCount, int poolSize)
Called when aPoolableObject
is returned to aPool
.void
shutDownPool()
Called when aPool
has shut down.String
toString()
-
-
-
Method Detail
-
creatingPool
public void creatingPool(PoolConfig config)
Called when aPool
is being created.- Parameters:
config
- The configuration for thePool
.
-
createdPool
public void createdPool(PoolConfig config)
Called when aPool
has been created.- Parameters:
config
- The configuration for thePool
.
-
failedToCreatePool
public void failedToCreatePool(Exception exception)
Called when aPool
could not be created.- Parameters:
exception
- The exception that was thrown while creating thePool
.
-
drainedPool
public void drainedPool(int poolSize)
Called when aPool
is drained. This is like acquiring all available idlePoolableObject
s in one call.- Parameters:
poolSize
- The total pool size - the number of acquiredPoolableObject
s.
-
shutDownPool
public void shutDownPool()
Called when aPool
has shut down.
-
createdObject
public void createdObject(PoolableObject<?> object)
Called when a newPoolableObject
has been created.- Parameters:
object
- ThePoolableObject
.
-
createdNonPooledObject
public void createdNonPooledObject(PoolableObject<?> object)
Called when a newPoolableObject
has been created that will not be returned to the pool it was acquired from.- Parameters:
object
- ThePoolableObject
.
-
increasedObjectRefCount
public void increasedObjectRefCount(PoolableObject<?> object, int refCount)
Called when an additional reference was added to aPoolableObject
.- Parameters:
object
- ThePoolableObject
.refCount
- The new number of references, including thePoolableObject
itself.- See Also:
PoolableObject.addReference()
-
decreasedObjectRefCount
public void decreasedObjectRefCount(PoolableObject<?> object, int refCount)
Called when a reference was removed from aPoolableObject
.- Parameters:
object
- ThePoolableObject
.refCount
- The new number of references, including thePoolableObject
itself.- See Also:
PoolableObject.Reference.remove()
-
releasingObjectResources
public void releasingObjectResources(PoolableObject<?> object)
Called before the resources of aPoolableObject
will be released.- Parameters:
object
- ThePoolableObject
.- See Also:
PoolableObject.releaseResources()
-
releasedObjectResources
public void releasedObjectResources(PoolableObject<?> object)
Called when the resources of aPoolableObject
have been released.- Parameters:
object
- ThePoolableObject
.- See Also:
PoolableObject.releaseResources()
-
releaseObjectResourcesFailed
public void releaseObjectResourcesFailed(PoolableObject<?> object, Exception exception)
Called when an error occurs when quietly releasing the resources of aPoolableObject
.- Parameters:
object
- ThePoolableObject
.exception
- The exception that was thrown while quietly releasing the resources of thePoolableObject
.- See Also:
PoolableObject.releaseResources()
-
acquiredObject
public void acquiredObject(PoolableObject<?> object, int idleCount, int poolSize)
Called when aPoolableObject
is acquired from aPool
.- Parameters:
object
- ThePoolableObject
.idleCount
- The number of idlePoolableObject
s after acquiring thePoolableObject
.poolSize
- The total pool size - the number of acquired and idlePoolableObject
s combined.
-
returnedObject
public void returnedObject(PoolableObject<?> object, int idleCount, int poolSize)
Called when aPoolableObject
is returned to aPool
.- Parameters:
object
- ThePoolableObject
.idleCount
- The number of idlePoolableObject
s after returning thePoolableObject
.poolSize
- The total pool size - the number of acquired and idlePoolableObject
s combined.
-
objectInvalidated
public void objectInvalidated(PoolableObject<?> object, int idleCount, int poolSize)
Called when aPoolableObject
is no longer valid and has been removed from itsPool
.- Parameters:
object
- ThePoolableObject
.idleCount
- The number of idlePoolableObject
s after invalidating thePoolableObject
.poolSize
- The total pool size - the number of acquired and idlePoolableObject
s combined.- See Also:
PoolableObject.validate()
-
objectIdleTooLong
public void objectIdleTooLong(PoolableObject<?> object, int idleCount, int poolSize)
Called when aPoolableObject
has been idle for too long.- Parameters:
object
- ThePoolableObject
.idleCount
- The number of idlePoolableObject
s after invalidating thePoolableObject
.poolSize
- The total pool size - the number of acquired and idlePoolableObject
s combined.
-
objectEvent
public void objectEvent(LogLevel level, PoolableObject<?> object, String message)
Called whenPoolableObject.logEvent(LogLevel, String)
is called.- Parameters:
level
- The log level to use.object
- ThePoolableObject
.message
- The event message.
-
objectEvent
public void objectEvent(LogLevel level, PoolableObject<?> object, Supplier<String> messageSupplier)
Called whenPoolableObject.logEvent(LogLevel, Supplier)
is called.- Parameters:
level
- The log level to use.object
- ThePoolableObject
.messageSupplier
- A supplier for the event message.
-
isEnabled
public boolean isEnabled(LogLevel level)
Returns whether or not logging at a specific level is enabled. This can be used to perform conditional configuration, like adding logging listeners conditionally.- Parameters:
level
- The level to check.- Returns:
true
if logging at the given level is enabled, orfalse
otherwise.
-
defaultLogger
public static PoolLogger defaultLogger()
Returns a defaultPoolLogger
object. This has the same configuration as an object returned bycustom().build()
.- Returns:
- A default
PoolLogger
object.
-
noopLogger
public static PoolLogger noopLogger()
Returns aPoolLogger
object that does not perform any actual logging. This can be used as default value in case no logger should be used, instead of checking fornull
.- Returns:
- A
PoolLogger
object that does not perform any actual logging.
-
custom
public static PoolLogger.Builder custom()
Returns a new builder for creatingPoolLogger
objects.- Returns:
- A new builder for creating
PoolLogger
objects.
-
-