Skip to content

Commit

Permalink
minor config update so pool name is available. (#5)
Browse files Browse the repository at this point in the history
Updated to use automatic module name

Co-authored-by: venkata kishore <venkata.kishore@bonfire.camp>
  • Loading branch information
venkata-kishore and venkata kishore authored Jan 14, 2025
1 parent df45c09 commit ed81dee
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
29 changes: 27 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
<parent>
<groupId>today.bonfire.oss</groupId>
<artifactId>bonfire-oss-parent</artifactId>
<version>1.1.5</version>
<version>1.1.8</version>
</parent>

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

<properties>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<module.name>bonfire.oss.sop</module.name>
</properties>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down Expand Up @@ -70,6 +71,30 @@

<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
<manifestEntries>
<Automatic-Module-Name>${module.name}</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/today/bonfire/oss/sop/SimpleObjectPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class SimpleObjectPool<T extends PoolObject> implements AutoCloseable {
private final Condition retryCreationWait;
private final AtomicLong objectCreateCount = new AtomicLong(0);
private final AtomicInteger currentPoolSize = new AtomicInteger(0);
private final AtomicLong timesBorrowed = new AtomicLong(0);
private final AtomicLong timesBorrowed = new AtomicLong(0);

public SimpleObjectPool(SimpleObjectPoolConfig config, PooledObjectFactory<T> factory) {
this.config = config;
Expand All @@ -52,7 +52,7 @@ public SimpleObjectPool(SimpleObjectPoolConfig config, PooledObjectFactory<T> fa

scheduler.scheduleAtFixedRate(this::evictionRun, config.durationBetweenEvictionsRuns(), config.durationBetweenEvictionsRuns(), TimeUnit.MILLISECONDS);
scheduler.scheduleAtFixedRate(this::abandonCheckRun, config.durationBetweenAbandonCheckRuns(), config.durationBetweenAbandonCheckRuns(), TimeUnit.MILLISECONDS);
log.info("Object pool created with maxPoolSize: {}, minPoolSize: {}", config.maxPoolSize(), config.minPoolSize());
log.info("Pool - {} created with maxPoolSize: {}, minPoolSize: {}", config.poolName(), config.maxPoolSize(), config.minPoolSize());
if (config.minPoolSize() > 0) {
for (int i = 0; i < config.minPoolSize(); i++) {
idleObjects.add(createObject());
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/today/bonfire/oss/sop/SimpleObjectPoolConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.Getter;
import lombok.experimental.Accessors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;

Expand All @@ -18,7 +19,10 @@
@Getter @Accessors(fluent = true)
public class SimpleObjectPoolConfig {

private static final Logger log = org.slf4j.LoggerFactory.getLogger(SimpleObjectPoolConfig.class);
private static final Logger log = LoggerFactory.getLogger(SimpleObjectPoolConfig.class);


private final String poolName;

/**
* Returns the maximum number of objects that the pool can hold.
Expand Down Expand Up @@ -150,6 +154,7 @@ protected SimpleObjectPoolConfig(Builder builder) {
this.maxRetries = builder.maxRetries;
this.retryCreationDelay = builder.retryCreationDelay.toNanos();
this.waitingForObjectTimeout = builder.waitingForObjectTimeout.toNanos();
poolName = builder.poolName;
}

public static Builder builder() {
Expand Down Expand Up @@ -193,6 +198,7 @@ public enum EvictionPolicy {
* It allows for a flexible and readable configuration setup.
*/
public static class Builder {
private String poolName;
private int maxPoolSize = 8;
private int minPoolSize = 0;
private boolean fairness = false;
Expand All @@ -210,6 +216,20 @@ public static class Builder {
private Duration retryCreationDelay = Duration.ZERO;
private Duration waitingForObjectTimeout = Duration.ofSeconds(10);


/**
* Sets the name of the pool.
* <p>
* The name is used for logging and debugging purposes.
*
* @param poolName The name of the pool.
* @return This {@code Builder} instance.
*/
public Builder poolName(String poolName) {
this.poolName = poolName;
return this;
}

/**
* Sets the maximum number of objects that the pool can hold.
*
Expand Down Expand Up @@ -348,7 +368,7 @@ public Builder objEvictionTimeout(Duration objEvictionTimeout) {
* many cases take some time compared to simple tests.
* <br>
* If set to 0 then no factory validation will be done. <br>
* If set to null or not set then the factory validation will be limited to {@link SimpleObjectPoolConfig#maxPoolSize()}
* If set to null or not set then the factory validation will be limited to {@link SimpleObjectPoolConfig#maxPoolSize}
*
* @param numValidationsPerEvictionRun The number of objects to test per eviction run.
* @return This {@code Builder} instance.
Expand Down

0 comments on commit ed81dee

Please sign in to comment.