Skip to content

Commit f0981a4

Browse files
updated to use pool name in logs (#6)
1 parent ed81dee commit f0981a4

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</parent>
1212

1313
<artifactId>simple-object-pool</artifactId>
14-
<version>2.3.0</version>
14+
<version>2.3.1</version>
1515
<packaging>jar</packaging>
1616

1717
<properties>

src/main/java/today/bonfire/oss/sop/SimpleObjectPool.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private void evictionRun() {
136136
shouldEvict = true;
137137
}
138138
} catch (Exception e) {
139-
log.warn("Object validation failed with error for object with id {}", pooledObject.id(), e);
139+
log.warn("Object validation failed with error for object with id {} in pool - {}", pooledObject.id(), config.poolName(), e);
140140
shouldEvict = true;
141141
}
142142
}
@@ -167,13 +167,13 @@ private void evictionRun() {
167167
"used {} time(s), ",
168168
pooledObject.id(), Duration.ofMillis(System.currentTimeMillis() - pooledObject.creationTime()), pooledObject.idlingTime(), pooledObject.borrowCount());
169169
} catch (Exception e) {
170-
log.warn("Failed to destroy object with id {}", pooledObject.id(), e);
170+
log.warn("Failed to destroy object with id {} in pool - {}", pooledObject.id(), config.poolName(), e);
171171
}
172172
}
173173

174174
if (!objectsToDestroy.isEmpty()) {
175-
log.debug("Evicted {} idle objects. Current pool size: {}, Idle: {}, Borrowed: {}",
176-
objectsToDestroy.size(), currentPoolSize(), idleObjectCount(), borrowedObjectsCount());
175+
log.debug("Evicted {} idle objects in pool - {}. Current pool size: {}, Idle: {}, Borrowed: {}",
176+
objectsToDestroy.size(), config.poolName(), currentPoolSize(), idleObjectCount(), borrowedObjectsCount());
177177
objectsToDestroy.clear();
178178
}
179179
}
@@ -197,7 +197,7 @@ public void destroyAllIdleObjects() {
197197
try {
198198
factory.destroyObject(pooledObject.object());
199199
} catch (Exception e) {
200-
log.warn("Failed to destroy object with id {}", pooledObject.id(), e);
200+
log.warn("Failed to destroy object with id {} in pool - {}", pooledObject.id(), config.poolName(), e);
201201
}
202202
}
203203
log.info("Destroyed {} idle objects. Current pool size: {}",
@@ -226,11 +226,11 @@ private void abandonCheckRun() {
226226
});
227227

228228
for (PooledObject<T> pooledObject : objectsToRemove) {
229-
log.warn("Removing abandoned object with id {} borrowed for more than {} ms and destroying it.", pooledObject.id(), now - pooledObject.lastBorrowedTime());
229+
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());
230230
removeAndDestroyBorrowedObjects(pooledObject);
231231
}
232232
} catch (Exception e) {
233-
log.warn("Error removing abandoned objects", e);
233+
log.warn("Error removing abandoned objects in pool - {}", config.poolName(), e);
234234
} finally {
235235
lock.unlock();
236236
}
@@ -248,7 +248,7 @@ private void removeAndDestroyBorrowedObjects(PooledObject<T> pooledObject) {
248248
try {
249249
factory.destroyObject(pooledObject.object());
250250
} catch (Exception e) {
251-
log.warn("Failed to destroy object with id {}", pooledObject.id(), e.getCause());
251+
log.warn("Failed to destroy object with id {} in pool - {}", pooledObject.id(), config.poolName(), e.getCause());
252252
}
253253
}
254254

@@ -392,7 +392,7 @@ public void returnObject(T obj, boolean broken) throws PoolObjectException {
392392
lock.lock();
393393
var pooledObject = borrowedObjects.get(obj.getEntityId());
394394
if (pooledObject == null) {
395-
log.warn("Attempted returning object that is not in borrowed objects list. id: {}", obj.getEntityId());
395+
log.warn("Attempted returning object that is not in borrowed objects list. id: {}, pool - {}", obj.getEntityId(), config.poolName());
396396
return;
397397
}
398398
if (broken) {
@@ -413,7 +413,7 @@ public void returnObject(T obj, boolean broken) throws PoolObjectException {
413413
}
414414

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

@@ -452,10 +452,10 @@ public void returnObject(T obj) throws PoolObjectException {
452452
@Override
453453
public void close() {
454454
if (!scheduler.isShutdown()) {
455-
log.info("Closing object pool. Current pool size: {}", currentPoolSize.get());
455+
log.info("Closing object pool - {}. Current pool size: {}", config.poolName(), currentPoolSize.get());
456456
scheduler.shutdown();
457457
} else {
458-
log.warn("Trying to close an Object pool that is already closed");
458+
log.warn("Trying to close an Object pool - {} that is already closed", config.poolName());
459459
return;
460460
}
461461

@@ -477,6 +477,7 @@ public void close() {
477477
// Clear collections
478478
borrowedObjects.clear();
479479
idleObjects.clear();
480+
log.info("Closed object pool - {}", config.poolName());
480481
} finally {
481482
lock.unlock();
482483
}

src/main/java/today/bonfire/oss/sop/SimpleObjectPoolConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.slf4j.LoggerFactory;
77

88
import java.time.Duration;
9+
import java.util.UUID;
910

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

0 commit comments

Comments
 (0)