diff --git a/.asf.yaml b/.asf.yaml
index 98c155e98..5db049546 100644
--- a/.asf.yaml
+++ b/.asf.yaml
@@ -5,7 +5,7 @@
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -23,7 +23,8 @@ notifications:
pullrequests: issues@commons.apache.org
jira_options: link label
jobs: notifications@commons.apache.org
- issues_bot_dependabot: notifications@commons.apache.org
- pullrequests_bot_dependabot: notifications@commons.apache.org
+ # commits_bot_dependabot: dependabot@commons.apache.org
+ issues_bot_dependabot: dependabot@commons.apache.org
+ pullrequests_bot_dependabot: dependabot@commons.apache.org
issues_bot_codecov-commenter: notifications@commons.apache.org
pullrequests_bot_codecov-commenter: notifications@commons.apache.org
diff --git a/.github/GH-ROBOTS.txt b/.github/GH-ROBOTS.txt
index e3329e55f..64a88674f 100644
--- a/.github/GH-ROBOTS.txt
+++ b/.github/GH-ROBOTS.txt
@@ -5,7 +5,7 @@
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 9ebcd0ebb..90ec55f74 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -5,7 +5,7 @@
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,10 +18,8 @@ updates:
- package-ecosystem: "maven"
directory: "/"
schedule:
- interval: "weekly"
- day: "friday"
+ interval: "quarterly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
- interval: "weekly"
- day: "friday"
+ interval: "quarterly"
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
new file mode 100644
index 000000000..9ff35c83e
--- /dev/null
+++ b/.github/pull_request_template.md
@@ -0,0 +1,30 @@
+
+
+Thanks for your contribution to [Apache Commons](https://commons.apache.org/)! Your help is appreciated!
+
+Before you push a pull request, review this list:
+
+- [ ] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
+- [ ] Read the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) if you use Artificial Intelligence (AI).
+- [ ] I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute?
+- [ ] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself.
+- [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
+- [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
+- [ ] Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index 4605ce109..25084aa7c 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -5,7 +5,7 @@
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -45,19 +45,23 @@ jobs:
steps:
- name: Checkout repository
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
+ uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
persist-credentials: false
- - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
+ - uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
-
+ - uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0
+ with:
+ java-version: 17
+ distribution: 'temurin'
+
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
- uses: github/codeql-action/init@46ed16ded91731b2df79a2893d3aea8e9f03b5c4 # v2.20.3
+ uses: github/codeql-action/init@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -68,7 +72,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
- uses: github/codeql-action/autobuild@46ed16ded91731b2df79a2893d3aea8e9f03b5c4 # v2.20.3
+ uses: github/codeql-action/autobuild@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
@@ -82,4 +86,4 @@ jobs:
# make release
- name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@46ed16ded91731b2df79a2893d3aea8e9f03b5c4 # v2.20.3
+ uses: github/codeql-action/analyze@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
deleted file mode 100644
index d984e1f30..000000000
--- a/.github/workflows/coverage.yml
+++ /dev/null
@@ -1,52 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-name: Coverage
-
-on: [push, pull_request]
-
-permissions:
- contents: read
-
-jobs:
- build:
-
- runs-on: ubuntu-latest
- strategy:
- matrix:
- java: [ 8 ]
-
- steps:
- - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- with:
- persist-credentials: false
- - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
- with:
- path: ~/.m2/repository
- key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
- restore-keys: |
- ${{ runner.os }}-maven-
- - name: Set up JDK ${{ matrix.java }}
- uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
- with:
- distribution: 'temurin'
- java-version: ${{ matrix.java }}
- - name: Build with Maven
- run: mvn -V test jacoco:report --file pom.xml --no-transfer-progress
-
- - name: Upload coverage to Codecov
- uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
- with:
- files: ./target/site/jacoco/jacoco.xml
diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml
new file mode 100644
index 000000000..1df866604
--- /dev/null
+++ b/.github/workflows/dependency-review.yml
@@ -0,0 +1,31 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: 'Dependency Review'
+on: [pull_request]
+
+permissions:
+ contents: read
+
+jobs:
+ dependency-review:
+ runs-on: ubuntu-latest
+ steps:
+ - name: 'Checkout Repository'
+ uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
+ - name: 'Dependency Review PR'
+ uses: actions/dependency-review-action@3c4e3dcb1aa7874d2c16be7d79418e9b7efd6261 # v4.8.2
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index d74eae20e..befc6da1e 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -5,7 +5,7 @@
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,8 +15,12 @@
name: Java CI
-on: [push, pull_request]
-
+on:
+ push:
+ branches: [ master ]
+ pull_request:
+ branches: [ master ]
+
permissions:
contents: read
@@ -27,26 +31,26 @@ jobs:
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
- java: [ 8, 11, 17 ]
+ java: [ 17, 21, 24 ]
experimental: [false]
-# include:
-# - java: 18-ea
-# experimental: true
+ include:
+ - java: 25-ea
+ experimental: true
steps:
- - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
+ - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
persist-credentials: false
- - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
+ - uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK ${{ matrix.java }}
- uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
+ uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
- name: Build with Maven
- run: mvn -V -B --file pom.xml --no-transfer-progress
+ run: mvn --show-version --batch-mode --no-transfer-progress
diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml
index eba354fe9..3c49b0d63 100644
--- a/.github/workflows/scorecards-analysis.yml
+++ b/.github/workflows/scorecards-analysis.yml
@@ -5,7 +5,7 @@
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -40,12 +40,12 @@ jobs:
steps:
- name: "Checkout code"
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
+ uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
persist-credentials: false
- name: "Run analysis"
- uses: ossf/scorecard-action@08b4669551908b1024bb425080c797723083c031 # 2.2.0
+ uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # 2.4.3
with:
results_file: results.sarif
results_format: sarif
@@ -57,13 +57,13 @@ jobs:
publish_results: true
- name: "Upload artifact"
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # 3.1.0
+ uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # 6.0.0
with:
name: SARIF file
path: results.sarif
retention-days: 5
- name: "Upload to code-scanning"
- uses: github/codeql-action/upload-sarif@46ed16ded91731b2df79a2893d3aea8e9f03b5c4 # 2.20.3
+ uses: github/codeql-action/upload-sarif@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9
with:
sarif_file: results.sarif
diff --git a/.gitignore b/.gitignore
index 443c59a66..b39768638 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,9 @@ site-content
/.settings/
/bin/
.idea/
+.vscode/
*.iml
+
+# NetBeans files
+nb-configuration.xml
+nbactions.xml
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
index 3ed501501..b4342f33c 100644
--- a/CODE_OF_CONDUCT.md
+++ b/CODE_OF_CONDUCT.md
@@ -6,7 +6,7 @@
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 5814970db..8f8f321b5 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -6,7 +6,7 @@
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@@ -61,16 +61,15 @@ Making Changes
--------------
+ Create a _topic branch_ for your isolated work.
- * Usually you should base your branch on the `master` branch.
- * A good topic branch name can be the JIRA bug id plus a keyword, e.g. `POOL-123-InputStream`.
+ * Usually you should base your branch from the `master` branch.
+ * A good topic branch name can be the JIRA bug id plus a keyword, for example, `POOL-123-InputStream`.
* If you have submitted multiple JIRA issues, try to maintain separate branches and pull requests.
+ Make commits of logical units.
* Make sure your commit messages are meaningful and in the proper format. Your commit message should contain the key of the JIRA issue.
- * e.g. `POOL-123: Close input stream earlier`
+ * For example, `[POOL-123] Close input stream earlier`
+ Respect the original code style:
- + Only use spaces for indentation.
+ + Only use spaces for indentation; you can check for unnecessary whitespace with `git diff` before committing.
+ Create minimal diffs - disable _On Save_ actions like _Reformat Source Code_ or _Organize Imports_. If you feel the source code should be reformatted create a separate PR for this change first.
- + Check for unnecessary whitespace with `git diff` -- check before committing.
+ Make sure you have added the necessary tests for your changes, typically in `src/test/java`.
+ Run all the tests with `mvn clean verify` to assure nothing else was accidentally broken.
@@ -80,8 +79,7 @@ Making Trivial Changes
The JIRA tickets are used to generate the changelog for the next release.
For changes of a trivial nature to comments and documentation, it is not always necessary to create a new ticket in JIRA.
-In this case, it is appropriate to start the first line of a commit with '(doc)' instead of a ticket number.
-
+In this case, it is appropriate to start the first line of a commit with '[doc]' or '[javadoc]' instead of a ticket number.
Submitting Changes
------------------
diff --git a/LICENSE.txt b/LICENSE.txt
index 06b2ca877..167bbe266 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -193,16 +193,16 @@
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-
+
APACHE COMMONS POOL DERIVATIVE WORKS:
-
+
The LinkedBlockingDeque implementation is based on an implementation written by
Doug Lea with assistance from members of JCP JSR-166 Expert Group and released
to the public domain, as explained at
diff --git a/NOTICE.txt b/NOTICE.txt
index 2c90b4379..e7123c404 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -1,5 +1,5 @@
Apache Commons Pool
-Copyright 2001-2023 The Apache Software Foundation
+Copyright 2001-2026 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (https://www.apache.org/).
diff --git a/README.md b/README.md
index f07fdc8a8..867c1004b 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@@ -43,11 +43,10 @@
Apache Commons Pool
===================
-[](https://github.com/apache/commons-pool/actions)
-[](https://app.codecov.io/gh/apache/commons-pool)
-[](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-pool2/?gav=true)
+[](https://github.com/apache/commons-pool/actions/workflows/maven.yml)
+[](https://search.maven.org/artifact/org.apache.commons/commons-pool2)
[](https://javadoc.io/doc/org.apache.commons/commons-pool2/2.12.0)
-[](https://github.com/apache/commons-pool/actions/workflows/codeql-analysis.yml?query=workflow%3ACodeQL)
+[](https://github.com/apache/commons-pool/actions/workflows/codeql-analysis.yml)
[](https://api.securityscorecards.dev/projects/github.com/apache/commons-pool)
The Apache Commons Object Pooling Library.
@@ -57,7 +56,7 @@ Documentation
More information can be found on the [Apache Commons Pool homepage](https://commons.apache.org/proper/commons-pool).
The [Javadoc](https://commons.apache.org/proper/commons-pool/apidocs) can be browsed.
-Questions related to the usage of Apache Commons Pool should be posted to the [user mailing list][ml].
+Questions related to the usage of Apache Commons Pool should be posted to the [user mailing list](https://commons.apache.org/mail-lists.html).
Where can I get the latest release?
-----------------------------------
@@ -68,8 +67,8 @@ Alternatively, you can pull it from the central Maven repositories:
```xml
org.apache.commons
- commons-pool2
- 2.12.0
+ commons-pool3
+ 3.0.0
```
@@ -81,14 +80,16 @@ There are some guidelines which will make applying PRs easier for us:
+ No tabs! Please use spaces for indentation.
+ Respect the code style.
+ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change.
-+ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn```.
++ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running `mvn`.
++ Before you pushing a PR, run `mvn` (by itself), this runs the default goal, which contains all build checks.
++ To see the code coverage report, regardless of coverage failures, run `mvn clean site -Dcommons.jacoco.haltOnFailure=false`
If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas).
You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md).
License
-------
-This code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0).
+This code is under the [Apache License v2](https://www.apache.org/licenses/LICENSE-2.0).
See the `NOTICE.txt` file for required notices and attributions.
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 29f9dc6ac..9a23594a5 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -1,29 +1,73 @@
+Apache Commons Pool 2.12.1 Release Notes
+----------------------------------------
+
+The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.12.1.
+
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
+In addition to performance and scalability improvements, version 2 includes robust instance
+tracking and pool monitoring.
+
+Version 2.7.x and up requires Java 8 or above.
+Version 2.6.x requires Java 7 or above.
+Version 2.5.x requires Java 7 or above.
+Version 2.0 requires 6 or above.
+
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
+ and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
+ be able to upgrade to a new minor or patch release without requiring code
+ changes.
+
+Changes in version 2.12.1 include:
+
+Fixed Bugs:
+o Use java.time.Instant precision in org.apache.commons.pool2.impl.ThrowableCallStack.Snapshot throwable message. Thanks to Gary Gregory.
+o GenericObjectPool.borrowObject(Duration) doesn't obey its borrowMaxWait Duration argument when the argument is different from GenericObjectPool.getMaxWaitDuration(). Thanks to Gary Gregory.
+o POOL-418: The maximum wait time for GenericObjectPool.borrowObject(*) may exceed expectations due to a spurious thread wakeup. Thanks to Gary Gregory.
+o Javadoc is missing its Overview page. Thanks to Gary Gregory.
+o Migrate site generation templates to https://maven.apache.org/xsd/xdoc-2.0.xsd. Thanks to Gary Gregory.
+
+Changes:
+o Bump org.apache.commons:commons-parent from 62 to 79. Thanks to Gary Gregory.
+o [test] Bump commons-lang3 from 3.13.0 to 3.17.0. Thanks to Gary Gregory.
+o [site] Pickup org.apache.bcel:bcel version from parent POM. Thanks to Gary Gregory.
+o [test] Bump org.ow2.asm:asm-util from 9.5 to 9.7.1. Thanks to Gary Gregory.
+
+
+For complete information on Apache Commons Pool, including instructions on how to submit bug reports,
+patches, or suggestions for improvement, see the Apache Commons Pool website:
+
+https://commons.apache.org/proper/commons-pool/
+
+Download page: https://commons.apache.org/proper/commons-pool/download_pool.cgi
+
+-----------------------------------------------------------------------------------------------
Apache Commons Pool 2.12.0 RELEASE NOTES
The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.12.0.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
-tracking and pool monitoring.
+tracking and pool monitoring.
Version 2.7.x and up requires Java 8 or above.
Version 2.6.x requires Java 7 or above.
Version 2.5.x requires Java 7 or above.
Version 2.0 requires 6 or above.
-No client code changes are required to migrate from versions 2.0-2.3 to version 2.4.3.
-Users of version 1.x should consult the migration guide on the Commons Pool web site.
-
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
-This is a feature and maintenance release (Java 8).
+This is a feature and maintenance release (Java 8 or above).
Changes in version 2.12.0 include:
@@ -33,23 +77,26 @@ o Add GenericKeyedObjectPool.getKeys(). Thanks to Vamsi Pavan Kumar S
o Add KeyedObjectPool.getKeys(). Thanks to Gary Gregory.
o Add github/codeql-action.
o Add BaseGenericObjectPool.Evictor.toString().
-o BaseGenericObjectPool now implements AutoCloseable.
+o Make BaseGenericObjectPool implement AutoCloseable.
+o Add BaseGenericObjectPool methods that return Duration and deprecate equivalents that return milliseconds as long.
+o Add BaseObjectPoolConfig.DEFAULT_DURATION_BETWEEN_EVICTION_RUNS and deprecate BaseObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS.
Fixed Bugs:
o POOL-401: Ensure that capacity freed by invalidateObject is available to all keyed pools.
o POOL-391: Ensure capacity freed by clear is made available to GKOP borrowers. Thanks to Codievilky August.
o POOL-402: Check blockWhenExhausted in hasBorrowWaiters #116. Thanks to Cp-John, Phil Steitz, Bruno P. Kinoshita, Gary Gregory.
o Simplify test assertion with similar call but simpler. #131. Thanks to Arturo Bernal.
-o POOL-269: Use generic exceptions instead of java.lang.Exception. Thanks to Gary Gregory.
o POOL-405: NullPointerException GenericKeyedObjectPool.invalidateObject(GenericKeyedObjectPool.java:1343). Thanks to Gary Gregory.
-o POOL-408: A typo of KeyedPooledObjectFactory on the site and Javadoc. Thanks to Zhenyu Luo, Gary Gregory.
+o POOL-408: Fix a typo related to KeyedPooledObjectFactory on the site and Javadoc. Thanks to Zhenyu Luo, Gary Gregory.
o Fail-fast on null input for DefaultPooledObjectInfo.DefaultPooledObjectInfo(PooledObject) with a NullPointerException. Thanks to Gary Gregory.
o POOL-393: Improve BaseGenericObjectPool's JMX Register performance when creating many pools. Thanks to Shichao Yuan, Phil Steitz, Niall Pemberton.
o Null-guard in GenericObjectPool.use(T) like other call sites of GenericObjectPool.getPooledObject(T). Thanks to Réda Housni Alaoui, Gary Gregory.
-o POOL-411: NPE when deregistering key at end of borrow. Thanks to Richard Eckart de Castilho, Gary Gregory.
-o Make private class GenericKeyedObjectPool.ObjectDeque class static. Thanks to Gary Gregory.
-o Make private class BaseGenericObjectPool.StatsStore class static. Thanks to Gary Gregory.
+o POOL-411: Guard against NPE when deregistering a key at the end of borrow. Thanks to Richard Eckart de Castilho, Gary Gregory.
+o Make private GenericKeyedObjectPool.ObjectDeque class static. Thanks to Gary Gregory.
+o Make private BaseGenericObjectPool.StatsStore class static. Thanks to Gary Gregory.
o [StepSecurity] ci: Harden GitHub Actions #225. Thanks to step-security-bot, Gary Gregory.
+o Fix possible NPE in DefaultPooledObjectInfo.getPooledObjectToString(). Thanks to Gary Gregory.
+o Fix possible NPE in DefaultPooledObjectInfo.getPooledObjectType(). Thanks to Gary Gregory.
Changes:
o Bump actions/cache from 2.1.6 to 3.0.10 #117, #138, #158, #174, #178. Thanks to Dependabot, Gary Gregory.
@@ -70,6 +117,7 @@ o Bump commons-parent from 52 to 58 #173, #195, #204, #222. Thanks to
o Bump japicmp-maven-plugin from 0.15.3 to 0.16.0. Thanks to Gary Gregory.
o Bump animal-sniffer-maven-plugin 1.20 to 1.21. Thanks to Gary Gregory.
o Bump Apache Commons BCEL 6.5.0 to 6.7.0 #194. Thanks to Gary Gregory, Dependabot.
+o Bump commons-lang3 from 3.12.0 to 3.13.0. Thanks to Gary Gregory.
For complete information on Apache Commons Pool, including instructions on how to submit bug reports,
@@ -85,10 +133,10 @@ Download page: https://commons.apache.org/proper/commons-pool/download_pool.cgi
The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.11.1.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
-tracking and pool monitoring.
+tracking and pool monitoring.
Version 2.7.x and up requires Java 8 or above.
Version 2.6.x requires Java 7 or above.
@@ -98,15 +146,15 @@ Version 2.0 requires 6 or above.
No client code changes are required to migrate from versions 2.0-2.3 to version 2.4.3.
Users of version 1.x should consult the migration guide on the Commons Pool web site.
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
-This is a maintenance release (Java 8).
+This is a maintenance release (Java 8 or above).
Changes in version 2.11.1 include:
@@ -144,10 +192,10 @@ Download page: https://commons.apache.org/proper/commons-pool/download_pool.cgi
The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.11.0.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
-tracking and pool monitoring.
+tracking and pool monitoring.
Version 2.10.x requires Java 8 or above.
Version 2.9.x requires Java 8 or above.
@@ -160,15 +208,15 @@ Version 2.0 requires 6 or above.
No client code changes are required to migrate from versions 2.0-2.3 to version 2.4.3.
Users of version 1.x should consult the migration guide on the Commons Pool web site.
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
-This is a feature release (Java 8).
+This is a feature release (Java 8 or above).
Changes in version 2.11.0 include:
@@ -231,10 +279,10 @@ Download page: https://commons.apache.org/proper/commons-pool/download_pool.cgi
The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.10.0.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
-tracking and pool monitoring.
+tracking and pool monitoring.
Version 2.10.x requires Java 8 or above.
Version 2.9.x requires Java 8 or above.
@@ -247,15 +295,15 @@ Version 2.0 requires 6 or above.
No client code changes are required to migrate from versions 2.0-2.3 to version 2.4.3.
Users of version 1.x should consult the migration guide on the Commons Pool web site.
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
-This is a MMMM release (Java 8).
+This is a MMMM release (Java 8 or above).
Changes in version 2.10.0 include:
@@ -303,10 +351,10 @@ Download page: https://commons.apache.org/proper/commons-pool/download_pool.cgi
The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.9.0.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
-tracking and pool monitoring.
+tracking and pool monitoring.
Version 2.9.x requires Java 8 or above.
Version 2.8.x requires Java 8 or above.
@@ -318,15 +366,15 @@ Version 2.0 requires 6 or above.
No client code changes are required to migrate from versions 2.0-2.3 to version 2.4.3.
Users of version 1.x should consult the migration guide on the Commons Pool web site.
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
-This is a minor release (Java 8).
+This is a minor release (Java 8 or above).
Changes in version 2.9.0 include:
@@ -350,23 +398,25 @@ Download page: https://commons.apache.org/proper/commons-pool/download_pool.cgi
The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.8.1.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
-tracking and pool monitoring. Version 2 requires JDK level 1.6 or above.
+tracking and pool monitoring.
+
+Version 2 requires JDK level 1.6 or above.
No client code changes are required to migrate from versions 2.0-2.3 to version 2.4.3.
Users of version 1.x should consult the migration guide on the Commons Pool web site.
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
-This is a maintenance release (Java 8).
+This is a maintenance release (Java 8 or above).
Changes in version 2.8.1 include:
@@ -403,23 +453,25 @@ Download page: https://commons.apache.org/proper/commons-pool/download_pool.cgi
The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.8.0.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
-tracking and pool monitoring. Version 2 requires JDK level 1.6 or above.
+tracking and pool monitoring.
+
+Version 2 requires JDK level 1.6 or above.
No client code changes are required to migrate from versions 2.0-2.3 to version 2.4.3.
Users of version 1.x should consult the migration guide on the Commons Pool web site.
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
-This is a maintenance release (Java 8).
+This is a maintenance release (Java 8 or above).
Changes in version 2.8.0 include:
@@ -455,23 +507,25 @@ Download page: https://commons.apache.org/proper/commons-pool/download_pool.cgi
The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.7.0.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
-tracking and pool monitoring. Version 2 requires JDK level 1.6 or above.
+tracking and pool monitoring.
+
+Version 2 requires JDK level 1.6 or above.
No client code changes are required to migrate from versions 2.0-2.3 to version 2.4.3.
Users of version 1.x should consult the migration guide on the Commons Pool web site.
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
-This is a feature release (Java 8).
+This is a feature release (Java 8 or above).
Changes in version 2.7.0 include:
@@ -502,19 +556,21 @@ Download page: https://commons.apache.org/proper/commons-pool/download_pool.cgi
The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.6.2.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
-tracking and pool monitoring. Version 2 requires JDK level 1.6 or above.
+tracking and pool monitoring.
+
+Version 2 requires JDK level 1.6 or above.
No client code changes are required to migrate from versions 2.0-2.3 to version 2.4.3.
Users of version 1.x should consult the migration guide on the Commons Pool web site.
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
@@ -540,19 +596,21 @@ Download page: https://commons.apache.org/proper/commons-pool/download_pool.cgi
The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.6.1.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
-tracking and pool monitoring. Version 2 requires JDK level 1.6 or above.
+tracking and pool monitoring.
+
+Version 2 requires JDK level 1.6 or above.
No client code changes are required to migrate from versions 2.0-2.3 to version 2.4.3.
Users of version 1.x should consult the migration guide on the Commons Pool web site.
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
@@ -589,8 +647,8 @@ Download page: https://commons.apache.org/proper/commons-pool/download_pool.cgi
The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.6.0.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
tracking and pool monitoring.
@@ -601,11 +659,11 @@ tracking and pool monitoring.
No client code changes are required to migrate from versions 2.0-2.3 to version 2.4.3.
Users of version 1.x should consult the migration guide on the Commons Pool web site.
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
@@ -643,19 +701,21 @@ Download page: https://commons.apache.org/proper/commons-pool/download_pool.cgi
The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.5.0.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
-tracking and pool monitoring. Version 2 requires JDK level 1.6 or above.
+tracking and pool monitoring.
+
+Version 2 requires JDK level 1.6 or above.
No client code changes are required to migrate from versions 2.0-2.3 to version 2.4.3.
Users of version 1.x should consult the migration guide on the Commons Pool web site.
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
@@ -686,19 +746,21 @@ https://commons.apache.org/proper/commons-pool/
The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.4.3.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
-tracking and pool monitoring. Version 2 requires JDK level 1.6 or above.
+tracking and pool monitoring.
+
+Version 2 requires JDK level 1.6 or above.
No client code changes are required to migrate from versions 2.0-2.3 to version 2.4.3.
Users of version 1.x should consult the migration guide on the Commons Pool web site.
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
@@ -745,19 +807,21 @@ https://commons.apache.org/proper/commons-pool/
The Apache Commons Pool team is pleased to announce the release of Apache Commons Pool 2.4.2.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
-tracking and pool monitoring. Version 2 requires JDK level 1.6 or above.
+tracking and pool monitoring.
+
+Version 2 requires JDK level 1.6 or above.
No client code changes are required to migrate from versions 2.0-2.3 to version 2.4.2.
Users of version 1.x should consult the migration guide on the Commons Pool web site.
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
@@ -772,10 +836,7 @@ o POOL-298: Changed default jmxNameBase in BaseObjectPoolConfig to the correct
o POOL-300: Added PrintWriter flush to DefaultPooledObject's printStackTrace method.
-
For complete information on Apache Commons Pool, including instructions on how to submit bug reports,
patches, or suggestions for improvement, see the Apache Commons Pool website:
https://commons.apache.org/proper/commons-pool/
-
-
diff --git a/SECURITY.md b/SECURITY.md
index 51943ba7b..744d4cddb 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -6,7 +6,7 @@
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/doc/ReaderUtil.java b/doc/ReaderUtil.java
index 0720b9005..0c292a560 100644
--- a/doc/ReaderUtil.java
+++ b/doc/ReaderUtil.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -24,7 +24,7 @@
import java.io.IOException;
import java.io.Reader;
-import org.apache.commons.pool2.ObjectPool;
+import org.apache.commons.pool3.ObjectPool;
/**
* Maintains a pool of StringBuffers used to dump contents of Readers.
diff --git a/doc/ReaderUtilClient.java b/doc/ReaderUtilClient.java
index c6039e70e..878e19d78 100644
--- a/doc/ReaderUtilClient.java
+++ b/doc/ReaderUtilClient.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -25,7 +25,7 @@
import java.io.Reader;
import java.io.StringReader;
-import org.apache.commons.pool2.impl.GenericObjectPool;
+import org.apache.commons.pool3.impl.GenericObjectPool;
/**
* Instantiates and uses a ReaderUtil. The GenericObjectPool supplied to the constructor will have
diff --git a/doc/StringBufferFactory.java b/doc/StringBufferFactory.java
index 5bcb62f42..b96c862fe 100644
--- a/doc/StringBufferFactory.java
+++ b/doc/StringBufferFactory.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,9 +21,9 @@
* It is not intended to be included in a source release.
*/
-import org.apache.commons.pool2.BasePooledObjectFactory;
-import org.apache.commons.pool2.PooledObject;
-import org.apache.commons.pool2.impl.DefaultPooledObject;
+import org.apache.commons.pool3.BasePooledObjectFactory;
+import org.apache.commons.pool3.PooledObject;
+import org.apache.commons.pool3.impl.DefaultPooledObject;
/**
* Example PooledObjectFactory for pooled StringBuffers.
diff --git a/pom.xml b/pom.xml
index c77bc54d9..cdf63099d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,4 @@
-
+
@@ -156,20 +62,13 @@
junit-jupitertest
-
- org.hamcrest
- hamcrest-library
- 2.2
- test
- org.apache.commonscommons-lang3
- 3.12.0
+ 3.20.0test
-
@@ -178,37 +77,48 @@
scm:svn:https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-pool/
-
UTF-8UTF-8
- 1.8
- 1.8
+
+ 2024-02-01T03:27:02Z
+ 17
+ 17
+ 17pool
- org.apache.commons.pool2
+ org.apache.commons.pool3RC1
+ ${basedir}/src/conf/checkstyle-suppressions.xml
+
+ 3.0.0
+ (Java 17)
- 2.12.0
- (Java 8)
+ 2.12.0
+ (Java 8 or above)
- 2.6.2
- (Java 7)
-
+ 2.6.2
+ (Java 7 or above)POOL12310488site-contentnet.sf.cglib.proxy;resolution:=optional,*
-
-
- 2.11.1
+
+ 3.0.0-SNAPSHOTtrue
- Gary Gregory
- 86fdc7e2a11262cb
-
- false
+
+ truefalse
+ true
+ --add-opens java.base/java.lang=ALL-UNNAMED
+
+ true
+ 0.98
+ 0.86
+ 0.87
+ 0.83
+ 0.86
+ 0.80
-
clean verify apache-rat:check checkstyle:check japicmp:cmp javadoc:javadoc spotbugs:check pmd:check pmd:cpd-check
@@ -222,27 +132,15 @@
true
-
-
- org.apache.maven.plugins
- maven-project-info-reports-plugin
- ${commons.project-info.version}
-
-
-
- org.apache.bcel
- bcel
- 6.7.0
-
-
- org.apache.maven.pluginsmaven-checkstyle-plugin${basedir}/src/conf/checkstyle.xml
- false
+ ${checkstyle.suppress.file}${basedir}/license-header.txt
+ false
+ true
@@ -252,6 +150,15 @@
${basedir}/src/conf/findbugs-exclude-filter.xml
+
+ maven-pmd-plugin
+
+ ${maven.compiler.target}
+
+ ${basedir}/src/conf/pmd-ruleset.xml
+
+
+
@@ -259,20 +166,21 @@
org.apache.ratapache-rat-plugin
-
- src/test/resources/test1
- src/test/resources/test2
- .checkstyle
- .fbprefs
- .pmd
-
+
+ src/test/resources/test1
+ src/test/resources/test2
+ .checkstyle
+ .fbprefs
+ .pmd
+ org.apache.maven.pluginsmaven-surefire-plugin
-
+ ${argLine} ${surefire.argline}
+
1800**/Test*.java
@@ -284,56 +192,61 @@
+
+ maven-assembly-plugin
+
+
+ src/assembly/bin.xml
+ src/assembly/src.xml
+
+ gnu
+
+
+
+ org.apache.maven.plugins
+ maven-scm-publish-plugin
+
+
+ api-*
+
+
+
- maven-assembly-plugin
+ com.github.siom79.japicmp
+ japicmp-maven-plugin
-
- src/assembly/bin.xml
- src/assembly/src-tar-gz.xml
- src/assembly/src-zip.xml
-
- gnu
+
+
+
+ METHOD_NEW_DEFAULT
+ true
+ true
+ PATCH
+
+
+ org.apache.maven.plugins
- maven-scm-publish-plugin
+ maven-jar-plugin
-
- api-*
-
+
+
+ ${commons.module.name}
+
+
-
- com.github.siom79.japicmp
- japicmp-maven-plugin
-
-
-
-
- METHOD_NEW_DEFAULT
- true
- true
- PATCH
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
-
-
-
- ${commons.module.name}
-
-
-
-
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+
+ src/main/java
+
+
-
@@ -365,13 +278,13 @@
org.apache.ratapache-rat-plugin
-
- src/test/resources/test1
- src/test/resources/test2
- .checkstyle
- .fbprefs
- .pmd
-
+
+ src/test/resources/test1
+ src/test/resources/test2
+ .checkstyle
+ .fbprefs
+ .pmd
+
@@ -406,39 +319,90 @@
-
-
- java9
-
- 9
-
+
+
+
+ Morgan Delagrange
+ morgand
+
+
+
+
+ Geir Magnusson
+ geirm
+
+
+
+
+ Craig McClanahan
+ craigmcc
+
+
+
+
+ Rodney Waldhoff
+ rwaldhoff
+
+
+
+
+ David Weinrich
+ dweinr1
+
+
+
+
+ Dirk Verbeeck
+ dirkv
+
+
+
+
+ Robert Burrell Donkin
+ rdonkin
+
+ The Apache Software Foundation
+
+
+ Sandy McArthur
+ sandymac
+
+ The Apache Software Foundation
+
+
+ Simone Tripodi
+ simonetripodi
+ The Apache Software Foundation
+
+
+ ggregory
+ Gary Gregory
+ ggregory at apache.org
+ https://www.garygregory.com
+ The Apache Software Foundation
+ https://www.apache.org/
+
+ PMC Member
+
+ America/New_York
-
- true
+ https://people.apache.org/~ggregory/img/garydgregory80.png
-
-
- java16
-
-
- [16,)
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- --illegal-access=permit
- --add-opens java.base/java.lang=ALL-UNNAMED
-
-
-
-
-
-
-
-
+
+
+ Matt Sicker
+ mattsicker
+ The Apache Software Foundation
+
+
+
+
+ Todd Carmichael
+ toddc@concur.com
+
+
+ Arturo Bernal
+
+
diff --git a/pool-RC.sh b/pool-RC.sh
index 3b37fbc81..74354d870 100755
--- a/pool-RC.sh
+++ b/pool-RC.sh
@@ -7,7 +7,7 @@
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -25,8 +25,6 @@
# svn pub/sub dev checkout.
# 2) Nexus repo from previous RC has been dropped.
#
-# $Revision$ $Date$
-# -----------------------------------------------------------------------------
# Set script variables
version=2.4.3
repo_path=~/.m2/repository/org/apache/commons/commons-pool2/${version}
diff --git a/pool-pre-RC.sh b/pool-pre-RC.sh
index 26b68a816..3cfa36859 100755
--- a/pool-pre-RC.sh
+++ b/pool-pre-RC.sh
@@ -7,7 +7,7 @@
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -23,7 +23,6 @@
# to checkin. Both RELEASE-NOTES.txt and the generated download
# page need to be checked in after review.
#
-# $Revision$ $Date$
# ----------------------------------------------------------------------------
version=2.4.3
mvn changes:announcement-generate -Prelease-notes -Dchanges.version=${version}
diff --git a/pool-release.sh b/pool-release.sh
index 7ccf1c481..5290630e2 100755
--- a/pool-release.sh
+++ b/pool-release.sh
@@ -7,7 +7,7 @@
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -28,7 +28,6 @@
# 0) Commit the local changes to actually publish the artifacts
# 1) Cleanup old versions in dist
#
-# $Revision$ $Date$
# -----------------------------------------------------------------------------
# Set script variables
version=2.4.3 # version being released
diff --git a/src/assembly/bin.xml b/src/assembly/bin.xml
index 576229197..1d0d7f420 100644
--- a/src/assembly/bin.xml
+++ b/src/assembly/bin.xml
@@ -6,7 +6,7 @@
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,31 +14,33 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
- bin
-
- tar.gz
- zip
-
- false
-
-
-
- LICENSE.txt
- NOTICE.txt
- RELEASE-NOTES.txt
-
-
-
- target
-
-
- *.jar
-
-
-
- target/site/apidocs
- apidocs
-
-
+
+ bin
+
+ tar.gz
+ zip
+
+ false
+
+
+
+ LICENSE.txt
+ NOTICE.txt
+ RELEASE-NOTES.txt
+
+
+
+ target
+
+
+ *.jar
+
+ 644
+
+
+ target/site/apidocs
+ apidocs
+
+
diff --git a/src/assembly/src-tar-gz.xml b/src/assembly/src-tar-gz.xml
deleted file mode 100644
index b2b9bfcdc..000000000
--- a/src/assembly/src-tar-gz.xml
+++ /dev/null
@@ -1,74 +0,0 @@
-
-
- src
-
- tar.gz
-
- ${project.artifactId}-${project.version}-src
-
-
-
- build.xml
- checkstyle.xml
- LICENSE.txt
- license-header.txt
- NOTICE.txt
- pom.xml
- README.txt
- RELEASE-NOTES.txt
- findbugs-exclude-filter.xml
- build.properties.sample
-
- lf
-
-
- doc
- lf
-
-
- src/site/resources
-
-
- src/site/xdoc
- lf
-
-
- src/site
-
- site.xml
-
- lf
-
-
- src/changes
- lf
-
-
- src/main
- lf
-
-
- src/test/java
- lf
-
-
- src/test/resources
-
-
-
-
diff --git a/src/assembly/src-zip.xml b/src/assembly/src-zip.xml
deleted file mode 100644
index 5fafe189c..000000000
--- a/src/assembly/src-zip.xml
+++ /dev/null
@@ -1,73 +0,0 @@
-
-
- src
-
- zip
-
- ${project.artifactId}-${project.version}-src
-
-
-
- build.xml
- checkstyle.xml
- LICENSE.txt
- license-header.txt
- NOTICE.txt
- pom.xml
- README.txt
- RELEASE-NOTES.txt
- findbugs-exclude-filter.xml
- build.properties.sample
-
- crlf
-
-
- doc
- crlf
-
-
- src/site/resources
-
-
- src/site/xdoc
- crlf
-
-
- src/site
-
- site.xml
-
- crlf
-
-
- src/changes
- crlf
-
-
- src/main
- crlf
-
-
- src/test/java
- crlf
-
-
- src/test/resources
-
-
-
diff --git a/src/assembly/src.xml b/src/assembly/src.xml
new file mode 100644
index 000000000..9f9f8df5f
--- /dev/null
+++ b/src/assembly/src.xml
@@ -0,0 +1,46 @@
+
+
+
+ src
+
+ tar.gz
+ zip
+
+ ${artifactId}-${version}-src
+
+
+
+ BUILDING.txt
+ CODE_OF_CONDUCT.md
+ CONTRIBUTING.md
+ LICENSE.txt
+ NOTICE.txt
+ pom.xml
+ README.md
+ RELEASE-NOTES.txt
+ SECURITY.md
+
+
+
+ src
+
+
+
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 14ed56aa0..89f633895 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -7,7 +7,7 @@
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@@ -37,15 +37,52 @@ and commit
The type attribute can be add,update,fix,remove.
-->
-
-
+ xsi:schemaLocation="http://maven.apache.org/changes/2.0.0 https://maven.apache.org/xsd/changes-2.0.0.xsd">
Apache Commons Pool Release Notes
-
+
+
+ Add ReslientPooledObjectFactory to provide resilience against factory outages.
+ Add an option to JdkProxySource allowing to unwrap UndeclaredThrowableException #261.
+ Add org.apache.commons.pool3.proxy.CglibProxySource.Builder.
+ Add org.apache.commons.pool3.proxy.JdkProxySource.Builder.
+ Add org.apache.commons.pool3.proxy.AbstractProxySource.
+ Made statistics collection optional in BaseGenericObjectPool #429.
+
+ Remove -nouses directive from maven-bundle-plugin. OSGi package imports now state 'uses' definitions for package imports, this doesn't affect JPMS (from org.apache.commons:commons-parent:80).
+ Operation on the "idleHighWaterMark" shared variable in "ErodingFactor" class is not atomic [org.apache.commons.pool3.PoolUtils$ErodingFactor] At PoolUtils.java:[line 101] AT_NONATOMIC_OPERATIONS_ON_SHARED_VARIABLE.
+ org.apache.commons.pool3.impl.GenericObjectPool.create(Duration) duration computation doesn't match 2.x. See also PR #409 from shengulong.
+ Fix potential ConcurrentModificationException in EvictionTimer thread clean-up.
+ Fix potential ConcurrentModificationException in EvictionTimer tasks.
+ Fix Apache RAT plugin console warnings.
+
+ Deprecations from version 2.x have been removed.
+
+ Bump Java from 8 to 17.
+ Bump org.apache.commons:commons-parent from 58 to 93 #297, #328, #338, #341, #347, #351, #354, #361, #431, #445, #448.
+ Bump org.ow2.asm:asm-util from 9.5 to 9.7.1 #252, #294, #355.
+ Bump org.apache.commons:commons-lang3 from 3.13.0 to 3.20.0 #326, #333, #342, #415.
+ Bump org.apache.bcel:bcel from 6.7.0 to 6.10.0 #263, #306, #327.
+
+
+
+ Use java.time.Instant precision in org.apache.commons.pool2.impl.ThrowableCallStack.Snapshot throwable message.
+ GenericObjectPool.borrowObject(Duration) doesn't obey its borrowMaxWait Duration argument when the argument is different from GenericObjectPool.getMaxWaitDuration().
+ The maximum wait time for GenericObjectPool.borrowObject(*) may exceed expectations due to a spurious thread wakeup.
+ Javadoc is missing its Overview page.
+ Migrate site generation templates to https://maven.apache.org/xsd/xdoc-2.0.xsd.
+
+
+ Bump org.apache.commons:commons-parent from 62 to 79.
+ [test] Bump commons-lang3 from 3.13.0 to 3.19.0.
+ [site] Pickup org.apache.bcel:bcel version from parent POM.
+ [test] Bump org.ow2.asm:asm-util from 9.5 to 9.7.1.
+
+
Ensure that capacity freed by invalidateObject is available to all keyed pools.
@@ -169,8 +206,11 @@ The type attribute can be add,update,fix,remove.
Bump Apache Commons BCEL 6.5.0 to 6.7.0 #194.
+
+ Bump commons-lang3 from 3.12.0 to 3.13.0.
+
-
+
Getting a PooledObject's active duration returns a negative duration when the object is borrowed but not returned. Affects:
@@ -211,7 +251,7 @@ The type attribute can be add,update,fix,remove.
Bump spotbugs from 4.2.3 to 4.3.0 and ignore new medium warnings EI_EXPOSE_REP and EI_EXPOSE_REP2.
-
+
Fix "[WARNING] Old version of checkstyle detected. Consider updating to >= v8.30." Update Checktyle to 8.44.
@@ -290,7 +330,7 @@ The type attribute can be add,update,fix,remove.
Bump checkstyle from 8.44 to 8.45 #92.
-
+
Add and use java.time.Duration APIs timeouts instead of using ints for seconds.
@@ -365,7 +405,7 @@ The type attribute can be add,update,fix,remove.
Bump animal-sniffer-maven-plugin from 1.19 to 1.20.
-
+
Object factory destroy method should carry information on activation context.
@@ -382,7 +422,7 @@ The type attribute can be add,update,fix,remove.
Update optional asm-util from 8.0.1 to 9.0 #44.
-
+
Refactored EvictionTimer usage tracking to fix POOL-386 and handle abandoned pools. #32.
@@ -420,7 +460,7 @@ The type attribute can be add,update,fix,remove.
Update animal-sniffer-maven-plugin from 1.16 to 1.19.
-
+
GenericKeyedObjectPool.returnObject(K, T) should throw IllegalStateException instead of NullPointerException when a key is not found in the pool map.
@@ -455,7 +495,7 @@ The type attribute can be add,update,fix,remove.
[Javadoc] Add missing @throws comment in SoftReferenceObjectPool. #28.
-
+
Update from Java 7 to Java 8.
@@ -472,18 +512,18 @@ The type attribute can be add,update,fix,remove.
Move validation for newly created objects into create(). Fixes #23.
- Add org.apache.commons.pool2.PooledObject#getBorrowedCount().
+ Add org.apache.commons.pool3.PooledObject#getBorrowedCount().
- Add org.apache.commons.pool2.PooledObject#setRequireFullStackTrace(boolean).
+ Add org.apache.commons.pool3.PooledObject#setRequireFullStackTrace(boolean).
CallStackUtils mishandles security manager check part 1.
-
+
- Always null out org.apache.commons.pool2.impl.BaseGenericObjectPool.evictionIterator to match org.apache.commons.pool2.impl.BaseGenericObjectPool.evictor.
+ Always null out org.apache.commons.pool3.impl.BaseGenericObjectPool.evictionIterator to match org.apache.commons.pool3.impl.BaseGenericObjectPool.evictor.
Evictor Thread prevents Spring Context shutdown in standalone app.
@@ -492,7 +532,7 @@ The type attribute can be add,update,fix,remove.
The commons-pool-evictor-thread should run as a Deamon.
-
+
Correct validateObject with concurrent borrowObject
@@ -524,7 +564,7 @@ The type attribute can be add,update,fix,remove.
CallStackUtils mishandles security manager check (partial fix.)
-
+
GenericObjectPool's borrowObject lock if create() fails with Error.
@@ -544,13 +584,13 @@ The type attribute can be add,update,fix,remove.
GenericObjectPool constructor may throw an exception under OSGi.
- org.apache.commons.pool2.impl.GenericObjectPool.getFactoryType() throws java.lang.ClassCastException.
+ org.apache.commons.pool3.impl.GenericObjectPool.getFactoryType() throws java.lang.ClassCastException.
Delete repeated call startEvictor.
-
+
Update from Java 6 to 7.
@@ -564,7 +604,7 @@ The type attribute can be add,update,fix,remove.
Update optional dependency asm-util from 5.2 to 6.0.
- org.apache.commons.pool2.impl.ThrowableCallStack.Snapshot is missing serialVersionUID.
+ org.apache.commons.pool3.impl.ThrowableCallStack.Snapshot is missing serialVersionUID.
Make abandoned logging stack trace requirements configurable. This also reverts
@@ -575,7 +615,7 @@ The type attribute can be add,update,fix,remove.
the default behavior introduced by POOL-320.
-
+
Documentation with repeated words (sources, tests, and examples).
@@ -628,7 +668,7 @@ The type attribute can be add,update,fix,remove.
Update optional OW2 ASM from 5.0.4 to 5.2.
-
+
Changed default jmxNameBase in BaseObjectPoolConfig to the correct (null)
default.
@@ -638,7 +678,7 @@ The type attribute can be add,update,fix,remove.
@@ -646,7 +686,7 @@ to version 2.4.">
+ "This is a maintenance release that includes bug fixes and minor enhancements (Java 6 or above).">
Fixed capacity leak when an object is offered from a GenericKeyedObjectPool while it is
being validated by the evictor.
@@ -681,7 +721,7 @@ to version 2.4.">
+"This is a maintenance release that includes bug fixes and minor enhancements (Java 6 or above).">
Eliminated possibility that DefaultPoolObject#getIdleTimeMillis() could
return a negative value. Use by pool implementations would not hit this
@@ -752,7 +792,7 @@ to version 2.4.">
Ensure that if an attempt is made to return an object multiple times that
@@ -770,7 +810,7 @@ and fixes a small number of bugs.">
Added missing create counter decrement in GenericKeyedObjectPool create method on factory
@@ -806,7 +846,7 @@ including bugfixes and test case improvements.">
is prevented after they have been returned to the pool.
-
+
Support Java 1.5 Generics in version 1.x.
diff --git a/src/changes/release-notes.vm b/src/changes/release-notes.vm
index e4b3356a4..ecc258c88 100644
--- a/src/changes/release-notes.vm
+++ b/src/changes/release-notes.vm
@@ -6,7 +6,7 @@
## "License"); you may not use this file except in compliance
## with the License. You may obtain a copy of the License at
##
-## http://www.apache.org/licenses/LICENSE-2.0
+## https://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing,
## software distributed under the License is distributed on an
@@ -14,29 +14,30 @@
## KIND, either express or implied. See the License for the
## specific language governing permissions and limitations
## under the License.
- ${project.name} ${version} RELEASE NOTES
+${project.name} ${version} Release Notes
+------------------------------------------------
The ${developmentTeam} is pleased to announce the release of ${project.name} ${version}.
-Apache Commons Pool provides an object-pooling API and a number of object pool implementations.
-Version 2 contains a completely re-written pooling implementation compared to the 1.x series.
+Apache Commons Pool provides an object-pooling API and several object-pool implementations.
+Version 2 contains a completely rewritten pooling implementation compared to the 1.x series.
In addition to performance and scalability improvements, version 2 includes robust instance
-tracking and pool monitoring.
+tracking and pool monitoring.
Version 2.7.x and up requires Java 8 or above.
Version 2.6.x requires Java 7 or above.
Version 2.5.x requires Java 7 or above.
Version 2.0 requires 6 or above.
-NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean
+NOTE: The MBean interfaces (DefaultPooledObjectInfoMBean, GenericKeyedObjectPoolMXBean,
and GenericKeyedObjectPoolMXBean) exist only to define the attributes and methods
- that will be made available via JMX. They must not be implemented by clients as
- they are subject to change between major, minor and patch version releases of
- Commons Pool. Clients that implement any of these interfaces may not, therefore,
+ that will be made available via JMX. Clients must not implement them as
+ they are subject to change between major, minor, and patch version releases of
+ Commons Pool. Clients that implement any of these interfaces may not
be able to upgrade to a new minor or patch release without requiring code
changes.
-## N.B. the available variables are described here:
+## The available variables are described here:
## http://maven.apache.org/plugins/maven-changes-plugin/examples/using-a-custom-announcement-template.html
##
## Hack to get line breaks to work in release description. For this to work, each line break in the
diff --git a/src/conf/checkstyle-suppressions.xml b/src/conf/checkstyle-suppressions.xml
new file mode 100644
index 000000000..74924812f
--- /dev/null
+++ b/src/conf/checkstyle-suppressions.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
diff --git a/src/conf/checkstyle.xml b/src/conf/checkstyle.xml
index 3f884e113..36a9d49a9 100644
--- a/src/conf/checkstyle.xml
+++ b/src/conf/checkstyle.xml
@@ -7,7 +7,7 @@
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,66 +16,84 @@
limitations under the License.
-->
+ "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
+ "https://checkstyle.org/dtds/configuration_1_3.dtd">
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
+
+
-
-
-
-
-
diff --git a/src/conf/findbugs-exclude-filter.xml b/src/conf/findbugs-exclude-filter.xml
index 40e75c3f8..a93b46edc 100644
--- a/src/conf/findbugs-exclude-filter.xml
+++ b/src/conf/findbugs-exclude-filter.xml
@@ -7,7 +7,7 @@
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@@ -28,14 +28,14 @@
-
+
-
-
+
+
@@ -45,39 +45,39 @@
-
+
-
+
-
+
-
+
-
+
-
+
@@ -89,9 +89,9 @@
-
-
-
+
+
+
@@ -99,24 +99,24 @@
-
-
+
+
-
+
-
-
-
-
+
+
+
+
@@ -124,79 +124,79 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -206,4 +206,15 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/conf/pmd-ruleset.xml b/src/conf/pmd-ruleset.xml
new file mode 100644
index 000000000..55d17e2e7
--- /dev/null
+++ b/src/conf/pmd-ruleset.xml
@@ -0,0 +1,75 @@
+
+
+
+
+ This ruleset checks the code for discouraged programming constructs.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/org/apache/commons/pool2/overview.html b/src/main/java/org/apache/commons/pool2/overview.html
deleted file mode 100644
index b301d1d64..000000000
--- a/src/main/java/org/apache/commons/pool2/overview.html
+++ /dev/null
@@ -1,49 +0,0 @@
-
-
-
- Overview of the org.apache.commons.pool2 component
-
-
-
- Generic Object pooling API with several implementations.
-
-
- The org.apache.commons.pool2 package defines a simple
- interface for a pool of object instances, and a handful of base
- classes that may be useful when creating pool implementations.
- The API supports pooling of unique objects which can be requested
- via a key as well as pools where all objects are equivalent.
-
-
- The org.apache.commons.pool2.impl package contains
- several pool implementations.
- {@link org.apache.commons.pool2.impl.GenericObjectPool
- GenericObjectPool} has many configuration options and can support
- a limited set of objects such as would be useful in a database
- connection pool.
- {@link org.apache.commons.pool2.impl.SoftReferenceObjectPool
- SoftReferenceObjectPool} has no limit on the number of objects in the
- pool, but the garbage collector can remove idle objects from the pool
- as needed. There is also a keyed version of
- {@link org.apache.commons.pool2.impl.GenericObjectPool
- GenericObjectPool},
- {@link org.apache.commons.pool2.impl.GenericKeyedObjectPool
- GenericKeyedObjectPool}
-
-
-
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/pool2/proxy/CglibProxySource.java b/src/main/java/org/apache/commons/pool2/proxy/CglibProxySource.java
deleted file mode 100644
index 56613d99d..000000000
--- a/src/main/java/org/apache/commons/pool2/proxy/CglibProxySource.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.pool2.proxy;
-
-import org.apache.commons.pool2.UsageTracking;
-
-import net.sf.cglib.proxy.Enhancer;
-import net.sf.cglib.proxy.Factory;
-
-/**
- * Provides proxy objects using CGLib.
- *
- * @param type of the pooled object to be proxied
- *
- * @since 2.0
- */
-public class CglibProxySource implements ProxySource {
-
- private final Class extends T> superclass;
-
- /**
- * Constructs a new proxy source for the given class.
- *
- * @param superclass The class to proxy
- */
- public CglibProxySource(final Class extends T> superclass) {
- this.superclass = superclass;
- }
-
- @SuppressWarnings("unchecked") // Case to T on return
- @Override
- public T createProxy(final T pooledObject, final UsageTracking usageTracking) {
- final Enhancer enhancer = new Enhancer();
- enhancer.setSuperclass(superclass);
-
- final CglibProxyHandler proxyInterceptor =
- new CglibProxyHandler<>(pooledObject, usageTracking);
- enhancer.setCallback(proxyInterceptor);
-
- return (T) enhancer.create();
- }
-
-
- @Override
- public T resolveProxy(final T proxy) {
- @SuppressWarnings("unchecked")
- final
- CglibProxyHandler cglibProxyHandler =
- (CglibProxyHandler) ((Factory) proxy).getCallback(0);
- return cglibProxyHandler.disableProxy();
- }
-
- /**
- * @since 2.4.3
- */
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("CglibProxySource [superclass=");
- builder.append(superclass);
- builder.append("]");
- return builder.toString();
- }
-}
diff --git a/src/main/java/org/apache/commons/pool2/proxy/JdkProxySource.java b/src/main/java/org/apache/commons/pool2/proxy/JdkProxySource.java
deleted file mode 100644
index 32c57ae6c..000000000
--- a/src/main/java/org/apache/commons/pool2/proxy/JdkProxySource.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.pool2.proxy;
-
-import java.lang.reflect.Proxy;
-import java.util.Arrays;
-
-import org.apache.commons.pool2.UsageTracking;
-
-/**
- * Provides proxy objects using Java reflection.
- *
- * @param type of the pooled object to be proxied
- *
- * @since 2.0
- */
-public class JdkProxySource implements ProxySource {
-
- private final ClassLoader classLoader;
- private final Class>[] interfaces;
-
- /**
- * Constructs a new proxy source for the given interfaces.
- *
- * @param classLoader The class loader with which to create the proxy
- * @param interfaces The interfaces to proxy
- */
- public JdkProxySource(final ClassLoader classLoader, final Class>[] interfaces) {
- this.classLoader = classLoader;
- // Defensive copy
- this.interfaces = Arrays.copyOf(interfaces, interfaces.length);
- }
-
- @SuppressWarnings("unchecked") // Cast to T on return.
- @Override
- public T createProxy(final T pooledObject, final UsageTracking usageTracking) {
- return (T) Proxy.newProxyInstance(classLoader, interfaces,
- new JdkProxyHandler<>(pooledObject, usageTracking));
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T resolveProxy(final T proxy) {
- return ((JdkProxyHandler) Proxy.getInvocationHandler(proxy)).disableProxy();
- }
-
- /**
- * @since 2.4.3
- */
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("JdkProxySource [classLoader=");
- builder.append(classLoader);
- builder.append(", interfaces=");
- builder.append(Arrays.toString(interfaces));
- builder.append("]");
- return builder.toString();
- }
-}
diff --git a/src/main/java/org/apache/commons/pool2/BaseKeyedPooledObjectFactory.java b/src/main/java/org/apache/commons/pool3/BaseKeyedPooledObjectFactory.java
similarity index 95%
rename from src/main/java/org/apache/commons/pool2/BaseKeyedPooledObjectFactory.java
rename to src/main/java/org/apache/commons/pool3/BaseKeyedPooledObjectFactory.java
index 7c65822aa..3e651d497 100644
--- a/src/main/java/org/apache/commons/pool2/BaseKeyedPooledObjectFactory.java
+++ b/src/main/java/org/apache/commons/pool3/BaseKeyedPooledObjectFactory.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
import java.util.Objects;
@@ -28,15 +28,20 @@
*
*
* @see KeyedPooledObjectFactory
- *
* @param The type of keys managed by this factory.
* @param Type of element managed by this factory.
* @param Type of exception thrown by this factory.
- *
* @since 2.0
*/
public abstract class BaseKeyedPooledObjectFactory extends BaseObject implements KeyedPooledObjectFactory {
+ /**
+ * Constructs a new instance.
+ */
+ public BaseKeyedPooledObjectFactory() {
+ // empty
+ }
+
/**
* Reinitializes an instance to be returned by the pool.
*
@@ -56,7 +61,6 @@ public void activateObject(final K key, final PooledObject p) throws E {
*
* @param key the key used when constructing the object
* @return an instance that can be served by the pool
- *
* @throws E if there is a problem creating a new instance,
* this will be propagated to the code requesting an object.
*/
diff --git a/src/main/java/org/apache/commons/pool2/BaseObject.java b/src/main/java/org/apache/commons/pool3/BaseObject.java
similarity index 89%
rename from src/main/java/org/apache/commons/pool2/BaseObject.java
rename to src/main/java/org/apache/commons/pool3/BaseObject.java
index cc7f37616..18c6b0d4f 100644
--- a/src/main/java/org/apache/commons/pool2/BaseObject.java
+++ b/src/main/java/org/apache/commons/pool3/BaseObject.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
/**
* A base class for common functionality.
@@ -23,6 +23,13 @@
*/
public abstract class BaseObject {
+ /**
+ * Constructs a new instance.
+ */
+ public BaseObject() {
+ // empty
+ }
+
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
diff --git a/src/main/java/org/apache/commons/pool2/BaseObjectPool.java b/src/main/java/org/apache/commons/pool3/BaseObjectPool.java
similarity index 94%
rename from src/main/java/org/apache/commons/pool2/BaseObjectPool.java
rename to src/main/java/org/apache/commons/pool3/BaseObjectPool.java
index 62b94d4b8..252d51765 100644
--- a/src/main/java/org/apache/commons/pool2/BaseObjectPool.java
+++ b/src/main/java/org/apache/commons/pool3/BaseObjectPool.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
/**
* A simple base implementation of {@link ObjectPool}.
@@ -26,13 +26,19 @@
*
* @param Type of element pooled in this pool.
* @param Type of exception thrown by this pool.
- *
* @since 2.0
*/
public abstract class BaseObjectPool extends BaseObject implements ObjectPool {
private volatile boolean closed;
+ /**
+ * Constructs a new instance.
+ */
+ public BaseObjectPool() {
+ // empty
+ }
+
/**
* Not supported in this base implementation. Subclasses should override
* this behavior.
@@ -50,7 +56,6 @@ public void addObject() throws E, UnsupportedOperationException {
* closed.
*
* @throws IllegalStateException when this pool has been closed.
- *
* @see #isClosed()
*/
protected final void assertOpen() throws IllegalStateException {
diff --git a/src/main/java/org/apache/commons/pool2/BasePooledObjectFactory.java b/src/main/java/org/apache/commons/pool3/BasePooledObjectFactory.java
similarity index 93%
rename from src/main/java/org/apache/commons/pool2/BasePooledObjectFactory.java
rename to src/main/java/org/apache/commons/pool3/BasePooledObjectFactory.java
index 56f21337b..87cfb8e37 100644
--- a/src/main/java/org/apache/commons/pool2/BasePooledObjectFactory.java
+++ b/src/main/java/org/apache/commons/pool3/BasePooledObjectFactory.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
import java.util.Objects;
@@ -27,14 +27,19 @@
*
* @param Type of element managed in this factory.
* @param Type of exception thrown in this factory.
- *
* @see PooledObjectFactory
* @see BaseKeyedPooledObjectFactory
- *
* @since 2.0
*/
public abstract class BasePooledObjectFactory extends BaseObject implements PooledObjectFactory {
+ /**
+ * Constructs a new instance.
+ */
+ public BasePooledObjectFactory() {
+ // empty
+ }
+
/**
* No-op.
*
@@ -51,7 +56,6 @@ public void activateObject(final PooledObject p) throws E {
* invocation.
*
* @return an instance to be served by the pool, not null.
- *
* @throws E if there is a problem creating a new instance,
* this will be propagated to the code requesting an object.
*/
@@ -86,7 +90,6 @@ public void passivateObject(final PooledObject p) throws E {
* Always returns {@code true}.
*
* @param p ignored
- *
* @return {@code true}
*/
@Override
@@ -99,7 +102,6 @@ public boolean validateObject(final PooledObject p) {
* {@link PooledObject}.
*
* @param obj the instance to wrap, should not be null.
- *
* @return The provided instance, wrapped by a {@link PooledObject}
*/
public abstract PooledObject wrap(T obj);
diff --git a/src/main/java/org/apache/commons/pool2/DestroyMode.java b/src/main/java/org/apache/commons/pool3/DestroyMode.java
similarity index 92%
rename from src/main/java/org/apache/commons/pool2/DestroyMode.java
rename to src/main/java/org/apache/commons/pool3/DestroyMode.java
index ec5b1b07d..555af4a43 100644
--- a/src/main/java/org/apache/commons/pool2/DestroyMode.java
+++ b/src/main/java/org/apache/commons/pool3/DestroyMode.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
/**
* Destroy context provided to object factories via {@code destroyObject} and {@code invalidateObject} methods. Values
diff --git a/src/main/java/org/apache/commons/pool2/KeyedObjectPool.java b/src/main/java/org/apache/commons/pool3/KeyedObjectPool.java
similarity index 97%
rename from src/main/java/org/apache/commons/pool2/KeyedObjectPool.java
rename to src/main/java/org/apache/commons/pool3/KeyedObjectPool.java
index 88a4fbc91..ac1c78468 100644
--- a/src/main/java/org/apache/commons/pool2/KeyedObjectPool.java
+++ b/src/main/java/org/apache/commons/pool3/KeyedObjectPool.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
import java.io.Closeable;
import java.util.Collection;
@@ -49,24 +49,22 @@
* }
* }
*
- * {@link KeyedObjectPool} implementations may choose to store at most
+ * {@link KeyedObjectPool} implementations may choose to store at most
* one instance per key value, or may choose to maintain a pool of instances
* for each key (essentially creating a {@link java.util.Map Map} of
* {@link ObjectPool pools}).
*
*
- * See {@link org.apache.commons.pool2.impl.GenericKeyedObjectPool
+ * See {@link org.apache.commons.pool3.impl.GenericKeyedObjectPool
* GenericKeyedObjectPool} for an implementation.
*
*
* @param The type of keys maintained by this pool.
* @param Type of element pooled in this pool.
* @param Type of exception thrown by this pool.
- *
* @see KeyedPooledObjectFactory
* @see ObjectPool
- * @see org.apache.commons.pool2.impl.GenericKeyedObjectPool GenericKeyedObjectPool
- *
+ * @see org.apache.commons.pool3.impl.GenericKeyedObjectPool GenericKeyedObjectPool
* @since 2.0
*/
public interface KeyedObjectPool extends Closeable {
@@ -78,7 +76,6 @@ public interface KeyedObjectPool extends Closeable {
* "pre-loading" a pool with idle objects (Optional operation).
*
* @param key the key a new instance should be added to
- *
* @throws E
* when {@link KeyedPooledObjectFactory#makeObject} fails.
* @throws IllegalStateException
@@ -161,9 +158,7 @@ default void addObjects(final K key, final int count) throws E, IllegalArgumentE
*
*
* @param key the key used to obtain the object
- *
* @return an instance from this pool.
- *
* @throws IllegalStateException
* after {@link #close close} has been called on this pool
* @throws E
@@ -190,7 +185,6 @@ default void addObjects(final K key, final int count) throws E, IllegalArgumentE
* the given {@code key} (optional operation).
*
* @param key the key to clear
- *
* @throws UnsupportedOperationException when this implementation doesn't
* support the operation
*
@@ -276,7 +270,6 @@ default List getKeys() {
*
* @param key the key used to obtain the object
* @param obj a {@link #borrowObject borrowed} instance to be returned.
- *
* @throws E if the instance cannot be invalidated
*/
void invalidateObject(K key, V obj) throws E;
@@ -299,7 +292,6 @@ default List getKeys() {
* @param key the key used to obtain the object
* @param obj a {@link #borrowObject borrowed} instance to be returned.
* @param destroyMode destroy activation context provided to the factory
- *
* @throws E if the instance cannot be invalidated
* @since 2.9.0
*/
@@ -316,7 +308,6 @@ default void invalidateObject(final K key, final V obj, final DestroyMode destro
*
* @param key the key used to obtain the object
* @param obj a {@link #borrowObject borrowed} instance to be returned.
- *
* @throws IllegalStateException
* if an attempt is made to return an object to the pool that
* is in any state other than allocated (i.e. borrowed).
diff --git a/src/main/java/org/apache/commons/pool2/KeyedPooledObjectFactory.java b/src/main/java/org/apache/commons/pool3/KeyedPooledObjectFactory.java
similarity index 96%
rename from src/main/java/org/apache/commons/pool2/KeyedPooledObjectFactory.java
rename to src/main/java/org/apache/commons/pool3/KeyedPooledObjectFactory.java
index 60afa0aa3..0924d4bcd 100644
--- a/src/main/java/org/apache/commons/pool2/KeyedPooledObjectFactory.java
+++ b/src/main/java/org/apache/commons/pool3/KeyedPooledObjectFactory.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
/**
* An interface defining life-cycle methods for
@@ -62,17 +62,15 @@
* While clients of a {@link KeyedObjectPool} borrow and return instances of
* the underlying value type V, the factory methods act on instances of
* {@link PooledObject PooledObject<V>}. These are the object wrappers that
- * pools use to track and maintain state informations about the objects that
+ * pools use to track and maintain state information about the objects that
* they manage.
*
*
* @see KeyedObjectPool
* @see BaseKeyedPooledObjectFactory
- *
* @param The type of keys managed by this factory.
* @param Type of element managed by this factory.
* @param Type of exception thrown by this factory.
- *
* @since 2.0
*/
public interface KeyedPooledObjectFactory {
@@ -82,7 +80,6 @@ public interface KeyedPooledObjectFactory {
*
* @param key the key used when selecting the object
* @param p a {@code PooledObject} wrapping the instance to be activated
- *
* @throws E if there is a problem activating {@code obj},
* this exception may be swallowed by the pool.
*
@@ -104,7 +101,6 @@ public interface KeyedPooledObjectFactory {
*
* @param key the key used when selecting the instance
* @param p a {@code PooledObject} wrapping the instance to be destroyed
- *
* @throws E should be avoided as it may be swallowed by
* the pool implementation.
*
@@ -119,7 +115,6 @@ public interface KeyedPooledObjectFactory {
* @param key the key used when selecting the instance
* @param p a {@code PooledObject} wrapping the instance to be destroyed
* @param destroyMode DestroyMode providing context to the factory
- *
* @throws E should be avoided as it may be swallowed by
* the pool implementation.
*
@@ -138,7 +133,6 @@ default void destroyObject(final K key, final PooledObject p, final DestroyMo
* wrap it in a {@link PooledObject} to be managed by the pool.
*
* @param key the key used when constructing the object
- *
* @return a {@code PooledObject} wrapping an instance that can
* be served by the pool.
*
@@ -152,7 +146,6 @@ default void destroyObject(final K key, final PooledObject p, final DestroyMo
*
* @param key the key used when selecting the object
* @param p a {@code PooledObject} wrapping the instance to be passivated
- *
* @throws E if there is a problem passivating {@code obj},
* this exception may be swallowed by the pool.
*
@@ -165,7 +158,6 @@ default void destroyObject(final K key, final PooledObject p, final DestroyMo
*
* @param key the key used when selecting the object
* @param p a {@code PooledObject} wrapping the instance to be validated
- *
* @return {@code false} if {@code obj} is not valid and should
* be dropped from the pool, {@code true} otherwise.
*/
diff --git a/src/main/java/org/apache/commons/pool2/ObjectPool.java b/src/main/java/org/apache/commons/pool3/ObjectPool.java
similarity index 98%
rename from src/main/java/org/apache/commons/pool2/ObjectPool.java
rename to src/main/java/org/apache/commons/pool3/ObjectPool.java
index 04f8e11d4..e16fcadfd 100644
--- a/src/main/java/org/apache/commons/pool2/ObjectPool.java
+++ b/src/main/java/org/apache/commons/pool3/ObjectPool.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
import java.io.Closeable;
import java.util.NoSuchElementException;
@@ -51,11 +51,9 @@
*
* @param Type of element pooled in this pool.
* @param Type of exception thrown by this pool.
- *
* @see PooledObjectFactory
* @see KeyedObjectPool
* @see BaseObjectPool
- *
* @since 2.0
*/
public interface ObjectPool extends Closeable {
@@ -111,7 +109,6 @@ default void addObjects(final int count) throws E {
*
*
* @return an instance from this pool.
- *
* @throws IllegalStateException
* after {@link #close close} has been called on this pool.
* @throws E
@@ -177,7 +174,6 @@ default void addObjects(final int count) throws E {
*
*
* @param obj a {@link #borrowObject borrowed} instance to be disposed.
- *
* @throws E if the instance cannot be invalidated
*/
void invalidateObject(T obj) throws E;
@@ -210,7 +206,6 @@ default void invalidateObject(final T obj, final DestroyMode destroyMode) throws
* a related method as defined in an implementation or sub-interface.
*
* @param obj a {@link #borrowObject borrowed} instance to be returned.
- *
* @throws IllegalStateException
* if an attempt is made to return an object to the pool that
* is in any state other than allocated (i.e. borrowed).
diff --git a/src/main/java/org/apache/commons/pool2/PoolUtils.java b/src/main/java/org/apache/commons/pool3/PoolUtils.java
similarity index 91%
rename from src/main/java/org/apache/commons/pool2/PoolUtils.java
rename to src/main/java/org/apache/commons/pool3/PoolUtils.java
index 9c350c310..4222f9028 100644
--- a/src/main/java/org/apache/commons/pool2/PoolUtils.java
+++ b/src/main/java/org/apache/commons/pool3/PoolUtils.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
import java.util.Collection;
import java.util.Collections;
@@ -24,6 +24,7 @@
import java.util.NoSuchElementException;
import java.util.Timer;
import java.util.TimerTask;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
@@ -49,6 +50,9 @@ public final class PoolUtils {
* frequently.
*/
private static final class ErodingFactor {
+
+ private static final float MAX_INTERVAL = 15f;
+
/** Determines frequency of "erosion" events */
private final float factor;
@@ -56,7 +60,9 @@ private static final class ErodingFactor {
private transient volatile long nextShrinkMillis;
/** High water mark - largest numIdle encountered */
- private transient volatile int idleHighWaterMark;
+ private transient volatile int idleHighWaterMark = 1;
+
+ private final ReentrantLock lock = new ReentrantLock();
/**
* Creates a new ErodingFactor with the given erosion factor.
@@ -64,10 +70,9 @@ private static final class ErodingFactor {
* @param factor
* erosion factor
*/
- public ErodingFactor(final float factor) {
+ ErodingFactor(final float factor) {
this.factor = factor;
- nextShrinkMillis = System.currentTimeMillis() + (long) (900000 * factor); // now + 15 min * factor
- idleHighWaterMark = 1;
+ nextShrinkMillis = System.currentTimeMillis() + (long) (90_0000 * factor); // now + 15 min * factor
}
/**
@@ -84,7 +89,7 @@ public long getNextShrink() {
*/
@Override
public String toString() {
- return "ErodingFactor{" + "factor=" + factor +
+ return "ErodingFactor{factor=" + factor +
", idleHighWaterMark=" + idleHighWaterMark + '}';
}
@@ -98,11 +103,14 @@ public String toString() {
*/
public void update(final long nowMillis, final int numIdle) {
final int idle = Math.max(0, numIdle);
- idleHighWaterMark = Math.max(idle, idleHighWaterMark);
- final float maxInterval = 15f;
- final float minutes = maxInterval +
- (1f - maxInterval) / idleHighWaterMark * idle;
- nextShrinkMillis = nowMillis + (long) (minutes * 60000f * factor);
+ lock.lock();
+ try {
+ idleHighWaterMark = Math.max(idle, idleHighWaterMark);
+ final float minutes = MAX_INTERVAL + (1f - MAX_INTERVAL) / idleHighWaterMark * idle;
+ nextShrinkMillis = nowMillis + (long) (minutes * 60000f * factor);
+ } finally {
+ lock.unlock();
+ }
}
}
/**
@@ -133,11 +141,9 @@ private static class ErodingKeyedObjectPool implement
* events
* @see #erodingFactor
*/
- protected ErodingKeyedObjectPool(final KeyedObjectPool keyedPool,
- final ErodingFactor erodingFactor) {
+ ErodingKeyedObjectPool(final KeyedObjectPool keyedPool, final ErodingFactor erodingFactor) {
if (keyedPool == null) {
- throw new IllegalArgumentException(
- MSG_NULL_KEYED_POOL);
+ throw new IllegalArgumentException(MSG_NULL_KEYED_POOL);
}
this.keyedPool = keyedPool;
this.erodingFactor = erodingFactor;
@@ -154,8 +160,7 @@ protected ErodingKeyedObjectPool(final KeyedObjectPool keyedPool,
* events
* @see #erodingFactor
*/
- public ErodingKeyedObjectPool(final KeyedObjectPool keyedPool,
- final float factor) {
+ ErodingKeyedObjectPool(final KeyedObjectPool keyedPool, final float factor) {
this(keyedPool, new ErodingFactor(factor));
}
@@ -319,7 +324,7 @@ public void returnObject(final K key, final V obj) throws E {
*/
@Override
public String toString() {
- return "ErodingKeyedObjectPool{" + "factor=" +
+ return "ErodingKeyedObjectPool{factor=" +
erodingFactor + ", keyedPool=" + keyedPool + '}';
}
}
@@ -332,7 +337,7 @@ public String toString() {
* @param type of objects in the pool
* @param type of exceptions from the pool
*/
- private static class ErodingObjectPool implements ObjectPool {
+ private static final class ErodingObjectPool implements ObjectPool {
/** Underlying object pool */
private final ObjectPool pool;
@@ -351,7 +356,7 @@ private static class ErodingObjectPool implements Object
* events
* @see #factor
*/
- public ErodingObjectPool(final ObjectPool pool, final float factor) {
+ ErodingObjectPool(final ObjectPool pool, final float factor) {
this.pool = pool;
this.factor = new ErodingFactor(factor);
}
@@ -360,7 +365,7 @@ public ErodingObjectPool(final ObjectPool pool, final float factor) {
* {@inheritDoc}
*/
@Override
- public void addObject() throws E, IllegalStateException, UnsupportedOperationException{
+ public void addObject() throws E, IllegalStateException, UnsupportedOperationException {
pool.addObject();
}
@@ -462,7 +467,7 @@ public void returnObject(final T obj) {
*/
@Override
public String toString() {
- return "ErodingObjectPool{" + "factor=" + factor + ", pool=" +
+ return "ErodingObjectPool{factor=" + factor + ", pool=" +
pool + '}';
}
}
@@ -492,7 +497,7 @@ private static final class ErodingPerKeyKeyedObjectPool keyedPool, final float factor) {
+ ErodingPerKeyKeyedObjectPool(final KeyedObjectPool keyedPool, final float factor) {
super(keyedPool, null);
this.factor = factor;
}
@@ -513,7 +518,7 @@ protected ErodingFactor getErodingFactor(final K key) {
@SuppressWarnings("resource") // getKeyedPool(): ivar access
@Override
public String toString() {
- return "ErodingPerKeyKeyedObjectPool{" + "factor=" + factor +
+ return "ErodingPerKeyKeyedObjectPool{factor=" + factor +
", keyedPool=" + getKeyedPool() + '}';
}
}
@@ -673,7 +678,7 @@ public String toString() {
* A synchronized (thread-safe) KeyedObjectPool backed by the specified
* KeyedObjectPool.
*
- * Note: This should not be used on pool implementations that already
+ * Note: This should not be used on pool implementations that already
* provide proper synchronization such as the pools provided in the Commons
* Pool library. Wrapping a pool that {@link #wait() waits} for poolable
* objects to be returned before allowing another one to be borrowed with
@@ -905,7 +910,7 @@ public String toString() {
* KeyedPooledObjectFactory and synchronizes access to the wrapped factory
* methods.
*
- * Note: This should not be used on pool implementations that already
+ * Note: This should not be used on pool implementations that already
* provide proper synchronization such as the pools provided in the Commons
* Pool library.
*
@@ -1021,7 +1026,7 @@ public boolean validateObject(final K key, final PooledObject p) {
* A synchronized (thread-safe) ObjectPool backed by the specified
* ObjectPool.
*
- * Note: This should not be used on pool implementations that already
+ * Note: This should not be used on pool implementations that already
* provide proper synchronization such as the pools provided in the Commons
* Pool library. Wrapping a pool that {@link #wait() waits} for poolable
* objects to be returned before allowing another one to be borrowed with
@@ -1040,7 +1045,7 @@ private static final class SynchronizedObjectPool implem
*/
private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
- /** the underlying object pool */
+ /** The underlying object pool */
private final ObjectPool pool;
/**
@@ -1196,7 +1201,7 @@ public String toString() {
* PooledObjectFactory and synchronizes access to the wrapped factory
* methods.
*
- * Note: This should not be used on pool implementations that already
+ * Note: This should not be used on pool implementations that already
* provide proper synchronization such as the pools provided in the Commons
* Pool library.
*
@@ -1655,93 +1660,6 @@ private static Timer getMinIdleTimer() {
return TimerHolder.MIN_IDLE_TIMER;
}
- /**
- * Calls {@link KeyedObjectPool#addObject(Object)} on {@code keyedPool} with
- * each key in {@code keys} for {@code count} number of times. This has
- * the same effect as calling {@link #prefill(KeyedObjectPool, Object, int)}
- * for each key in the {@code keys} collection.
- *
- * @param keyedPool
- * the keyedPool to prefill.
- * @param keys
- * {@link Collection} of keys to add objects for.
- * @param count
- * the number of idle objects to add for each {@code key}.
- * @param the type of the pool key
- * @param the type of pool entries
- * @param the type of exception thrown by a pool
- * @throws E
- * when {@link KeyedObjectPool#addObject(Object)} fails.
- * @throws IllegalArgumentException
- * when {@code keyedPool}, {@code keys}, or any value in
- * {@code keys} is {@code null}.
- * @see #prefill(KeyedObjectPool, Object, int)
- * @deprecated Use {@link KeyedObjectPool#addObjects(Collection, int)}.
- */
- @Deprecated
- public static void prefill(final KeyedObjectPool keyedPool,
- final Collection keys, final int count) throws E,
- IllegalArgumentException {
- if (keys == null) {
- throw new IllegalArgumentException(MSG_NULL_KEYS);
- }
- keyedPool.addObjects(keys, count);
- }
-
- /**
- * Calls {@link KeyedObjectPool#addObject(Object)} on {@code keyedPool} with
- * {@code key} {@code count} number of times.
- *
- * @param keyedPool
- * the keyedPool to prefill.
- * @param key
- * the key to add objects for.
- * @param count
- * the number of idle objects to add for {@code key}.
- * @param the type of the pool key
- * @param the type of pool entries
- * @param the type of exception thrown by a pool
- * @throws E
- * when {@link KeyedObjectPool#addObject(Object)} fails.
- * @throws IllegalArgumentException
- * when {@code keyedPool} or {@code key} is {@code null}.
- * @deprecated Use {@link KeyedObjectPool#addObjects(Object, int)}.
- */
- @Deprecated
- public static void prefill(final KeyedObjectPool keyedPool,
- final K key, final int count) throws E,
- IllegalArgumentException {
- if (keyedPool == null) {
- throw new IllegalArgumentException(MSG_NULL_KEYED_POOL);
- }
- keyedPool.addObjects(key, count);
- }
-
- /**
- * Calls {@link ObjectPool#addObject()} on {@code pool} {@code count} number
- * of times.
- *
- * @param pool
- * the pool to prefill.
- * @param count
- * the number of idle objects to add.
- * @param the type of objects in the pool
- * @param type of exceptions from the pool
- * @throws E
- * when {@link ObjectPool#addObject()} fails.
- * @throws IllegalArgumentException
- * when {@code pool} is {@code null}.
- * @deprecated Use {@link ObjectPool#addObjects(int)}.
- */
- @Deprecated
- public static void prefill(final ObjectPool pool, final int count)
- throws E, IllegalArgumentException {
- if (pool == null) {
- throw new IllegalArgumentException(MSG_NULL_POOL);
- }
- pool.addObjects(count);
- }
-
/**
* Returns a synchronized (thread-safe) KeyedPooledObjectFactory backed by
* the specified KeyedPooledObjectFactory.
@@ -1763,7 +1681,7 @@ public static KeyedPooledObjectFactory sync
* Returns a synchronized (thread-safe) KeyedObjectPool backed by the
* specified KeyedObjectPool.
*
- * Note: This should not be used on pool implementations that already
+ * Note: This should not be used on pool implementations that already
* provide proper synchronization such as the pools provided in the Commons
* Pool library. Wrapping a pool that {@link #wait() waits} for poolable
* objects to be returned before allowing another one to be borrowed with
@@ -1796,7 +1714,7 @@ public static KeyedObjectPool synchronizedP
* Returns a synchronized (thread-safe) ObjectPool backed by the specified
* ObjectPool.
*
- * Note: This should not be used on pool implementations that already
+ * Note: This should not be used on pool implementations that already
* provide proper synchronization such as the pools provided in the Commons
* Pool library. Wrapping a pool that {@link #wait() waits} for poolable
* objects to be returned before allowing another one to be borrowed with
diff --git a/src/main/java/org/apache/commons/pool2/PooledObject.java b/src/main/java/org/apache/commons/pool3/PooledObject.java
similarity index 66%
rename from src/main/java/org/apache/commons/pool2/PooledObject.java
rename to src/main/java/org/apache/commons/pool3/PooledObject.java
index dc76b46ef..43dc282ea 100644
--- a/src/main/java/org/apache/commons/pool2/PooledObject.java
+++ b/src/main/java/org/apache/commons/pool3/PooledObject.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
import java.io.PrintWriter;
import java.time.Duration;
@@ -34,14 +34,37 @@
public interface PooledObject extends Comparable> {
/**
- * Tests whether the given PooledObject is null or contains a null.
+ * Gets the wrapped object or null.
*
- * @param pooledObject the PooledObject to test.
- * @return whether the given PooledObject is null or contains a null.
+ * @param the type of object in the pool.
+ * @param pooledObject the PooledObject to unwrap, may be null.
+ * @return the wrapped object or null.
+ * @since 2.13.0
+ */
+ static T getObject(final PooledObject pooledObject) {
+ return pooledObject != null ? pooledObject.getObject() : null;
+ }
+
+ /**
+ * Tests whether the given PooledObject is null or wraps a null.
+ *
+ * @param pooledObject the PooledObject to test, may be null.
+ * @return whether the given PooledObject is null or wraps a null.
* @since 2.12.0
*/
static boolean isNull(final PooledObject> pooledObject) {
- return pooledObject == null || pooledObject.getObject() == null;
+ return getObject(pooledObject) == null;
+ }
+
+ /**
+ * Tests whether the given PooledObject isn't null and doesn't wraps a null.
+ *
+ * @param pooledObject the PooledObject to test, may be null.
+ * @return whether the given PooledObject isn't null and doesn't wraps a null.
+ * @since 2.13.0
+ */
+ static boolean nonNull(final PooledObject> pooledObject) {
+ return getObject(pooledObject) != null;
}
/**
@@ -103,30 +126,6 @@ default Duration getActiveDuration() {
// @formatter:on
}
- /**
- * Gets the amount of time this object last spent in the active state (it may still be active in which case
- * subsequent calls will return an increased value).
- *
- * @return The duration last spent in the active state.
- * @since 2.10.0
- * @deprecated Use {@link #getActiveDuration()}.
- */
- @Deprecated
- default Duration getActiveTime() {
- return getActiveDuration();
- }
-
- /**
- * Gets the amount of time in milliseconds this object last spent in the
- * active state (it may still be active in which case subsequent calls will
- * return an increased value).
- *
- * @return The time in milliseconds last spent in the active state.
- * @deprecated Use {@link #getActiveTime()} which offers the best precision.
- */
- @Deprecated
- long getActiveTimeMillis();
-
/**
* Gets the number of times this object has been borrowed.
*
@@ -143,19 +142,7 @@ default long getBorrowedCount() {
* @return The creation time for the wrapped object.
* @since 2.11.0
*/
- default Instant getCreateInstant() {
- return Instant.ofEpochMilli(getCreateTime());
- }
-
- /**
- * Gets the time (using the same basis as
- * {@link java.time.Clock#instant()}) that this object was created.
- *
- * @return The creation time for the wrapped object.
- * @deprecated Use {@link #getCreateInstant()} which offers the best precision.
- */
- @Deprecated
- long getCreateTime();
+ Instant getCreateInstant();
/**
* Gets the duration since this object was created (using {@link Instant#now()}).
@@ -175,34 +162,7 @@ default Duration getFullDuration() {
* @return The amount of time in last spent in the idle state.
* @since 2.11.0
*/
- default Duration getIdleDuration() {
- return Duration.ofMillis(getIdleTimeMillis());
- }
-
- /**
- * Gets the amount of time that this object last spend in the
- * idle state (it may still be idle in which case subsequent calls will
- * return an increased value).
- *
- * @return The amount of time in last spent in the idle state.
- * @since 2.10.0
- * @deprecated Use {@link #getIdleDuration()}.
- */
- @Deprecated
- default Duration getIdleTime() {
- return Duration.ofMillis(getIdleTimeMillis());
- }
-
- /**
- * Gets the amount of time in milliseconds that this object last spend in the
- * idle state (it may still be idle in which case subsequent calls will
- * return an increased value).
- *
- * @return The time in milliseconds last spent in the idle state.
- * @deprecated Use {@link #getIdleTime()} which offers the best precision.
- */
- @Deprecated
- long getIdleTimeMillis();
+ Duration getIdleDuration();
/**
* Gets the time the wrapped object was last borrowed.
@@ -210,18 +170,7 @@ default Duration getIdleTime() {
* @return The time the object was last borrowed.
* @since 2.11.0
*/
- default Instant getLastBorrowInstant() {
- return Instant.ofEpochMilli(getLastBorrowTime());
- }
-
- /**
- * Gets the time the wrapped object was last borrowed.
- *
- * @return The time the object was last borrowed.
- * @deprecated Use {@link #getLastBorrowInstant()} which offers the best precision.
- */
- @Deprecated
- long getLastBorrowTime();
+ Instant getLastBorrowInstant();
/**
* Gets the time the wrapped object was last borrowed.
@@ -229,43 +178,17 @@ default Instant getLastBorrowInstant() {
* @return The time the object was last borrowed.
* @since 2.11.0
*/
- default Instant getLastReturnInstant() {
- return Instant.ofEpochMilli(getLastReturnTime());
- }
-
- /**
- * Gets the time the wrapped object was last returned.
- *
- * @return The time the object was last returned.
- * @deprecated Use {@link #getLastReturnInstant()} which offers the best precision.
- */
- @Deprecated
- long getLastReturnTime();
+ Instant getLastReturnInstant();
/**
* Gets an estimate of the last time this object was used. If the class of the pooled object implements
* {@link TrackedUse}, what is returned is the maximum of {@link TrackedUse#getLastUsedInstant()} and
- * {@link #getLastBorrowTime()}; otherwise this method gives the same value as {@link #getLastBorrowTime()}.
+ * {@link #getLastBorrowInstant()}; otherwise this method gives the same value as {@link #getLastBorrowInstant()}.
*
* @return the last time this object was used
* @since 2.11.0
*/
- default Instant getLastUsedInstant() {
- return Instant.ofEpochMilli(getLastUsedTime());
- }
-
- /**
- * Gets an estimate of the last time this object was used. If the class
- * of the pooled object implements {@link TrackedUse}, what is returned is
- * the maximum of {@link TrackedUse#getLastUsedInstant()} and
- * {@link #getLastBorrowTime()}; otherwise this method gives the same
- * value as {@link #getLastBorrowTime()}.
- *
- * @return the last time this object was used.
- * @deprecated Use {@link #getLastUsedInstant()} which offers the best precision.
- */
- @Deprecated
- long getLastUsedTime();
+ Instant getLastUsedInstant();
/**
* Gets the underlying object that is wrapped by this instance of
diff --git a/src/main/java/org/apache/commons/pool2/PooledObjectFactory.java b/src/main/java/org/apache/commons/pool3/PooledObjectFactory.java
similarity index 97%
rename from src/main/java/org/apache/commons/pool2/PooledObjectFactory.java
rename to src/main/java/org/apache/commons/pool3/PooledObjectFactory.java
index c9c97837b..390f6b57a 100644
--- a/src/main/java/org/apache/commons/pool2/PooledObjectFactory.java
+++ b/src/main/java/org/apache/commons/pool3/PooledObjectFactory.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
/**
* An interface defining life-cycle methods for instances to be served by an
@@ -66,9 +66,7 @@
*
* @param Type of element managed in this factory.
* @param Type of exception thrown in this factory.
- *
* @see ObjectPool
- *
* @since 2.0
*/
public interface PooledObjectFactory {
@@ -77,7 +75,6 @@ public interface PooledObjectFactory {
* Reinitializes an instance to be returned by the pool.
*
* @param p a {@code PooledObject} wrapping the instance to be activated
- *
* @throws E if there is a problem activating {@code obj},
* this exception may be swallowed by the pool.
*
@@ -99,7 +96,6 @@ public interface PooledObjectFactory {
*
*
* @param p a {@code PooledObject} wrapping the instance to be destroyed
- *
* @throws E should be avoided as it may be swallowed by
* the pool implementation.
*
@@ -114,7 +110,6 @@ public interface PooledObjectFactory {
*
* @param p a {@code PooledObject} wrapping the instance to be destroyed
* @param destroyMode DestroyMode providing context to the factory
- *
* @throws E should be avoided as it may be swallowed by
* the pool implementation.
*
@@ -133,7 +128,6 @@ default void destroyObject(final PooledObject p, final DestroyMode destroyMod
* {@link PooledObject} to be managed by the pool.
*
* @return a {@code PooledObject} wrapping an instance that can be served by the pool, not null.
- *
* @throws E if there is a problem creating a new instance,
* this will be propagated to the code requesting an object.
*/
@@ -143,7 +137,6 @@ default void destroyObject(final PooledObject p, final DestroyMode destroyMod
* Uninitializes an instance to be returned to the idle object pool.
*
* @param p a {@code PooledObject} wrapping the instance to be passivated
- *
* @throws E if there is a problem passivating {@code obj},
* this exception may be swallowed by the pool.
*
@@ -155,7 +148,6 @@ default void destroyObject(final PooledObject p, final DestroyMode destroyMod
* Ensures that the instance is safe to be returned by the pool.
*
* @param p a {@code PooledObject} wrapping the instance to be validated
- *
* @return {@code false} if {@code obj} is not valid and should
* be dropped from the pool, {@code true} otherwise.
*/
diff --git a/src/main/java/org/apache/commons/pool2/PooledObjectState.java b/src/main/java/org/apache/commons/pool3/PooledObjectState.java
similarity index 96%
rename from src/main/java/org/apache/commons/pool2/PooledObjectState.java
rename to src/main/java/org/apache/commons/pool3/PooledObjectState.java
index f09dbb8a6..6094fdb20 100644
--- a/src/main/java/org/apache/commons/pool2/PooledObjectState.java
+++ b/src/main/java/org/apache/commons/pool3/PooledObjectState.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
/**
* Provides all possible states of a {@link PooledObject}.
diff --git a/src/main/java/org/apache/commons/pool2/SwallowedExceptionListener.java b/src/main/java/org/apache/commons/pool3/SwallowedExceptionListener.java
similarity index 93%
rename from src/main/java/org/apache/commons/pool2/SwallowedExceptionListener.java
rename to src/main/java/org/apache/commons/pool3/SwallowedExceptionListener.java
index 69df39676..808fd2e7c 100644
--- a/src/main/java/org/apache/commons/pool2/SwallowedExceptionListener.java
+++ b/src/main/java/org/apache/commons/pool3/SwallowedExceptionListener.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
/**
* Pools that unavoidably swallow exceptions may be configured with an instance
diff --git a/src/main/java/org/apache/commons/pool2/TrackedUse.java b/src/main/java/org/apache/commons/pool3/TrackedUse.java
similarity index 76%
rename from src/main/java/org/apache/commons/pool2/TrackedUse.java
rename to src/main/java/org/apache/commons/pool3/TrackedUse.java
index 0e7806a55..5e70b0475 100644
--- a/src/main/java/org/apache/commons/pool2/TrackedUse.java
+++ b/src/main/java/org/apache/commons/pool3/TrackedUse.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
import java.time.Instant;
@@ -27,15 +27,6 @@
*/
public interface TrackedUse {
- /**
- * Gets the last time this object was used in milliseconds.
- *
- * @return the last time this object was used in milliseconds.
- * @deprecated Use {@link #getLastUsedInstant()} which offers the best precision.
- */
- @Deprecated
- long getLastUsed();
-
/**
* Gets the last Instant this object was used.
*
@@ -46,7 +37,5 @@ public interface TrackedUse {
* @return the last Instant this object was used.
* @since 2.11.0
*/
- default Instant getLastUsedInstant() {
- return Instant.ofEpochMilli(getLastUsed());
- }
+ Instant getLastUsedInstant();
}
diff --git a/src/main/java/org/apache/commons/pool2/UsageTracking.java b/src/main/java/org/apache/commons/pool3/UsageTracking.java
similarity index 94%
rename from src/main/java/org/apache/commons/pool2/UsageTracking.java
rename to src/main/java/org/apache/commons/pool3/UsageTracking.java
index 48bdb2f56..3a5a75a9b 100644
--- a/src/main/java/org/apache/commons/pool2/UsageTracking.java
+++ b/src/main/java/org/apache/commons/pool3/UsageTracking.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
/**
* This interface may be implemented by an object pool to enable clients (primarily those clients that wrap pools to
@@ -22,7 +22,6 @@
* more informed decisions and reporting to be made regarding abandoned objects.
*
* @param The type of object provided by the pool.
- *
* @since 2.0
*/
public interface UsageTracking {
diff --git a/src/main/java/org/apache/commons/pool3/doc-files/leaf.svg b/src/main/java/org/apache/commons/pool3/doc-files/leaf.svg
new file mode 100644
index 000000000..71de588c6
--- /dev/null
+++ b/src/main/java/org/apache/commons/pool3/doc-files/leaf.svg
@@ -0,0 +1,45 @@
+
+
+
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/pool3/doc-files/logo.png b/src/main/java/org/apache/commons/pool3/doc-files/logo.png
new file mode 100644
index 000000000..f1b03aff2
Binary files /dev/null and b/src/main/java/org/apache/commons/pool3/doc-files/logo.png differ
diff --git a/src/main/java/org/apache/commons/pool2/impl/AbandonedConfig.java b/src/main/java/org/apache/commons/pool3/impl/AbandonedConfig.java
similarity index 88%
rename from src/main/java/org/apache/commons/pool2/impl/AbandonedConfig.java
rename to src/main/java/org/apache/commons/pool3/impl/AbandonedConfig.java
index 5b86a151e..b03f12c8c 100644
--- a/src/main/java/org/apache/commons/pool2/impl/AbandonedConfig.java
+++ b/src/main/java/org/apache/commons/pool3/impl/AbandonedConfig.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,15 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.time.Duration;
-import org.apache.commons.pool2.TrackedUse;
-import org.apache.commons.pool2.UsageTracking;
+import org.apache.commons.pool3.TrackedUse;
+import org.apache.commons.pool3.UsageTracking;
/**
* Configuration settings for abandoned object removal.
@@ -124,7 +124,6 @@ private AbandonedConfig(final AbandonedConfig abandonedConfig) {
*
* @return boolean true if stack trace logging is turned on for abandoned
* objects
- *
*/
public boolean getLogAbandoned() {
return this.logAbandoned;
@@ -176,23 +175,6 @@ public boolean getRemoveAbandonedOnMaintenance() {
return this.removeAbandonedOnMaintenance;
}
- /**
- *
Timeout in seconds before an abandoned object can be removed.
- *
- *
The time of most recent use of an object is the maximum (latest) of
- * {@link TrackedUse#getLastUsedInstant()} (if this class of the object implements
- * TrackedUse) and the time when the object was borrowed from the pool.
- *
- *
The default value is 300 seconds.
- *
- * @return the abandoned object timeout in seconds.
- * @deprecated Use {@link #getRemoveAbandonedTimeoutDuration()}.
- */
- @Deprecated
- public int getRemoveAbandonedTimeout() {
- return (int) this.removeAbandonedTimeoutDuration.getSeconds();
- }
-
/**
*
Timeout before an abandoned object can be removed.
*
@@ -241,7 +223,6 @@ public boolean getUseUsageTracking() {
*
* @param logAbandoned true turns on abandoned stack trace logging
* @see #getLogAbandoned()
- *
*/
public void setLogAbandoned(final boolean logAbandoned) {
this.logAbandoned = logAbandoned;
@@ -298,24 +279,6 @@ public void setRemoveAbandonedTimeout(final Duration removeAbandonedTimeout) {
this.removeAbandonedTimeoutDuration = PoolImplUtils.nonNull(removeAbandonedTimeout, DEFAULT_REMOVE_ABANDONED_TIMEOUT_DURATION);
}
- /**
- * Sets the timeout in seconds before an abandoned object can be
- * removed.
- *
- *
Setting this property has no effect if
- * {@link #getRemoveAbandonedOnBorrow() removeAbandonedOnBorrow} and
- * {@link #getRemoveAbandonedOnMaintenance() removeAbandonedOnMaintenance}
- * are both false.
- *
- * @param removeAbandonedTimeoutSeconds new abandoned timeout in seconds
- * @see #getRemoveAbandonedTimeoutDuration()
- * @deprecated Use {@link #setRemoveAbandonedTimeout(Duration)}.
- */
- @Deprecated
- public void setRemoveAbandonedTimeout(final int removeAbandonedTimeoutSeconds) {
- setRemoveAbandonedTimeout(Duration.ofSeconds(removeAbandonedTimeoutSeconds));
- }
-
/**
* Sets the flag to require full stack traces for logging abandoned connections when enabled.
*
diff --git a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java b/src/main/java/org/apache/commons/pool3/impl/BaseGenericObjectPool.java
similarity index 81%
rename from src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
rename to src/main/java/org/apache/commons/pool3/impl/BaseGenericObjectPool.java
index 6b7612440..e128d52a1 100644
--- a/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
+++ b/src/main/java/org/apache/commons/pool3/impl/BaseGenericObjectPool.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -44,10 +44,10 @@
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
-import org.apache.commons.pool2.BaseObject;
-import org.apache.commons.pool2.PooledObject;
-import org.apache.commons.pool2.PooledObjectState;
-import org.apache.commons.pool2.SwallowedExceptionListener;
+import org.apache.commons.pool3.BaseObject;
+import org.apache.commons.pool3.PooledObject;
+import org.apache.commons.pool3.PooledObjectState;
+import org.apache.commons.pool3.SwallowedExceptionListener;
/**
* Base class that provides common functionality for {@link GenericObjectPool}
@@ -66,7 +66,7 @@ public abstract class BaseGenericObjectPool extends Base
/**
* The idle object eviction iterator. Holds a reference to the idle objects.
*/
- class EvictionIterator implements Iterator> {
+ final class EvictionIterator implements Iterator> {
private final Deque> idleObjects;
private final Iterator> idleObjectIterator;
@@ -118,7 +118,7 @@ public void remove() {
*
* @see GenericKeyedObjectPool#setTimeBetweenEvictionRunsMillis
*/
- class Evictor implements Runnable {
+ final class Evictor implements Runnable {
private ScheduledFuture> scheduledFuture;
@@ -203,18 +203,30 @@ public String toString() {
* objects under management using maps keyed on the objects. This wrapper
* class ensures that objects can work as hash keys.
*
- * @param type of objects in the pool
+ * @param type of objects in the pool.
*/
static class IdentityWrapper {
+
+ /**
+ * Constructs a wrapper for the object in the {@link PooledObject}.
+ *
+ * @param type of objects in the {@link PooledObject}.
+ * @param pooledObject contains the object to wrap.
+ * @return a new instance wrapping the object in the {@link PooledObject}.
+ */
+ static IdentityWrapper unwrap(final PooledObject pooledObject) {
+ return new IdentityWrapper<>(pooledObject.getObject());
+ }
+
/** Wrapped object */
private final T instance;
/**
* Constructs a wrapper for an instance.
*
- * @param instance object to wrap
+ * @param instance object to wrap.
*/
- public IdentityWrapper(final T instance) {
+ IdentityWrapper(final T instance) {
this.instance = instance;
}
@@ -250,7 +262,7 @@ public String toString() {
* Maintains a cache of values for a single metric and reports
* statistics on the cached values.
*/
- private static class StatsStore {
+ private static final class StatsStore {
private static final int NULL = -1;
private final AtomicLong[] values;
@@ -286,15 +298,6 @@ synchronized void add(final long value) {
}
}
- /**
- * Gets the current values as a List.
- *
- * @return the current values as a List.
- */
- synchronized List getCurrentValues() {
- return Arrays.stream(values, 0, index).collect(Collectors.toList());
- }
-
/**
* Gets the mean of the cached values.
*
@@ -313,12 +316,30 @@ public long getMean() {
return (long) result;
}
+ /**
+ * Gets the mean Duration of the cached values.
+ *
+ * @return the mean Duration of the cache, truncated to long milliseconds of a Duration.
+ */
+ Duration getMeanDuration() {
+ return Duration.ofMillis(getMean());
+ }
+
+ /**
+ * Gets the current values as a List.
+ *
+ * @return the current values as a List.
+ */
+ synchronized List getValues() {
+ return Arrays.stream(values, 0, index).collect(Collectors.toList());
+ }
+
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("StatsStore [");
// Only append what's been filled in.
- builder.append(getCurrentValues());
+ builder.append(getValues());
builder.append("], size=");
builder.append(size);
builder.append(", index=");
@@ -347,7 +368,7 @@ public String toString() {
private volatile boolean testOnBorrow = BaseObjectPoolConfig.DEFAULT_TEST_ON_BORROW;
private volatile boolean testOnReturn = BaseObjectPoolConfig.DEFAULT_TEST_ON_RETURN;
private volatile boolean testWhileIdle = BaseObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE;
- private volatile Duration durationBetweenEvictionRuns = BaseObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS;
+ private volatile Duration durationBetweenEvictionRuns = BaseObjectPoolConfig.DEFAULT_DURATION_BETWEEN_EVICTION_RUNS;
private volatile int numTestsPerEvictionRun = BaseObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
private volatile Duration minEvictableIdleDuration = BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_DURATION;
@@ -387,6 +408,7 @@ public String toString() {
private volatile SwallowedExceptionListener swallowedExceptionListener;
private volatile boolean messageStatistics;
+ private volatile boolean collectDetailedStatistics = BaseObjectPoolConfig.DEFAULT_COLLECT_DETAILED_STATISTICS;
/** Additional configuration properties for abandoned object tracking. */
protected volatile AbandonedConfig abandonedConfig;
@@ -582,9 +604,8 @@ public final long getDestroyedCount() {
* object evictor thread. When non-positive, no idle object evictor thread
* will be run.
*
- * @return number of milliseconds to sleep between evictor runs
- *
- * @see #setTimeBetweenEvictionRuns
+ * @return duration to sleep between evictor runs
+ * @see #setDurationBetweenEvictionRuns(Duration)
* @since 2.11.0
*/
public final Duration getDurationBetweenEvictionRuns() {
@@ -607,28 +628,12 @@ public EvictionPolicy getEvictionPolicy() {
* used by this pool.
*
* @return The fully qualified class name of the {@link EvictionPolicy}
- *
* @see #setEvictionPolicyClassName(String)
*/
public final String getEvictionPolicyClassName() {
return evictionPolicy.getClass().getName();
}
- /**
- * Gets the timeout that will be used when waiting for the Evictor to
- * shutdown if this pool is closed and it is the only pool still using the
- * the value for the Evictor.
- *
- * @return The timeout that will be used while waiting for
- * the Evictor to shut down.
- * @since 2.10.0
- * @deprecated Use {@link #getEvictorShutdownTimeoutDuration()}.
- */
- @Deprecated
- public final Duration getEvictorShutdownTimeout() {
- return evictorShutdownTimeoutDuration;
- }
-
/**
* Gets the timeout that will be used when waiting for the Evictor to
* shutdown if this pool is closed and it is the only pool still using the
@@ -642,20 +647,6 @@ public final Duration getEvictorShutdownTimeoutDuration() {
return evictorShutdownTimeoutDuration;
}
- /**
- * Gets the timeout that will be used when waiting for the Evictor to
- * shutdown if this pool is closed and it is the only pool still using the
- * the value for the Evictor.
- *
- * @return The timeout in milliseconds that will be used while waiting for
- * the Evictor to shut down.
- * @deprecated Use {@link #getEvictorShutdownTimeoutDuration()}.
- */
- @Deprecated
- public final long getEvictorShutdownTimeoutMillis() {
- return evictorShutdownTimeoutDuration.toMillis();
- }
-
/**
* Gets whether or not the pool serves threads waiting to borrow objects fairly.
* True means that waiting threads are served as if waiting in a FIFO queue.
@@ -757,7 +748,6 @@ public final Duration getMaxWaitDuration() {
*
* @return the maximum number of milliseconds {@code borrowObject()}
* will block.
- *
* @see #setMaxWait
* @see #setBlockWhenExhausted
* @deprecated Use {@link #getMaxWaitDuration()}.
@@ -767,6 +757,16 @@ public final long getMaxWaitMillis() {
return maxWaitDuration.toMillis();
}
+ /**
+ * Gets the mean time objects are active for based on the last {@link
+ * #MEAN_TIMING_STATS_CACHE_SIZE} objects returned to the pool.
+ * @return mean time an object has been checked out from the pool among
+ * recently returned objects
+ */
+ public final Duration getMeanActiveDuration() {
+ return activeTimes.getMeanDuration();
+ }
+
/**
* Gets the mean time objects are active for based on the last {@link
* #MEAN_TIMING_STATS_CACHE_SIZE} objects returned to the pool.
@@ -777,6 +777,18 @@ public final long getMeanActiveTimeMillis() {
return activeTimes.getMean();
}
+ /**
+ * Gets the mean time threads wait to borrow an object based on the last {@link
+ * #MEAN_TIMING_STATS_CACHE_SIZE} objects borrowed from the pool.
+ *
+ * @return mean time in milliseconds that a recently served thread has had
+ * to wait to borrow an object from the pool.
+ * @since 2.12.0
+ */
+ public final Duration getMeanBorrowWaitDuration() {
+ return waitTimes.getMeanDuration();
+ }
+
/**
* Gets the mean time threads wait to borrow an object based on the last {@link
* #MEAN_TIMING_STATS_CACHE_SIZE} objects borrowed from the pool.
@@ -793,6 +805,19 @@ public final long getMeanBorrowWaitTimeMillis() {
* @return mean time an object has been idle in the pool among recently
* borrowed objects
*/
+ public final Duration getMeanIdleDuration() {
+ return idleTimes.getMeanDuration();
+ }
+
+ /**
+ * Gets the mean time objects are idle for based on the last {@link
+ * #MEAN_TIMING_STATS_CACHE_SIZE} objects borrowed from the pool.
+ *
+ * @return mean time an object has been idle in the pool among recently
+ * borrowed objects.
+ * @deprecated Use {@link #getMeanIdleDuration()}.
+ */
+ @Deprecated
public final long getMeanIdleTimeMillis() {
return idleTimes.getMean();
}
@@ -812,52 +837,47 @@ public boolean getMessageStatistics() {
}
/**
- * Gets the minimum amount of time an object may sit idle in the pool
- * before it is eligible for eviction by the idle object evictor (if any -
- * see {@link #setTimeBetweenEvictionRuns(Duration)}). When non-positive,
- * no objects will be evicted from the pool due to idle time alone.
- *
- * @return minimum amount of time an object may sit idle in the pool before
- * it is eligible for eviction
+ * Gets whether detailed timing statistics collection is enabled.
+ * When {@code false}, the pool will not collect detailed timing statistics for
+ * mean active time, mean idle time, and mean borrow wait time,
+ * improving performance under high load.
*
- * @see #setMinEvictableIdleTimeMillis
- * @see #setTimeBetweenEvictionRunsMillis
- * @since 2.11.0
+ * @return {@code true} if detailed statistics collection is enabled,
+ * {@code false} if disabled for improved performance.
+ * @since 2.13.0
*/
- public final Duration getMinEvictableIdleDuration() {
- return minEvictableIdleDuration;
+ public boolean getCollectDetailedStatistics() {
+ return collectDetailedStatistics;
}
/**
* Gets the minimum amount of time an object may sit idle in the pool
* before it is eligible for eviction by the idle object evictor (if any -
- * see {@link #setTimeBetweenEvictionRuns(Duration)}). When non-positive,
+ * see {@link #setDurationBetweenEvictionRuns(Duration)}). When non-positive,
* no objects will be evicted from the pool due to idle time alone.
*
* @return minimum amount of time an object may sit idle in the pool before
* it is eligible for eviction
*
- * @see #setMinEvictableIdleTimeMillis
- * @see #setTimeBetweenEvictionRunsMillis
- * @since 2.10.0
- * @deprecated Use {@link #getMinEvictableIdleDuration()}.
+ * @see #setMinEvictableIdleDuration(Duration)
+ * @see #setDurationBetweenEvictionRuns(Duration)
+ * @since 2.11.0
*/
- @Deprecated
- public final Duration getMinEvictableIdleTime() {
+ public final Duration getMinEvictableIdleDuration() {
return minEvictableIdleDuration;
}
/**
* Gets the minimum amount of time an object may sit idle in the pool
* before it is eligible for eviction by the idle object evictor (if any -
- * see {@link #setTimeBetweenEvictionRunsMillis(long)}). When non-positive,
+ * see {@link #setDurationBetweenEvictionRuns(Duration)}). When non-positive,
* no objects will be evicted from the pool due to idle time alone.
*
* @return minimum amount of time an object may sit idle in the pool before
* it is eligible for eviction
*
- * @see #setMinEvictableIdleTimeMillis
- * @see #setTimeBetweenEvictionRunsMillis
+ * @see #setMinEvictableIdleDuration(Duration)
+ * @see #setDurationBetweenEvictionRuns(Duration)
* @deprecated Use {@link #getMinEvictableIdleDuration()}.
*/
@Deprecated
@@ -882,9 +902,8 @@ public final long getMinEvictableIdleTimeMillis() {
* tested per run.
*
* @return max number of objects to examine during each evictor run
- *
* @see #setNumTestsPerEvictionRun
- * @see #setTimeBetweenEvictionRunsMillis
+ * @see #setDurationBetweenEvictionRuns(Duration)
*/
public final int getNumTestsPerEvictionRun() {
return numTestsPerEvictionRun;
@@ -964,66 +983,23 @@ public final long getReturnedCount() {
/**
* Gets the minimum amount of time an object may sit idle in the pool
* before it is eligible for eviction by the idle object evictor (if any -
- * see {@link #setTimeBetweenEvictionRuns(Duration)}),
+ * see {@link #setDurationBetweenEvictionRuns(Duration)}),
* with the extra condition that at least {@code minIdle} object
* instances remain in the pool. This setting is overridden by
- * {@link #getMinEvictableIdleTime} (that is, if
- * {@link #getMinEvictableIdleTime} is positive, then
- * {@link #getSoftMinEvictableIdleTime} is ignored).
+ * {@link #getMinEvictableIdleDuration} (that is, if
+ * {@link #getMinEvictableIdleDuration} is positive, then
+ * {@link #getSoftMinEvictableIdleDuration()} is ignored).
*
* @return minimum amount of time an object may sit idle in the pool before
* it is eligible for eviction if minIdle instances are available
*
- * @see #setSoftMinEvictableIdle(Duration)
+ * @see #setSoftMinEvictableIdleDuration(Duration)
* @since 2.11.0
*/
public final Duration getSoftMinEvictableIdleDuration() {
return softMinEvictableIdleDuration;
}
- /**
- * Gets the minimum amount of time an object may sit idle in the pool
- * before it is eligible for eviction by the idle object evictor (if any -
- * see {@link #setTimeBetweenEvictionRuns(Duration)}),
- * with the extra condition that at least {@code minIdle} object
- * instances remain in the pool. This setting is overridden by
- * {@link #getMinEvictableIdleTime} (that is, if
- * {@link #getMinEvictableIdleTime} is positive, then
- * {@link #getSoftMinEvictableIdleTime} is ignored).
- *
- * @return minimum amount of time an object may sit idle in the pool before
- * it is eligible for eviction if minIdle instances are available
- *
- * @see #setSoftMinEvictableIdle(Duration)
- * @since 2.10.0
- * @deprecated Use {@link #getSoftMinEvictableIdleDuration}.
- */
- @Deprecated
- public final Duration getSoftMinEvictableIdleTime() {
- return softMinEvictableIdleDuration;
- }
-
- /**
- * Gets the minimum amount of time an object may sit idle in the pool
- * before it is eligible for eviction by the idle object evictor (if any -
- * see {@link #setTimeBetweenEvictionRunsMillis(long)}),
- * with the extra condition that at least {@code minIdle} object
- * instances remain in the pool. This setting is overridden by
- * {@link #getMinEvictableIdleTimeMillis} (that is, if
- * {@link #getMinEvictableIdleTimeMillis} is positive, then
- * {@link #getSoftMinEvictableIdleTimeMillis} is ignored).
- *
- * @return minimum amount of time an object may sit idle in the pool before
- * it is eligible for eviction if minIdle instances are available
- *
- * @see #setSoftMinEvictableIdleTimeMillis
- * @deprecated Use {@link #getSoftMinEvictableIdleTime()}.
- */
- @Deprecated
- public final long getSoftMinEvictableIdleTimeMillis() {
- return softMinEvictableIdleDuration.toMillis();
- }
-
/**
* Gets the stack trace of an exception as a string.
* @param e exception to trace
@@ -1052,10 +1028,10 @@ String getStatsString() {
"maxTotal=%s, maxWaitDuration=%s, minEvictableIdleDuration=%s, numTestsPerEvictionRun=%s, returnedCount=%s, " +
"softMinEvictableIdleDuration=%s, testOnBorrow=%s, testOnCreate=%s, testOnReturn=%s, testWhileIdle=%s, " +
"durationBetweenEvictionRuns=%s, waitTimes=%s",
- activeTimes.getCurrentValues(), blockWhenExhausted, borrowedCount.get(), closed, createdCount.get(), destroyedByBorrowValidationCount.get(),
- destroyedByEvictorCount.get(), evictorShutdownTimeoutDuration, fairness, idleTimes.getCurrentValues(), lifo, maxBorrowWaitDuration.get(),
+ activeTimes.getValues(), blockWhenExhausted, borrowedCount.get(), closed, createdCount.get(), destroyedByBorrowValidationCount.get(),
+ destroyedByEvictorCount.get(), evictorShutdownTimeoutDuration, fairness, idleTimes.getValues(), lifo, maxBorrowWaitDuration.get(),
maxTotal, maxWaitDuration, minEvictableIdleDuration, numTestsPerEvictionRun, returnedCount, softMinEvictableIdleDuration, testOnBorrow,
- testOnCreate, testOnReturn, testWhileIdle, durationBetweenEvictionRuns, waitTimes.getCurrentValues());
+ testOnCreate, testOnReturn, testWhileIdle, durationBetweenEvictionRuns, waitTimes.getValues());
}
/**
@@ -1096,7 +1072,6 @@ public final boolean getTestOnBorrow() {
* being returned from the {@code borrowObject()} method
*
* @see #setTestOnCreate
- *
* @since 2.2
*/
public final boolean getTestOnCreate() {
@@ -1122,44 +1097,26 @@ public final boolean getTestOnReturn() {
/**
* Gets whether objects sitting idle in the pool will be validated by the
* idle object evictor (if any - see
- * {@link #setTimeBetweenEvictionRuns(Duration)}). Validation is performed
+ * {@link #setDurationBetweenEvictionRuns(Duration)}). Validation is performed
* by the {@code validateObject()} method of the factory associated
* with the pool. If the object fails to validate, it will be removed from
* the pool and destroyed.
*
* @return {@code true} if objects will be validated by the evictor
- *
* @see #setTestWhileIdle
- * @see #setTimeBetweenEvictionRunsMillis
+ * @see #setDurationBetweenEvictionRuns(Duration)
*/
public final boolean getTestWhileIdle() {
return testWhileIdle;
}
- /**
- * Gets the duration to sleep between runs of the idle
- * object evictor thread. When non-positive, no idle object evictor thread
- * will be run.
- *
- * @return number of milliseconds to sleep between evictor runs
- *
- * @see #setTimeBetweenEvictionRuns
- * @since 2.10.0
- * @deprecated {@link #getDurationBetweenEvictionRuns()}.
- */
- @Deprecated
- public final Duration getTimeBetweenEvictionRuns() {
- return durationBetweenEvictionRuns;
- }
-
/**
* Gets the number of milliseconds to sleep between runs of the idle
* object evictor thread. When non-positive, no idle object evictor thread
* will be run.
*
* @return number of milliseconds to sleep between evictor runs
- *
- * @see #setTimeBetweenEvictionRunsMillis
+ * @see #setDurationBetweenEvictionRuns(Duration)
* @deprecated Use {@link #getDurationBetweenEvictionRuns()}.
*/
@Deprecated
@@ -1179,8 +1136,9 @@ public boolean isAbandonedConfig() {
}
/**
- * Tests whether this pool instance been closed.
- * @return {@code true} when this pool has been closed.
+ * Tests whether this pool instance is closed.
+ *
+ * @return {@code true} when this pool is closed.
*/
public final boolean isClosed() {
return closed;
@@ -1211,7 +1169,7 @@ private ObjectName jmxRegister(final BaseObjectPoolConfig config,
}
while (!registered) {
try {
- ObjectName objName;
+ final ObjectName objName;
// Skip the numeric suffix for the first pool in case there is
// only one so the names are cleaner.
if (i == 1) {
@@ -1279,7 +1237,6 @@ protected void markReturningState(final PooledObject pooledObject) {
* Sets the abandoned object removal configuration.
*
* @param abandonedConfig the new configuration to use. This is used by value.
- *
* @see AbandonedConfig
* @since 2.11.0
*/
@@ -1316,9 +1273,9 @@ protected void setConfig(final BaseObjectPoolConfig config) {
setTestOnReturn(config.getTestOnReturn());
setTestWhileIdle(config.getTestWhileIdle());
setNumTestsPerEvictionRun(config.getNumTestsPerEvictionRun());
- setMinEvictableIdle(config.getMinEvictableIdleDuration());
- setTimeBetweenEvictionRuns(config.getDurationBetweenEvictionRuns());
- setSoftMinEvictableIdle(config.getSoftMinEvictableIdleDuration());
+ setMinEvictableIdleDuration(config.getMinEvictableIdleDuration());
+ setDurationBetweenEvictionRuns(config.getDurationBetweenEvictionRuns());
+ setSoftMinEvictableIdleDuration(config.getSoftMinEvictableIdleDuration());
final EvictionPolicy policy = config.getEvictionPolicy();
if (policy == null) {
// Use the class name (pre-2.6.0 compatible)
@@ -1328,6 +1285,24 @@ protected void setConfig(final BaseObjectPoolConfig config) {
setEvictionPolicy(policy);
}
setEvictorShutdownTimeout(config.getEvictorShutdownTimeoutDuration());
+ setCollectDetailedStatistics(config.getCollectDetailedStatistics());
+ }
+
+ /**
+ * Sets the number of milliseconds to sleep between runs of the idle object evictor thread.
+ *
+ *
When positive, the idle object evictor thread starts.
+ *
When non-positive, no idle object evictor thread runs.
+ *
+ *
+ * @param timeBetweenEvictionRuns
+ * duration to sleep between evictor runs
+ *
+ * @see #getDurationBetweenEvictionRuns()
+ */
+ public final void setDurationBetweenEvictionRuns(final Duration timeBetweenEvictionRuns) {
+ this.durationBetweenEvictionRuns = PoolImplUtils.nonNull(timeBetweenEvictionRuns, BaseObjectPoolConfig.DEFAULT_DURATION_BETWEEN_EVICTION_RUNS);
+ startEvictor(this.durationBetweenEvictionRuns);
}
/**
@@ -1432,19 +1407,6 @@ public final void setEvictorShutdownTimeout(final Duration evictorShutdownTimeou
this.evictorShutdownTimeoutDuration = PoolImplUtils.nonNull(evictorShutdownTimeout, BaseObjectPoolConfig.DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT);
}
- /**
- * Sets the timeout that will be used when waiting for the Evictor to shutdown if this pool is closed and it is the
- * only pool still using the value for the Evictor.
- *
- * @param evictorShutdownTimeoutMillis the timeout in milliseconds that will be used while waiting for the Evictor
- * to shut down.
- * @deprecated Use {@link #setEvictorShutdownTimeout(Duration)}.
- */
- @Deprecated
- public final void setEvictorShutdownTimeoutMillis(final long evictorShutdownTimeoutMillis) {
- setEvictorShutdownTimeout(Duration.ofMillis(evictorShutdownTimeoutMillis));
- }
-
/**
* Sets whether the pool has LIFO (last in, first out) behavior with
* respect to idle objects - always returning the most recently used object
@@ -1495,26 +1457,6 @@ public final void setMaxWait(final Duration maxWaitDuration) {
this.maxWaitDuration = PoolImplUtils.nonNull(maxWaitDuration, BaseObjectPoolConfig.DEFAULT_MAX_WAIT);
}
- /**
- * Sets the maximum amount of time (in milliseconds) the
- * {@code borrowObject()} method should block before throwing an
- * exception when the pool is exhausted and
- * {@link #getBlockWhenExhausted} is true. When less than 0, the
- * {@code borrowObject()} method may block indefinitely.
- *
- * @param maxWaitMillis the maximum number of milliseconds
- * {@code borrowObject()} will block or negative
- * for indefinitely.
- *
- * @see #getMaxWaitDuration
- * @see #setBlockWhenExhausted
- * @deprecated Use {@link #setMaxWait}.
- */
- @Deprecated
- public final void setMaxWaitMillis(final long maxWaitMillis) {
- setMaxWait(Duration.ofMillis(maxWaitMillis));
- }
-
/**
* Sets whether to include statistics in exception messages.
*
@@ -1530,62 +1472,37 @@ public void setMessagesStatistics(final boolean messagesDetails) {
}
/**
- * Sets the minimum amount of time an object may sit idle in the pool
- * before it is eligible for eviction by the idle object evictor (if any -
- * see {@link #setTimeBetweenEvictionRuns(Duration)}). When non-positive,
- * no objects will be evicted from the pool due to idle time alone.
- *
- * @param minEvictableIdleTime
- * minimum amount of time an object may sit idle in the pool
- * before it is eligible for eviction
+ * Sets whether detailed timing statistics collection is enabled.
+ * When {@code false}, the pool will not collect detailed timing statistics,
+ * improving performance under high load at the cost of reduced monitoring capabilities.
+ *
+ * This setting affects data collection for mean active time, mean idle time, and mean borrow wait time.
+ *
*
- * @see #getMinEvictableIdleTime
- * @see #setTimeBetweenEvictionRuns
- * @since 2.11.0
+ * @param collectDetailedStatistics whether to collect detailed statistics.
+ * @since 2.13.0
*/
- public final void setMinEvictableIdle(final Duration minEvictableIdleTime) {
- this.minEvictableIdleDuration = PoolImplUtils.nonNull(minEvictableIdleTime, BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_DURATION);
+ public void setCollectDetailedStatistics(final boolean collectDetailedStatistics) {
+ this.collectDetailedStatistics = collectDetailedStatistics;
}
/**
* Sets the minimum amount of time an object may sit idle in the pool
* before it is eligible for eviction by the idle object evictor (if any -
- * see {@link #setTimeBetweenEvictionRuns(Duration)}). When non-positive,
+ * see {@link #setDurationBetweenEvictionRuns(Duration)}). When non-positive,
* no objects will be evicted from the pool due to idle time alone.
*
* @param minEvictableIdleTime
* minimum amount of time an object may sit idle in the pool
* before it is eligible for eviction
*
- * @see #getMinEvictableIdleTime
- * @see #setTimeBetweenEvictionRuns
- * @since 2.10.0
- * @deprecated Use {@link #setMinEvictableIdle(Duration)}.
+ * @see #getMinEvictableIdleDuration
+ * @see #setDurationBetweenEvictionRuns(Duration)
*/
- @Deprecated
- public final void setMinEvictableIdleTime(final Duration minEvictableIdleTime) {
+ public final void setMinEvictableIdleDuration(final Duration minEvictableIdleTime) {
this.minEvictableIdleDuration = PoolImplUtils.nonNull(minEvictableIdleTime, BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_DURATION);
}
- /**
- * Sets the minimum amount of time an object may sit idle in the pool
- * before it is eligible for eviction by the idle object evictor (if any -
- * see {@link #setTimeBetweenEvictionRunsMillis(long)}). When non-positive,
- * no objects will be evicted from the pool due to idle time alone.
- *
- * @param minEvictableIdleTimeMillis
- * minimum amount of time an object may sit idle in the pool
- * before it is eligible for eviction
- *
- * @see #getMinEvictableIdleTimeMillis
- * @see #setTimeBetweenEvictionRunsMillis
- * @deprecated Use {@link #setMinEvictableIdleTime(Duration)}.
- */
- @Deprecated
- public final void setMinEvictableIdleTimeMillis(final long minEvictableIdleTimeMillis) {
- setMinEvictableIdleTime(Duration.ofMillis(minEvictableIdleTimeMillis));
- }
-
/**
* Sets the maximum number of objects to examine during each run (if any)
* of the idle object evictor thread. When positive, the number of tests
@@ -1600,7 +1517,7 @@ public final void setMinEvictableIdleTimeMillis(final long minEvictableIdleTimeM
* max number of objects to examine during each evictor run
*
* @see #getNumTestsPerEvictionRun
- * @see #setTimeBetweenEvictionRunsMillis
+ * @see #setDurationBetweenEvictionRuns(Duration)
*/
public final void setNumTestsPerEvictionRun(final int numTestsPerEvictionRun) {
this.numTestsPerEvictionRun = numTestsPerEvictionRun;
@@ -1609,72 +1526,25 @@ public final void setNumTestsPerEvictionRun(final int numTestsPerEvictionRun) {
/**
* Sets the minimum amount of time an object may sit idle in the pool
* before it is eligible for eviction by the idle object evictor (if any -
- * see {@link #setTimeBetweenEvictionRuns(Duration)}),
+ * see {@link #setDurationBetweenEvictionRuns(Duration)}),
* with the extra condition that at least {@code minIdle} object
* instances remain in the pool. This setting is overridden by
- * {@link #getMinEvictableIdleTime} (that is, if
- * {@link #getMinEvictableIdleTime} is positive, then
- * {@link #getSoftMinEvictableIdleTime} is ignored).
+ * {@link #getMinEvictableIdleDuration} (that is, if
+ * {@link #getMinEvictableIdleDuration} is positive, then
+ * {@link #getSoftMinEvictableIdleDuration} is ignored).
*
* @param softMinEvictableIdleTime
* minimum amount of time an object may sit idle in the pool
* before it is eligible for eviction if minIdle instances are
* available
*
- * @see #getSoftMinEvictableIdleTimeMillis
+ * @see #getSoftMinEvictableIdleDuration
* @since 2.11.0
*/
- public final void setSoftMinEvictableIdle(final Duration softMinEvictableIdleTime) {
- this.softMinEvictableIdleDuration = PoolImplUtils.nonNull(softMinEvictableIdleTime, BaseObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION);
- }
-
- /**
- * Sets the minimum amount of time an object may sit idle in the pool
- * before it is eligible for eviction by the idle object evictor (if any -
- * see {@link #setTimeBetweenEvictionRuns(Duration)}),
- * with the extra condition that at least {@code minIdle} object
- * instances remain in the pool. This setting is overridden by
- * {@link #getMinEvictableIdleTime} (that is, if
- * {@link #getMinEvictableIdleTime} is positive, then
- * {@link #getSoftMinEvictableIdleTime} is ignored).
- *
- * @param softMinEvictableIdleTime
- * minimum amount of time an object may sit idle in the pool
- * before it is eligible for eviction if minIdle instances are
- * available
- *
- * @see #getSoftMinEvictableIdleTimeMillis
- * @since 2.10.0
- * @deprecated Use {@link #setSoftMinEvictableIdle(Duration)}.
- */
- @Deprecated
- public final void setSoftMinEvictableIdleTime(final Duration softMinEvictableIdleTime) {
+ public final void setSoftMinEvictableIdleDuration(final Duration softMinEvictableIdleTime) {
this.softMinEvictableIdleDuration = PoolImplUtils.nonNull(softMinEvictableIdleTime, BaseObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION);
}
- /**
- * Sets the minimum amount of time an object may sit idle in the pool
- * before it is eligible for eviction by the idle object evictor (if any -
- * see {@link #setTimeBetweenEvictionRunsMillis(long)}),
- * with the extra condition that at least {@code minIdle} object
- * instances remain in the pool. This setting is overridden by
- * {@link #getMinEvictableIdleTimeMillis} (that is, if
- * {@link #getMinEvictableIdleTimeMillis} is positive, then
- * {@link #getSoftMinEvictableIdleTimeMillis} is ignored).
- *
- * @param softMinEvictableIdleTimeMillis
- * minimum amount of time an object may sit idle in the pool
- * before it is eligible for eviction if minIdle instances are
- * available
- *
- * @see #getSoftMinEvictableIdleTimeMillis
- * @deprecated Use {@link #setSoftMinEvictableIdle(Duration)}.
- */
- @Deprecated
- public final void setSoftMinEvictableIdleTimeMillis(final long softMinEvictableIdleTimeMillis) {
- setSoftMinEvictableIdleTime(Duration.ofMillis(softMinEvictableIdleTimeMillis));
- }
-
/**
* Sets the listener used (if any) to receive notifications of exceptions
* unavoidably swallowed by the pool.
@@ -1717,7 +1587,6 @@ public final void setTestOnBorrow(final boolean testOnBorrow) {
* {@code borrowObject()} method
*
* @see #getTestOnCreate
- *
* @since 2.2
*/
public final void setTestOnCreate(final boolean testOnCreate) {
@@ -1744,7 +1613,7 @@ public final void setTestOnReturn(final boolean testOnReturn) {
/**
* Sets whether objects sitting idle in the pool will be validated by the
* idle object evictor (if any - see
- * {@link #setTimeBetweenEvictionRuns(Duration)}). Validation is performed
+ * {@link #setDurationBetweenEvictionRuns(Duration)}). Validation is performed
* by the {@code validateObject()} method of the factory associated
* with the pool. If the object fails to validate, it will be removed from
* the pool and destroyed. Note that setting this property has no effect
@@ -1755,48 +1624,12 @@ public final void setTestOnReturn(final boolean testOnReturn) {
* {@code true} so objects will be validated by the evictor
*
* @see #getTestWhileIdle
- * @see #setTimeBetweenEvictionRuns
+ * @see #setDurationBetweenEvictionRuns(Duration)
*/
public final void setTestWhileIdle(final boolean testWhileIdle) {
this.testWhileIdle = testWhileIdle;
}
- /**
- * Sets the number of milliseconds to sleep between runs of the idle object evictor thread.
- *
- *
When positive, the idle object evictor thread starts.
- *
When non-positive, no idle object evictor thread runs.
- *
- *
- * @param timeBetweenEvictionRuns
- * duration to sleep between evictor runs
- *
- * @see #getDurationBetweenEvictionRuns()
- * @since 2.10.0
- */
- public final void setTimeBetweenEvictionRuns(final Duration timeBetweenEvictionRuns) {
- this.durationBetweenEvictionRuns = PoolImplUtils.nonNull(timeBetweenEvictionRuns, BaseObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS);
- startEvictor(this.durationBetweenEvictionRuns);
- }
-
- /**
- * Sets the number of milliseconds to sleep between runs of the idle object evictor thread.
- *
- *
When positive, the idle object evictor thread starts.
- *
When non-positive, no idle object evictor thread runs.
- *
- *
- * @param timeBetweenEvictionRunsMillis
- * number of milliseconds to sleep between evictor runs
- *
- * @see #getDurationBetweenEvictionRuns()
- * @deprecated Use {@link #setTimeBetweenEvictionRuns(Duration)}.
- */
- @Deprecated
- public final void setTimeBetweenEvictionRunsMillis(final long timeBetweenEvictionRunsMillis) {
- setTimeBetweenEvictionRuns(Duration.ofMillis(timeBetweenEvictionRunsMillis));
- }
-
/**
*
Starts the evictor with the given delay. If there is an evictor
* running when this method is called, it is stopped and replaced with a
@@ -1805,7 +1638,7 @@ public final void setTimeBetweenEvictionRunsMillis(final long timeBetweenEvictio
*
This method needs to be final, since it is called from a constructor.
* See POOL-195.
*
- * @param delay time in milliseconds before start and between eviction runs
+ * @param delay duration before start and between eviction runs.
*/
final void startEvictor(final Duration delay) {
synchronized (evictionLock) {
@@ -1936,20 +1769,19 @@ protected void toStringAppendFields(final StringBuilder builder) {
*/
final void updateStatsBorrow(final PooledObject p, final Duration waitDuration) {
borrowedCount.incrementAndGet();
- idleTimes.add(p.getIdleDuration());
- waitTimes.add(waitDuration);
-
- // lock-free optimistic-locking maximum
- Duration currentMaxDuration;
- do {
- currentMaxDuration = maxBorrowWaitDuration.get();
-// if (currentMaxDuration >= waitDuration) {
-// break;
-// }
- if (currentMaxDuration.compareTo(waitDuration) >= 0) {
- break;
- }
- } while (!maxBorrowWaitDuration.compareAndSet(currentMaxDuration, waitDuration));
+ // Only collect detailed statistics if enabled
+ if (collectDetailedStatistics) {
+ idleTimes.add(p.getIdleDuration());
+ waitTimes.add(waitDuration);
+ // lock-free optimistic-locking maximum
+ Duration currentMaxDuration;
+ do {
+ currentMaxDuration = maxBorrowWaitDuration.get();
+ if (currentMaxDuration.compareTo(waitDuration) >= 0) {
+ break;
+ }
+ } while (!maxBorrowWaitDuration.compareAndSet(currentMaxDuration, waitDuration));
+ }
}
/**
@@ -1960,8 +1792,10 @@ final void updateStatsBorrow(final PooledObject p, final Duration waitDuratio
*/
final void updateStatsReturn(final Duration activeTime) {
returnedCount.incrementAndGet();
- activeTimes.add(activeTime);
+ // Only collect detailed statistics if enabled
+ if (collectDetailedStatistics) {
+ activeTimes.add(activeTime);
+ }
}
-
}
diff --git a/src/main/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java b/src/main/java/org/apache/commons/pool3/impl/BaseObjectPoolConfig.java
similarity index 65%
rename from src/main/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java
rename to src/main/java/org/apache/commons/pool3/impl/BaseObjectPoolConfig.java
index 081105483..e47a04510 100644
--- a/src/main/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java
+++ b/src/main/java/org/apache/commons/pool3/impl/BaseObjectPoolConfig.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,11 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.time.Duration;
-import org.apache.commons.pool2.BaseObject;
+import org.apache.commons.pool3.BaseObject;
/**
* Provides the implementation for the common attributes shared by the
@@ -47,32 +47,13 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
*/
public static final boolean DEFAULT_FAIRNESS = false;
- /**
- * The default value for the {@code maxWait} configuration attribute.
- * @see GenericObjectPool#getMaxWaitDuration()
- * @see GenericKeyedObjectPool#getMaxWaitDuration()
- * @deprecated Use {@link #DEFAULT_MAX_WAIT}.
- */
- @Deprecated
- public static final long DEFAULT_MAX_WAIT_MILLIS = -1L;
-
/**
* The default value for the {@code maxWait} configuration attribute.
* @see GenericObjectPool#getMaxWaitDuration()
* @see GenericKeyedObjectPool#getMaxWaitDuration()
* @since 2.10.0
*/
- public static final Duration DEFAULT_MAX_WAIT = Duration.ofMillis(DEFAULT_MAX_WAIT_MILLIS);
-
- /**
- * The default value for the {@code minEvictableIdleDuration}
- * configuration attribute.
- * @see GenericObjectPool#getMinEvictableIdleDuration()
- * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
- * @deprecated Use {@link #DEFAULT_MIN_EVICTABLE_IDLE_TIME}.
- */
- @Deprecated
- public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS = 1000L * 60L * 30L;
+ public static final Duration DEFAULT_MAX_WAIT = Duration.ofMillis(-1L);
/**
* The default value for the {@code minEvictableIdleDuration}
@@ -81,42 +62,7 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
* @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
* @since 2.11.0
*/
- public static final Duration DEFAULT_MIN_EVICTABLE_IDLE_DURATION =
- Duration.ofMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
-
- /**
- * The default value for the {@code minEvictableIdleDuration}
- * configuration attribute.
- * @see GenericObjectPool#getMinEvictableIdleDuration()
- * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
- * @since 2.10.0
- * @deprecated Use {@link #DEFAULT_MIN_EVICTABLE_IDLE_DURATION}.
- */
- @Deprecated
- public static final Duration DEFAULT_MIN_EVICTABLE_IDLE_TIME =
- Duration.ofMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
-
- /**
- * The default value for the {@code softMinEvictableIdleTime}
- * configuration attribute.
- * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
- * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
- * @deprecated Use {@link #DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME}.
- */
- @Deprecated
- public static final long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = -1;
-
- /**
- * The default value for the {@code softMinEvictableIdleTime}
- * configuration attribute.
- * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
- * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
- * @since 2.10.0
- * @deprecated Use {@link #DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION}.
- */
- @Deprecated
- public static final Duration DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME =
- Duration.ofMillis(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
+ public static final Duration DEFAULT_MIN_EVICTABLE_IDLE_DURATION = Duration.ofMillis(1000L * 60L * 30L);
/**
* The default value for the {@code softMinEvictableIdleTime}
@@ -125,18 +71,7 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
* @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
* @since 2.11.0
*/
- public static final Duration DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION =
- Duration.ofMillis(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
-
- /**
- * The default value for {@code evictorShutdownTimeout} configuration
- * attribute.
- * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
- * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
- * @deprecated Use {@link #DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT}.
- */
- @Deprecated
- public static final long DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS = 10L * 1000L;
+ public static final Duration DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION = Duration.ofMillis(-1);
/**
* The default value for {@code evictorShutdownTimeout} configuration
@@ -145,8 +80,7 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
* @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
* @since 2.10.0
*/
- public static final Duration DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT =
- Duration.ofMillis(DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS);
+ public static final Duration DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT = Duration.ofMillis(10L * 1000L);
/**
* The default value for the {@code numTestsPerEvictionRun} configuration
@@ -160,7 +94,6 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
* The default value for the {@code testOnCreate} configuration attribute.
* @see GenericObjectPool#getTestOnCreate()
* @see GenericKeyedObjectPool#getTestOnCreate()
- *
* @since 2.2
*/
public static final boolean DEFAULT_TEST_ON_CREATE = false;
@@ -186,24 +119,13 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
*/
public static final boolean DEFAULT_TEST_WHILE_IDLE = false;
- /**
- * The default value for the {@code timeBetweenEvictionRuns}
- * configuration attribute.
- * @see GenericObjectPool#getDurationBetweenEvictionRuns()
- * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
- * @deprecated Use {@link #DEFAULT_TIME_BETWEEN_EVICTION_RUNS}.
- */
- @Deprecated
- public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L;
-
/**
* The default value for the {@code timeBetweenEvictionRuns}
* configuration attribute.
* @see GenericObjectPool#getDurationBetweenEvictionRuns()
* @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
*/
- public static final Duration DEFAULT_TIME_BETWEEN_EVICTION_RUNS = Duration
- .ofMillis(DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
+ public static final Duration DEFAULT_DURATION_BETWEEN_EVICTION_RUNS = Duration.ofMillis(-1L);
/**
* The default value for the {@code blockWhenExhausted} configuration
@@ -244,17 +166,30 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
*/
public static final String DEFAULT_EVICTION_POLICY_CLASS_NAME = DefaultEvictionPolicy.class.getName();
+ /**
+ * The default value for the {@code collectDetailedStatistics} configuration
+ * attribute. When {@code true}, the pool will collect detailed timing statistics
+ * for monitoring purposes. When {@code false}, detailed statistics collection
+ * is disabled, improving performance under high load.
+ *
+ * This setting affects data collection for mean active time, mean idle time, and mean borrow wait time.
+ *
+ *
+ * @since 2.13.0
+ */
+ public static final boolean DEFAULT_COLLECT_DETAILED_STATISTICS = true;
+
private boolean lifo = DEFAULT_LIFO;
private boolean fairness = DEFAULT_FAIRNESS;
private Duration maxWaitDuration = DEFAULT_MAX_WAIT;
- private Duration minEvictableIdleDuration = DEFAULT_MIN_EVICTABLE_IDLE_TIME;
+ private Duration minEvictableIdleDuration = DEFAULT_MIN_EVICTABLE_IDLE_DURATION;
private Duration evictorShutdownTimeoutDuration = DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT;
- private Duration softMinEvictableIdleDuration = DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME;
+ private Duration softMinEvictableIdleDuration = DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION;
private int numTestsPerEvictionRun = DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
@@ -270,7 +205,7 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
private boolean testWhileIdle = DEFAULT_TEST_WHILE_IDLE;
- private Duration durationBetweenEvictionRuns = DEFAULT_TIME_BETWEEN_EVICTION_RUNS;
+ private Duration durationBetweenEvictionRuns = DEFAULT_DURATION_BETWEEN_EVICTION_RUNS;
private boolean blockWhenExhausted = DEFAULT_BLOCK_WHEN_EXHAUSTED;
@@ -281,6 +216,14 @@ public abstract class BaseObjectPoolConfig extends BaseObject implements Clon
private String jmxNameBase = DEFAULT_JMX_NAME_BASE;
+ private boolean collectDetailedStatistics = DEFAULT_COLLECT_DETAILED_STATISTICS;
+
+ /**
+ * Constructs a new instance.
+ */
+ public BaseObjectPoolConfig() {
+ // empty
+ }
/**
* Gets the value for the {@code blockWhenExhausted} configuration attribute
@@ -296,6 +239,23 @@ public boolean getBlockWhenExhausted() {
return blockWhenExhausted;
}
+ /**
+ * Gets the value for the {@code collectDetailedStatistics} configuration attribute
+ * for pools created with this configuration instance.
+ *
+ * This setting affects data collection for mean active time, mean idle time, and mean borrow wait time.
+ *
+ *
+ * @return {@code true} if detailed statistics collection is enabled,
+ * {@code false} if disabled for improved performance.
+ * @see GenericObjectPool#getCollectDetailedStatistics()
+ * @see GenericKeyedObjectPool#getCollectDetailedStatistics()
+ * @since 2.13.0
+ */
+ public boolean getCollectDetailedStatistics() {
+ return collectDetailedStatistics;
+ }
+
/**
* Gets the value for the {@code timeBetweenEvictionRuns} configuration
* attribute for pools created with this configuration instance.
@@ -340,23 +300,6 @@ public String getEvictionPolicyClassName() {
return evictionPolicyClassName;
}
- /**
- * Gets the value for the {@code evictorShutdownTimeout} configuration
- * attribute for pools created with this configuration instance.
- *
- * @return The current setting of {@code evictorShutdownTimeout} for
- * this configuration instance
- *
- * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
- * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
- * @since 2.10.0
- * @deprecated Use {@link #getEvictorShutdownTimeoutDuration()}.
- */
- @Deprecated
- public Duration getEvictorShutdownTimeout() {
- return evictorShutdownTimeoutDuration;
- }
-
/**
* Gets the value for the {@code evictorShutdownTimeout} configuration
* attribute for pools created with this configuration instance.
@@ -372,22 +315,6 @@ public Duration getEvictorShutdownTimeoutDuration() {
return evictorShutdownTimeoutDuration;
}
- /**
- * Gets the value for the {@code evictorShutdownTimeout} configuration
- * attribute for pools created with this configuration instance.
- *
- * @return The current setting of {@code evictorShutdownTimeout} for
- * this configuration instance
- *
- * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
- * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
- * @deprecated Use {@link #getEvictorShutdownTimeout()}.
- */
- @Deprecated
- public long getEvictorShutdownTimeoutMillis() {
- return evictorShutdownTimeoutDuration.toMillis();
- }
-
/**
* Gets the value for the {@code fairness} configuration attribute for pools
* created with this configuration instance.
@@ -467,22 +394,6 @@ public Duration getMaxWaitDuration() {
return maxWaitDuration;
}
- /**
- * Gets the value for the {@code maxWait} configuration attribute for pools
- * created with this configuration instance.
- *
- * @return The current setting of {@code maxWait} for this
- * configuration instance
- *
- * @see GenericObjectPool#getMaxWaitDuration()
- * @see GenericKeyedObjectPool#getMaxWaitDuration()
- * @deprecated Use {@link #getMaxWaitDuration()}.
- */
- @Deprecated
- public long getMaxWaitMillis() {
- return maxWaitDuration.toMillis();
- }
-
/**
* Gets the value for the {@code minEvictableIdleTime} configuration
* attribute for pools created with this configuration instance.
@@ -498,39 +409,6 @@ public Duration getMinEvictableIdleDuration() {
return minEvictableIdleDuration;
}
- /**
- * Gets the value for the {@code minEvictableIdleTime} configuration
- * attribute for pools created with this configuration instance.
- *
- * @return The current setting of {@code minEvictableIdleTime} for
- * this configuration instance
- *
- * @see GenericObjectPool#getMinEvictableIdleDuration()
- * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
- * @since 2.10.0
- * @deprecated Use {@link #getMinEvictableIdleDuration()}.
- */
- @Deprecated
- public Duration getMinEvictableIdleTime() {
- return minEvictableIdleDuration;
- }
-
- /**
- * Gets the value for the {@code minEvictableIdleTime} configuration
- * attribute for pools created with this configuration instance.
- *
- * @return The current setting of {@code minEvictableIdleTime} for
- * this configuration instance
- *
- * @see GenericObjectPool#getMinEvictableIdleDuration()
- * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
- * @deprecated Use {@link #getMinEvictableIdleTime()}.
- */
- @Deprecated
- public long getMinEvictableIdleTimeMillis() {
- return minEvictableIdleDuration.toMillis();
- }
-
/**
* Gets the value for the {@code numTestsPerEvictionRun} configuration
* attribute for pools created with this configuration instance.
@@ -561,41 +439,6 @@ public Duration getSoftMinEvictableIdleDuration() {
return softMinEvictableIdleDuration;
}
- /**
- * Gets the value for the {@code softMinEvictableIdleTime}
- * configuration attribute for pools created with this configuration
- * instance.
- *
- * @return The current setting of {@code softMinEvictableIdleTime}
- * for this configuration instance
- *
- * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
- * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
- * @since 2.10.0
- * @deprecated Use {@link #getSoftMinEvictableIdleDuration()}.
- */
- @Deprecated
- public Duration getSoftMinEvictableIdleTime() {
- return softMinEvictableIdleDuration;
- }
-
- /**
- * Gets the value for the {@code softMinEvictableIdleTime}
- * configuration attribute for pools created with this configuration
- * instance.
- *
- * @return The current setting of {@code softMinEvictableIdleTime}
- * for this configuration instance
- *
- * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
- * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
- * @deprecated Use {@link #getSoftMinEvictableIdleDuration()}.
- */
- @Deprecated
- public long getSoftMinEvictableIdleTimeMillis() {
- return softMinEvictableIdleDuration.toMillis();
- }
-
/**
* Gets the value for the {@code testOnBorrow} configuration attribute for
* pools created with this configuration instance.
@@ -619,7 +462,6 @@ public boolean getTestOnBorrow() {
*
* @see GenericObjectPool#getTestOnCreate()
* @see GenericKeyedObjectPool#getTestOnCreate()
- *
* @since 2.2
*/
public boolean getTestOnCreate() {
@@ -655,50 +497,53 @@ public boolean getTestWhileIdle() {
}
/**
- * Gets the value for the {@code timeBetweenEvictionRuns} configuration
- * attribute for pools created with this configuration instance.
+ * Sets the value for the {@code blockWhenExhausted} configuration attribute
+ * for pools created with this configuration instance.
*
- * @return The current setting of {@code timeBetweenEvictionRuns} for
- * this configuration instance
+ * @param blockWhenExhausted The new setting of {@code blockWhenExhausted}
+ * for this configuration instance
*
- * @see GenericObjectPool#getDurationBetweenEvictionRuns()
- * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
- * @since 2.10.0
- * @deprecated Use {@link #getDurationBetweenEvictionRuns()}.
+ * @see GenericObjectPool#getBlockWhenExhausted()
+ * @see GenericKeyedObjectPool#getBlockWhenExhausted()
*/
- @Deprecated
- public Duration getTimeBetweenEvictionRuns() {
- return durationBetweenEvictionRuns;
+ public void setBlockWhenExhausted(final boolean blockWhenExhausted) {
+ this.blockWhenExhausted = blockWhenExhausted;
}
/**
- * Gets the value for the {@code timeBetweenEvictionRuns} configuration
- * attribute for pools created with this configuration instance.
+ * Sets the value for the {@code collectDetailedStatistics} configuration attribute
+ * for pools created with this configuration instance. When {@code false}, the pool
+ * will not collect detailed timing statistics, improving performance under high load
+ * at the cost of reduced monitoring capabilities.
+ *
+ * This setting affects data collection for mean active time, mean idle time, and mean borrow wait time.
+ *
*
- * @return The current setting of {@code timeBetweenEvictionRuns} for
- * this configuration instance
+ * @param collectDetailedStatistics The new setting of {@code collectDetailedStatistics}
+ * for this configuration instance.
*
- * @see GenericObjectPool#getDurationBetweenEvictionRuns()
- * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
- * @deprecated Use {@link #getDurationBetweenEvictionRuns()}.
+ * @see GenericObjectPool#getCollectDetailedStatistics()
+ * @see GenericKeyedObjectPool#getCollectDetailedStatistics()
+ * @since 2.13.0
*/
- @Deprecated
- public long getTimeBetweenEvictionRunsMillis() {
- return durationBetweenEvictionRuns.toMillis();
+ public void setCollectDetailedStatistics(final boolean collectDetailedStatistics) {
+ this.collectDetailedStatistics = collectDetailedStatistics;
}
/**
- * Sets the value for the {@code blockWhenExhausted} configuration attribute
- * for pools created with this configuration instance.
+ * Sets the value for the {@code timeBetweenEvictionRuns} configuration
+ * attribute for pools created with this configuration instance.
*
- * @param blockWhenExhausted The new setting of {@code blockWhenExhausted}
- * for this configuration instance
+ * @param timeBetweenEvictionRuns The new setting of
+ * {@code timeBetweenEvictionRuns} for this configuration
+ * instance
*
- * @see GenericObjectPool#getBlockWhenExhausted()
- * @see GenericKeyedObjectPool#getBlockWhenExhausted()
+ * @see GenericObjectPool#getDurationBetweenEvictionRuns()
+ * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
+ * @since 2.10.0
*/
- public void setBlockWhenExhausted(final boolean blockWhenExhausted) {
- this.blockWhenExhausted = blockWhenExhausted;
+ public void setDurationBetweenEvictionRuns(final Duration timeBetweenEvictionRuns) {
+ this.durationBetweenEvictionRuns = PoolImplUtils.nonNull(timeBetweenEvictionRuns, DEFAULT_DURATION_BETWEEN_EVICTION_RUNS);
}
/**
@@ -746,41 +591,6 @@ public void setEvictorShutdownTimeout(final Duration evictorShutdownTimeoutDurat
this.evictorShutdownTimeoutDuration = PoolImplUtils.nonNull(evictorShutdownTimeoutDuration, DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT);
}
- /**
- * Sets the value for the {@code evictorShutdownTimeout} configuration
- * attribute for pools created with this configuration instance.
- *
- * @param evictorShutdownTimeout The new setting of
- * {@code evictorShutdownTimeout} for this configuration
- * instance
- *
- * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
- * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
- * @since 2.10.0
- * @deprecated Use {@link #setEvictorShutdownTimeout(Duration)}.
- */
- @Deprecated
- public void setEvictorShutdownTimeoutMillis(final Duration evictorShutdownTimeout) {
- setEvictorShutdownTimeout(evictorShutdownTimeout);
- }
-
- /**
- * Sets the value for the {@code evictorShutdownTimeout} configuration
- * attribute for pools created with this configuration instance.
- *
- * @param evictorShutdownTimeoutMillis The new setting of
- * {@code evictorShutdownTimeout} for this configuration
- * instance
- *
- * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
- * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
- * @deprecated Use {@link #setEvictorShutdownTimeout(Duration)}.
- */
- @Deprecated
- public void setEvictorShutdownTimeoutMillis(final long evictorShutdownTimeoutMillis) {
- setEvictorShutdownTimeout(Duration.ofMillis(evictorShutdownTimeoutMillis));
- }
-
/**
* Sets the value for the {@code fairness} configuration attribute for pools
* created with this configuration instance.
@@ -860,22 +670,6 @@ public void setMaxWait(final Duration maxWaitDuration) {
this.maxWaitDuration = PoolImplUtils.nonNull(maxWaitDuration, DEFAULT_MAX_WAIT);
}
- /**
- * Sets the value for the {@code maxWait} configuration attribute for pools
- * created with this configuration instance.
- *
- * @param maxWaitMillis The new setting of {@code maxWaitMillis}
- * for this configuration instance
- *
- * @see GenericObjectPool#getMaxWaitDuration()
- * @see GenericKeyedObjectPool#getMaxWaitDuration()
- * @deprecated Use {@link #setMaxWait(Duration)}.
- */
- @Deprecated
- public void setMaxWaitMillis(final long maxWaitMillis) {
- setMaxWait(Duration.ofMillis(maxWaitMillis));
- }
-
/**
* Sets the value for the {@code minEvictableIdleTime} configuration
* attribute for pools created with this configuration instance.
@@ -887,24 +681,8 @@ public void setMaxWaitMillis(final long maxWaitMillis) {
* @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
* @since 2.10.0
*/
- public void setMinEvictableIdleTime(final Duration minEvictableIdleTime) {
- this.minEvictableIdleDuration = PoolImplUtils.nonNull(minEvictableIdleTime, DEFAULT_MIN_EVICTABLE_IDLE_TIME);
- }
-
- /**
- * Sets the value for the {@code minEvictableIdleTime} configuration
- * attribute for pools created with this configuration instance.
- *
- * @param minEvictableIdleTimeMillis The new setting of
- * {@code minEvictableIdleTime} for this configuration instance
- *
- * @see GenericObjectPool#getMinEvictableIdleDuration()
- * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
- * @deprecated Use {@link #setMinEvictableIdleTime(Duration)}.
- */
- @Deprecated
- public void setMinEvictableIdleTimeMillis(final long minEvictableIdleTimeMillis) {
- this.minEvictableIdleDuration = Duration.ofMillis(minEvictableIdleTimeMillis);
+ public void setMinEvictableIdleDuration(final Duration minEvictableIdleTime) {
+ this.minEvictableIdleDuration = PoolImplUtils.nonNull(minEvictableIdleTime, DEFAULT_MIN_EVICTABLE_IDLE_DURATION);
}
/**
@@ -934,27 +712,8 @@ public void setNumTestsPerEvictionRun(final int numTestsPerEvictionRun) {
* @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
* @since 2.10.0
*/
- public void setSoftMinEvictableIdleTime(final Duration softMinEvictableIdleTime) {
- this.softMinEvictableIdleDuration = PoolImplUtils.nonNull(softMinEvictableIdleTime, DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME);
- }
-
- /**
- * Sets the value for the {@code softMinEvictableIdleTime}
- * configuration attribute for pools created with this configuration
- * instance.
- *
- * @param softMinEvictableIdleTimeMillis The new setting of
- * {@code softMinEvictableIdleTime} for this configuration
- * instance
- *
- * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
- * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
- * @deprecated Use {@link #setSoftMinEvictableIdleTime(Duration)}.
- */
- @Deprecated
- public void setSoftMinEvictableIdleTimeMillis(
- final long softMinEvictableIdleTimeMillis) {
- setSoftMinEvictableIdleTime(Duration.ofMillis(softMinEvictableIdleTimeMillis));
+ public void setSoftMinEvictableIdleDuration(final Duration softMinEvictableIdleTime) {
+ this.softMinEvictableIdleDuration = PoolImplUtils.nonNull(softMinEvictableIdleTime, DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION);
}
/**
@@ -980,7 +739,6 @@ public void setTestOnBorrow(final boolean testOnBorrow) {
*
* @see GenericObjectPool#getTestOnCreate()
* @see GenericKeyedObjectPool#getTestOnCreate()
- *
* @since 2.2
*/
public void setTestOnCreate(final boolean testOnCreate) {
@@ -1015,39 +773,6 @@ public void setTestWhileIdle(final boolean testWhileIdle) {
this.testWhileIdle = testWhileIdle;
}
- /**
- * Sets the value for the {@code timeBetweenEvictionRuns} configuration
- * attribute for pools created with this configuration instance.
- *
- * @param timeBetweenEvictionRuns The new setting of
- * {@code timeBetweenEvictionRuns} for this configuration
- * instance
- *
- * @see GenericObjectPool#getDurationBetweenEvictionRuns()
- * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
- * @since 2.10.0
- */
- public void setTimeBetweenEvictionRuns(final Duration timeBetweenEvictionRuns) {
- this.durationBetweenEvictionRuns = PoolImplUtils.nonNull(timeBetweenEvictionRuns, DEFAULT_TIME_BETWEEN_EVICTION_RUNS);
- }
-
- /**
- * Sets the value for the {@code timeBetweenEvictionRuns} configuration
- * attribute for pools created with this configuration instance.
- *
- * @param timeBetweenEvictionRunsMillis The new setting of
- * {@code timeBetweenEvictionRuns} for this configuration
- * instance
- *
- * @see GenericObjectPool#getDurationBetweenEvictionRuns()
- * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
- * @deprecated Use {@link #setTimeBetweenEvictionRuns(Duration)}.
- */
- @Deprecated
- public void setTimeBetweenEvictionRunsMillis(final long timeBetweenEvictionRunsMillis) {
- setTimeBetweenEvictionRuns(Duration.ofMillis(timeBetweenEvictionRunsMillis));
- }
-
@Override
protected void toStringAppendFields(final StringBuilder builder) {
builder.append("lifo=");
@@ -1082,5 +807,7 @@ protected void toStringAppendFields(final StringBuilder builder) {
builder.append(jmxNamePrefix);
builder.append(", jmxNameBase=");
builder.append(jmxNameBase);
+ builder.append(", collectDetailedStatistics=");
+ builder.append(collectDetailedStatistics);
}
}
diff --git a/src/main/java/org/apache/commons/pool2/impl/CallStack.java b/src/main/java/org/apache/commons/pool3/impl/CallStack.java
similarity index 89%
rename from src/main/java/org/apache/commons/pool2/impl/CallStack.java
rename to src/main/java/org/apache/commons/pool3/impl/CallStack.java
index 9db0452a7..7c63558cb 100644
--- a/src/main/java/org/apache/commons/pool2/impl/CallStack.java
+++ b/src/main/java/org/apache/commons/pool3/impl/CallStack.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.io.PrintWriter;
-import org.apache.commons.pool2.PooledObject;
-import org.apache.commons.pool2.UsageTracking;
+import org.apache.commons.pool3.PooledObject;
+import org.apache.commons.pool3.UsageTracking;
/**
* Strategy for obtaining and printing the current call stack. This is primarily useful for
@@ -50,5 +50,5 @@ public interface CallStack {
* @param writer a PrintWriter to write the current stack trace to if available
* @return true if a stack trace was available to print or false if nothing was printed
*/
- boolean printStackTrace(final PrintWriter writer);
+ boolean printStackTrace(PrintWriter writer);
}
diff --git a/src/main/java/org/apache/commons/pool2/impl/CallStackUtils.java b/src/main/java/org/apache/commons/pool3/impl/CallStackUtils.java
similarity index 78%
rename from src/main/java/org/apache/commons/pool2/impl/CallStackUtils.java
rename to src/main/java/org/apache/commons/pool3/impl/CallStackUtils.java
index 1fdcad23e..a9e1f4426 100644
--- a/src/main/java/org/apache/commons/pool2/impl/CallStackUtils.java
+++ b/src/main/java/org/apache/commons/pool3/impl/CallStackUtils.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.security.AccessControlException;
@@ -44,20 +44,6 @@ private static boolean canCreateSecurityManager() {
}
}
- /**
- * Constructs a new {@link CallStack} using the fastest allowed strategy.
- *
- * @param messageFormat message (or format) to print first in stack traces
- * @param useTimestamp if true, interpret message as a SimpleDateFormat and print the created timestamp; otherwise,
- * print message format literally
- * @return a new CallStack
- * @deprecated use {@link #newCallStack(String, boolean, boolean)}
- */
- @Deprecated
- public static CallStack newCallStack(final String messageFormat, final boolean useTimestamp) {
- return newCallStack(messageFormat, useTimestamp, false);
- }
-
/**
* Constructs a new {@link CallStack} using the fasted allowed strategy.
*
diff --git a/src/main/java/org/apache/commons/pool2/impl/DefaultEvictionPolicy.java b/src/main/java/org/apache/commons/pool3/impl/DefaultEvictionPolicy.java
similarity index 88%
rename from src/main/java/org/apache/commons/pool2/impl/DefaultEvictionPolicy.java
rename to src/main/java/org/apache/commons/pool3/impl/DefaultEvictionPolicy.java
index 06a2eb8db..27e41550a 100644
--- a/src/main/java/org/apache/commons/pool2/impl/DefaultEvictionPolicy.java
+++ b/src/main/java/org/apache/commons/pool3/impl/DefaultEvictionPolicy.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
-import org.apache.commons.pool2.PooledObject;
+import org.apache.commons.pool3.PooledObject;
/**
* Provides the default implementation of {@link EvictionPolicy} used by the pools.
@@ -31,18 +31,24 @@
* {@link GenericKeyedObjectPoolConfig#getMinIdlePerKey()} idle objects in
* the pool and the object has been idle for longer than
* {@link GenericObjectPool#getSoftMinEvictableIdleDuration()} /
- * {@link GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()}
+ * {@link GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()}
*
*
* This class is immutable and thread-safe.
*
*
* @param the type of objects in the pool.
- *
* @since 2.0
*/
public class DefaultEvictionPolicy implements EvictionPolicy {
+ /**
+ * Constructs a new instance.
+ */
+ public DefaultEvictionPolicy() {
+ // empty
+ }
+
@Override
public boolean evict(final EvictionConfig config, final PooledObject underTest, final int idleCount) {
// @formatter:off
diff --git a/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObject.java b/src/main/java/org/apache/commons/pool3/impl/DefaultPooledObject.java
similarity index 85%
rename from src/main/java/org/apache/commons/pool2/impl/DefaultPooledObject.java
rename to src/main/java/org/apache/commons/pool3/impl/DefaultPooledObject.java
index 93ae2be43..0f67bd42f 100644
--- a/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObject.java
+++ b/src/main/java/org/apache/commons/pool3/impl/DefaultPooledObject.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,17 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.io.PrintWriter;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.util.Deque;
+import java.util.Objects;
-import org.apache.commons.pool2.PooledObject;
-import org.apache.commons.pool2.PooledObjectState;
-import org.apache.commons.pool2.TrackedUse;
+import org.apache.commons.pool3.PooledObject;
+import org.apache.commons.pool3.PooledObjectState;
+import org.apache.commons.pool3.TrackedUse;
/**
* This wrapper is used to track the additional information, such as state, for
@@ -34,7 +35,6 @@
*
*
* @param the type of object in the pool
- *
* @since 2.0
*/
public class DefaultPooledObject implements PooledObject {
@@ -136,11 +136,6 @@ public synchronized boolean endEvictionTest(
return false;
}
- @Override
- public long getActiveTimeMillis() {
- return getActiveDuration().toMillis();
- }
-
/**
* Gets the number of times this object has been borrowed.
* @return The number of times this object has been borrowed.
@@ -156,11 +151,6 @@ public Instant getCreateInstant() {
return createInstant;
}
- @Override
- public long getCreateTime() {
- return createInstant.toEpochMilli();
- }
-
@Override
public Duration getIdleDuration() {
// elapsed may be negative if:
@@ -170,42 +160,22 @@ public Duration getIdleDuration() {
return elapsed.isNegative() ? Duration.ZERO : elapsed;
}
- @Override
- public Duration getIdleTime() {
- return getIdleDuration();
- }
-
- @Override
- public long getIdleTimeMillis() {
- return getIdleDuration().toMillis();
- }
-
@Override
public Instant getLastBorrowInstant() {
return lastBorrowInstant;
}
- @Override
- public long getLastBorrowTime() {
- return lastBorrowInstant.toEpochMilli();
- }
-
@Override
public Instant getLastReturnInstant() {
return lastReturnInstant;
}
- @Override
- public long getLastReturnTime() {
- return lastReturnInstant.toEpochMilli();
- }
-
/**
* Gets an estimate of the last time this object was used. If the class
* of the pooled object implements {@link TrackedUse}, what is returned is
* the maximum of {@link TrackedUse#getLastUsedInstant()} and
- * {@link #getLastBorrowTime()}; otherwise this method gives the same
- * value as {@link #getLastBorrowTime()}.
+ * {@link #getLastBorrowInstant()}; otherwise this method gives the same
+ * value as {@link #getLastBorrowInstant()}.
*
* @return the last Instant this object was used.
*/
@@ -217,20 +187,6 @@ public Instant getLastUsedInstant() {
return lastUseInstant;
}
- /**
- * Gets an estimate of the last time this object was used. If the class
- * of the pooled object implements {@link TrackedUse}, what is returned is
- * the maximum of {@link TrackedUse#getLastUsedInstant()} and
- * {@link #getLastBorrowTime()}; otherwise this method gives the same
- * value as {@link #getLastBorrowTime()}.
- *
- * @return the last time this object was used
- */
- @Override
- public long getLastUsedTime() {
- return getLastUsedInstant().toEpochMilli();
- }
-
@Override
public T getObject() {
return object;
@@ -324,7 +280,7 @@ public synchronized boolean startEvictionTest() {
public String toString() {
final StringBuilder result = new StringBuilder();
result.append("Object: ");
- result.append(object.toString());
+ result.append(Objects.toString(object));
result.append(", State: ");
synchronized (this) {
result.append(state.toString());
@@ -339,5 +295,4 @@ public void use() {
usedBy.fillInStackTrace();
}
-
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObjectInfo.java b/src/main/java/org/apache/commons/pool3/impl/DefaultPooledObjectInfo.java
similarity index 93%
rename from src/main/java/org/apache/commons/pool2/impl/DefaultPooledObjectInfo.java
rename to src/main/java/org/apache/commons/pool3/impl/DefaultPooledObjectInfo.java
index 9caf13994..5bf1647fc 100644
--- a/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObjectInfo.java
+++ b/src/main/java/org/apache/commons/pool3/impl/DefaultPooledObjectInfo.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,18 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Objects;
-import org.apache.commons.pool2.PooledObject;
+import org.apache.commons.pool3.PooledObject;
/**
- * Implementation of object that is used to provide information on pooled
- * objects via JMX.
+ * Implements providing information on pooled objects via JMX.
*
* @since 2.0
*/
@@ -65,7 +64,6 @@ public long getLastBorrowTime() {
return pooledObject.getLastBorrowInstant().toEpochMilli();
}
-
@Override
public String getLastBorrowTimeFormatted() {
return getTimeMillisFormatted(getLastBorrowTime());
diff --git a/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObjectInfoMBean.java b/src/main/java/org/apache/commons/pool3/impl/DefaultPooledObjectInfoMBean.java
similarity index 61%
rename from src/main/java/org/apache/commons/pool2/impl/DefaultPooledObjectInfoMBean.java
rename to src/main/java/org/apache/commons/pool3/impl/DefaultPooledObjectInfoMBean.java
index 33ce08a7b..9b7eeebd8 100644
--- a/src/main/java/org/apache/commons/pool2/impl/DefaultPooledObjectInfoMBean.java
+++ b/src/main/java/org/apache/commons/pool3/impl/DefaultPooledObjectInfoMBean.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,18 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
/**
- * The interface that defines the information about pooled objects that will be
- * exposed via JMX.
+ * The interface that defines the information about pooled objects that will be exposed via JMX.
+ *
Note
*
- * NOTE: This interface exists only to define those attributes and methods that
- * will be made available via JMX. It must not be implemented by clients
- * as it is subject to change between major, minor and patch version
- * releases of commons pool. Clients that implement this interface may
- * not, therefore, be able to upgrade to a new minor or patch release
- * without requiring code changes.
+ * This interface exists only to define those attributes and methods that will be made available via JMX. It must not be implemented by clients as it is subject
+ * to change between major, minor and patch version releases of commons pool. Clients that implement this interface may not, therefore, be able to upgrade to a
+ * new minor or patch release without requiring code changes.
*
*
* @since 2.0
@@ -34,73 +31,65 @@ public interface DefaultPooledObjectInfoMBean {
/**
* Gets the number of times this object has been borrowed.
+ *
* @return The number of times this object has been borrowed.
* @since 2.1
*/
long getBorrowedCount();
/**
- * Gets the time (using the same basis as
- * {@link java.time.Clock#instant()}) that pooled object was created.
+ * Gets the time (using the same basis as {@link java.time.Clock#instant()}) that pooled object was created.
*
- * @return The creation time for the pooled object
+ * @return The creation time for the pooled object.
*/
long getCreateTime();
/**
* Gets the time that pooled object was created.
*
- * @return The creation time for the pooled object formatted as
- * {@code yyyy-MM-dd HH:mm:ss Z}
+ * @return The creation time for the pooled object formatted as {@code yyyy-MM-dd HH:mm:ss Z}.
*/
String getCreateTimeFormatted();
/**
- * Gets the time (using the same basis as
- * {@link java.time.Clock#instant()}) the polled object was last borrowed.
+ * Gets the time (using the same basis as {@link java.time.Clock#instant()}) the polled object was last borrowed.
*
- * @return The time the pooled object was last borrowed
+ * @return The time the pooled object was last borrowed.
*/
long getLastBorrowTime();
/**
* Gets the time that pooled object was last borrowed.
*
- * @return The last borrowed time for the pooled object formatted as
- * {@code yyyy-MM-dd HH:mm:ss Z}
+ * @return The last borrowed time for the pooled object formatted as {@code yyyy-MM-dd HH:mm:ss Z}.
*/
String getLastBorrowTimeFormatted();
/**
* Gets the stack trace recorded when the pooled object was last borrowed.
*
- * @return The stack trace showing which code last borrowed the pooled
- * object
+ * @return The stack trace showing which code last borrowed the pooled object.
*/
String getLastBorrowTrace();
/**
- * Gets the time (using the same basis as
- * {@link java.time.Clock#instant()})the wrapped object was last returned.
+ * Gets the time (using the same basis as {@link java.time.Clock#instant()})the wrapped object was last returned.
*
- * @return The time the object was last returned
+ * @return The time the object was last returned.
*/
long getLastReturnTime();
/**
* Gets the time that pooled object was last returned.
*
- * @return The last returned time for the pooled object formatted as
- * {@code yyyy-MM-dd HH:mm:ss Z}
+ * @return The last returned time for the pooled object formatted as {@code yyyy-MM-dd HH:mm:ss Z}.
*/
String getLastReturnTimeFormatted();
/**
- * Gets a String form of the wrapper for debug purposes. The format is
- * not fixed and may change at any time.
- *
- * @return A string representation of the pooled object
+ * Gets a String form of the wrapper for debug purposes. The format is not fixed and may change at any time.
*
+ * @return A string representation of the pooled object.
* @see Object#toString()
*/
String getPooledObjectToString();
@@ -108,8 +97,7 @@ public interface DefaultPooledObjectInfoMBean {
/**
* Gets the name of the class of the pooled object.
*
- * @return The pooled object's class name
- *
+ * @return The pooled object's class name.
* @see Class#getName()
*/
String getPooledObjectType();
diff --git a/src/main/java/org/apache/commons/pool2/impl/EvictionConfig.java b/src/main/java/org/apache/commons/pool3/impl/EvictionConfig.java
similarity index 57%
rename from src/main/java/org/apache/commons/pool2/impl/EvictionConfig.java
rename to src/main/java/org/apache/commons/pool3/impl/EvictionConfig.java
index a54868e55..15c9e4c10 100644
--- a/src/main/java/org/apache/commons/pool2/impl/EvictionConfig.java
+++ b/src/main/java/org/apache/commons/pool3/impl/EvictionConfig.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.time.Duration;
@@ -54,24 +54,6 @@ public EvictionConfig(final Duration idleEvictDuration, final Duration idleSoftE
this.minIdle = minIdle;
}
- /**
- * Creates a new eviction configuration with the specified parameters.
- * Instances are immutable.
- *
- * @param poolIdleEvictMillis Expected to be provided by
- * {@link BaseGenericObjectPool#getMinEvictableIdleDuration()}
- * @param poolIdleSoftEvictMillis Expected to be provided by
- * {@link BaseGenericObjectPool#getSoftMinEvictableIdleDuration()}
- * @param minIdle Expected to be provided by
- * {@link GenericObjectPool#getMinIdle()} or
- * {@link GenericKeyedObjectPool#getMinIdlePerKey()}
- * @deprecated Use {@link #EvictionConfig(Duration, Duration, int)}.
- */
- @Deprecated
- public EvictionConfig(final long poolIdleEvictMillis, final long poolIdleSoftEvictMillis, final int minIdle) {
- this(Duration.ofMillis(poolIdleEvictMillis), Duration.ofMillis(poolIdleSoftEvictMillis), minIdle);
- }
-
/**
* Gets the {@code idleEvictTime} for this eviction configuration
* instance.
@@ -87,39 +69,6 @@ public Duration getIdleEvictDuration() {
return idleEvictDuration;
}
- /**
- * Gets the {@code idleEvictTime} for this eviction configuration
- * instance.
- *
- * How the evictor behaves based on this value will be determined by the
- * configured {@link EvictionPolicy}.
- *
- *
- * @return The {@code idleEvictTime} in milliseconds
- * @deprecated Use {@link #getIdleEvictDuration()}.
- */
- @Deprecated
- public long getIdleEvictTime() {
- return idleEvictDuration.toMillis();
- }
-
- /**
- * Gets the {@code idleEvictTime} for this eviction configuration
- * instance.
- *
- * How the evictor behaves based on this value will be determined by the
- * configured {@link EvictionPolicy}.
- *
- *
- * @return The {@code idleEvictTime}.
- * @since 2.10.0
- * @deprecated Use {@link #getIdleEvictDuration()}.
- */
- @Deprecated
- public Duration getIdleEvictTimeDuration() {
- return idleEvictDuration;
- }
-
/**
* Gets the {@code idleSoftEvictTime} for this eviction configuration
* instance.
@@ -135,38 +84,6 @@ public Duration getIdleSoftEvictDuration() {
return idleSoftEvictDuration;
}
- /**
- * Gets the {@code idleSoftEvictTime} for this eviction configuration
- * instance.
- *
- * How the evictor behaves based on this value will be determined by the
- * configured {@link EvictionPolicy}.
- *
- *
- * @return The (@code idleSoftEvictTime} in milliseconds
- * @deprecated Use {@link #getIdleSoftEvictDuration()}.
- */
- @Deprecated
- public long getIdleSoftEvictTime() {
- return idleSoftEvictDuration.toMillis();
- }
-
- /**
- * Gets the {@code idleSoftEvictTime} for this eviction configuration
- * instance.
- *
- * How the evictor behaves based on this value will be determined by the
- * configured {@link EvictionPolicy}.
- *
- *
- * @return The (@code idleSoftEvictTime} in milliseconds
- * @deprecated Use {@link #getIdleSoftEvictDuration()}.
- */
- @Deprecated
- public Duration getIdleSoftEvictTimeDuration() {
- return idleSoftEvictDuration;
- }
-
/**
* Gets the {@code minIdle} for this eviction configuration instance.
*
diff --git a/src/main/java/org/apache/commons/pool2/impl/EvictionPolicy.java b/src/main/java/org/apache/commons/pool3/impl/EvictionPolicy.java
similarity index 86%
rename from src/main/java/org/apache/commons/pool2/impl/EvictionPolicy.java
rename to src/main/java/org/apache/commons/pool3/impl/EvictionPolicy.java
index ee14f58f9..58bc76cfc 100644
--- a/src/main/java/org/apache/commons/pool2/impl/EvictionPolicy.java
+++ b/src/main/java/org/apache/commons/pool3/impl/EvictionPolicy.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
-import org.apache.commons.pool2.PooledObject;
+import org.apache.commons.pool3.PooledObject;
/**
* To provide a custom eviction policy (i.e. something other than {@link
@@ -24,14 +24,12 @@
* this interface that provides the required eviction policy.
*
* @param the type of objects in the pool
- *
* @since 2.0
*/
public interface EvictionPolicy {
/**
- * This method is called to test if an idle object in the pool should be
- * evicted or not.
+ * Tests if an idle object in the pool should be evicted or not.
*
* @param config The pool configuration settings related to eviction
* @param underTest The pooled object being tested for eviction
diff --git a/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java b/src/main/java/org/apache/commons/pool3/impl/EvictionTimer.java
similarity index 85%
rename from src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java
rename to src/main/java/org/apache/commons/pool3/impl/EvictionTimer.java
index 6f5c57a9d..c48bb780c 100644
--- a/src/main/java/org/apache/commons/pool2/impl/EvictionTimer.java
+++ b/src/main/java/org/apache/commons/pool3/impl/EvictionTimer.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,26 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.time.Duration;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
-
/**
* Provides a shared idle object eviction timer for all pools.
*
* This class is currently implemented using {@link ScheduledThreadPoolExecutor}. This implementation may change in any
* future release. This class keeps track of how many pools are using it. If no pools are using the timer, it is
- * cancelled. This prevents a thread being left running which, in application server environments, can lead to memory
+ * canceled. This prevents a thread being left running which, in application server environments, can lead to memory
* leads and/or prevent applications from shutting down or reloading cleanly.
*
*
@@ -46,12 +46,12 @@
*
* @since 2.0
*/
-class EvictionTimer {
+final class EvictionTimer {
/**
* Thread factory that creates a daemon thread, with the context class loader from this class.
*/
- private static class EvictorThreadFactory implements ThreadFactory {
+ private static final class EvictorThreadFactory implements ThreadFactory {
@Override
public Thread newThread(final Runnable runnable) {
@@ -70,15 +70,21 @@ public Thread newThread(final Runnable runnable) {
* Task that removes references to abandoned tasks and shuts
* down the executor if there are no live tasks left.
*/
- private static class Reaper implements Runnable {
+ private static final class Reaper implements Runnable {
@Override
public void run() {
synchronized (EvictionTimer.class) {
- for (final Entry.Evictor>, WeakRunner.Evictor>> entry : TASK_MAP
- .entrySet()) {
+ /*
+ * Need to use iterator over TASK_MAP so entries can be removed when iterating without triggering a
+ * ConcurrentModificationException.
+ */
+ final Iterator.Evictor>, WeakRunner.Evictor>>> iterator =
+ TASK_MAP.entrySet().iterator();
+ while (iterator.hasNext()) {
+ final Entry.Evictor>, WeakRunner.Evictor>> entry = iterator.next();
if (entry.getKey().get() == null) {
executor.remove(entry.getValue());
- TASK_MAP.remove(entry.getKey());
+ iterator.remove();
}
}
if (TASK_MAP.isEmpty() && executor != null) {
@@ -95,7 +101,7 @@ public void run() {
* no longer reachable, run is no-op.
* @param The kind of Runnable.
*/
- private static class WeakRunner implements Runnable {
+ private static final class WeakRunner implements Runnable {
private final WeakReference ref;
@@ -114,13 +120,14 @@ public void run() {
if (task != null) {
task.run();
} else {
- executor.remove(this);
- TASK_MAP.remove(ref);
+ synchronized (EvictionTimer.class) {
+ executor.remove(this);
+ TASK_MAP.remove(ref);
+ }
}
}
}
-
/** Executor instance */
private static ScheduledThreadPoolExecutor executor; //@GuardedBy("EvictionTimer.class")
@@ -132,7 +139,7 @@ public void run() {
/**
* Removes the specified eviction task from the timer.
*
- * @param evictor Task to be cancelled.
+ * @param evictor Task to be canceled.
* @param timeout If the associated executor is no longer required, how
* long should this thread wait for the executor to
* terminate?
diff --git a/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java b/src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPool.java
similarity index 95%
rename from src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
rename to src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPool.java
index e00e60ac5..5c0f3d07b 100644
--- a/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
+++ b/src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPool.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.time.Duration;
import java.time.Instant;
@@ -28,6 +28,7 @@
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.TreeMap;
+import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -38,14 +39,14 @@
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors;
-import org.apache.commons.pool2.DestroyMode;
-import org.apache.commons.pool2.KeyedObjectPool;
-import org.apache.commons.pool2.KeyedPooledObjectFactory;
-import org.apache.commons.pool2.PoolUtils;
-import org.apache.commons.pool2.PooledObject;
-import org.apache.commons.pool2.PooledObjectState;
-import org.apache.commons.pool2.SwallowedExceptionListener;
-import org.apache.commons.pool2.UsageTracking;
+import org.apache.commons.pool3.DestroyMode;
+import org.apache.commons.pool3.KeyedObjectPool;
+import org.apache.commons.pool3.KeyedPooledObjectFactory;
+import org.apache.commons.pool3.PoolUtils;
+import org.apache.commons.pool3.PooledObject;
+import org.apache.commons.pool3.PooledObjectState;
+import org.apache.commons.pool3.SwallowedExceptionListener;
+import org.apache.commons.pool3.UsageTracking;
/**
* A configurable {@code KeyedObjectPool} implementation.
@@ -83,11 +84,9 @@
*
*
* @see GenericObjectPool
- *
* @param The type of keys maintained by this pool.
* @param Type of element pooled in this pool.
* @param Type of exception thrown in this pool.
- *
* @since 2.0
*/
public class GenericKeyedObjectPool extends BaseGenericObjectPool
@@ -98,7 +97,7 @@ public class GenericKeyedObjectPool extends BaseGener
*
* @param type of objects in the pool
*/
- private static class ObjectDeque {
+ private static final class ObjectDeque {
private final LinkedBlockingDeque> idleObjects;
@@ -106,7 +105,7 @@ private static class ObjectDeque {
* Number of instances created - number destroyed.
* Invariant: createCount <= maxTotalPerKey
*/
- private final AtomicInteger createCount = new AtomicInteger(0);
+ private final AtomicInteger createCount = new AtomicInteger();
private long makeObjectCount;
private final Object makeObjectCountLock = new Object();
@@ -131,16 +130,16 @@ private static class ObjectDeque {
* @param fairness true means client threads waiting to borrow / return instances
* will be served as if waiting in a FIFO queue.
*/
- public ObjectDeque(final boolean fairness) {
+ ObjectDeque(final boolean fairness) {
idleObjects = new LinkedBlockingDeque<>(fairness);
}
/**
* Gets all the objects for the current key.
*
- * @return All the objects
+ * @return All the objects.
*/
- public Map, PooledObject> getAllObjects() {
+ Map, PooledObject> getAllObjects() {
return allObjects;
}
@@ -148,27 +147,27 @@ public Map, PooledObject> getAllObjects() {
* Gets the number of instances created - number destroyed.
* Should always be less than or equal to maxTotalPerKey.
*
- * @return The net instance addition count for this deque
+ * @return The net instance addition count for this deque.
*/
- public AtomicInteger getCreateCount() {
+ AtomicInteger getCreateCount() {
return createCount;
}
/**
* Gets the idle objects for the current key.
*
- * @return The idle objects
+ * @return The idle objects.
*/
- public LinkedBlockingDeque> getIdleObjects() {
+ LinkedBlockingDeque> getIdleObjects() {
return idleObjects;
}
/**
* Gets the number of threads with an interest registered in this key.
*
- * @return The number of threads with a registered interest in this key
+ * @return The number of threads with a registered interest in this key.
*/
- public AtomicLong getNumInterested() {
+ AtomicLong getNumInterested() {
return numInterested;
}
@@ -193,7 +192,7 @@ public String toString() {
// JMX specific attributes
private static final String ONAME_BASE =
- "org.apache.commons.pool2:type=GenericKeyedObjectPool,name=";
+ "org.apache.commons.pool3:type=GenericKeyedObjectPool,name=";
private volatile int maxIdlePerKey =
GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE_PER_KEY;
@@ -201,7 +200,6 @@ public String toString() {
private volatile int minIdlePerKey =
GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE_PER_KEY;
-
private volatile int maxTotalPerKey =
GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL_PER_KEY;
@@ -210,16 +208,21 @@ public String toString() {
private final boolean fairness;
/*
- * My hash of sub-pools (ObjectQueue). The list of keys must be kept
+ * My hash of sub-pools (ObjectQueue). The list of keys must be kept
* in step with {@link #poolKeyList} using {@link #keyLock} to ensure any
* changes to the list of current keys is made in a thread-safe manner.
+ *
+ * Correct operation of the pool requires that a Map implementation is used that
+ * supports concurrent read and write (e.g. ensureMinIdle() iterates over the key set
+ * while other threads may be adding or removing keys) therefore explicitly define
+ * this field as ConcurrentHashMap rather than Map.
*/
- private final Map> poolMap =
+ private final ConcurrentHashMap> poolMap =
new ConcurrentHashMap<>(); // @GuardedBy("keyLock") for write access (and some read access)
/*
* List of pool keys - used to control eviction order. The list of keys
- * must be kept in step with {@link #poolMap} using {@link #keyLock}
+ * must be kept in step with {@link #poolMap} using {@link #keyLock}
* to ensure any changes to the list of current keys is made in a
* thread-safe manner.
*/
@@ -233,11 +236,10 @@ public String toString() {
* {@link #maxTotal} but there will never be more than {@link #maxTotal}
* created at any one time.
*/
- private final AtomicInteger numTotal = new AtomicInteger(0);
+ private final AtomicInteger numTotal = new AtomicInteger();
private Iterator evictionKeyIterator; // @GuardedBy("evictionLock")
-
private K evictionKey; // @GuardedBy("evictionLock")
/**
@@ -300,13 +302,12 @@ public GenericKeyedObjectPool(final KeyedPooledObjectFactory factory,
*
* @param key The key to associate with the idle object
* @param p The wrapped object to add.
- *
* @throws E If the associated factory fails to passivate the object
*/
private void addIdleObject(final K key, final PooledObject p) throws E {
- if (!PooledObject.isNull(p)) {
+ if (PooledObject.nonNull(p)) {
factory.passivateObject(key, p);
- final LinkedBlockingDeque> idleObjects = poolMap.get(key).getIdleObjects();
+ final BlockingDeque> idleObjects = poolMap.get(key).getIdleObjects();
if (getLifo()) {
idleObjects.addFirst(p);
} else {
@@ -330,7 +331,6 @@ private void addIdleObject(final K key, final PooledObject p) throws E {
*
*
* @param key the key a new instance should be added to
- *
* @throws E when {@link KeyedPooledObjectFactory#makeObject}
* fails.
*/
@@ -411,7 +411,6 @@ public T borrowObject(final K key) throws E {
* to become available
*
* @return object instance from the keyed pool
- *
* @throws NoSuchElementException if a keyed object instance cannot be
* returned because the pool is exhausted.
*
@@ -443,7 +442,7 @@ public T borrowObject(final K key, final long borrowMaxWaitMillis) throws E {
p = objectDeque.getIdleObjects().pollFirst();
if (p == null) {
p = create(key);
- if (!PooledObject.isNull(p)) {
+ if (PooledObject.nonNull(p)) {
create = true;
}
}
@@ -525,7 +524,6 @@ public T borrowObject(final K key, final long borrowMaxWaitMillis) throws E {
* on the maximum number of objects either per key or totally.
*
* @param objectDeque The set of objects to check
- *
* @return The number of new objects to create
*/
private int calculateDeficit(final ObjectDeque objectDeque) {
@@ -620,7 +618,7 @@ public void clear(final K key, final boolean reuseCapacity) {
final ObjectDeque objectDeque = register(key);
int freedCapacity = 0;
try {
- final LinkedBlockingDeque> idleObjects = objectDeque.getIdleObjects();
+ final BlockingDeque> idleObjects = objectDeque.getIdleObjects();
PooledObject p = idleObjects.poll();
while (p != null) {
try {
@@ -649,11 +647,9 @@ public void clearOldest() {
// build sorted map of idle objects
final TreeMap, K> map = new TreeMap<>();
- poolMap.forEach((key, value) -> {
- // Each item into the map using the PooledObject object as the
- // key. It then gets sorted based on the idle time
- value.getIdleObjects().forEach(p -> map.put(p, key));
- });
+ // Each item into the map using the PooledObject object as the
+ // key. It then gets sorted based on the idle time
+ poolMap.forEach((key, value) -> value.getIdleObjects().forEach(p -> map.put(p, key)));
// Now iterate created map and kill the first 15% plus one to account
// for zero
@@ -662,9 +658,9 @@ public void clearOldest() {
while (iter.hasNext() && itemsToRemove > 0) {
final Entry, K> entry = iter.next();
- // kind of backwards on naming. In the map, each key is the
+ // kind of backwards on naming. In the map, each key is the
// PooledObject because it has the ordering with the timestamp
- // value. Each value that the key references is the key of the
+ // value. Each value that the key references is the key of the
// list it belongs to.
final K key = entry.getValue();
final PooledObject p = entry.getKey();
@@ -681,7 +677,6 @@ public void clearOldest() {
}
}
-
/**
* Closes the keyed object pool. Once the pool is closed,
* {@link #borrowObject(Object)} will fail with IllegalStateException, but
@@ -714,21 +709,18 @@ public void close() {
jmxUnregister();
// Release any threads that were waiting for an object
- poolMap.values().forEach(e -> e.getIdleObjects().interuptTakeWaiters());
+ poolMap.values().forEach(e -> e.getIdleObjects().interruptTakeWaiters());
// This clear cleans up the keys now any waiting threads have been
// interrupted
clear();
}
}
-
/**
* Creates a new pooled object or null.
*
* @param key Key associated with new pooled object.
- *
* @return The new, wrapped pooled object. May return null.
- *
* @throws E If the objection creation fails.
*/
private PooledObject create(final K key) throws E {
@@ -831,7 +823,7 @@ private PooledObject create(final K key) throws E {
}
createdCount.incrementAndGet();
- objectDeque.getAllObjects().put(new IdentityWrapper<>(p.getObject()), p);
+ objectDeque.getAllObjects().put(IdentityWrapper.unwrap(p), p);
return p;
}
@@ -875,7 +867,6 @@ private void deregister(final K k) {
* @param always Should the object be destroyed even if it is not currently
* in the set of idle objects for the given key
* @param destroyMode DestroyMode context provided to the factory
- *
* @return {@code true} if the object was destroyed, otherwise {@code false}
* @throws E If the object destruction failed
*/
@@ -895,7 +886,7 @@ private boolean destroy(final K key, final PooledObject toDestroy, final bool
}
}
if (isIdle || always) {
- objectDeque.getAllObjects().remove(new IdentityWrapper<>(toDestroy.getObject()));
+ objectDeque.getAllObjects().remove(IdentityWrapper.unwrap(toDestroy));
toDestroy.invalidate();
try {
@@ -913,7 +904,6 @@ private boolean destroy(final K key, final PooledObject toDestroy, final bool
}
}
-
@Override
void ensureMinIdle() throws E {
final int minIdlePerKeySave = getMinIdlePerKey();
@@ -939,7 +929,6 @@ void ensureMinIdle() throws E {
*
*
* @param key The key to check for idle objects
- *
* @throws E If a new object is required and cannot be created
*/
private void ensureMinIdle(final K key) throws E {
@@ -1114,7 +1103,6 @@ public void evict() throws E {
}
}
-
/**
* Gets a reference to the factory used to create, destroy and validate
* the objects used by this pool.
@@ -1163,7 +1151,6 @@ public int getMaxIdlePerKey() {
* is said to be exhausted. A negative value indicates no limit.
*
* @return the limit on the number of active instances per key
- *
* @see #setMaxTotalPerKey
*/
@Override
@@ -1185,8 +1172,7 @@ public int getMaxTotalPerKey() {
*
*
* @return minimum size of the each keyed pool
- *
- * @see #setTimeBetweenEvictionRunsMillis
+ * @see #setDurationBetweenEvictionRuns(Duration)
*/
@Override
public int getMinIdlePerKey() {
@@ -1305,7 +1291,6 @@ private boolean hasBorrowWaiters() {
*
* @param key pool key
* @param obj instance to invalidate
- *
* @throws E if an exception occurs destroying the
* object
* @throws IllegalStateException if obj does not belong to the pool
@@ -1326,7 +1311,6 @@ public void invalidateObject(final K key, final T obj) throws E {
* @param key pool key
* @param obj instance to invalidate
* @param destroyMode DestroyMode context provided to factory
- *
* @throws E if an exception occurs destroying the
* object
* @throws IllegalStateException if obj does not belong to the pool
@@ -1362,7 +1346,7 @@ public void invalidateObject(final K key, final T obj, final DestroyMode destroy
*/
@Override
public Map> listAllObjects() {
- return poolMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().toString(),
+ return poolMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().toString(),
e -> e.getValue().getAllObjects().values().stream().map(DefaultPooledObjectInfo::new).collect(Collectors.toList())));
}
@@ -1370,8 +1354,7 @@ public Map> listAllObjects() {
* Registers a key for pool control and ensures that
* {@link #getMinIdlePerKey()} idle instances are created.
*
- * @param key - The key to register for pool control.
- *
+ * @param key The key to register for pool control.
* @throws E If the associated factory throws an exception
*/
public void preparePool(final K key) throws E {
@@ -1389,7 +1372,6 @@ public void preparePool(final K key) throws E {
*
*
* @param k The key to register
- *
* @return The objects currently associated with the given key. If this
* method returns without throwing an exception then it will never
* return null.
@@ -1405,7 +1387,7 @@ private ObjectDeque register(final K k) {
lock.unlock();
lock = keyLock.writeLock();
lock.lock();
- final AtomicBoolean allocated = new AtomicBoolean();
+ final AtomicBoolean allocated = new AtomicBoolean();
objectDeque = poolMap.computeIfAbsent(k, key -> {
allocated.set(true);
final ObjectDeque deque = new ObjectDeque<>(fairness);
@@ -1472,7 +1454,6 @@ private void removeAbandoned(final AbandonedConfig abandonedConfig) {
*
* @param key pool key
* @param obj instance to return to the keyed pool
- *
* @throws IllegalStateException if an object is returned to the pool that
* was not borrowed from it or if an object is
* returned to the pool multiple times
@@ -1525,7 +1506,7 @@ public void returnObject(final K key, final T obj) {
}
final int maxIdle = getMaxIdlePerKey();
- final LinkedBlockingDeque> idleObjects = objectDeque.getIdleObjects();
+ final BlockingDeque> idleObjects = objectDeque.getIdleObjects();
if (isClosed() || maxIdle > -1 && maxIdle <= idleObjects.size()) {
try {
@@ -1570,9 +1551,8 @@ public void returnObject(final K key, final T obj) {
private void reuseCapacity() {
final int maxTotalPerKeySave = getMaxTotalPerKey();
int maxQueueLength = 0;
- LinkedBlockingDeque> mostLoadedPool = null;
+ BlockingDeque> mostLoadedPool = null;
K mostLoadedKey = null;
-
// Find the most loaded pool that could take a new instance
for (final Map.Entry> entry : poolMap.entrySet()) {
final K k = entry.getKey();
@@ -1584,7 +1564,6 @@ private void reuseCapacity() {
mostLoadedKey = k;
}
}
-
// Attempt to add an instance to the most loaded pool.
if (mostLoadedPool != null) {
register(mostLoadedKey);
@@ -1618,7 +1597,6 @@ private void reuseCapacity(final int newCapacity) {
* Sets the configuration.
*
* @param conf the new configuration to use. This is used by value.
- *
* @see GenericKeyedObjectPoolConfig
*/
public void setConfig(final GenericKeyedObjectPoolConfig conf) {
@@ -1655,7 +1633,6 @@ public void setMaxIdlePerKey(final int maxIdlePerKey) {
* is said to be exhausted. A negative value indicates no limit.
*
* @param maxTotalPerKey the limit on the number of active instances per key
- *
* @see #getMaxTotalPerKey
*/
public void setMaxTotalPerKey(final int maxTotalPerKey) {
@@ -1676,10 +1653,9 @@ public void setMaxTotalPerKey(final int maxTotalPerKey) {
*
*
* @param minIdlePerKey The minimum size of the each keyed pool
- *
* @see #getMinIdlePerKey()
* @see #getMaxIdlePerKey()
- * @see #setTimeBetweenEvictionRuns(Duration)
+ * @see #setDurationBetweenEvictionRuns(Duration)
*/
public void setMinIdlePerKey(final int minIdlePerKey) {
this.minIdlePerKey = minIdlePerKey;
diff --git a/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java b/src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPoolConfig.java
similarity index 89%
rename from src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java
rename to src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPoolConfig.java
index e9a7a29ef..3e88b0fdb 100644
--- a/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java
+++ b/src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPoolConfig.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
/**
* A simple structure encapsulating the configuration for a
@@ -54,7 +54,6 @@ public class GenericKeyedObjectPoolConfig extends BaseObjectPoolConfig {
*/
public static final int DEFAULT_MAX_IDLE_PER_KEY = 8;
-
private int minIdlePerKey = DEFAULT_MIN_IDLE_PER_KEY;
private int maxIdlePerKey = DEFAULT_MAX_IDLE_PER_KEY;
@@ -80,7 +79,7 @@ public GenericKeyedObjectPoolConfig clone() {
}
/**
- * Get the value for the {@code maxIdlePerKey} configuration attribute
+ * Gets the value for the {@code maxIdlePerKey} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code maxIdlePerKey} for this
@@ -93,7 +92,7 @@ public int getMaxIdlePerKey() {
}
/**
- * Get the value for the {@code maxTotal} configuration attribute
+ * Gets the value for the {@code maxTotal} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code maxTotal} for this
@@ -106,7 +105,7 @@ public int getMaxTotal() {
}
/**
- * Get the value for the {@code maxTotalPerKey} configuration attribute
+ * Gets the value for the {@code maxTotalPerKey} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code maxTotalPerKey} for this
@@ -119,7 +118,7 @@ public int getMaxTotalPerKey() {
}
/**
- * Get the value for the {@code minIdlePerKey} configuration attribute
+ * Gets the value for the {@code minIdlePerKey} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code minIdlePerKey} for this
@@ -132,7 +131,7 @@ public int getMinIdlePerKey() {
}
/**
- * Set the value for the {@code maxIdlePerKey} configuration attribute for
+ * Sets the value for the {@code maxIdlePerKey} configuration attribute for
* pools created with this configuration instance.
*
* @param maxIdlePerKey The new setting of {@code maxIdlePerKey}
@@ -145,7 +144,7 @@ public void setMaxIdlePerKey(final int maxIdlePerKey) {
}
/**
- * Set the value for the {@code maxTotal} configuration attribute for
+ * Sets the value for the {@code maxTotal} configuration attribute for
* pools created with this configuration instance.
*
* @param maxTotal The new setting of {@code maxTotal}
@@ -158,7 +157,7 @@ public void setMaxTotal(final int maxTotal) {
}
/**
- * Set the value for the {@code maxTotalPerKey} configuration attribute for
+ * Sets the value for the {@code maxTotalPerKey} configuration attribute for
* pools created with this configuration instance.
*
* @param maxTotalPerKey The new setting of {@code maxTotalPerKey}
@@ -171,7 +170,7 @@ public void setMaxTotalPerKey(final int maxTotalPerKey) {
}
/**
- * Set the value for the {@code minIdlePerKey} configuration attribute for
+ * Sets the value for the {@code minIdlePerKey} configuration attribute for
* pools created with this configuration instance.
*
* @param minIdlePerKey The new setting of {@code minIdlePerKey}
diff --git a/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolMXBean.java b/src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPoolMXBean.java
similarity index 67%
rename from src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolMXBean.java
rename to src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPoolMXBean.java
index 884a42ba1..97556700f 100644
--- a/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolMXBean.java
+++ b/src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPoolMXBean.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,23 +14,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.util.List;
import java.util.Map;
/**
* Defines the methods that will be made available via JMX.
- *
- * NOTE: This interface exists only to define those attributes and methods that
- * will be made available via JMX. It must not be implemented by clients
- * as it is subject to change between major, minor and patch version
- * releases of commons pool. Clients that implement this interface may
- * not, therefore, be able to upgrade to a new minor or patch release
- * without requiring code changes.
+ *
Note
+ *
+ * This interface exists only to define those attributes and methods that will be made available via JMX. It must not be implemented by clients as it is subject
+ * to change between major, minor and patch version releases of commons pool. Clients that implement this interface may not, therefore, be able to upgrade to a
+ * new minor or patch release without requiring code changes.
+ *
*
* @param The type of keys maintained by the pool.
- *
* @since 2.0
*/
public interface GenericKeyedObjectPoolMXBean {
@@ -38,62 +36,72 @@ public interface GenericKeyedObjectPoolMXBean {
// Expose getters for configuration settings
/**
- * See {@link GenericKeyedObjectPool#getBlockWhenExhausted()}
- * @return See {@link GenericKeyedObjectPool#getBlockWhenExhausted()}
+ * See {@link GenericKeyedObjectPool#getBlockWhenExhausted()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getBlockWhenExhausted()}.
*/
boolean getBlockWhenExhausted();
/**
- * See {@link GenericKeyedObjectPool#getBorrowedCount()}
- * @return See {@link GenericKeyedObjectPool#getBorrowedCount()}
+ * See {@link GenericKeyedObjectPool#getBorrowedCount()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getBorrowedCount()}.
*/
long getBorrowedCount();
/**
- * See {@link GenericKeyedObjectPool#getCreatedCount()}
- * @return See {@link GenericKeyedObjectPool#getCreatedCount()}
+ * See {@link GenericKeyedObjectPool#getCreatedCount()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getCreatedCount()}.
*/
long getCreatedCount();
/**
- * See {@link GenericKeyedObjectPool#getCreationStackTrace()}
- * @return See {@link GenericKeyedObjectPool#getCreationStackTrace()}
+ * See {@link GenericKeyedObjectPool#getCreationStackTrace()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getCreationStackTrace()}.
*/
String getCreationStackTrace();
/**
- * See {@link GenericKeyedObjectPool#getDestroyedByBorrowValidationCount()}
- * @return See {@link GenericKeyedObjectPool#getDestroyedByBorrowValidationCount()}
+ * See {@link GenericKeyedObjectPool#getDestroyedByBorrowValidationCount()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getDestroyedByBorrowValidationCount()}.
*/
long getDestroyedByBorrowValidationCount();
/**
- * See {@link GenericKeyedObjectPool#getDestroyedByEvictorCount()}
- * @return See {@link GenericKeyedObjectPool#getDestroyedByEvictorCount()}
+ * See {@link GenericKeyedObjectPool#getDestroyedByEvictorCount()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getDestroyedByEvictorCount()}.
*/
long getDestroyedByEvictorCount();
/**
- * See {@link GenericKeyedObjectPool#getDestroyedCount()}
- * @return See {@link GenericKeyedObjectPool#getDestroyedCount()}
+ * See {@link GenericKeyedObjectPool#getDestroyedCount()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getDestroyedCount()}.
*/
long getDestroyedCount();
/**
- * See {@link GenericKeyedObjectPool#getFairness()}
- * @return See {@link GenericKeyedObjectPool#getFairness()}
+ * See {@link GenericKeyedObjectPool#getFairness()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getFairness()}.
*/
boolean getFairness();
/**
- * See {@link GenericKeyedObjectPool#getLifo()}
- * @return See {@link GenericKeyedObjectPool#getLifo()}
+ * See {@link GenericKeyedObjectPool#getLifo()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getLifo()}.
*/
boolean getLifo();
/**
- * See {@link GenericKeyedObjectPool#getLogAbandoned()}
- * @return See {@link GenericKeyedObjectPool#getLogAbandoned()}
+ * See {@link GenericKeyedObjectPool#getLogAbandoned()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getLogAbandoned()}.
* @since 2.10.0
*/
default boolean getLogAbandoned() {
@@ -101,106 +109,123 @@ default boolean getLogAbandoned() {
}
/**
- * See {@link GenericKeyedObjectPool#getMaxBorrowWaitTimeMillis()}
- * @return See {@link GenericKeyedObjectPool#getMaxBorrowWaitTimeMillis()}
+ * See {@link GenericKeyedObjectPool#getMaxBorrowWaitTimeMillis()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getMaxBorrowWaitTimeMillis()}.
*/
long getMaxBorrowWaitTimeMillis();
/**
- * See {@link GenericKeyedObjectPool#getMaxIdlePerKey()}
- * @return See {@link GenericKeyedObjectPool#getMaxIdlePerKey()}
+ * See {@link GenericKeyedObjectPool#getMaxIdlePerKey()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getMaxIdlePerKey()}.
*/
int getMaxIdlePerKey();
/**
- * See {@link GenericKeyedObjectPool#getMaxTotal()}
- * @return See {@link GenericKeyedObjectPool#getMaxTotal()}
+ * See {@link GenericKeyedObjectPool#getMaxTotal()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getMaxTotal()}.
*/
int getMaxTotal();
/**
- * See {@link GenericKeyedObjectPool#getMaxTotalPerKey()}
- * @return See {@link GenericKeyedObjectPool#getMaxTotalPerKey()}
+ * See {@link GenericKeyedObjectPool#getMaxTotalPerKey()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getMaxTotalPerKey()}.
*/
int getMaxTotalPerKey();
/**
- * See {@link GenericKeyedObjectPool#getMaxWaitDuration()}
- * @return See {@link GenericKeyedObjectPool#getMaxWaitDuration()}
+ * See {@link GenericKeyedObjectPool#getMaxWaitDuration()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getMaxWaitDuration()}.
*/
long getMaxWaitMillis();
/**
- * See {@link GenericKeyedObjectPool#getMeanActiveTimeMillis()}
- * @return See {@link GenericKeyedObjectPool#getMeanActiveTimeMillis()}
+ * See {@link GenericKeyedObjectPool#getMeanActiveTimeMillis()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getMeanActiveTimeMillis()}.
*/
long getMeanActiveTimeMillis();
/**
- * See {@link GenericKeyedObjectPool#getMaxBorrowWaitTimeMillis()}
- * @return See {@link GenericKeyedObjectPool#getMaxBorrowWaitTimeMillis()}
+ * See {@link GenericKeyedObjectPool#getMaxBorrowWaitTimeMillis()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getMaxBorrowWaitTimeMillis()}.
*/
long getMeanBorrowWaitTimeMillis();
/**
- * See {@link GenericKeyedObjectPool#getMeanIdleTimeMillis()}
- * @return See {@link GenericKeyedObjectPool#getMeanIdleTimeMillis()}
+ * See {@link GenericKeyedObjectPool#getMeanIdleTimeMillis()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getMeanIdleTimeMillis()}.
*/
long getMeanIdleTimeMillis();
/**
- * See {@link GenericKeyedObjectPool#getMinEvictableIdleDuration()}
- * @return See {@link GenericKeyedObjectPool#getMinEvictableIdleDuration()}
+ * See {@link GenericKeyedObjectPool#getMinEvictableIdleDuration()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getMinEvictableIdleDuration()}.
*/
long getMinEvictableIdleTimeMillis();
// Expose getters for monitoring attributes
/**
- * See {@link GenericKeyedObjectPool#getMinIdlePerKey()}
- * @return See {@link GenericKeyedObjectPool#getMinIdlePerKey()}
+ * See {@link GenericKeyedObjectPool#getMinIdlePerKey()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getMinIdlePerKey()}.
*/
int getMinIdlePerKey();
/**
- * See {@link GenericKeyedObjectPool#getNumActive()}
- * @return See {@link GenericKeyedObjectPool#getNumActive()}
+ * See {@link GenericKeyedObjectPool#getNumActive()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getNumActive()}.
*/
int getNumActive();
/**
- * See {@link GenericKeyedObjectPool#getNumActivePerKey()}
- * @return See {@link GenericKeyedObjectPool#getNumActivePerKey()}
+ * See {@link GenericKeyedObjectPool#getNumActivePerKey()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getNumActivePerKey()}.
*/
Map getNumActivePerKey();
/**
- * See {@link GenericKeyedObjectPool#getNumIdle()}
- * @return See {@link GenericKeyedObjectPool#getNumIdle()}
+ * See {@link GenericKeyedObjectPool#getNumIdle()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getNumIdle()}.
*/
int getNumIdle();
/**
- * See {@link GenericKeyedObjectPool#getNumTestsPerEvictionRun()}
- * @return See {@link GenericKeyedObjectPool#getNumTestsPerEvictionRun()}
+ * See {@link GenericKeyedObjectPool#getNumTestsPerEvictionRun()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getNumTestsPerEvictionRun()}.
*/
int getNumTestsPerEvictionRun();
/**
- * See {@link GenericKeyedObjectPool#getNumWaiters()}
- * @return See {@link GenericKeyedObjectPool#getNumWaiters()}
+ * See {@link GenericKeyedObjectPool#getNumWaiters()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getNumWaiters()}.
*/
int getNumWaiters();
/**
- * See {@link GenericKeyedObjectPool#getNumWaitersByKey()}
- * @return See {@link GenericKeyedObjectPool#getNumWaitersByKey()}
+ * See {@link GenericKeyedObjectPool#getNumWaitersByKey()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getNumWaitersByKey()}.
*/
Map getNumWaitersByKey();
/**
- * See {@link GenericKeyedObjectPool#getRemoveAbandonedOnBorrow()}
- * @return See {@link GenericKeyedObjectPool#getRemoveAbandonedOnBorrow()}
+ * See {@link GenericKeyedObjectPool#getRemoveAbandonedOnBorrow()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getRemoveAbandonedOnBorrow()}.
* @since 2.10.0
*/
default boolean getRemoveAbandonedOnBorrow() {
@@ -208,17 +233,19 @@ default boolean getRemoveAbandonedOnBorrow() {
}
/**
- * See {@link GenericKeyedObjectPool#getRemoveAbandonedOnMaintenance()}
- * @return See {@link GenericKeyedObjectPool#getRemoveAbandonedOnMaintenance()}
+ * See {@link GenericKeyedObjectPool#getRemoveAbandonedOnMaintenance()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getRemoveAbandonedOnMaintenance()}.
* @since 2.10.0
*/
- default boolean getRemoveAbandonedOnMaintenance() {
+ default boolean getRemoveAbandonedOnMaintenance() {
return false;
}
/**
- * See {@link GenericKeyedObjectPool#getRemoveAbandonedTimeoutDuration()}
- * @return See {@link GenericKeyedObjectPool#getRemoveAbandonedTimeoutDuration()}
+ * See {@link GenericKeyedObjectPool#getRemoveAbandonedTimeoutDuration()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getRemoveAbandonedTimeoutDuration()}.
* @since 2.10.0
*/
default int getRemoveAbandonedTimeout() {
@@ -226,45 +253,52 @@ default int getRemoveAbandonedTimeout() {
}
/**
- * See {@link GenericKeyedObjectPool#getReturnedCount()}
- * @return See {@link GenericKeyedObjectPool#getReturnedCount()}
+ * See {@link GenericKeyedObjectPool#getReturnedCount()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getReturnedCount()}.
*/
long getReturnedCount();
/**
- * See {@link GenericKeyedObjectPool#getTestOnBorrow()}
- * @return See {@link GenericKeyedObjectPool#getTestOnBorrow()}
+ * See {@link GenericKeyedObjectPool#getTestOnBorrow()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getTestOnBorrow()}.
*/
boolean getTestOnBorrow();
/**
- * See {@link GenericKeyedObjectPool#getTestOnCreate()}
- * @return See {@link GenericKeyedObjectPool#getTestOnCreate()}
+ * See {@link GenericKeyedObjectPool#getTestOnCreate()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getTestOnCreate()}.
* @since 2.2
*/
boolean getTestOnCreate();
/**
- * See {@link GenericKeyedObjectPool#getTestOnReturn()}
- * @return See {@link GenericKeyedObjectPool#getTestOnReturn()}
+ * See {@link GenericKeyedObjectPool#getTestOnReturn()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getTestOnReturn()}.
*/
boolean getTestOnReturn();
/**
- * See {@link GenericKeyedObjectPool#getTestWhileIdle()}
- * @return See {@link GenericKeyedObjectPool#getTestWhileIdle()}
+ * See {@link GenericKeyedObjectPool#getTestWhileIdle()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#getTestWhileIdle()}.
*/
boolean getTestWhileIdle();
/**
* See {@link GenericKeyedObjectPool#getDurationBetweenEvictionRuns}
- * @return See {@link GenericKeyedObjectPool#getDurationBetweenEvictionRuns()}
+ *
+ * @return See {@link GenericKeyedObjectPool#getDurationBetweenEvictionRuns()}.
*/
long getTimeBetweenEvictionRunsMillis();
/**
- * See {@link GenericKeyedObjectPool#isAbandonedConfig()}
- * @return See {@link GenericKeyedObjectPool#isAbandonedConfig()}
+ * See {@link GenericKeyedObjectPool#isAbandonedConfig()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#isAbandonedConfig()}.
* @since 2.10.0
*/
default boolean isAbandonedConfig() {
@@ -272,14 +306,16 @@ default boolean isAbandonedConfig() {
}
/**
- * See {@link GenericKeyedObjectPool#isClosed()}
- * @return See {@link GenericKeyedObjectPool#isClosed()}
+ * See {@link GenericKeyedObjectPool#isClosed()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#isClosed()}.
*/
boolean isClosed();
/**
- * See {@link GenericKeyedObjectPool#listAllObjects()}
- * @return See {@link GenericKeyedObjectPool#listAllObjects()}
+ * See {@link GenericKeyedObjectPool#listAllObjects()}.
+ *
+ * @return See {@link GenericKeyedObjectPool#listAllObjects()}.
*/
Map> listAllObjects();
}
diff --git a/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java b/src/main/java/org/apache/commons/pool3/impl/GenericObjectPool.java
similarity index 92%
rename from src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
rename to src/main/java/org/apache/commons/pool3/impl/GenericObjectPool.java
index dbc1ef7a1..284052933 100644
--- a/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
+++ b/src/main/java/org/apache/commons/pool3/impl/GenericObjectPool.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.time.Duration;
import java.time.Instant;
@@ -25,15 +25,15 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
-import org.apache.commons.pool2.DestroyMode;
-import org.apache.commons.pool2.ObjectPool;
-import org.apache.commons.pool2.PoolUtils;
-import org.apache.commons.pool2.PooledObject;
-import org.apache.commons.pool2.PooledObjectFactory;
-import org.apache.commons.pool2.PooledObjectState;
-import org.apache.commons.pool2.SwallowedExceptionListener;
-import org.apache.commons.pool2.TrackedUse;
-import org.apache.commons.pool2.UsageTracking;
+import org.apache.commons.pool3.DestroyMode;
+import org.apache.commons.pool3.ObjectPool;
+import org.apache.commons.pool3.PoolUtils;
+import org.apache.commons.pool3.PooledObject;
+import org.apache.commons.pool3.PooledObjectFactory;
+import org.apache.commons.pool3.PooledObjectState;
+import org.apache.commons.pool3.SwallowedExceptionListener;
+import org.apache.commons.pool3.TrackedUse;
+import org.apache.commons.pool3.UsageTracking;
/**
* A configurable {@link ObjectPool} implementation.
@@ -74,10 +74,8 @@
*
*
* @see GenericKeyedObjectPool
- *
* @param Type of element pooled in this pool.
* @param Type of exception thrown in this pool.
- *
* @since 2.0
*/
public class GenericObjectPool extends BaseGenericObjectPool
@@ -85,10 +83,12 @@ public class GenericObjectPool extends BaseGenericObject
// JMX specific attributes
private static final String ONAME_BASE =
- "org.apache.commons.pool2:type=GenericObjectPool,name=";
+ "org.apache.commons.pool3:type=GenericObjectPool,name=";
private static void wait(final Object obj, final Duration duration) throws InterruptedException {
- obj.wait(duration.toMillis(), duration.getNano() % 1_000_000);
+ if (!duration.isNegative()) {
+ obj.wait(duration.toMillis(), duration.getNano() % 1_000_000);
+ }
}
private volatile String factoryType;
@@ -100,6 +100,8 @@ private static void wait(final Object obj, final Duration duration) throws Inter
private final PooledObjectFactory factory;
/*
+ * TODO The references to _maxActive are from 1.x and need to be updated.
+ *
* All of the objects currently associated with this pool in any state. It
* excludes objects that have been destroyed. The size of
* {@link #allObjects} will always be less than or equal to {@link
@@ -109,6 +111,8 @@ private static void wait(final Object obj, final Duration duration) throws Inter
private final ConcurrentHashMap, PooledObject> allObjects = new ConcurrentHashMap<>();
/*
+ * TODO The references to _maxActive are from 1.x and need to be updated.
+ *
* The combined count of the currently created objects and those in the
* process of being created. Under load, it may exceed {@link #_maxActive}
* if multiple threads try and create a new object at the same time but
@@ -186,11 +190,10 @@ public GenericObjectPool(final PooledObjectFactory factory,
* is null, this is a no-op (no exception, but no impact on the pool).
*
* @param p The object to make idle
- *
* @throws E If the factory fails to passivate the object
*/
private void addIdleObject(final PooledObject p) throws E {
- if (!PooledObject.isNull(p)) {
+ if (PooledObject.nonNull(p)) {
factory.passivateObject(p);
if (getLifo()) {
idleObjects.addFirst(p);
@@ -212,7 +215,7 @@ private void addIdleObject(final PooledObject p) throws E {
* is thrown. If there is no factory set (factory == null), an {@code IllegalStateException}
* is thrown.
*
- *
+ *
*/
@Override
public void addObject() throws E {
@@ -220,7 +223,7 @@ public void addObject() throws E {
if (factory == null) {
throw new IllegalStateException("Cannot add objects without a factory.");
}
- addIdleObject(create());
+ addIdleObject(create(getMaxWaitDuration()));
}
/**
@@ -274,53 +277,48 @@ public T borrowObject() throws E {
* available instances in request arrival order.
*
*
- * @param borrowMaxWaitDuration The time to wait for an object
- * to become available
- *
+ * @param maxWaitDuration The time to wait for an object to become available, not null.
* @return object instance from the pool
* @throws NoSuchElementException if an instance cannot be returned
* @throws E if an object instance cannot be returned due to an error
* @since 2.10.0
*/
- public T borrowObject(final Duration borrowMaxWaitDuration) throws E {
+ public T borrowObject(final Duration maxWaitDuration) throws E {
assertOpen();
-
+ final Instant startInstant = Instant.now();
+ final boolean negativeDuration = maxWaitDuration.isNegative();
+ Duration remainingWaitDuration = maxWaitDuration;
final AbandonedConfig ac = this.abandonedConfig;
- if (ac != null && ac.getRemoveAbandonedOnBorrow() && getNumIdle() < 2 &&
- getNumActive() > getMaxTotal() - 3) {
+ if (ac != null && ac.getRemoveAbandonedOnBorrow() && getNumIdle() < 2 && getNumActive() > getMaxTotal() - 3) {
removeAbandoned(ac);
}
-
PooledObject p = null;
-
// Get local copy of current config so it is consistent for entire
// method execution
final boolean blockWhenExhausted = getBlockWhenExhausted();
-
boolean create;
- final Instant waitTime = Instant.now();
-
while (p == null) {
+ remainingWaitDuration = maxWaitDuration.minus(durationSince(startInstant));
create = false;
p = idleObjects.pollFirst();
if (p == null) {
- p = create();
- if (!PooledObject.isNull(p)) {
+ p = create(remainingWaitDuration);
+ if (PooledObject.nonNull(p)) {
create = true;
}
}
if (blockWhenExhausted) {
if (PooledObject.isNull(p)) {
try {
- p = borrowMaxWaitDuration.isNegative() ? idleObjects.takeFirst() : idleObjects.pollFirst(borrowMaxWaitDuration);
+ remainingWaitDuration = maxWaitDuration.minus(durationSince(startInstant));
+ p = negativeDuration ? idleObjects.takeFirst() : idleObjects.pollFirst(maxWaitDuration);
} catch (final InterruptedException e) {
// Don't surface exception type of internal locking mechanism.
throw cast(e);
}
}
if (PooledObject.isNull(p)) {
- throw new NoSuchElementException(appendStats(
- "Timeout waiting for idle object, borrowMaxWaitDuration=" + borrowMaxWaitDuration));
+ throw new NoSuchElementException(appendStats("Timeout waiting for idle object, borrowMaxWaitDuration=" + remainingWaitDuration));
}
} else if (PooledObject.isNull(p)) {
throw new NoSuchElementException(appendStats("Pool exhausted"));
@@ -328,7 +326,6 @@ public T borrowObject(final Duration borrowMaxWaitDuration) throws E {
if (!p.allocate()) {
p = null;
}
-
if (!PooledObject.isNull(p)) {
try {
factory.activateObject(p);
@@ -340,8 +337,7 @@ public T borrowObject(final Duration borrowMaxWaitDuration) throws E {
}
p = null;
if (create) {
- final NoSuchElementException nsee = new NoSuchElementException(
- appendStats("Unable to activate object"));
+ final NoSuchElementException nsee = new NoSuchElementException(appendStats("Unable to activate object"));
nsee.initCause(e);
throw nsee;
}
@@ -364,8 +360,7 @@ public T borrowObject(final Duration borrowMaxWaitDuration) throws E {
}
p = null;
if (create) {
- final NoSuchElementException nsee = new NoSuchElementException(
- appendStats("Unable to validate object"));
+ final NoSuchElementException nsee = new NoSuchElementException(appendStats("Unable to validate object"));
nsee.initCause(validationThrowable);
throw nsee;
}
@@ -373,9 +368,7 @@ public T borrowObject(final Duration borrowMaxWaitDuration) throws E {
}
}
}
-
- updateStatsBorrow(p, Duration.between(waitTime, Instant.now()));
-
+ updateStatsBorrow(p, durationSince(startInstant));
return p.getObject();
}
@@ -423,9 +416,7 @@ public T borrowObject(final Duration borrowMaxWaitDuration) throws E {
* to become available
*
* @return object instance from the pool
- *
* @throws NoSuchElementException if an instance cannot be returned
- *
* @throws E if an object instance cannot be returned due to an
* error
*/
@@ -496,7 +487,7 @@ public void close() {
jmxUnregister();
// Release any threads that were waiting for an object
- idleObjects.interuptTakeWaiters();
+ idleObjects.interruptTakeWaiters();
}
}
@@ -510,20 +501,19 @@ public void close() {
* If the factory makeObject returns null, this method throws a NullPointerException.
*
*
+ * @param maxWaitDurationRequest The time to wait for an object to become available.
* @return The new wrapped pooled object or null.
* @throws E if the object factory's {@code makeObject} fails
*/
- private PooledObject create() throws E {
+ private PooledObject create(final Duration maxWaitDurationRequest) throws E {
+ final Instant startInstant = Instant.now();
+ final Duration maxWaitDuration = maxWaitDurationRequest.isNegative() ? Duration.ZERO : maxWaitDurationRequest;
int localMaxTotal = getMaxTotal();
// This simplifies the code later in this method
if (localMaxTotal < 0) {
localMaxTotal = Integer.MAX_VALUE;
}
-
final Instant localStartInstant = Instant.now();
- final Duration maxWaitDurationRaw = getMaxWaitDuration();
- final Duration localMaxWaitDuration = maxWaitDurationRaw.isNegative() ? Duration.ZERO : maxWaitDurationRaw;
-
// Flag that indicates if create should:
// - TRUE: call the factory to create an object
// - FALSE: return null
@@ -531,6 +521,8 @@ private PooledObject create() throws E {
// call the factory
Boolean create = null;
while (create == null) {
+ // remainingWaitDuration handles spurious wakeup from wait().
+ final Duration remainingWaitDuration = maxWaitDuration.minus(durationSince(startInstant));
synchronized (makeObjectCountLock) {
final long newCreateCount = createCount.incrementAndGet();
if (newCreateCount > localMaxTotal) {
@@ -548,7 +540,7 @@ private PooledObject create() throws E {
// fail so wait until they complete and then re-test if
// the pool is at capacity or not.
try {
- wait(makeObjectCountLock, localMaxWaitDuration);
+ wait(makeObjectCountLock, remainingWaitDuration);
} catch (final InterruptedException e) {
// Don't surface exception type of internal locking mechanism.
throw cast(e);
@@ -560,10 +552,9 @@ private PooledObject create() throws E {
create = Boolean.TRUE;
}
}
-
- // Do not block more if maxWaitTimeMillis is set.
- if (create == null && localMaxWaitDuration.compareTo(Duration.ZERO) > 0 &&
- Duration.between(localStartInstant, Instant.now()).compareTo(localMaxWaitDuration) >= 0) {
+ // Do not block more if remainingWaitDuration > 0.
+ if (create == null && remainingWaitDuration.compareTo(Duration.ZERO) > 0 &&
+ durationSince(localStartInstant).compareTo(remainingWaitDuration) >= 0) {
create = Boolean.FALSE;
}
}
@@ -600,7 +591,7 @@ private PooledObject create() throws E {
}
createdCount.incrementAndGet();
- allObjects.put(new IdentityWrapper<>(p.getObject()), p);
+ allObjects.put(IdentityWrapper.unwrap(p), p);
return p;
}
@@ -609,14 +600,13 @@ private PooledObject create() throws E {
*
* @param toDestroy The wrapped pooled object to destroy
* @param destroyMode DestroyMode context provided to the factory
- *
* @throws E If the factory fails to destroy the pooled object
* cleanly
*/
private void destroy(final PooledObject toDestroy, final DestroyMode destroyMode) throws E {
toDestroy.invalidate();
idleObjects.remove(toDestroy);
- allObjects.remove(new IdentityWrapper<>(toDestroy.getObject()));
+ allObjects.remove(IdentityWrapper.unwrap(toDestroy));
try {
factory.destroyObject(toDestroy, destroyMode);
} finally {
@@ -625,6 +615,10 @@ private void destroy(final PooledObject toDestroy, final DestroyMode destroyM
}
}
+ private Duration durationSince(final Instant startInstant) {
+ return Duration.between(startInstant, Instant.now());
+ }
+
/**
* Tries to ensure that {@code idleCount} idle instances exist in the pool.
*
@@ -648,7 +642,7 @@ private void ensureIdle(final int idleCount, final boolean always) throws E {
}
while (idleObjects.size() < idleCount) {
- final PooledObject p = create();
+ final PooledObject p = create(getMaxWaitDuration());
if (PooledObject.isNull(p)) {
// Can't create objects, no reason to think another call to
// create will work. Give up.
@@ -856,10 +850,9 @@ public int getMaxIdle() {
*
*
* @return The minimum number of objects.
- *
* @see #setMinIdle(int)
* @see #setMaxIdle(int)
- * @see #setTimeBetweenEvictionRuns(Duration)
+ * @see #setDurationBetweenEvictionRuns(Duration)
*/
@Override
public int getMinIdle() {
@@ -979,11 +972,12 @@ public void invalidateObject(final T obj, final DestroyMode destroyMode) throws
public Set listAllObjects() {
return allObjects.values().stream().map(DefaultPooledObjectInfo::new).collect(Collectors.toSet());
}
+
/**
* Tries to ensure that {@link #getMinIdle()} idle instances are available
* in the pool.
*
- * @throws E If the associated factory throws an exception
+ * @throws E If the associated factory throws an exception.
* @since 2.4
*/
public void preparePool() throws E {
@@ -1119,7 +1113,6 @@ public void returnObject(final T obj) {
* Sets the base pool configuration.
*
* @param conf the new configuration to use. This is used by value.
- *
* @see GenericObjectPoolConfig
*/
public void setConfig(final GenericObjectPoolConfig conf) {
diff --git a/src/main/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java b/src/main/java/org/apache/commons/pool3/impl/GenericObjectPoolConfig.java
similarity index 87%
rename from src/main/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java
rename to src/main/java/org/apache/commons/pool3/impl/GenericObjectPoolConfig.java
index 8bdd7f321..72437bf4c 100644
--- a/src/main/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java
+++ b/src/main/java/org/apache/commons/pool3/impl/GenericObjectPoolConfig.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
/**
* A simple structure encapsulating the configuration for a
@@ -48,13 +48,19 @@ public class GenericObjectPoolConfig extends BaseObjectPoolConfig {
*/
public static final int DEFAULT_MIN_IDLE = 0;
-
private int maxTotal = DEFAULT_MAX_TOTAL;
private int maxIdle = DEFAULT_MAX_IDLE;
private int minIdle = DEFAULT_MIN_IDLE;
+ /**
+ * Constructs a new instance.
+ */
+ public GenericObjectPoolConfig() {
+ // empty
+ }
+
@SuppressWarnings("unchecked")
@Override
public GenericObjectPoolConfig clone() {
@@ -66,7 +72,7 @@ public GenericObjectPoolConfig clone() {
}
/**
- * Get the value for the {@code maxIdle} configuration attribute
+ * Gets the value for the {@code maxIdle} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code maxIdle} for this
@@ -78,9 +84,8 @@ public int getMaxIdle() {
return maxIdle;
}
-
/**
- * Get the value for the {@code maxTotal} configuration attribute
+ * Gets the value for the {@code maxTotal} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code maxTotal} for this
@@ -93,7 +98,7 @@ public int getMaxTotal() {
}
/**
- * Get the value for the {@code minIdle} configuration attribute
+ * Gets the value for the {@code minIdle} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code minIdle} for this
@@ -105,9 +110,8 @@ public int getMinIdle() {
return minIdle;
}
-
/**
- * Set the value for the {@code maxIdle} configuration attribute for
+ * Sets the value for the {@code maxIdle} configuration attribute for
* pools created with this configuration instance.
*
* @param maxIdle The new setting of {@code maxIdle}
@@ -120,7 +124,7 @@ public void setMaxIdle(final int maxIdle) {
}
/**
- * Set the value for the {@code maxTotal} configuration attribute for
+ * Sets the value for the {@code maxTotal} configuration attribute for
* pools created with this configuration instance.
*
* @param maxTotal The new setting of {@code maxTotal}
@@ -133,7 +137,7 @@ public void setMaxTotal(final int maxTotal) {
}
/**
- * Set the value for the {@code minIdle} configuration attribute for
+ * Sets the value for the {@code minIdle} configuration attribute for
* pools created with this configuration instance.
*
* @param minIdle The new setting of {@code minIdle}
diff --git a/src/main/java/org/apache/commons/pool2/impl/GenericObjectPoolMXBean.java b/src/main/java/org/apache/commons/pool3/impl/GenericObjectPoolMXBean.java
similarity index 55%
rename from src/main/java/org/apache/commons/pool2/impl/GenericObjectPoolMXBean.java
rename to src/main/java/org/apache/commons/pool3/impl/GenericObjectPoolMXBean.java
index 5f6d73a0c..3e0bd1266 100644
--- a/src/main/java/org/apache/commons/pool2/impl/GenericObjectPoolMXBean.java
+++ b/src/main/java/org/apache/commons/pool3/impl/GenericObjectPoolMXBean.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,244 +14,273 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.util.Set;
/**
* Defines the methods that will be made available via JMX.
- *
- * NOTE: This interface exists only to define those attributes and methods that
- * will be made available via JMX. It must not be implemented by clients
- * as it is subject to change between major, minor and patch version
- * releases of commons pool. Clients that implement this interface may
- * not, therefore, be able to upgrade to a new minor or patch release
- * without requiring code changes.
+ *
Note
+ *
+ * This interface exists only to define those attributes and methods that will be made available via JMX. It must not be implemented by clients as it is subject
+ * to change between major, minor and patch version releases of commons pool. Clients that implement this interface may not, therefore, be able to upgrade to a
+ * new minor or patch release without requiring code changes.
+ *
*
* @since 2.0
*/
public interface GenericObjectPoolMXBean {
- // Getters for basic configuration settings
-
/**
- * See {@link GenericObjectPool#getBlockWhenExhausted()}
- * @return See {@link GenericObjectPool#getBlockWhenExhausted()}
+ * See {@link GenericObjectPool#getBlockWhenExhausted()}.
+ *
+ * @return See {@link GenericObjectPool#getBlockWhenExhausted()}.
*/
boolean getBlockWhenExhausted();
/**
- * See {@link GenericObjectPool#getBorrowedCount()}
- * @return See {@link GenericObjectPool#getBorrowedCount()}
+ * See {@link GenericObjectPool#getBorrowedCount()}.
+ *
+ * @return See {@link GenericObjectPool#getBorrowedCount()}.
*/
long getBorrowedCount();
/**
- * See {@link GenericObjectPool#getCreatedCount()}
- * @return See {@link GenericObjectPool#getCreatedCount()}
+ * See {@link GenericObjectPool#getCreatedCount()}.
+ *
+ * @return See {@link GenericObjectPool#getCreatedCount()}.
*/
long getCreatedCount();
/**
- * See {@link GenericObjectPool#getCreationStackTrace()}
- * @return See {@link GenericObjectPool#getCreationStackTrace()}
+ * See {@link GenericObjectPool#getCreationStackTrace()}.
+ *
+ * @return See {@link GenericObjectPool#getCreationStackTrace()}.
*/
String getCreationStackTrace();
/**
- * See {@link GenericObjectPool#getDestroyedByBorrowValidationCount()}
- * @return See {@link GenericObjectPool#getDestroyedByBorrowValidationCount()}
+ * See {@link GenericObjectPool#getDestroyedByBorrowValidationCount()}.
+ *
+ * @return See {@link GenericObjectPool#getDestroyedByBorrowValidationCount()}.
*/
long getDestroyedByBorrowValidationCount();
/**
- * See {@link GenericObjectPool#getDestroyedByEvictorCount()}
- * @return See {@link GenericObjectPool#getDestroyedByEvictorCount()}
+ * See {@link GenericObjectPool#getDestroyedByEvictorCount()}.
+ *
+ * @return See {@link GenericObjectPool#getDestroyedByEvictorCount()}.
*/
long getDestroyedByEvictorCount();
/**
- * See {@link GenericObjectPool#getDestroyedCount()}
- * @return See {@link GenericObjectPool#getDestroyedCount()}
+ * See {@link GenericObjectPool#getDestroyedCount()}.
+ *
+ * @return See {@link GenericObjectPool#getDestroyedCount()}.
*/
long getDestroyedCount();
/**
- * See {@link GenericObjectPool#getFactoryType()}
- * @return See {@link GenericObjectPool#getFactoryType()}
+ * See {@link GenericObjectPool#getFactoryType()}.
+ *
+ * @return See {@link GenericObjectPool#getFactoryType()}.
*/
String getFactoryType();
/**
- * See {@link GenericObjectPool#getLifo()}
- * @return See {@link GenericObjectPool#getLifo()}
+ * See {@link GenericObjectPool#getLifo()}.
+ *
+ * @return See {@link GenericObjectPool#getLifo()}.
*/
boolean getFairness();
/**
- * See {@link GenericObjectPool#getFairness()}
- * @return See {@link GenericObjectPool#getFairness()}
+ * See {@link GenericObjectPool#getFairness()}.
+ *
+ * @return See {@link GenericObjectPool#getFairness()}.
*/
boolean getLifo();
/**
- * See {@link GenericObjectPool#getLogAbandoned()}
- * @return See {@link GenericObjectPool#getLogAbandoned()}
+ * See {@link GenericObjectPool#getLogAbandoned()}.
+ *
+ * @return See {@link GenericObjectPool#getLogAbandoned()}.
*/
boolean getLogAbandoned();
/**
- * See {@link GenericObjectPool#getMaxBorrowWaitTimeMillis()}
- * @return See {@link GenericObjectPool#getMaxBorrowWaitTimeMillis()}
+ * See {@link GenericObjectPool#getMaxBorrowWaitTimeMillis()}.
+ *
+ * @return See {@link GenericObjectPool#getMaxBorrowWaitTimeMillis()}.
*/
long getMaxBorrowWaitTimeMillis();
/**
- * See {@link GenericObjectPool#getMaxIdle()}
- * @return See {@link GenericObjectPool#getMaxIdle()}
+ * See {@link GenericObjectPool#getMaxIdle()}.
+ *
+ * @return See {@link GenericObjectPool#getMaxIdle()}.
*/
int getMaxIdle();
/**
- * See {@link GenericObjectPool#getMaxTotal()}
- * @return See {@link GenericObjectPool#getMaxTotal()}
+ * See {@link GenericObjectPool#getMaxTotal()}.
+ *
+ * @return See {@link GenericObjectPool#getMaxTotal()}.
*/
int getMaxTotal();
/**
- * See {@link GenericObjectPool#getMaxWaitDuration()}
- * @return See {@link GenericObjectPool#getMaxWaitDuration()}
+ * See {@link GenericObjectPool#getMaxWaitDuration()}.
+ *
+ * @return See {@link GenericObjectPool#getMaxWaitDuration()}.
*/
long getMaxWaitMillis();
/**
- * See {@link GenericObjectPool#getMeanActiveTimeMillis()}
- * @return See {@link GenericObjectPool#getMeanActiveTimeMillis()}
+ * See {@link GenericObjectPool#getMeanActiveTimeMillis()}.
+ *
+ * @return See {@link GenericObjectPool#getMeanActiveTimeMillis()}.
*/
long getMeanActiveTimeMillis();
/**
- * See {@link GenericObjectPool#getMeanBorrowWaitTimeMillis()}
- * @return See {@link GenericObjectPool#getMeanBorrowWaitTimeMillis()}
+ * See {@link GenericObjectPool#getMeanBorrowWaitTimeMillis()}.
+ *
+ * @return See {@link GenericObjectPool#getMeanBorrowWaitTimeMillis()}.
*/
long getMeanBorrowWaitTimeMillis();
- // Getters for monitoring attributes
-
/**
- * See {@link GenericObjectPool#getMeanIdleTimeMillis()}
- * @return See {@link GenericObjectPool#getMeanIdleTimeMillis()}
+ * See {@link GenericObjectPool#getMeanIdleTimeMillis()}.
+ *
+ * @return See {@link GenericObjectPool#getMeanIdleTimeMillis()}.
*/
long getMeanIdleTimeMillis();
/**
- * See {@link GenericObjectPool#getMinEvictableIdleDuration()}
- * @return See {@link GenericObjectPool#getMinEvictableIdleDuration()}
+ * See {@link GenericObjectPool#getMinEvictableIdleDuration()}.
+ *
+ * @return See {@link GenericObjectPool#getMinEvictableIdleDuration()}.
*/
long getMinEvictableIdleTimeMillis();
/**
- * See {@link GenericObjectPool#getMinIdle()}
- * @return See {@link GenericObjectPool#getMinIdle()}
+ * See {@link GenericObjectPool#getMinIdle()}.
+ *
+ * @return See {@link GenericObjectPool#getMinIdle()}.
*/
int getMinIdle();
/**
- * See {@link GenericObjectPool#getNumActive()}
- * @return See {@link GenericObjectPool#getNumActive()}
+ * See {@link GenericObjectPool#getNumActive()}.
+ *
+ * @return See {@link GenericObjectPool#getNumActive()}.
*/
int getNumActive();
/**
- * See {@link GenericObjectPool#getNumIdle()}
- * @return See {@link GenericObjectPool#getNumIdle()}
+ * See {@link GenericObjectPool#getNumIdle()}.
+ *
+ * @return See {@link GenericObjectPool#getNumIdle()}.
*/
int getNumIdle();
/**
- * See {@link GenericObjectPool#getNumTestsPerEvictionRun()}
- * @return See {@link GenericObjectPool#getNumTestsPerEvictionRun()}
+ * See {@link GenericObjectPool#getNumTestsPerEvictionRun()}.
+ *
+ * @return See {@link GenericObjectPool#getNumTestsPerEvictionRun()}.
*/
int getNumTestsPerEvictionRun();
/**
- * See {@link GenericObjectPool#getNumWaiters()}
- * @return See {@link GenericObjectPool#getNumWaiters()}
+ * See {@link GenericObjectPool#getNumWaiters()}.
+ *
+ * @return See {@link GenericObjectPool#getNumWaiters()}.
*/
int getNumWaiters();
/**
- * See {@link GenericObjectPool#getRemoveAbandonedOnBorrow()}
- * @return See {@link GenericObjectPool#getRemoveAbandonedOnBorrow()}
+ * See {@link GenericObjectPool#getRemoveAbandonedOnBorrow()}.
+ *
+ * @return See {@link GenericObjectPool#getRemoveAbandonedOnBorrow()}.
*/
boolean getRemoveAbandonedOnBorrow();
/**
- * See {@link GenericObjectPool#getRemoveAbandonedOnMaintenance()}
- * @return See {@link GenericObjectPool#getRemoveAbandonedOnMaintenance()}
+ * See {@link GenericObjectPool#getRemoveAbandonedOnMaintenance()}.
+ *
+ * @return See {@link GenericObjectPool#getRemoveAbandonedOnMaintenance()}.
*/
boolean getRemoveAbandonedOnMaintenance();
/**
- * See {@link GenericObjectPool#getRemoveAbandonedTimeoutDuration()}
- * @return See {@link GenericObjectPool#getRemoveAbandonedTimeoutDuration()}
+ * See {@link GenericObjectPool#getRemoveAbandonedTimeoutDuration()}.
+ *
+ * @return See {@link GenericObjectPool#getRemoveAbandonedTimeoutDuration()}.
*/
int getRemoveAbandonedTimeout();
/**
- * See {@link GenericObjectPool#getReturnedCount()}
- * @return See {@link GenericObjectPool#getReturnedCount()}
+ * See {@link GenericObjectPool#getReturnedCount()}.
+ *
+ * @return See {@link GenericObjectPool#getReturnedCount()}.
*/
long getReturnedCount();
/**
- * See {@link GenericObjectPool#getTestOnBorrow()}
- * @return See {@link GenericObjectPool#getTestOnBorrow()}
+ * See {@link GenericObjectPool#getTestOnBorrow()}.
+ *
+ * @return See {@link GenericObjectPool#getTestOnBorrow()}.
*/
boolean getTestOnBorrow();
- // Getters for abandoned object removal configuration
-
/**
- * See {@link GenericObjectPool#getTestOnCreate()}
- * @return See {@link GenericObjectPool#getTestOnCreate()}
+ * See {@link GenericObjectPool#getTestOnCreate()}.
+ *
+ * @return See {@link GenericObjectPool#getTestOnCreate()}.
* @since 2.2
*/
boolean getTestOnCreate();
/**
- * See {@link GenericObjectPool#getTestOnReturn()}
- * @return See {@link GenericObjectPool#getTestOnReturn()}
+ * See {@link GenericObjectPool#getTestOnReturn()}.
+ *
+ * @return See {@link GenericObjectPool#getTestOnReturn()}.
*/
boolean getTestOnReturn();
/**
- * See {@link GenericObjectPool#getTestWhileIdle()}
- * @return See {@link GenericObjectPool#getTestWhileIdle()}
+ * See {@link GenericObjectPool#getTestWhileIdle()}.
+ *
+ * @return See {@link GenericObjectPool#getTestWhileIdle()}.
*/
boolean getTestWhileIdle();
/**
- * See {@link GenericObjectPool#getDurationBetweenEvictionRuns()}
- * @return See {@link GenericObjectPool#getDurationBetweenEvictionRuns()}
+ * See {@link GenericObjectPool#getDurationBetweenEvictionRuns()}.
+ *
+ * @return See {@link GenericObjectPool#getDurationBetweenEvictionRuns()}.
*/
long getTimeBetweenEvictionRunsMillis();
/**
- * See {@link GenericObjectPool#isAbandonedConfig()}
- * @return See {@link GenericObjectPool#isAbandonedConfig()}
+ * See {@link GenericObjectPool#isAbandonedConfig()}.
+ *
+ * @return See {@link GenericObjectPool#isAbandonedConfig()}.
*/
boolean isAbandonedConfig();
/**
- * See {@link GenericObjectPool#isClosed()}
- * @return See {@link GenericObjectPool#isClosed()}
+ * See {@link GenericObjectPool#isClosed()}.
+ *
+ * @return See {@link GenericObjectPool#isClosed()}.
*/
boolean isClosed();
/**
- * See {@link GenericObjectPool#listAllObjects()}
- * @return See {@link GenericObjectPool#listAllObjects()}
+ * See {@link GenericObjectPool#listAllObjects()}.
+ *
+ * @return See {@link GenericObjectPool#listAllObjects()}.
*/
Set listAllObjects();
}
diff --git a/src/main/java/org/apache/commons/pool2/impl/InterruptibleReentrantLock.java b/src/main/java/org/apache/commons/pool3/impl/InterruptibleReentrantLock.java
similarity index 84%
rename from src/main/java/org/apache/commons/pool2/impl/InterruptibleReentrantLock.java
rename to src/main/java/org/apache/commons/pool3/impl/InterruptibleReentrantLock.java
index fae6230e7..c964bc708 100644
--- a/src/main/java/org/apache/commons/pool2/impl/InterruptibleReentrantLock.java
+++ b/src/main/java/org/apache/commons/pool3/impl/InterruptibleReentrantLock.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
@@ -29,7 +29,7 @@
*
* @since 2.0
*/
-class InterruptibleReentrantLock extends ReentrantLock {
+final class InterruptibleReentrantLock extends ReentrantLock {
private static final long serialVersionUID = 1L;
@@ -37,18 +37,18 @@ class InterruptibleReentrantLock extends ReentrantLock {
* Constructs a new InterruptibleReentrantLock with the given fairness policy.
*
* @param fairness true means threads should acquire contended locks as if
- * waiting in a FIFO queue
+ * waiting in a FIFO queue.
*/
- public InterruptibleReentrantLock(final boolean fairness) {
+ InterruptibleReentrantLock(final boolean fairness) {
super(fairness);
}
/**
- * Interrupts the threads that are waiting on a specific condition
+ * Interrupts the threads that are waiting on a specific condition.
*
* @param condition the condition on which the threads are waiting.
*/
- public void interruptWaiters(final Condition condition) {
+ void interruptWaiters(final Condition condition) {
getWaitingThreads(condition).forEach(Thread::interrupt);
}
}
diff --git a/src/main/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java b/src/main/java/org/apache/commons/pool3/impl/LinkedBlockingDeque.java
similarity index 95%
rename from src/main/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java
rename to src/main/java/org/apache/commons/pool3/impl/LinkedBlockingDeque.java
index 15a3912ae..200a89a50 100644
--- a/src/main/java/org/apache/commons/pool2/impl/LinkedBlockingDeque.java
+++ b/src/main/java/org/apache/commons/pool3/impl/LinkedBlockingDeque.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -22,10 +22,10 @@
import java.time.Duration;
import java.util.AbstractQueue;
import java.util.Collection;
-import java.util.Deque;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
+import java.util.concurrent.BlockingDeque;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
@@ -65,8 +65,8 @@
*
* @since 2.0
*/
-class LinkedBlockingDeque extends AbstractQueue
- implements Deque, Serializable {
+final class LinkedBlockingDeque extends AbstractQueue
+ implements BlockingDeque, Serializable {
/*
* Implemented as a simple doubly-linked list protected by a
@@ -90,7 +90,7 @@ class LinkedBlockingDeque extends AbstractQueue
/*
* We have "diamond" multiple interface/abstract class inheritance
* here, and that introduces ambiguities. Often we want the
- * BlockingDeque javadoc combined with the AbstractQueue
+ * BlockingDeque Javadoc combined with the AbstractQueue
* implementation, so a lot of method specs are duplicated here.
*/
@@ -173,7 +173,6 @@ public E next() {
* iterator.
*
* @param n given node
- *
* @return next node
*/
abstract Node nextNode(Node n);
@@ -222,20 +221,30 @@ private Node succ(Node n) {
}
/** Descending iterator */
- private class DescendingItr extends AbstractItr {
+ private final class DescendingItr extends AbstractItr {
@Override
- Node firstNode() { return last; }
+ Node firstNode() {
+ return last;
+ }
+
@Override
- Node nextNode(final Node n) { return n.prev; }
+ Node nextNode(final Node n) {
+ return n.prev;
+ }
}
/** Forward iterator */
- private class Itr extends AbstractItr {
+ private final class Itr extends AbstractItr {
@Override
- Node firstNode() { return first; }
+ Node firstNode() {
+ return first;
+ }
+
@Override
- Node nextNode(final Node n) { return n.next; }
+ Node nextNode(final Node n) {
+ return n.next;
}
+ }
/**
* Doubly-linked list node class.
@@ -313,7 +322,7 @@ private static final class Node {
* Creates a {@code LinkedBlockingDeque} with a capacity of
* {@link Integer#MAX_VALUE}.
*/
- public LinkedBlockingDeque() {
+ LinkedBlockingDeque() {
this(Integer.MAX_VALUE);
}
@@ -323,11 +332,10 @@ public LinkedBlockingDeque() {
* @param fairness true means threads waiting on the deque should be served
* as if waiting in a FIFO request queue
*/
- public LinkedBlockingDeque(final boolean fairness) {
+ LinkedBlockingDeque(final boolean fairness) {
this(Integer.MAX_VALUE, fairness);
}
-
// Basic linking and unlinking operations, called only while holding lock
/**
@@ -340,7 +348,7 @@ public LinkedBlockingDeque(final boolean fairness) {
* @throws NullPointerException if the specified collection or any
* of its elements are null
*/
- public LinkedBlockingDeque(final Collection extends E> c) {
+ LinkedBlockingDeque(final Collection extends E> c) {
this(Integer.MAX_VALUE);
lock.lock(); // Never contended, but necessary for visibility
try {
@@ -361,7 +369,7 @@ public LinkedBlockingDeque(final Collection extends E> c) {
* @param capacity the capacity of this deque
* @throws IllegalArgumentException if {@code capacity} is less than 1
*/
- public LinkedBlockingDeque(final int capacity) {
+ LinkedBlockingDeque(final int capacity) {
this(capacity, false);
}
@@ -374,7 +382,7 @@ public LinkedBlockingDeque(final int capacity) {
* as if waiting in a FIFO request queue
* @throws IllegalArgumentException if {@code capacity} is less than 1
*/
- public LinkedBlockingDeque(final int capacity, final boolean fairness) {
+ LinkedBlockingDeque(final int capacity, final boolean fairness) {
if (capacity <= 0) {
throw new IllegalArgumentException();
}
@@ -476,9 +484,7 @@ public Iterator descendingIterator() {
* Drains the queue to the specified collection.
*
* @param c The collection to add the elements to
- *
* @return number of elements added to the collection
- *
* @throws UnsupportedOperationException if the add operation is not
* supported by the specified collection
* @throws ClassCastException if the class of the elements held by this
@@ -487,6 +493,7 @@ public Iterator descendingIterator() {
* @throws NullPointerException if c is null
* @throws IllegalArgumentException if c is this instance
*/
+ @Override
public int drainTo(final Collection super E> c) {
return drainTo(c, Integer.MAX_VALUE);
}
@@ -495,9 +502,8 @@ public int drainTo(final Collection super E> c) {
* Drains no more than the specified number of elements from the queue to the
* specified collection.
*
- * @param c collection to add the elements to
+ * @param collection collection to add the elements to
* @param maxElements maximum number of elements to remove from the queue
- *
* @return number of elements added to the collection
* @throws UnsupportedOperationException if the add operation is not
* supported by the specified collection
@@ -507,16 +513,17 @@ public int drainTo(final Collection super E> c) {
* @throws NullPointerException if c is null
* @throws IllegalArgumentException if c is this instance
*/
- public int drainTo(final Collection super E> c, final int maxElements) {
- Objects.requireNonNull(c, "c");
- if (c == this) {
+ @Override
+ public int drainTo(final Collection super E> collection, final int maxElements) {
+ Objects.requireNonNull(collection, "c");
+ if (collection == this) {
throw new IllegalArgumentException();
}
lock.lock();
try {
final int n = Math.min(maxElements, count);
for (int i = 0; i < n; i++) {
- c.add(first.item); // In this order, in case add() throws.
+ collection.add(first.item); // In this order, in case add() throws.
unlinkFirst();
}
return n;
@@ -570,7 +577,7 @@ public E getLast() {
*
* @return number of threads waiting on this deque's notEmpty condition.
*/
- public int getTakeQueueLength() {
+ int getTakeQueueLength() {
lock.lock();
try {
return lock.getWaitQueueLength(notEmpty);
@@ -585,7 +592,7 @@ public int getTakeQueueLength() {
*
* @return true if there is at least one thread waiting on this deque's notEmpty condition.
*/
- public boolean hasTakeWaiters() {
+ boolean hasTakeWaiters() {
lock.lock();
try {
return lock.hasWaiters(notEmpty);
@@ -598,7 +605,7 @@ public boolean hasTakeWaiters() {
* Interrupts the threads currently waiting to take an object from the pool. See disclaimer on accuracy in
* {@link java.util.concurrent.locks.ReentrantLock#getWaitingThreads(Condition)}.
*/
- public void interuptTakeWaiters() {
+ void interruptTakeWaiters() {
lock.lock();
try {
lock.interruptWaiters(notEmpty);
@@ -628,7 +635,6 @@ public Iterator iterator() {
* Links provided element as first element, or returns false if full.
*
* @param e The element to link as the first element.
- *
* @return {@code true} if successful, otherwise {@code false}
*/
private boolean linkFirst(final E e) {
@@ -653,7 +659,6 @@ private boolean linkFirst(final E e) {
* Links provided element as last element, or returns false if full.
*
* @param e The element to link as the last element.
- *
* @return {@code true} if successful, otherwise {@code false}
*/
private boolean linkLast(final E e) {
@@ -690,9 +695,7 @@ public boolean offer(final E e) {
*
* @param e element to link
* @param timeout length of time to wait
- *
* @return {@code true} if successful, otherwise {@code false}
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whilst waiting
* for space
@@ -710,13 +713,12 @@ boolean offer(final E e, final Duration timeout) throws InterruptedException {
* @param e element to link
* @param timeout length of time to wait
* @param unit units that timeout is expressed in
- *
* @return {@code true} if successful, otherwise {@code false}
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whilst waiting
* for space
*/
+ @Override
public boolean offer(final E e, final long timeout, final TimeUnit unit) throws InterruptedException {
return offerLast(e, timeout, unit);
}
@@ -741,14 +743,12 @@ public boolean offerFirst(final E e) {
*
* @param e element to link
* @param timeout length of time to wait
- *
* @return {@code true} if successful, otherwise {@code false}
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whilst waiting
* for space
*/
- public boolean offerFirst(final E e, final Duration timeout) throws InterruptedException {
+ boolean offerFirst(final E e, final Duration timeout) throws InterruptedException {
Objects.requireNonNull(e, "e");
long nanos = timeout.toNanos();
lock.lockInterruptibly();
@@ -772,13 +772,12 @@ public boolean offerFirst(final E e, final Duration timeout) throws InterruptedE
* @param e element to link
* @param timeout length of time to wait
* @param unit units that timeout is expressed in
- *
* @return {@code true} if successful, otherwise {@code false}
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whilst waiting
* for space
*/
+ @Override
public boolean offerFirst(final E e, final long timeout, final TimeUnit unit) throws InterruptedException {
return offerFirst(e, PoolImplUtils.toDuration(timeout, unit));
}
@@ -803,9 +802,7 @@ public boolean offerLast(final E e) {
*
* @param e element to link
* @param timeout length of time to wait
- *
* @return {@code true} if successful, otherwise {@code false}
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whist waiting
* for space
@@ -834,13 +831,12 @@ boolean offerLast(final E e, final Duration timeout) throws InterruptedException
* @param e element to link
* @param timeout length of time to wait
* @param unit units that timeout is expressed in
- *
* @return {@code true} if successful, otherwise {@code false}
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whist waiting
* for space
*/
+ @Override
public boolean offerLast(final E e, final long timeout, final TimeUnit unit) throws InterruptedException {
return offerLast(e, PoolImplUtils.toDuration(timeout, unit));
}
@@ -884,7 +880,6 @@ public E poll() {
*
This method is equivalent to {@link #pollFirst(long, TimeUnit)}.
*
* @param timeout length of time to wait
- *
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
@@ -900,10 +895,10 @@ E poll(final Duration timeout) throws InterruptedException {
*
* @param timeout length of time to wait
* @param unit units that timeout is expressed in
- *
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
+ @Override
public E poll(final long timeout, final TimeUnit unit) throws InterruptedException {
return pollFirst(timeout, unit);
}
@@ -923,7 +918,6 @@ public E pollFirst() {
* to do so if the queue is empty.
*
* @param timeout length of time to wait
- *
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
@@ -950,10 +944,10 @@ E pollFirst(final Duration timeout) throws InterruptedException {
*
* @param timeout length of time to wait
* @param unit units that timeout is expressed in
- *
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
+ @Override
public E pollFirst(final long timeout, final TimeUnit unit) throws InterruptedException {
return pollFirst(PoolImplUtils.toDuration(timeout, unit));
}
@@ -973,17 +967,15 @@ public E pollLast() {
* to do so if the queue is empty.
*
* @param timeout length of time to wait
- *
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
- public E pollLast(final Duration timeout)
- throws InterruptedException {
+ E pollLast(final Duration timeout) throws InterruptedException {
long nanos = timeout.toNanos();
lock.lockInterruptibly();
try {
E x;
- while ( (x = unlinkLast()) == null) {
+ while ((x = unlinkLast()) == null) {
if (nanos <= 0) {
return null;
}
@@ -1001,10 +993,10 @@ public E pollLast(final Duration timeout)
*
* @param timeout length of time to wait
* @param unit units that timeout is expressed in
- *
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
+ @Override
public E pollLast(final long timeout, final TimeUnit unit)
throws InterruptedException {
return pollLast(PoolImplUtils.toDuration(timeout, unit));
@@ -1035,11 +1027,11 @@ public void push(final E e) {
*
*
* @param e element to link
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whilst waiting
* for space
*/
+ @Override
public void put(final E e) throws InterruptedException {
putLast(e);
}
@@ -1049,11 +1041,11 @@ public void put(final E e) throws InterruptedException {
* is space to do so if the queue is full.
*
* @param e element to link
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whilst waiting
* for space
*/
+ @Override
public void putFirst(final E e) throws InterruptedException {
Objects.requireNonNull(e, "e");
lock.lock();
@@ -1071,11 +1063,11 @@ public void putFirst(final E e) throws InterruptedException {
* is space to do so if the queue is full.
*
* @param e element to link
- *
* @throws NullPointerException if e is null
* @throws InterruptedException if the thread is interrupted whilst waiting
* for space
*/
+ @Override
public void putLast(final E e) throws InterruptedException {
Objects.requireNonNull(e, "e");
lock.lock();
@@ -1088,15 +1080,12 @@ public void putLast(final E e) throws InterruptedException {
}
}
- // Stack methods
-
/**
- * Reconstitutes this deque from a stream (that is,
- * deserialize it).
+ * Reconstitutes this deque from a stream (that is, deserialize it).
+ *
* @param s the stream
*/
- private void readObject(final ObjectInputStream s)
- throws IOException, ClassNotFoundException {
+ private void readObject(final ObjectInputStream s) throws IOException, ClassNotFoundException {
s.defaultReadObject();
count = 0;
first = null;
@@ -1104,7 +1093,7 @@ private void readObject(final ObjectInputStream s)
// Read in all elements and place in queue
for (;;) {
@SuppressWarnings("unchecked")
- final E item = (E)s.readObject();
+ final E item = (E) s.readObject();
if (item == null) {
break;
}
@@ -1127,6 +1116,7 @@ private void readObject(final ObjectInputStream s)
*
* @return The number of additional elements the queue is able to accept
*/
+ @Override
public int remainingCapacity() {
lock.lock();
try {
@@ -1305,6 +1295,7 @@ public int size() {
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
+ @Override
public E take() throws InterruptedException {
return takeFirst();
}
@@ -1316,11 +1307,12 @@ public E take() throws InterruptedException {
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
+ @Override
public E takeFirst() throws InterruptedException {
lock.lock();
try {
E x;
- while ( (x = unlinkFirst()) == null) {
+ while ((x = unlinkFirst()) == null) {
notEmpty.await();
}
return x;
@@ -1336,11 +1328,12 @@ public E takeFirst() throws InterruptedException {
* @return the unlinked element
* @throws InterruptedException if the current thread is interrupted
*/
+ @Override
public E takeLast() throws InterruptedException {
lock.lock();
try {
E x;
- while ( (x = unlinkLast()) == null) {
+ while ((x = unlinkLast()) == null) {
notEmpty.await();
}
return x;
@@ -1389,12 +1382,11 @@ public T[] toArray(T[] a) {
lock.lock();
try {
if (a.length < count) {
- a = (T[])java.lang.reflect.Array.newInstance
- (a.getClass().getComponentType(), count);
+ a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), count);
}
int k = 0;
for (Node p = first; p != null; p = p.next) {
- a[k++] = (T)p.item;
+ a[k++] = (T) p.item;
}
if (a.length > k) {
a[k] = null;
diff --git a/src/main/java/org/apache/commons/pool2/impl/NoOpCallStack.java b/src/main/java/org/apache/commons/pool3/impl/NoOpCallStack.java
similarity index 92%
rename from src/main/java/org/apache/commons/pool2/impl/NoOpCallStack.java
rename to src/main/java/org/apache/commons/pool3/impl/NoOpCallStack.java
index 6cf4bd751..c01a9027c 100644
--- a/src/main/java/org/apache/commons/pool2/impl/NoOpCallStack.java
+++ b/src/main/java/org/apache/commons/pool3/impl/NoOpCallStack.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.io.PrintWriter;
@@ -27,7 +27,7 @@
public class NoOpCallStack implements CallStack {
/**
- * Singleton instance.
+ * The singleton instance.
*/
public static final CallStack INSTANCE = new NoOpCallStack();
diff --git a/src/main/java/org/apache/commons/pool2/impl/PoolImplUtils.java b/src/main/java/org/apache/commons/pool3/impl/PoolImplUtils.java
similarity index 96%
rename from src/main/java/org/apache/commons/pool2/impl/PoolImplUtils.java
rename to src/main/java/org/apache/commons/pool3/impl/PoolImplUtils.java
index 412c8f229..1abb5612f 100644
--- a/src/main/java/org/apache/commons/pool2/impl/PoolImplUtils.java
+++ b/src/main/java/org/apache/commons/pool3/impl/PoolImplUtils.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@@ -25,20 +25,19 @@
import java.util.Objects;
import java.util.concurrent.TimeUnit;
-import org.apache.commons.pool2.PooledObjectFactory;
+import org.apache.commons.pool3.PooledObjectFactory;
/**
* Implementation specific utilities.
*
* @since 2.0
*/
-class PoolImplUtils {
+final class PoolImplUtils {
/**
* Identifies the concrete type of object that an object factory creates.
*
* @param factoryClass The factory to examine
- *
* @return the type of object the factory creates
*/
@SuppressWarnings("rawtypes")
@@ -46,7 +45,7 @@ static Class> getFactoryType(final Class extends PooledObjectFactory> factor
final Class type = PooledObjectFactory.class;
final Object genericType = getGenericType(type, factoryClass);
if (genericType instanceof Integer) {
- // POOL-324 org.apache.commons.pool2.impl.GenericObjectPool.getFactoryType() throws
+ // POOL-324 org.apache.commons.pool3.impl.GenericObjectPool.getFactoryType() throws
// java.lang.ClassCastException
//
// A bit hackish, but we must handle cases when getGenericType() does not return a concrete types.
@@ -73,7 +72,6 @@ static Class> getFactoryType(final Class extends PooledObjectFactory> factor
* @param type The interface that defines a generic type
* @param clazz The class that implements the interface with a concrete type
* @param The interface type
- *
* @return concrete type used by the implementation
*/
private static Object getGenericType(final Class type, final Class extends T> clazz) {
@@ -135,7 +133,6 @@ private static ParameterizedType getParameterizedType(final Class type, f
*
* @param clazz defining class
* @param argType the type argument of interest
- *
* @return An instance of {@link Class} representing the type used by the type parameter or an instance of
* {@link Integer} representing the index for the type in the definition of the defining class
*/
@@ -227,7 +224,7 @@ static ChronoUnit toChronoUnit(final TimeUnit timeUnit) {
* @return a Duration.
*/
static Duration toDuration(final long amount, final TimeUnit timeUnit) {
- return Duration.of(amount, PoolImplUtils.toChronoUnit(timeUnit));
+ return Duration.of(amount, toChronoUnit(timeUnit));
}
}
diff --git a/src/main/java/org/apache/commons/pool2/impl/PooledSoftReference.java b/src/main/java/org/apache/commons/pool3/impl/PooledSoftReference.java
similarity index 97%
rename from src/main/java/org/apache/commons/pool2/impl/PooledSoftReference.java
rename to src/main/java/org/apache/commons/pool3/impl/PooledSoftReference.java
index be10346c5..2c78fb6c6 100644
--- a/src/main/java/org/apache/commons/pool2/impl/PooledSoftReference.java
+++ b/src/main/java/org/apache/commons/pool3/impl/PooledSoftReference.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.lang.ref.SoftReference;
diff --git a/src/main/java/org/apache/commons/pool3/impl/ResilientPooledObjectFactory.java b/src/main/java/org/apache/commons/pool3/impl/ResilientPooledObjectFactory.java
new file mode 100644
index 000000000..4d36c6e42
--- /dev/null
+++ b/src/main/java/org/apache/commons/pool3/impl/ResilientPooledObjectFactory.java
@@ -0,0 +1,541 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.pool3.impl;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import org.apache.commons.pool3.PooledObject;
+import org.apache.commons.pool3.PooledObjectFactory;
+
+/**
+ * Wraps a PooledObjectFactory, extending to provide resilient features.
+ *
+ * Maintains a circular log of makeObject calls and makes strategy-based
+ * decisions on whether to keep trying proactively to create objects.
+ * Decisions use data in the makeObject log and information reported by
+ * the pool that the factory is attached to.
+ *
+ *
+ * @param Type of object managed by the factory
+ * @param Type of exception that the factory may throw
+ */
+public class ResilientPooledObjectFactory implements PooledObjectFactory {
+
+ /**
+ * Adder thread that adds objects to the pool, waiting for a fixed delay between
+ * adds.
+ *
+ * The adder thread will stop under any of the following conditions:
+ *
+ *
+ *
The pool is closed.
+ *
The factory is down.
+ *
The pool is full.
+ *
The pool has no waiters.
+ *
+ */
+ final class Adder extends Thread {
+
+ private static final int MAX_FAILURES = 5;
+
+ private volatile boolean killed;
+ private volatile boolean running;
+ private int failures;
+
+ public boolean isRunning() {
+ return running;
+ }
+
+ public void kill() {
+ killed = true;
+ }
+
+ @Override
+ public void run() {
+ running = true;
+ while (!up && !killed && !pool.isClosed()) {
+ try {
+ pool.addObject();
+ if (pool.getNumWaiters() == 0 || pool.getNumActive() + pool.getNumIdle() == pool.getMaxTotal()) {
+ kill();
+ }
+ } catch (final Throwable e) {
+ failures++;
+ if (failures > MAX_FAILURES) {
+ kill();
+ }
+ } finally {
+ // Wait for delay
+ try {
+ sleep(delay.toMillis());
+ } catch (final InterruptedException e) {
+ kill();
+ }
+ }
+ }
+ kill();
+ running = false;
+ }
+ }
+
+ /**
+ * Record of a makeObject event.
+ */
+ static final class MakeEvent {
+ private final Instant startTime;
+ private Instant endTime;
+ private boolean success;
+ private Throwable exception;
+
+ /**
+ * Constructs a new instance and set statTime to now.
+ */
+ MakeEvent() {
+ startTime = Instant.now();
+ }
+
+ /**
+ * Mark completion of makeObject call.
+ */
+ public void end() {
+ this.endTime = Instant.now();
+ }
+
+ /**
+ * @return the time the makeObject call ended
+ */
+ public Instant getEndTime() {
+ return endTime;
+ }
+
+ /**
+ * @return the exception thrown by the makeObject call
+ */
+ public Throwable getException() {
+ return exception;
+ }
+
+ /**
+ * @return the start time of the makeObject call
+ */
+ public Instant getStartTime() {
+ return startTime;
+ }
+
+ /**
+ * @return true if the makeObject call succeeded
+ */
+ public boolean isSuccess() {
+ return success;
+ }
+
+ /**
+ * Set the exception thrown by the makeObject call.
+ *
+ * @param exception
+ */
+ public void setException(final Throwable exception) {
+ this.exception = exception;
+ }
+
+ /**
+ * Set the success status of the makeObject call.
+ *
+ * @param success
+ */
+ public void setSuccess(final boolean success) {
+ this.success = success;
+ }
+ }
+
+ /**
+ * Monitor thread that runs checks to examine the makeObject log and pool state.
+ */
+ final class Monitor extends Thread {
+ @Override
+ public void run() {
+ while (monitoring && !pool.isClosed()) {
+ runChecks();
+ try {
+ sleep(timeBetweenChecks.toMillis());
+ } catch (final InterruptedException e) {
+ monitoring = false;
+ } catch (final Throwable e) {
+ monitoring = false;
+ throw e;
+ }
+ }
+ monitoring = false;
+ }
+ }
+
+ private static final int DEFAULT_LOG_SIZE = 10;
+ private static final Duration DEFAULT_DELAY = Duration.ofSeconds(1);
+ private static final Duration DEFAULT_LOOK_BACK = Duration.ofMinutes(5);
+ private static final Duration DEFAULT_TIME_BETWEEN_CHECKS = Duration.ofSeconds(10);
+
+ /**
+ * Gets the default time between makeObject calls by the adder thread.
+ *
+ * @return the default time between makeObject calls by the adder thread.
+ */
+ public static Duration getDefaultDelay() {
+ return DEFAULT_DELAY;
+ }
+
+ /**
+ * Gets the default makeObject log size.
+ *
+ * @return the default makeObject log size.
+ */
+ public static int getDefaultLogSize() {
+ return DEFAULT_LOG_SIZE;
+ }
+
+ /**
+ * Gets the default look back duration.
+ *
+ * @return the default look back duration.
+ */
+ public static Duration getDefaultLookBack() {
+ return DEFAULT_LOOK_BACK;
+ }
+
+ /**
+ * Gets the default time between monitor checks.
+ *
+ * @return the default time between monitor checks.
+ */
+ public static Duration getDefaultTimeBetweenChecks() {
+ return DEFAULT_TIME_BETWEEN_CHECKS;
+ }
+
+ /** Wrapped factory */
+ private final PooledObjectFactory factory;
+
+ /** GOP that factory is attached to. */
+ private GenericObjectPool pool;
+
+ /** Size of the circular log of makeObject events */
+ private int logSize;
+
+ /** Duration of time window for statistics */
+ private final Duration lookBack;
+
+ /** Circular log of makeObject events */
+ private final ConcurrentLinkedQueue makeObjectLog = new ConcurrentLinkedQueue<>();
+
+ /** Time of last factory failure */
+ private Instant downStart;
+
+ /** Time factory last returned to "up" state. */
+ private Instant upStart;
+
+ /** Exception counts */
+ @SuppressWarnings("rawtypes")
+ private final ConcurrentHashMap exceptionCounts = new ConcurrentHashMap<>();
+
+ /** Whether or not the factory is "up" */
+ private boolean up = true;
+
+ /**
+ * @return the factory wrapped by this resilient factory
+ */
+ /** Whether or not the monitor thread is running */
+ private boolean monitoring;
+
+ /** Time to wait between object creations by the adder thread */
+ private final Duration delay;
+
+ /** Time between monitor checks */
+ private Duration timeBetweenChecks = Duration.ofSeconds(10);
+
+ // Delegate all other methods to the wrapped factory.
+
+ /** Adder thread */
+ private Adder adder;
+
+ /**
+ * Construct a ResilientPooledObjectFactory from a factory and pool, using
+ * defaults for logSize, delay, and lookBack.
+ *
+ * @param factory PooledObjectFactory to wrap
+ */
+ public ResilientPooledObjectFactory(final PooledObjectFactory factory) {
+ this(factory, DEFAULT_LOG_SIZE, DEFAULT_DELAY, DEFAULT_LOOK_BACK, DEFAULT_TIME_BETWEEN_CHECKS);
+ }
+
+ /**
+ * Construct a ResilientPooledObjectFactory from a factory with specified
+ * parameters.
+ *
+ * @param factory PooledObjectFactory to wrap
+ * @param logSize length of the makeObject log
+ * @param delay time to wait between object creations by the adder
+ * thread
+ * @param lookBack length of time over which metrics are kept
+ * @param timeBetweenChecks time between checks by the monitor thread
+ */
+ public ResilientPooledObjectFactory(final PooledObjectFactory factory,
+ final int logSize, final Duration delay, final Duration lookBack, final Duration timeBetweenChecks) {
+ this.logSize = logSize;
+ this.factory = factory;
+ this.delay = delay;
+ this.lookBack = lookBack;
+ this.timeBetweenChecks = timeBetweenChecks;
+ }
+
+ @Override
+ public void activateObject(final PooledObject p) throws E {
+ factory.activateObject(p);
+ }
+
+ @Override
+ public void destroyObject(final PooledObject p) throws E {
+ factory.destroyObject(p);
+ }
+
+ /**
+ * Gets the time to wait between object creations by the adder thread.
+ *
+ * @return the time to wait between object creations by the adder thread.
+ */
+ public Duration getDelay() {
+ return delay;
+ }
+
+ /**
+ * Gets the start time of the last factory outage.
+ *
+ * @return the start time of the last factory outage.
+ */
+ public Instant getDownStart() {
+ return downStart;
+ }
+
+ /**
+ * Gets the size of the makeObject log.
+ *
+ * @return the size of the makeObject log.
+ */
+ public int getLogSize() {
+ return logSize;
+ }
+
+ /**
+ * Gets the look back duration.
+ *
+ * @return the look back duration.
+ */
+ public Duration getLookBack() {
+ return lookBack;
+ }
+
+ /**
+ * Gets a copy of the makeObject log.
+ *
+ * @return a copy of the makeObject log.
+ */
+ public List getMakeObjectLog() {
+ final ArrayList makeObjectLog = new ArrayList<>();
+ return new ArrayList<>(makeObjectLog.stream().toList());
+ }
+
+ /**
+ * Gets the duration between monitor checks.
+ *
+ * @return the duration between monitor checks.
+ */
+ public Duration getTimeBetweenChecks() {
+ return timeBetweenChecks;
+ }
+
+ /**
+ * Gets the time of the last factory outage recovery.
+ *
+ * @return the time of the last factory outage recovery.
+ */
+ public Instant getUpStart() {
+ return upStart;
+ }
+
+ /**
+ * Tests whether the adder is running.
+ *
+ * @return true if the adder is running.
+ */
+ public boolean isAdderRunning() {
+ return adder != null && adder.isRunning();
+ }
+
+ /**
+ * Tests whether the monitor is running.
+ *
+ * @return true if the monitor is running.
+ */
+ public boolean isMonitorRunning() {
+ return monitoring;
+ }
+
+ /**
+ * Tests whether the factory is considered "up".
+ *
+ * @return true if the factory is considered "up".
+ */
+ public boolean isUp() {
+ return up;
+ }
+
+ /**
+ * Delegate to the wrapped factory, but log the makeObject call.
+ */
+ @Override
+ public PooledObject makeObject() throws E {
+ final MakeEvent makeEvent = new MakeEvent();
+ try {
+ final PooledObject obj = factory.makeObject();
+ makeEvent.setSuccess(PooledObject.nonNull(obj));
+ return obj;
+ } catch (final Throwable t) {
+ makeEvent.setSuccess(false);
+ makeEvent.setException(t);
+ exceptionCounts.put(t.getClass(), exceptionCounts.getOrDefault(t, 0) + 1);
+ throw t;
+ } finally {
+ makeEvent.end();
+ makeObjectLog.add(makeEvent);
+ }
+ }
+
+ @Override
+ public void passivateObject(final PooledObject p) throws E {
+ factory.passivateObject(p);
+ }
+
+ /**
+ * Default implementation considers the factory down as soon as a single
+ * makeObject call fails and considers it back up if the last logSize makes have
+ * succeeded.
+ *
+ * Sets downStart to time of the first failure found in makeObjectLog and
+ * upStart to the time when logSize consecutive makes have succeeded.
+ *
+ *
+ * When a failure is observed, the adder thread is started if the pool
+ * is not closed and has take waiters.
+ *
+ *
+ * Removes the oldest event from the log if it is full.
+ *
+ */
+ protected void runChecks() {
+ boolean upOverLog = true;
+ // 1. If the log is full, remove the oldest (first) event.
+ //
+ // 2. Walk the event log. If we find a failure, set downStart, set up to false
+ // and start the adder thread.
+ //
+ // 3. If the log contains only successes, if up is false, set upStart and up to
+ // true
+ // and kill the adder thread.
+ while (makeObjectLog.size() > logSize) {
+ makeObjectLog.poll();
+ }
+ for (final MakeEvent makeEvent : makeObjectLog) {
+ if (!makeEvent.isSuccess()) {
+ upOverLog = false;
+ downStart = Instant.now();
+ up = false;
+ if (pool.getNumWaiters() > 0 && !pool.isClosed() && adder == null) {
+ adder = new Adder();
+ adder.start();
+ }
+ }
+
+ }
+ if (upOverLog && !up) {
+ // Kill adder thread and set up to true
+ upStart = Instant.now();
+ up = true;
+ adder.kill();
+ adder = null;
+ }
+ }
+
+ /**
+ * Sets the makeObject log size.
+ *
+ * @param logSize the number of makeObject events to keep in the log
+ */
+ public void setLogSize(final int logSize) {
+ this.logSize = logSize;
+ }
+
+ /**
+ * Sets the underlying pool. For tests.
+ *
+ * @param pool the underlying pool.
+ */
+ void setPool(final GenericObjectPool pool) {
+ this.pool = pool;
+ }
+
+ /**
+ * Sets the time between monitor checks.
+ *
+ * @param timeBetweenChecks The time between monitor checks.
+ */
+ public void setTimeBetweenChecks(final Duration timeBetweenChecks) {
+ this.timeBetweenChecks = timeBetweenChecks;
+ }
+
+ /**
+ * Starts the monitor thread with the currently configured time between checks.
+ */
+ public void startMonitor() {
+ monitoring = true;
+ new Monitor().start();
+ }
+
+ /**
+ * Starts the monitor thread with the given time between checks.
+ *
+ * @param timeBetweenChecks time between checks
+ */
+ public void startMonitor(final Duration timeBetweenChecks) {
+ this.timeBetweenChecks = timeBetweenChecks;
+ startMonitor();
+ }
+
+ /**
+ * Stops the monitor thread.
+ */
+ public void stopMonitor() {
+ monitoring = false;
+ }
+
+ @Override
+ public boolean validateObject(final PooledObject p) {
+ return factory.validateObject(p);
+ }
+
+}
diff --git a/src/main/java/org/apache/commons/pool2/impl/SecurityManagerCallStack.java b/src/main/java/org/apache/commons/pool3/impl/SecurityManagerCallStack.java
similarity index 94%
rename from src/main/java/org/apache/commons/pool2/impl/SecurityManagerCallStack.java
rename to src/main/java/org/apache/commons/pool3/impl/SecurityManagerCallStack.java
index 1276e1d77..93b2f0dad 100644
--- a/src/main/java/org/apache/commons/pool2/impl/SecurityManagerCallStack.java
+++ b/src/main/java/org/apache/commons/pool3/impl/SecurityManagerCallStack.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
@@ -40,7 +40,7 @@ public class SecurityManagerCallStack implements CallStack {
/**
* A custom security manager.
*/
- private static class PrivateSecurityManager extends SecurityManager {
+ private static final class PrivateSecurityManager extends SecurityManager {
/**
* Gets the class stack.
@@ -56,7 +56,7 @@ private List>> getCallStack() {
/**
* A snapshot of a class stack.
*/
- private static class Snapshot {
+ private static final class Snapshot {
private final long timestampMillis = System.currentTimeMillis();
private final List>> stack;
diff --git a/src/main/java/org/apache/commons/pool2/impl/SoftReferenceObjectPool.java b/src/main/java/org/apache/commons/pool3/impl/SoftReferenceObjectPool.java
similarity index 80%
rename from src/main/java/org/apache/commons/pool2/impl/SoftReferenceObjectPool.java
rename to src/main/java/org/apache/commons/pool3/impl/SoftReferenceObjectPool.java
index c00e7cc7c..b61e71b0e 100644
--- a/src/main/java/org/apache/commons/pool2/impl/SoftReferenceObjectPool.java
+++ b/src/main/java/org/apache/commons/pool3/impl/SoftReferenceObjectPool.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,20 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.Collection;
import java.util.NoSuchElementException;
+import java.util.Objects;
import java.util.Optional;
+import java.util.concurrent.BlockingDeque;
-import org.apache.commons.pool2.BaseObjectPool;
-import org.apache.commons.pool2.ObjectPool;
-import org.apache.commons.pool2.PoolUtils;
-import org.apache.commons.pool2.PooledObjectFactory;
+import org.apache.commons.pool3.BaseObjectPool;
+import org.apache.commons.pool3.ObjectPool;
+import org.apache.commons.pool3.PoolUtils;
+import org.apache.commons.pool3.PooledObjectFactory;
/**
* A {@link java.lang.ref.SoftReference SoftReference} based {@link ObjectPool}.
@@ -44,7 +46,7 @@
*/
public class SoftReferenceObjectPool extends BaseObjectPool {
- /** Factory to source pooled objects */
+ /** Factory to source pooled objects. */
private final PooledObjectFactory factory;
/**
@@ -60,25 +62,22 @@ public class SoftReferenceObjectPool extends BaseObjectP
/** Total number of instances that have been destroyed */
private long destroyCount; // @GuardedBy("this")
-
/** Total number of instances that have been created */
private long createCount; // @GuardedBy("this")
/** Idle references - waiting to be borrowed */
- private final LinkedBlockingDeque> idleReferences =
- new LinkedBlockingDeque<>();
+ private final BlockingDeque> idleReferences = new LinkedBlockingDeque<>();
/** All references - checked out or waiting to be borrowed. */
- private final ArrayList> allReferences =
- new ArrayList<>();
+ private final ArrayList> allReferences = new ArrayList<>();
/**
* Constructs a {@code SoftReferenceObjectPool} with the specified factory.
*
- * @param factory object factory to use.
+ * @param factory non-null object factory to use.
*/
public SoftReferenceObjectPool(final PooledObjectFactory factory) {
- this.factory = factory;
+ this.factory = Objects.requireNonNull(factory, "factory");
}
/**
@@ -87,12 +86,12 @@ public SoftReferenceObjectPool(final PooledObjectFactory factory) {
*
* Before being added to the pool, the newly created instance is
* {@link PooledObjectFactory#validateObject(
- * org.apache.commons.pool2.PooledObject) validated} and
+ * org.apache.commons.pool3.PooledObject) validated} and
* {@link PooledObjectFactory#passivateObject(
- * org.apache.commons.pool2.PooledObject) passivated}. If
+ * org.apache.commons.pool3.PooledObject) passivated}. If
* validation fails, the new instance is
* {@link PooledObjectFactory#destroyObject(
- * org.apache.commons.pool2.PooledObject) destroyed}. Exceptions
+ * org.apache.commons.pool3.PooledObject) destroyed}. Exceptions
* generated by the factory {@code makeObject} or
* {@code passivate} are propagated to the caller. Exceptions
* destroying instances are silently swallowed.
@@ -107,15 +106,10 @@ public SoftReferenceObjectPool(final PooledObjectFactory factory) {
@Override
public synchronized void addObject() throws E {
assertOpen();
- if (factory == null) {
- throw new IllegalStateException(
- "Cannot add objects without a factory.");
- }
final T obj = factory.makeObject().getObject();
createCount++;
// Create and register with the queue
- final PooledSoftReference ref = new PooledSoftReference<>(
- new SoftReference<>(obj, refQueue));
+ final PooledSoftReference ref = new PooledSoftReference<>(new SoftReference<>(obj, refQueue));
allReferences.add(ref);
boolean success = true;
@@ -147,13 +141,13 @@ public synchronized void addObject() throws E {
* new instance.
*
* All instances are {@link PooledObjectFactory#activateObject(
- * org.apache.commons.pool2.PooledObject) activated}
+ * org.apache.commons.pool3.PooledObject) activated}
* and {@link PooledObjectFactory#validateObject(
- * org.apache.commons.pool2.PooledObject)
+ * org.apache.commons.pool3.PooledObject)
* validated} before being returned by this method. If validation fails or
* an exception occurs activating or validating an idle instance, the
* failing instance is {@link PooledObjectFactory#destroyObject(
- * org.apache.commons.pool2.PooledObject)
+ * org.apache.commons.pool3.PooledObject)
* destroyed} and another instance is retrieved from the pool, validated and
* activated. This process continues until either the pool is empty or an
* instance passes validation. If the pool is empty on activation or it does
@@ -184,9 +178,6 @@ public synchronized T borrowObject() throws E {
PooledSoftReference ref = null;
while (null == obj) {
if (idleReferences.isEmpty()) {
- if (null == factory) {
- throw new NoSuchElementException();
- }
newlyCreated = true;
obj = factory.makeObject().getObject();
createCount++;
@@ -202,7 +193,7 @@ public synchronized T borrowObject() throws E {
ref.getReference().clear();
ref.setReference(new SoftReference<>(obj));
}
- if (null != factory && null != obj) {
+ if (null != obj) {
try {
factory.activateObject(ref);
if (!factory.validateObject(ref)) {
@@ -234,17 +225,15 @@ public synchronized T borrowObject() throws E {
*/
@Override
public synchronized void clear() {
- if (null != factory) {
- idleReferences.forEach(ref -> {
- try {
- if (null != ref.getObject()) {
- factory.destroyObject(ref);
- }
- } catch (final Exception ignored) {
- // ignored, keep destroying the rest
+ idleReferences.forEach(pooledSoftRef -> {
+ try {
+ if (null != pooledSoftRef.getObject()) {
+ factory.destroyObject(pooledSoftRef);
}
- });
- }
+ } catch (final Exception ignored) {
+ // ignored, keep destroying the rest
+ }
+ });
idleReferences.clear();
pruneClearedReferences();
}
@@ -265,11 +254,10 @@ public void close() {
}
/**
- * Destroys a {@code PooledSoftReference} and removes it from the idle and all
+ * Destroys a {@link PooledSoftReference} and removes it from the idle and all
* references pools.
*
* @param toDestroy PooledSoftReference to destroy
- *
* @throws E If an error occurs while trying to destroy the object
*/
private void destroy(final PooledSoftReference toDestroy) throws E {
@@ -292,7 +280,7 @@ private void destroy(final PooledSoftReference toDestroy) throws E {
*/
private PooledSoftReference findReference(final T obj) {
final Optional> first = allReferences.stream()
- .filter(reference -> reference.getObject() != null && reference.getObject().equals(obj)).findFirst();
+ .filter(reference -> Objects.equals(reference.getObject(), obj)).findFirst();
return first.orElse(null);
}
@@ -335,12 +323,9 @@ public synchronized int getNumIdle() {
public synchronized void invalidateObject(final T obj) throws E {
final PooledSoftReference ref = findReference(obj);
if (ref == null) {
- throw new IllegalStateException(
- "Object to invalidate is not currently part of this pool");
- }
- if (factory != null) {
- destroy(ref);
+ throw new IllegalStateException("Object to invalidate is not currently part of this pool");
}
+ destroy(ref);
numActive--;
notifyAll(); // numActive has changed
}
@@ -351,24 +336,20 @@ public synchronized void invalidateObject(final T obj) throws E {
*/
private void pruneClearedReferences() {
// Remove wrappers for enqueued references from idle and allReferences lists
- removeClearedReferences(idleReferences.iterator());
- removeClearedReferences(allReferences.iterator());
- while (refQueue.poll() != null) { // NOPMD
+ removeClearedReferences(idleReferences);
+ removeClearedReferences(allReferences);
+ while (refQueue.poll() != null) {
+ // loop until null
}
}
/**
- * Clears cleared references from iterator's collection
- * @param iterator iterator over idle/allReferences
+ * Clears cleared references from the collection.
+ *
+ * @param collection collection of idle/allReferences
*/
- private void removeClearedReferences(final Iterator> iterator) {
- PooledSoftReference ref;
- while (iterator.hasNext()) {
- ref = iterator.next();
- if (ref.getReference() == null || ref.getReference().isEnqueued()) {
- iterator.remove();
- }
- }
+ private void removeClearedReferences(final Collection> collection) {
+ collection.removeIf(ref -> ref.getReference() == null || ref.getReference().isEnqueued());
}
/**
@@ -378,10 +359,10 @@ private void removeClearedReferences(final Iterator> iter
*
* Exceptions passivating or destroying instances are silently swallowed.
@@ -397,18 +378,15 @@ public synchronized void returnObject(final T obj) throws E {
boolean success = !isClosed();
final PooledSoftReference ref = findReference(obj);
if (ref == null) {
- throw new IllegalStateException(
- "Returned object not currently part of this pool");
+ throw new IllegalStateException("Returned object not currently part of this pool");
}
- if (factory != null) {
- if (!factory.validateObject(ref)) {
+ if (!factory.validateObject(ref)) {
+ success = false;
+ } else {
+ try {
+ factory.passivateObject(ref);
+ } catch (final Exception e) {
success = false;
- } else {
- try {
- factory.passivateObject(ref);
- } catch (final Exception e) {
- success = false;
- }
}
}
@@ -422,7 +400,7 @@ public synchronized void returnObject(final T obj) throws E {
}
notifyAll(); // numActive has changed
- if (shouldDestroy && factory != null) {
+ if (shouldDestroy) {
try {
destroy(ref);
} catch (final Exception ignored) {
diff --git a/src/main/java/org/apache/commons/pool2/impl/ThrowableCallStack.java b/src/main/java/org/apache/commons/pool3/impl/ThrowableCallStack.java
similarity index 94%
rename from src/main/java/org/apache/commons/pool2/impl/ThrowableCallStack.java
rename to src/main/java/org/apache/commons/pool3/impl/ThrowableCallStack.java
index b220ab374..1af88d979 100644
--- a/src/main/java/org/apache/commons/pool2/impl/ThrowableCallStack.java
+++ b/src/main/java/org/apache/commons/pool3/impl/ThrowableCallStack.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
import java.io.PrintWriter;
import java.text.DateFormat;
@@ -33,7 +33,7 @@ public class ThrowableCallStack implements CallStack {
/**
* A snapshot of a throwable.
*/
- private static class Snapshot extends Throwable {
+ private static final class Snapshot extends Throwable {
private static final long serialVersionUID = 1L;
private final long timestampMillis = System.currentTimeMillis();
}
diff --git a/src/main/java/org/apache/commons/pool2/impl/package-info.java b/src/main/java/org/apache/commons/pool3/impl/package-info.java
similarity index 66%
rename from src/main/java/org/apache/commons/pool2/impl/package-info.java
rename to src/main/java/org/apache/commons/pool3/impl/package-info.java
index 7bbd45666..f2bde5733 100644
--- a/src/main/java/org/apache/commons/pool2/impl/package-info.java
+++ b/src/main/java/org/apache/commons/pool3/impl/package-info.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,16 +18,16 @@
/**
* Object pooling API implementations.
*
- * {@link org.apache.commons.pool2.impl.GenericObjectPool GenericObjectPool} ({@link org.apache.commons.pool2.impl.GenericKeyedObjectPool
- * GenericKeyedObjectPool}) provides a more robust (but also more complicated) implementation of {@link org.apache.commons.pool2.ObjectPool ObjectPool}
- * ({@link org.apache.commons.pool2.KeyedObjectPool KeyedObjectPool}).
+ * {@link org.apache.commons.pool3.impl.GenericObjectPool GenericObjectPool} ({@link org.apache.commons.pool3.impl.GenericKeyedObjectPool
+ * GenericKeyedObjectPool}) provides a more robust (but also more complicated) implementation of {@link org.apache.commons.pool3.ObjectPool ObjectPool}
+ * ({@link org.apache.commons.pool3.KeyedObjectPool KeyedObjectPool}).
*
*
- * {@link org.apache.commons.pool2.impl.SoftReferenceObjectPool SoftReferenceObjectPool} provides a {@link java.lang.ref.SoftReference SoftReference} based
- * {@link org.apache.commons.pool2.ObjectPool ObjectPool}.
+ * {@link org.apache.commons.pool3.impl.SoftReferenceObjectPool SoftReferenceObjectPool} provides a {@link java.lang.ref.SoftReference SoftReference} based
+ * {@link org.apache.commons.pool3.ObjectPool ObjectPool}.
*
*
- * See also the {@link org.apache.commons.pool2} package.
+ * See also the {@link org.apache.commons.pool3} package.
*
*/
-package org.apache.commons.pool2.impl;
+package org.apache.commons.pool3.impl;
diff --git a/src/main/java/org/apache/commons/pool2/package-info.java b/src/main/java/org/apache/commons/pool3/package-info.java
similarity index 56%
rename from src/main/java/org/apache/commons/pool2/package-info.java
rename to src/main/java/org/apache/commons/pool3/package-info.java
index 3a48b23f6..98f209f07 100644
--- a/src/main/java/org/apache/commons/pool2/package-info.java
+++ b/src/main/java/org/apache/commons/pool3/package-info.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,26 +18,26 @@
/**
* Object pooling API.
*
- * The org.apache.commons.pool2 package defines a simple interface for a pool of object instances, and a handful of base classes that may be useful
+ * The {@code org.apache.commons.pool3} package defines a simple interface for a pool of object instances, and a handful of base classes that may be useful
* when creating pool implementations.
*
*
- * The pool package itself doesn't define a specific object pooling implementation, but rather a contract that implementations may support in order
+ * The {@code pool} package itself doesn't define a specific object pooling implementation, but rather a contract that implementations may support in order
* to be fully interchangeable.
*
*
- * The pool package separates the way in which instances are pooled from the way in which they are created, resulting in a pair of interfaces:
+ * The {@code pool} package separates the way in which instances are pooled from the way in which they are created, resulting in a pair of interfaces:
*
defines lifecycle methods for object instances contained within a pool. By associating a factory with a pool, the pool can create new object instances as
* needed.
*
*
- * The pool package also provides a keyed pool interface, which pools instances of multiple types, accessed according to an arbitrary key. See
- * {@link org.apache.commons.pool2.KeyedObjectPool KeyedObjectPool} and {@link org.apache.commons.pool2.KeyedPooledObjectFactory KeyedPooledObjectFactory}.
+ * The {@code pool} package also provides a keyed pool interface, which pools instances of multiple types, accessed according to an arbitrary key. See
+ * {@link org.apache.commons.pool3.KeyedObjectPool KeyedObjectPool} and {@link org.apache.commons.pool3.KeyedPooledObjectFactory KeyedPooledObjectFactory}.
*
*/
-package org.apache.commons.pool2;
+package org.apache.commons.pool3;
diff --git a/src/main/java/org/apache/commons/pool3/proxy/AbstractProxySource.java b/src/main/java/org/apache/commons/pool3/proxy/AbstractProxySource.java
new file mode 100644
index 000000000..fafc70224
--- /dev/null
+++ b/src/main/java/org/apache/commons/pool3/proxy/AbstractProxySource.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.pool3.proxy;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.function.Supplier;
+
+/**
+ * Abstracts a proxy source implementation.
+ *
+ * @param type of the pooled object to be proxied.
+ * @since 3.0.0
+ */
+public abstract class AbstractProxySource implements ProxySource {
+
+ /**
+ * Abstract a builder implementations.
+ *
+ * @param type of the pooled object to be proxied.
+ * @param
the AbstractProxySource subclass
+ * @param the builder subclass.
+ */
+ public abstract static class AbstractBuilder> implements Supplier
{
+
+ /**
+ * Whether the proxy throws {@link InvocationTargetException#getTargetException()} instead of {@link InvocationTargetException}.
+ */
+ protected boolean unwrapInvocationTargetException;
+
+ /**
+ * Constructs a new instance for a subclass.
+ */
+ public AbstractBuilder() {
+ // empty
+ }
+
+ /**
+ * Returns {@code this} instance typed as a subclass.
+ *
+ * @return {@code this} instance typed as a subclass.
+ */
+ @SuppressWarnings("unchecked")
+ B asThis() {
+ return (B) this;
+ }
+
+ /**
+ * Sets whether the proxy throws {@link InvocationTargetException#getTargetException()} instead of {@link InvocationTargetException}.
+ *
+ * @param unwrapInvocationTargetException whether the proxy throws {@link InvocationTargetException#getTargetException()} instead of
+ * {@link InvocationTargetException}.
+ * @return {@code this} instance.
+ */
+ public B setUnwrapInvocationTargetException(final boolean unwrapInvocationTargetException) {
+ this.unwrapInvocationTargetException = unwrapInvocationTargetException;
+ return asThis();
+ }
+ }
+
+ /**
+ * Whether the proxy throws {@link InvocationTargetException#getTargetException()} instead of {@link InvocationTargetException}.
+ */
+ private final boolean unwrapInvocationTargetException;
+
+ /**
+ * Constructs a new instance.
+ *
+ * @param builder Information used to build the new instance.
+ */
+ protected AbstractProxySource(final AbstractBuilder builder) {
+ this.unwrapInvocationTargetException = builder.unwrapInvocationTargetException;
+ }
+
+ /**
+ * Tests whether the proxy throws {@link InvocationTargetException#getTargetException()} instead of {@link InvocationTargetException}.
+ *
+ * @return whether the proxy throws {@link InvocationTargetException#getTargetException()} instead of {@link InvocationTargetException}.
+ */
+ protected boolean isUnwrapInvocationTargetException() {
+ return unwrapInvocationTargetException;
+ }
+}
diff --git a/src/main/java/org/apache/commons/pool2/proxy/BaseProxyHandler.java b/src/main/java/org/apache/commons/pool3/proxy/BaseProxyHandler.java
similarity index 73%
rename from src/main/java/org/apache/commons/pool2/proxy/BaseProxyHandler.java
rename to src/main/java/org/apache/commons/pool3/proxy/BaseProxyHandler.java
index c22798df1..085caab16 100644
--- a/src/main/java/org/apache/commons/pool2/proxy/BaseProxyHandler.java
+++ b/src/main/java/org/apache/commons/pool3/proxy/BaseProxyHandler.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,40 +14,42 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.proxy;
+package org.apache.commons.pool3.proxy;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import org.apache.commons.pool2.UsageTracking;
+import org.apache.commons.pool3.UsageTracking;
/**
* Base implementation for object wrappers when using a
* {@link ProxiedObjectPool}.
*
* @param type of the wrapped pooled object
- *
* @since 2.0
*/
class BaseProxyHandler {
private volatile T pooledObject;
private final UsageTracking usageTracking;
-
+ private final boolean unwrapInvocationTargetException;
/**
* Constructs a new wrapper for the given pooled object.
*
- * @param pooledObject The object to wrap
- * @param usageTracking The instance, if any (usually the object pool) to
- * be provided with usage tracking information for this
- * wrapped object
+ * @param pooledObject The object to wrap
+ * @param usageTracking The instance, if any (usually the object pool) to
+ * be provided with usage tracking information for this
+ * wrapped object
+ * @param unwrapInvocationTargetException True to make the proxy throw {@link InvocationTargetException#getTargetException()}
+ * instead of {@link InvocationTargetException}
*/
- BaseProxyHandler(final T pooledObject, final UsageTracking usageTracking) {
+ BaseProxyHandler(final T pooledObject, final UsageTracking usageTracking, final boolean unwrapInvocationTargetException) {
this.pooledObject = pooledObject;
this.usageTracking = usageTracking;
+ this.unwrapInvocationTargetException = unwrapInvocationTargetException;
}
-
/**
* Disable the proxy wrapper. Called when the object has been returned to
* the pool. Further use of the wrapper should result in an
@@ -61,7 +63,6 @@ T disableProxy() {
return result;
}
-
/**
* Invoke the given method on the wrapped object.
*
@@ -76,10 +77,16 @@ Object doInvoke(final Method method, final Object[] args) throws Throwable {
if (usageTracking != null) {
usageTracking.use(object);
}
- return method.invoke(object, args);
+ try {
+ return method.invoke(object, args);
+ } catch (final InvocationTargetException e) {
+ if (unwrapInvocationTargetException) {
+ throw e.getTargetException();
+ }
+ throw e;
+ }
}
-
/**
* Gets the wrapped, pooled object.
*
@@ -89,7 +96,6 @@ T getPooledObject() {
return pooledObject;
}
-
/**
* @since 2.4.3
*/
@@ -105,7 +111,6 @@ public String toString() {
return builder.toString();
}
-
/**
* Check that the proxy is still valid (i.e. that {@link #disableProxy()}
* has not been called).
diff --git a/src/main/java/org/apache/commons/pool2/proxy/CglibProxyHandler.java b/src/main/java/org/apache/commons/pool3/proxy/CglibProxyHandler.java
similarity index 52%
rename from src/main/java/org/apache/commons/pool2/proxy/CglibProxyHandler.java
rename to src/main/java/org/apache/commons/pool3/proxy/CglibProxyHandler.java
index 63ce61bc9..da3dd255c 100644
--- a/src/main/java/org/apache/commons/pool2/proxy/CglibProxyHandler.java
+++ b/src/main/java/org/apache/commons/pool3/proxy/CglibProxyHandler.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,41 +14,43 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.proxy;
+package org.apache.commons.pool3.proxy;
+
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import org.apache.commons.pool2.UsageTracking;
+import org.apache.commons.pool3.UsageTracking;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
/**
+ * cglib is unmaintained and does not work well (or possibly at all?) in newer JDKs, particularly JDK17+; see https://github.com/cglib/cglib
+ *
* CGLib implementation of the proxy handler.
+ *
*
* @param type of the wrapped pooled object
- *
* @since 2.0
*/
-class CglibProxyHandler extends BaseProxyHandler
- implements MethodInterceptor {
-
+final class CglibProxyHandler extends BaseProxyHandler implements MethodInterceptor {
/**
* Constructs a CGLib proxy instance.
*
- * @param pooledObject The object to wrap
- * @param usageTracking The instance, if any (usually the object pool) to
- * be provided with usage tracking information for this
- * wrapped object
+ * @param pooledObject The object to wrap
+ * @param usageTracking The instance, if any (usually the object pool) to be provided with usage tracking information for this wrapped
+ * object
+ * @param unwrapInvocationTargetException True to make the proxy throw {@link InvocationTargetException#getTargetException()} instead of
+ * {@link InvocationTargetException}
*/
- CglibProxyHandler(final T pooledObject, final UsageTracking usageTracking) {
- super(pooledObject, usageTracking);
+ CglibProxyHandler(final T pooledObject, final UsageTracking usageTracking, final boolean unwrapInvocationTargetException) {
+ super(pooledObject, usageTracking, unwrapInvocationTargetException);
}
@Override
- public Object intercept(final Object object, final Method method, final Object[] args,
- final MethodProxy methodProxy) throws Throwable {
+ public Object intercept(final Object object, final Method method, final Object[] args, final MethodProxy methodProxy) throws Throwable {
return doInvoke(method, args);
}
}
diff --git a/src/main/java/org/apache/commons/pool3/proxy/CglibProxySource.java b/src/main/java/org/apache/commons/pool3/proxy/CglibProxySource.java
new file mode 100644
index 000000000..4bb9fde0b
--- /dev/null
+++ b/src/main/java/org/apache/commons/pool3/proxy/CglibProxySource.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.pool3.proxy;
+
+import org.apache.commons.pool3.UsageTracking;
+
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.Factory;
+
+/**
+ * cglib is unmaintained and does not work well (or possibly at all?) in newer JDKs, particularly JDK17+; see https://github.com/cglib/cglib
+ *
+ * Provides proxy objects using CGLib.
+ *
+ *
+ * @param type of the pooled object to be proxied.
+ * @since 2.0
+ */
+public class CglibProxySource extends AbstractProxySource {
+
+ /**
+ * Builds instances of {@link CglibProxySource}.
+ *
+ * @param type of the pooled object to be proxied.
+ * @since 3.0.0
+ */
+ public static class Builder extends AbstractBuilder, Builder> {
+
+ private Class extends T> superclass;
+
+ /**
+ * Constructs a new instance.
+ */
+ public Builder() {
+ // empty
+ }
+
+ @Override
+ public CglibProxySource get() {
+ return new CglibProxySource<>(this);
+ }
+
+ /**
+ * Sets the superclass.
+ *
+ * @param superclass the superclass.
+ * @return {@code this} instance.
+ */
+ public Builder setSuperclass(final Class extends T> superclass) {
+ this.superclass = superclass;
+ return asThis();
+ }
+ }
+
+ /**
+ * Constructs a new builder of {@link CglibProxySource}.
+ *
+ * @param type of the pooled object to be proxied.
+ * @return a new builder of {@link CglibProxySource}.
+ * @since 3.0.0
+ */
+ public static Builder builder() {
+ return new Builder<>();
+ }
+
+ private final Class extends T> superclass;
+
+ private CglibProxySource(final Builder builder) {
+ super(builder);
+ this.superclass = builder.superclass;
+ }
+
+ /**
+ * Constructs a new proxy source for the given class.
+ *
+ * For additional features, use a {@link #builder()}.
+ *
+ * @param superclass The class to proxy
+ */
+ public CglibProxySource(final Class extends T> superclass) {
+ super(builder());
+ this.superclass = superclass;
+ }
+
+ @SuppressWarnings("unchecked") // Case to T on return
+ @Override
+ public T createProxy(final T pooledObject, final UsageTracking usageTracking) {
+ final Enhancer enhancer = new Enhancer();
+ enhancer.setSuperclass(superclass);
+ final CglibProxyHandler proxyInterceptor = new CglibProxyHandler<>(pooledObject, usageTracking, isUnwrapInvocationTargetException());
+ enhancer.setCallback(proxyInterceptor);
+ return (T) enhancer.create();
+ }
+
+ @Override
+ public T resolveProxy(final T proxy) {
+ @SuppressWarnings("unchecked")
+ final CglibProxyHandler cglibProxyHandler = (CglibProxyHandler) ((Factory) proxy).getCallback(0);
+ return cglibProxyHandler.disableProxy();
+ }
+
+ /**
+ * Converts this instance to a string suitable for debugging.
+ *
+ * @since 2.4.3
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("CglibProxySource [superclass=");
+ builder.append(superclass);
+ builder.append("]");
+ return builder.toString();
+ }
+}
diff --git a/src/main/java/org/apache/commons/pool2/proxy/JdkProxyHandler.java b/src/main/java/org/apache/commons/pool3/proxy/JdkProxyHandler.java
similarity index 56%
rename from src/main/java/org/apache/commons/pool2/proxy/JdkProxyHandler.java
rename to src/main/java/org/apache/commons/pool3/proxy/JdkProxyHandler.java
index 451a6b7fb..d6d72e383 100644
--- a/src/main/java/org/apache/commons/pool2/proxy/JdkProxyHandler.java
+++ b/src/main/java/org/apache/commons/pool3/proxy/JdkProxyHandler.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,40 +14,38 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.proxy;
+
+package org.apache.commons.pool3.proxy;
import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import org.apache.commons.pool2.UsageTracking;
+import org.apache.commons.pool3.UsageTracking;
/**
* Java reflection implementation of the proxy handler.
*
* @param type of the wrapped pooled object
- *
* @since 2.0
*/
-class JdkProxyHandler extends BaseProxyHandler
- implements InvocationHandler {
+final class JdkProxyHandler extends BaseProxyHandler implements InvocationHandler {
/**
* Constructs a Java reflection proxy instance.
*
- * @param pooledObject The object to wrap
- * @param usageTracking The instance, if any (usually the object pool) to
- * be provided with usage tracking information for this
- * wrapped object
+ * @param pooledObject The object to wrap
+ * @param usageTracking The instance, if any (usually the object pool) to be provided with usage tracking information for this wrapped
+ * object
+ * @param unwrapInvocationTargetException True to make the proxy throw {@link InvocationTargetException#getTargetException()} instead of
+ * {@link InvocationTargetException}
*/
- JdkProxyHandler(final T pooledObject, final UsageTracking usageTracking) {
- super(pooledObject, usageTracking);
+ JdkProxyHandler(final T pooledObject, final UsageTracking usageTracking, final boolean unwrapInvocationTargetException) {
+ super(pooledObject, usageTracking, unwrapInvocationTargetException);
}
-
@Override
- public Object invoke(final Object proxy, final Method method, final Object[] args)
- throws Throwable {
+ public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
return doInvoke(method, args);
}
}
-
diff --git a/src/main/java/org/apache/commons/pool3/proxy/JdkProxySource.java b/src/main/java/org/apache/commons/pool3/proxy/JdkProxySource.java
new file mode 100644
index 000000000..6d2b5dbed
--- /dev/null
+++ b/src/main/java/org/apache/commons/pool3/proxy/JdkProxySource.java
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.pool3.proxy;
+
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+
+import org.apache.commons.pool3.UsageTracking;
+
+/**
+ * Provides proxy objects using Java reflection.
+ *
+ * @param type of the pooled object to be proxied
+ * @since 2.0
+ */
+public class JdkProxySource extends AbstractProxySource {
+
+ /**
+ * Builds instances of {@link JdkProxySource}.
+ *
+ * @param type of the pooled object to be proxied.
+ * @since 3.0.0
+ */
+ public static class Builder extends AbstractBuilder, Builder> {
+
+ private ClassLoader classLoader;
+ private Class>[] interfaces;
+
+ /**
+ * Constructs a new instance.
+ */
+ public Builder() {
+ // empty
+ }
+
+ @Override
+ public JdkProxySource get() {
+ return new JdkProxySource<>(this);
+ }
+
+ /**
+ * Sets the class loader to define the proxy class.
+ *
+ * @param classLoader the class loader to define the proxy class.
+ * @return {@code this} instance.
+ */
+ public Builder setClassLoader(final ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ return asThis();
+ }
+
+ /**
+ * Sets the list of interfaces for the proxy class.
+ *
+ * @param interfaces the list of interfaces for the proxy class.
+ * @return {@code this} instance.
+ */
+ public Builder setInterfaces(final Class>... interfaces) {
+ this.interfaces = interfaces != null ? interfaces.clone() : null;
+ return asThis();
+ }
+ }
+
+ /**
+ * Constructs a new builder of {@link CglibProxySource}.
+ *
+ * @param type of the pooled object to be proxied.
+ * @return a new builder of {@link CglibProxySource}.
+ * @since 3.0.0
+ */
+ public static Builder builder() {
+ return new Builder<>();
+ }
+
+ /** The class loader to define the proxy class. */
+ private final ClassLoader classLoader;
+
+ /** The list of interfaces for the proxy class to implement. */
+ private final Class>[] interfaces;
+
+ private JdkProxySource(final Builder builder) {
+ super(builder);
+ this.classLoader = builder.classLoader;
+ this.interfaces = builder.interfaces;
+ }
+
+ /**
+ * Constructs a new proxy source for the given interfaces.
+ *
+ * For additional features, use a {@link #builder()}.
+ *
+ *
+ * @param classLoader The class loader with which to create the proxy
+ * @param interfaces The interfaces to proxy
+ */
+ public JdkProxySource(final ClassLoader classLoader, final Class>[] interfaces) {
+ super(builder());
+ this.classLoader = classLoader;
+ this.interfaces = interfaces.clone();
+ }
+
+ @SuppressWarnings("unchecked") // Cast to T on return.
+ @Override
+ public T createProxy(final T pooledObject, final UsageTracking usageTracking) {
+ return (T) Proxy.newProxyInstance(classLoader, interfaces, new JdkProxyHandler<>(pooledObject, usageTracking, isUnwrapInvocationTargetException()));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T resolveProxy(final T proxy) {
+ return ((JdkProxyHandler) Proxy.getInvocationHandler(proxy)).disableProxy();
+ }
+
+ /**
+ * @since 2.4.3
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("JdkProxySource [classLoader=");
+ builder.append(classLoader);
+ builder.append(", interfaces=");
+ builder.append(Arrays.toString(interfaces));
+ builder.append("]");
+ return builder.toString();
+ }
+}
diff --git a/src/main/java/org/apache/commons/pool2/proxy/ProxiedKeyedObjectPool.java b/src/main/java/org/apache/commons/pool3/proxy/ProxiedKeyedObjectPool.java
similarity index 95%
rename from src/main/java/org/apache/commons/pool2/proxy/ProxiedKeyedObjectPool.java
rename to src/main/java/org/apache/commons/pool3/proxy/ProxiedKeyedObjectPool.java
index 38a6c4a59..b874d687f 100644
--- a/src/main/java/org/apache/commons/pool2/proxy/ProxiedKeyedObjectPool.java
+++ b/src/main/java/org/apache/commons/pool3/proxy/ProxiedKeyedObjectPool.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,13 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.proxy;
+package org.apache.commons.pool3.proxy;
import java.util.List;
import java.util.NoSuchElementException;
-import org.apache.commons.pool2.KeyedObjectPool;
-import org.apache.commons.pool2.UsageTracking;
+import org.apache.commons.pool3.KeyedObjectPool;
+import org.apache.commons.pool3.UsageTracking;
/**
* Create a new keyed object pool where the pooled objects are wrapped in
@@ -31,7 +31,6 @@
* @param type of the key
* @param type of the pooled object
* @param type of exception thrown by this pool
- *
* @since 2.0
*/
public class ProxiedKeyedObjectPool implements KeyedObjectPool {
@@ -39,7 +38,6 @@ public class ProxiedKeyedObjectPool implements KeyedO
private final KeyedObjectPool pool;
private final ProxySource proxySource;
-
/**
* Constructs a new proxied object pool.
*
@@ -52,7 +50,6 @@ public ProxiedKeyedObjectPool(final KeyedObjectPool pool,
this.proxySource = proxySource;
}
-
@Override
public void addObject(final K key) throws E, IllegalStateException,
UnsupportedOperationException {
diff --git a/src/main/java/org/apache/commons/pool2/proxy/ProxiedObjectPool.java b/src/main/java/org/apache/commons/pool3/proxy/ProxiedObjectPool.java
similarity index 94%
rename from src/main/java/org/apache/commons/pool2/proxy/ProxiedObjectPool.java
rename to src/main/java/org/apache/commons/pool3/proxy/ProxiedObjectPool.java
index e0b7cd7a2..882ee2ad1 100644
--- a/src/main/java/org/apache/commons/pool2/proxy/ProxiedObjectPool.java
+++ b/src/main/java/org/apache/commons/pool3/proxy/ProxiedObjectPool.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.proxy;
+package org.apache.commons.pool3.proxy;
import java.util.NoSuchElementException;
-import org.apache.commons.pool2.ObjectPool;
-import org.apache.commons.pool2.UsageTracking;
+import org.apache.commons.pool3.ObjectPool;
+import org.apache.commons.pool3.UsageTracking;
/**
* Create a new object pool where the pooled objects are wrapped in proxies
@@ -29,7 +29,6 @@
*
* @param type of the pooled object
* @param type of the exception
- *
* @since 2.0
*/
public class ProxiedObjectPool implements ObjectPool {
@@ -37,7 +36,6 @@ public class ProxiedObjectPool implements ObjectPool pool;
private final ProxySource proxySource;
-
/**
* Constructs a new proxied object pool.
*
@@ -54,7 +52,6 @@ public void addObject() throws E, IllegalStateException, UnsupportedOperationExc
pool.addObject();
}
-
@SuppressWarnings("unchecked")
@Override
public T borrowObject() throws E, NoSuchElementException, IllegalStateException {
@@ -65,37 +62,31 @@ public T borrowObject() throws E, NoSuchElementException, IllegalStateException
return proxySource.createProxy(pool.borrowObject(), usageTracking);
}
-
@Override
public void clear() throws E, UnsupportedOperationException {
pool.clear();
}
-
@Override
public void close() {
pool.close();
}
-
@Override
public int getNumActive() {
return pool.getNumActive();
}
-
@Override
public int getNumIdle() {
return pool.getNumIdle();
}
-
@Override
public void invalidateObject(final T proxy) throws E {
pool.invalidateObject(proxySource.resolveProxy(proxy));
}
-
@Override
public void returnObject(final T proxy) throws E {
pool.returnObject(proxySource.resolveProxy(proxy));
diff --git a/src/main/java/org/apache/commons/pool2/proxy/ProxySource.java b/src/main/java/org/apache/commons/pool3/proxy/ProxySource.java
similarity index 91%
rename from src/main/java/org/apache/commons/pool2/proxy/ProxySource.java
rename to src/main/java/org/apache/commons/pool3/proxy/ProxySource.java
index e756857a3..02ba68b6b 100644
--- a/src/main/java/org/apache/commons/pool2/proxy/ProxySource.java
+++ b/src/main/java/org/apache/commons/pool3/proxy/ProxySource.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,16 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.pool2.proxy;
+package org.apache.commons.pool3.proxy;
-import org.apache.commons.pool2.UsageTracking;
+import org.apache.commons.pool3.UsageTracking;
/**
* The interface that any provider of proxy instances must implement to allow the
* {@link ProxiedObjectPool} to create proxies as required.
*
* @param type of the pooled object to be proxied
- *
* @since 2.0
*/
interface ProxySource