If used in conjunction with {@link #seek(long)} the total number of returned bytes from this * channel will be reduced by the number of bytes specified to seek. * + *
The value provided as {@code limit} will define a left-closed, + * right-open interval along with either {@code 0} or any value provided to {@link + * #seek(long)}, i.e. {@code [}{@link #seek(long)}{@code , }{@link #limit(long)}{@code )}. + * + *
NOTE:Implementers are not required to return a new instance from this method, however
* they are allowed to. Users of this method should always use the instance returned from this
* method.
From 352600b21dd3392715d47f50805f384fc2ca6c9c Mon Sep 17 00:00:00 2001
From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com>
Date: Tue, 20 Dec 2022 21:30:28 +0000
Subject: [PATCH 03/21] build(deps): bump certifi from 2022.9.24 to 2022.12.7
in /synthtool/gcp/templates/java_library/.kokoro (#1732) (#1057)
build(deps): bump certifi
Bumps [certifi](https://togithub.com/certifi/python-certifi) from 2022.9.24 to 2022.12.7.
- [Release notes](https://togithub.com/certifi/python-certifi/releases)
- [Commits](https://togithub.com/certifi/python-certifi/compare/2022.09.24...2022.12.07)
---
updated-dependencies:
- dependency-name: certifi
dependency-type: direct:production
...
Signed-off-by: dependabot[bot] ThreeTen/threetenbp
### [`v1.6.5`](https://togithub.com/ThreeTen/threetenbp/releases/tag/v1.6.5)
[Compare Source](https://togithub.com/ThreeTen/threetenbp/compare/v1.6.4...v1.6.5)
See the [change notes](https://www.threeten.org/threetenbp/changes-report.html) for more information.
googleapis/api-common-java
### [`v2.3.1`](https://togithub.com/googleapis/api-common-java/blob/HEAD/CHANGELOG.md#231-httpsgithubcomgoogleapisapi-common-javacomparev230v231-2022-12-06)
[Compare Source](https://togithub.com/googleapis/api-common-java/compare/v2.2.2...v2.3.1)
##### Bug Fixes
- Build with JDK11 and target JDK8 ([1862611](https://togithub.com/googleapis/api-common-java/commit/1862611d8b5cff69288380fe567e6ce033148c55))
protocolbuffers/protobuf
### [`v3.21.12`](https://togithub.com/protocolbuffers/protobuf/compare/v3.21.11...v3.21.12)
[Compare Source](https://togithub.com/protocolbuffers/protobuf/compare/v3.21.11...v3.21.12)
### [`v3.21.11`](https://togithub.com/protocolbuffers/protobuf/compare/v3.21.10...v3.21.11)
[Compare Source](https://togithub.com/protocolbuffers/protobuf/compare/v3.21.10...v3.21.11)
googleapis/google-auth-library-java
### [`v1.14.0`](https://togithub.com/googleapis/google-auth-library-java/blob/HEAD/CHANGELOG.md#1140-httpsgithubcomgoogleapisgoogle-auth-library-javacomparev1130v1140-2022-12-06)
[Compare Source](https://togithub.com/googleapis/google-auth-library-java/compare/v1.13.0...v1.14.0)
##### Features
- Add GDCH support ([#1087](https://togithub.com/googleapis/google-auth-library-java/issues/1087)) ([cfafb2d](https://togithub.com/googleapis/google-auth-library-java/commit/cfafb2d4c8d6ab3179e709ff09fc09e6dbc11a70))
- Adding functional tests for Compute Engine ([#1105](https://togithub.com/googleapis/google-auth-library-java/issues/1105)) ([6f32ac3](https://togithub.com/googleapis/google-auth-library-java/commit/6f32ac3d4db91ff05fd7134ad6c788a16ffe44f4))
- Introduce Environment Variable for Quota Project Id ([#1082](https://togithub.com/googleapis/google-auth-library-java/issues/1082)) ([040acef](https://togithub.com/googleapis/google-auth-library-java/commit/040acefec507f419f6e4ec4eab9645a6e3888a15))
- Next release from main branch is 1.13.0 ([#1077](https://togithub.com/googleapis/google-auth-library-java/issues/1077)) ([d56eee0](https://togithub.com/googleapis/google-auth-library-java/commit/d56eee07911ba65a685ccba585e71061037ea756))
##### Bug Fixes
- AwsCredentials should not call metadata server if security creds and region are retrievable through environment vars ([#1100](https://togithub.com/googleapis/google-auth-library-java/issues/1100)) ([1ff5772](https://togithub.com/googleapis/google-auth-library-java/commit/1ff57720609fdf27f28b9c543c1ef63b57892593))
- Not loosing the access token when calling UserCredentials#ToBuil⦠([#993](https://togithub.com/googleapis/google-auth-library-java/issues/993)) ([84afdb8](https://togithub.com/googleapis/google-auth-library-java/commit/84afdb8f8d41e781dc93f04626411e10b35689de))
grpc/grpc-java
### [`v1.51.1`](https://togithub.com/grpc/grpc-java/releases/tag/v1.51.1)
[Compare Source](https://togithub.com/grpc/grpc-java/compare/v1.51.0...v1.51.1)
##### Bug Fixes
- xds: Fix ConcurrentModificationException in PriorityLoadBalancer. ([#9744](https://togithub.com/grpc/grpc-java/issues/9744))
googleapis/java-iam
### [`v1.6.23`](https://togithub.com/googleapis/java-iam/blob/HEAD/CHANGELOG.md#1623-httpsgithubcomgoogleapisjava-iamcomparev1622v1623-2022-12-20)
[Compare Source](https://togithub.com/googleapis/java-iam/compare/v1.6.22...v1.6.23)
##### Dependencies
- Update dependency com.google.api:api-common to v2.3.1 ([#567](https://togithub.com/googleapis/java-iam/issues/567)) ([17e62e8](https://togithub.com/googleapis/java-iam/commit/17e62e80f0ea8c2d4edfe6bb16ef5ee7acbc22f3))
- Update dependency com.google.auth:google-auth-library-oauth2-http to v1.14.0 ([#571](https://togithub.com/googleapis/java-iam/issues/571)) ([9c48311](https://togithub.com/googleapis/java-iam/commit/9c48311fbac25f9c9545f3404a42cdadf8ebb243))
- Update dependency com.google.cloud:google-cloud-shared-dependencies to v3.1.0 ([#565](https://togithub.com/googleapis/java-iam/issues/565)) ([32be2fb](https://togithub.com/googleapis/java-iam/commit/32be2fb0cfafa3681489c18e367cf12f22c567d3))
- Update dependency com.google.cloud:google-iam-policy to v1.6.22 ([#560](https://togithub.com/googleapis/java-iam/issues/560)) ([de39d89](https://togithub.com/googleapis/java-iam/commit/de39d89c08c9e45bc977ea393570a8d01cf48af2))
- Update dependency com.google.protobuf:protobuf-bom to v3.21.12 ([#563](https://togithub.com/googleapis/java-iam/issues/563)) ([607e260](https://togithub.com/googleapis/java-iam/commit/607e2601b71ff1fb51406e6c97dd79208296f404))
- Update dependency com.google.protobuf:protobuf-java to v3.21.12 ([#564](https://togithub.com/googleapis/java-iam/issues/564)) ([4b2b26b](https://togithub.com/googleapis/java-iam/commit/4b2b26bd29d88ccb602a71225d6e2decb49b9649))
- Update dependency io.grpc:grpc-protobuf to v1.51.1 ([#573](https://togithub.com/googleapis/java-iam/issues/573)) ([2143ec8](https://togithub.com/googleapis/java-iam/commit/2143ec8a90dbcdb128dffea9777fa9d183c3068e))
- Update dependency io.grpc:grpc-stub to v1.51.1 ([#574](https://togithub.com/googleapis/java-iam/issues/574)) ([488496a](https://togithub.com/googleapis/java-iam/commit/488496aa09c9d976bf0c450fb8584f07e7c74c03))
google/error-prone
### [`v2.17.0`](https://togithub.com/google/error-prone/releases/tag/v2.17.0): Error Prone 2.17.0
[Compare Source](https://togithub.com/google/error-prone/compare/v2.16...v2.17.0)
New Checkers:
- [`AvoidObjectArrays`](https://errorprone.info/bugpattern/AvoidObjectArrays)
- [`Finalize`](https://errorprone.info/bugpattern/Finalize)
- [`IgnoredPureGetter`](https://errorprone.info/bugpattern/IgnoredPureGetter)
- [`ImpossibleNullComparison`](https://errorprone.info/bugpattern/ProtoFieldNullComparison)
- [`MathAbsoluteNegative`](https://errorprone.info/bugpattern/MathAbsoluteNegative)
- [`NewFileSystem`](https://errorprone.info/bugpattern/NewFileSystem)
- [`StatementSwitchToExpressionSwitch`](https://errorprone.info/bugpattern/StatementSwitchToExpressionSwitch)
- [`UnqualifiedYield`](https://errorprone.info/bugpattern/UnqualifiedYield)
Fixed issues: [#2321](https://togithub.com/google/error-prone/issues/2321), [#3144](https://togithub.com/google/error-prone/issues/3144), [#3297](https://togithub.com/google/error-prone/issues/3297), [#3428](https://togithub.com/google/error-prone/issues/3428), [#3437](https://togithub.com/google/error-prone/issues/3437), [#3462](https://togithub.com/google/error-prone/issues/3462), [#3482](https://togithub.com/google/error-prone/issues/3482), [#3494](https://togithub.com/google/error-prone/issues/3494)
**Full Changelog**: https://togithub.com/google/error-prone/compare/v2.16...v2.17.0
A simple wrapper for a {@link Runnable} that logs any exception thrown by it, before + * re-throwing it. + */ +final class LogExceptionRunnable implements Runnable { + + private static final Logger log = Logger.getLogger(LogExceptionRunnable.class.getName()); + + private final Runnable task; + + public LogExceptionRunnable(Runnable task) { + this.task = checkNotNull(task, "task"); + } + + @Override + public void run() { + try { + task.run(); + } catch (Throwable t) { + log.log(Level.SEVERE, "Exception while executing runnable " + task, t); + Throwables.throwIfUnchecked(t); + throw new AssertionError(t); + } + } + + @Override + public String toString() { + return "LogExceptionRunnable(" + task + ")"; + } +} diff --git a/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/SharedResourceHolder.java b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/SharedResourceHolder.java new file mode 100644 index 0000000000..c8fc6a886b --- /dev/null +++ b/google-cloud-core-grpc/src/main/java/com/google/cloud/grpc/SharedResourceHolder.java @@ -0,0 +1,184 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed 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 com.google.cloud.grpc; + +import com.google.common.base.Preconditions; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import java.util.IdentityHashMap; +import java.util.concurrent.*; + +/** + * This class was copied from grpc-core to prevent dependence on an unstable API that may be subject + * to changes + * (https://github.com/grpc/grpc-java/blob/d07ecbe037d2705a1c9f4b6345581f860e505b56/core/src/main/java/io/grpc/internal/SharedResourceHolder.java) + * + *
A holder for shared resource singletons. + * + *
Components like client channels and servers need certain resources, e.g. a thread pool, to + * run. If the user has not provided such resources, these components will use a default one, which + * is shared as a static resource. This class holds these default resources and manages their + * life-cycles. + * + *
A resource is identified by the reference of a {@link Resource} object, which is typically a + * singleton, provided to the get() and release() methods. Each Resource object (not its class) maps + * to an object cached in the holder. + * + *
Resources are ref-counted and shut down after a delay when the ref-count reaches zero.
+ */
+final class SharedResourceHolder {
+ static final long DESTROY_DELAY_SECONDS = 1;
+
+ // The sole holder instance.
+ private static final SharedResourceHolder holder =
+ new SharedResourceHolder(
+ new ScheduledExecutorFactory() {
+ @Override
+ public ScheduledExecutorService createScheduledExecutor() {
+ return Executors.newSingleThreadScheduledExecutor(
+ getThreadFactory("grpc-shared-destroyer-%d", true));
+ }
+ });
+
+ private final IdentityHashMap The instance must have been obtained from {@link #get(Resource)}. Otherwise will throw
+ * IllegalArgumentException.
+ *
+ * Caller must not release a reference more than once. It's advisory that you clear the
+ * reference to the instance with the null returned by this method.
+ *
+ * @param resource the singleton Resource object that identifies the released static resource
+ * @param instance the released static resource
+ * @return a null which the caller can use to clear the reference to that instance.
+ */
+ public static Unit tests for {@link SharedResourceHolder}.
+ */
+@RunWith(JUnit4.class)
+public class SharedResourceHolderTest {
+
+ private final LinkedList