Skip to content

Commit

Permalink
updated to use pool name in logs (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
venkata-kishore authored Jan 14, 2025
1 parent ed81dee commit f0981a4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<artifactId>simple-object-pool</artifactId>
<version>2.3.0</version>
<version>2.3.1</version>
<packaging>jar</packaging>

<properties>
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/today/bonfire/oss/sop/SimpleObjectPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void evictionRun() {
shouldEvict = true;
}
} catch (Exception e) {
log.warn("Object validation failed with error for object with id {}", pooledObject.id(), e);
log.warn("Object validation failed with error for object with id {} in pool - {}", pooledObject.id(), config.poolName(), e);
shouldEvict = true;
}
}
Expand Down Expand Up @@ -167,13 +167,13 @@ private void evictionRun() {
"used {} time(s), ",
pooledObject.id(), Duration.ofMillis(System.currentTimeMillis() - pooledObject.creationTime()), pooledObject.idlingTime(), pooledObject.borrowCount());
} catch (Exception e) {
log.warn("Failed to destroy object with id {}", pooledObject.id(), e);
log.warn("Failed to destroy object with id {} in pool - {}", pooledObject.id(), config.poolName(), e);
}
}

if (!objectsToDestroy.isEmpty()) {
log.debug("Evicted {} idle objects. Current pool size: {}, Idle: {}, Borrowed: {}",
objectsToDestroy.size(), currentPoolSize(), idleObjectCount(), borrowedObjectsCount());
log.debug("Evicted {} idle objects in pool - {}. Current pool size: {}, Idle: {}, Borrowed: {}",
objectsToDestroy.size(), config.poolName(), currentPoolSize(), idleObjectCount(), borrowedObjectsCount());
objectsToDestroy.clear();
}
}
Expand All @@ -197,7 +197,7 @@ public void destroyAllIdleObjects() {
try {
factory.destroyObject(pooledObject.object());
} catch (Exception e) {
log.warn("Failed to destroy object with id {}", pooledObject.id(), e);
log.warn("Failed to destroy object with id {} in pool - {}", pooledObject.id(), config.poolName(), e);
}
}
log.info("Destroyed {} idle objects. Current pool size: {}",
Expand Down Expand Up @@ -226,11 +226,11 @@ private void abandonCheckRun() {
});

for (PooledObject<T> pooledObject : objectsToRemove) {
log.warn("Removing abandoned object with id {} borrowed for more than {} ms and destroying it.", pooledObject.id(), now - pooledObject.lastBorrowedTime());
log.warn("Removing abandoned object with id {} in pool - {}. It has been borrowed for more than {} ms and destroying it.", pooledObject.id(), config.poolName(), now - pooledObject.lastBorrowedTime());
removeAndDestroyBorrowedObjects(pooledObject);
}
} catch (Exception e) {
log.warn("Error removing abandoned objects", e);
log.warn("Error removing abandoned objects in pool - {}", config.poolName(), e);
} finally {
lock.unlock();
}
Expand All @@ -248,7 +248,7 @@ private void removeAndDestroyBorrowedObjects(PooledObject<T> pooledObject) {
try {
factory.destroyObject(pooledObject.object());
} catch (Exception e) {
log.warn("Failed to destroy object with id {}", pooledObject.id(), e.getCause());
log.warn("Failed to destroy object with id {} in pool - {}", pooledObject.id(), config.poolName(), e.getCause());
}
}

Expand Down Expand Up @@ -392,7 +392,7 @@ public void returnObject(T obj, boolean broken) throws PoolObjectException {
lock.lock();
var pooledObject = borrowedObjects.get(obj.getEntityId());
if (pooledObject == null) {
log.warn("Attempted returning object that is not in borrowed objects list. id: {}", obj.getEntityId());
log.warn("Attempted returning object that is not in borrowed objects list. id: {}, pool - {}", obj.getEntityId(), config.poolName());
return;
}
if (broken) {
Expand All @@ -413,7 +413,7 @@ public void returnObject(T obj, boolean broken) throws PoolObjectException {
}

if (!isValid) {
log.warn("Returned broken or invalid entity with id {} and destroying it.", pooledObject.id());
log.warn("Returned broken or invalid entity with id {} to pool - {} and destroying it.", pooledObject.id(), config.poolName());
removeAndDestroyBorrowedObjects(pooledObject);
} else {

Expand Down Expand Up @@ -452,10 +452,10 @@ public void returnObject(T obj) throws PoolObjectException {
@Override
public void close() {
if (!scheduler.isShutdown()) {
log.info("Closing object pool. Current pool size: {}", currentPoolSize.get());
log.info("Closing object pool - {}. Current pool size: {}", config.poolName(), currentPoolSize.get());
scheduler.shutdown();
} else {
log.warn("Trying to close an Object pool that is already closed");
log.warn("Trying to close an Object pool - {} that is already closed", config.poolName());
return;
}

Expand All @@ -477,6 +477,7 @@ public void close() {
// Clear collections
borrowedObjects.clear();
idleObjects.clear();
log.info("Closed object pool - {}", config.poolName());
} finally {
lock.unlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.util.UUID;

/**
* {@code SimpleObjectPoolConfig} provides the configuration settings for a {@link SimpleObjectPool}.
Expand Down Expand Up @@ -198,7 +199,7 @@ public enum EvictionPolicy {
* It allows for a flexible and readable configuration setup.
*/
public static class Builder {
private String poolName;
private String poolName = "SOP-" + UUID.randomUUID().toString().substring(28).toUpperCase();
private int maxPoolSize = 8;
private int minPoolSize = 0;
private boolean fairness = false;
Expand Down

0 comments on commit f0981a4

Please sign in to comment.