Giter VIP home page Giter VIP logo

gax-java's Introduction

Google API Extensions for Java

Build Status

๐ŸšŒ In January 2023, this library has moved to gapic-generator-java/gax-java. This repository will be archived in the future. Future releases will appear in the new repository (https://github.com/googleapis/gapic-generator-java/releases). The Maven artifact coordinates (com.google.api:gax) remain the same.

Google API Extensions for Java (GAX Java) is a library which aids in the development of client libraries for server APIs, based on GRPC and Google API conventions.

Application code will rarely need to use most of the classes within this library directly, but code generated automatically from the API definition files can use services such as paged list iteration, request batching, and polling of long-running operations to provide a more convenient and idiomatic API surface to callers.

Currently, this library shouldn't be used independently from google-cloud-java, otherwise there is a high risk of diamond dependency problems, because google-cloud-java uses beta features from this library which can change in breaking ways between versions. See VERSIONING for more information.

For new and existing Developers/ Contributors:

In December 2022, gax-java's build tool has been migrated from gradle to maven. Gradle related files are no longer being maintained and will be eventually removed.

The artifact coordinates in Maven Central ({{ group_id }}:{{ artifact_id }}) remain the same.

Quickstart

If you are using Maven, add this to your pom.xml file

<dependency>
  <groupId>com.google.api</groupId>
  <artifactId>gax</artifactId>
  <version>2.8.1</version>
</dependency>
<dependency>
  <groupId>com.google.api</groupId>
  <artifactId>gax-grpc</artifactId>
  <version>2.8.1</version>
</dependency>

If you are using Gradle, add this to your dependencies

compile 'com.google.api:gax:2.8.1',
  'com.google.api:gax-grpc:2.8.1'

If you are using SBT, add this to your dependencies

libraryDependencies += "com.google.api" % "gax" % "2.8.1"
libraryDependencies += "com.google.api" % "gax-grpc" % "2.8.1"

Java Versions

Java 8 or above is required for using this library.

To build this project, JDK 11 or above is required. The build produces Java bytecode targeted for Java 8.

The project uses Gradle to build while it also provides Bazel build.

If you build this project in Bazel, it requires Bazel 4 and basic UNIX commands (e.g., cat).

Contributing

Contributions to this library are always welcome and highly encouraged.

See the CONTRIBUTING documentation for more information on how to get started.

Versioning

This library follows Semantic Versioning, but with some additional qualifications:

  1. Components marked with @BetaApi are considered to be "0.x" features inside a "1.x" library. This means they can change between minor and patch releases in incompatible ways. These features should not be used by any library "B" that itself has consumers, unless the components of library B that use @BetaApi features are also marked with @BetaApi. Features marked as @BetaApi are on a path to eventually become "1.x" features with the marker removed.

    Special exception for google-cloud-java: google-cloud-java is allowed to depend on @BetaApi features without declaring the consuming code @BetaApi, because gax-java and google-cloud-java move in step with each other. For this reason, gax-java should not be used independently of google-cloud-java.

  2. Components marked with @InternalApi are technically public, but are only public for technical reasons, because of the limitations of Java's access modifiers. For the purposes of semver, they should be considered private.

  3. Components marked with @InternalExtensionOnly are stable for usage, but not for extension. Thus, methods will not be removed from interfaces marked with this annotation, but methods can be added, thus breaking any code implementing the interface. See the javadocs for more details on other consequences of this annotation.

Submodule notes

  • gax is stable (>= 1.0.0), so anything not marked @BetaApi, @InternalApi, or @InternalExtensionOnly won't break between minor releases. Anything marked @InternalExtensionOnly can only break extensions between minor releases.
  • gax-grpc is stable (>= 1.0.0), so anything not marked @BetaApi, @InternalApi, or @InternalExtensionOnly won't break between minor releases. Anything marked @InternalExtensionOnly can only break extensions between minor releases.
  • gax-httpjson is beta (0.x.y), so anything may change at any time and the public API should not be considered stable. There is no difference whether a class is marked @BetaApi or not; that annotation is only present as a reminder. There is also no difference whether a class is marked @InternalExtensionOnly or not; that only implies that the annotation will still be present in 1.0.0.

Feature notes

  • Long Running Operations - This feature is not yet considered stable.
  • Streaming - Streaming features are not yet considered stable.
  • Batching - Batching features are not yet considered stable.
  • Generated Code Support - Features to support generated code is not yet considered stable.
  • Testing - There are no plans to consider any code in the testlib jar to be stable.

Repository Structure

This repository contains the following java packages.

gax

  • com.google.api.gax.batching - Contains general-purpose batching logic.
  • com.google.api.gax.core - Contains core interfaces and classes that are not specific to grpc and could be used in other contexts.
  • com.google.api.gax.longrunning - Contains classes related to long running operations.
  • com.google.api.gax.paging - Contains classes related to list calls that return results in pages.
  • com.google.api.gax.retrying - Contains classes related to retrying API calls.
  • com.google.api.gax.rpc - Contains classes related to making RPC calls.

gax-grpc

  • com.google.api.gax.grpc - Contains classes that provide functionality on top of gRPC calls.
  • com.google.longrunning - Contains the mix-in client for long-running operations which is implemented by a number of Google APIs.

gax-httpjson

  • com.google.api.gax.httpjson - Contains classes that provide functionality on top of http/json calls.

License

BSD - See LICENSE for more information.

gax-java's People

Contributors

andreamlin avatar arithmetic1728 avatar blakeli0 avatar chanseokoh avatar chingor13 avatar codyoss avatar eaball35 avatar elharo avatar garrettjonesgoogle avatar igorbernstein2 avatar kolea2 avatar lqiu96 avatar meltsufin avatar michaelbausor avatar miraleung avatar mohanli-ml avatar mpeddada1 avatar mutianf avatar neenu1995 avatar noahdietz avatar pongad avatar rahulkql avatar release-please[bot] avatar renovate-bot avatar shinfan avatar suztomo avatar tcoffee-google avatar vam-google avatar weiranfang avatar yihanzhen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gax-java's Issues

Add reference to gRPC (and other) types in javadoc

Not sure if this bug should go in googleapis/toolkit instead, but logging this issue here for reference.

When looking at the JavaDoc of a specific GAPIC generated class, we should be able to access the underlying types (e.g. when clicking on the parameters or return values of a specific method).

PropertiesProvider writes exceptions to System.err instead of a logger

The new(ish) PropertiesProvider writes exceptions and other messages to System.err instead of using a logger. This creates a significant amount of noise for what appear to be non-critical errors.

For example, loadProperty invokes System.err.printStackTrace on line 81, but the return null after the catch suggests exceptions there are non-critical. By using a logger instead of System.err, users can suppress these messages if desired.

Example stderr output:

java.lang.NullPointerException
	at java.util.Properties$LineReader.readLine(Properties.java:434)
	at java.util.Properties.load0(Properties.java:353)
	at java.util.Properties.load(Properties.java:341)
	at com.google.api.gax.core.PropertiesProvider.loadProperty(PropertiesProvider.java:69)

Thanks

InstantiatingChannelProvider might leak Executor

cc @garrettjonesgoogle
If we call getChannel(), the provider gets an executor from a call to executorProvider.getExecutor(). Depending on the implementation of executorProvider, we might create a new executor in the process.

Who's responsible for shutting down this executor? My best guess is that the returned channel should shut down the executor whenever the channel itself is shut down. If this is the case, I think it should be explicitly documented.

ProtoReflectionUtils Functionality

@garrettjonesgoogle, @michaelbausor I found the ProtoReflectionUtils class (https://github.com/googleapis/gax-java/blob/05d4c20d2a302fee410001fe9e34fb7f59a64d7b/src/main/java/com/google/api/gax/protobuf/ProtoReflectionUtil.java) while looking for a way to get the Java Enum class of a proto enum field reflectively.

I see that the ProtoReflectionUtils class was removed in 964d3ab

Is that class or its functionality moved somewhere else, or is it retired for good?

Thank you,
Nikolay

Cherry-pick gRPC dependencies rather than using grpc-all

This was briefly discussed internally. As per title we should drop the grcp-all dependency and favor cherry-picking gRPC dependencies.

This should help us getting rid of some dependencies as well as duplicated classes (e.g. the ones pulled by both protobuf-java and protobuf-lite).

Warnings at Class Loading Time

Oct 06, 2017 3:17:48 PM com.google.api.gax.core.PropertiesProvider logMissingProperties
WARNING: Warning: Failed to open properties resource at '%s' of the given class '%s'

Oct 06, 2017 3:17:48 PM com.google.api.gax.core.PropertiesProvider logMissingProperties
WARNING: Warning: Failed to open properties resource at '%s' of the given class '%s'

Put operation name in ApiException

The user doesn't know what call causes exceptions:

Exception in thread "main" com.google.api.gax.grpc.ApiException: io.grpc.StatusRuntimeException: ALREADY_EXISTS: Resource already exists in the project (resource=zipkin).

Service specific settings does not override ServiceApiSettings setting methods.

A service API (e.g. PublisherApi) can be configured with its own specific PublisherSettings settings.

Some of PublisherSettings configuration are inherited from ServiceApiSettings.

To allow chaining this is returned from the settings methods, however because PublisherSettings
does not override its parent methods the returned this would be ServiceSettings and not PublisherSettings (which breaks chaining).

Also, I think it would have been nicer if ServiceApiSettings was immutable and using a Builder for construction.

Easy way to reuse channel

Following this comment from Garrett I am trying to reuse the same channel to instantiate multiple service objects.

I can do that by creating the channel myself and passing it to ServiceApiSettings.provideChannelWith(ManagedChannel, boolean), this however has several drawbacks:

A method like ServiceApiSettings.setChannelProvider(ChannelProvider) could really help on this. So that I can pass ServiceApiSettings.getChannelProvider() of a previously created settings object.

Related to this issue, the semantics of channel providers created with ServiceApiSettings.createChannelProvider(ConnectionSettings) is a bit confusing to me. The method getOrBuildChannel seems to create a new channel every time it's called, rather than creating it only the first time. Is this behavior intended?

Sort out BundlingSettings

@garrettjonesgoogle @davidtorres

From our meeting last Thursday, I think the decision was

  • These fields should be set and non-zero
    • elementCountThreshold
    • requestByteThreshold
    • delayThreshold
  • Delete the rest

I wanted to make sure I get it right to avoid code churn since this is tightly coupled with work in google-cloud-java.

PropertiesProvider resource (and native memory) leaking

Dear Google team,

During our internal performance testing we found out that there's a resource leak (which is causing abnormal native memory consumption) in com.google.api.gax.core.PropertiesProvider class. Test app with google datastore api consumed more than 20 GB of RAM and java process got killed by linux's OOM killer.

Methods

PropertiesProvider#loadProperty(Class<?> loadedClass, String propertiesPath, String key)
and
PropertiesProvider#loadProperty(Properties properties, String propertiesPath, String key)

are loading resources but not closing them(input stream is not closed). So native resources are held using java.util.zip.Inflater (See java.util.zip.GZIPInputStream).

Another proposal is to cache results of property loading by key. Even dumb implementation with synchronization of entire method and HashMap(as cache provider) will work quicker than loading of resource each time.

Tested on linux with latest JDK 8.

BR,
Dionis

Create variant of GAX with Guava and gRPC shaded

Consequences:

  1. Guava can't be exposed on the public surface of GAX
  2. gRPC can't be exposed on the public surface of GAX

Number 2 will be the larger effort, because Guava is already in the process of being hidden, but gRPC is currently exposed.

PageAccessor: support getNextPageAsync()

You can get a PageAccessor through an async call, but then it's not possible to do further async calls, so providing a getNextPageAsync() is necessary for completeness.

FlowController.reserve - deadlock on acquireUninterruptibly()

The FlowController:: reserve doesn't take the initial size of the semaphore into account when blocking.

Background: trying to provide limits to the pub/sub subscriber - wanted one-at-a-time. With the size of the semaphore set to 1, pub/sub subscriber code will usually pull back more than one message (could be as many as 1000 if I'm reading the code correctly). Each thread that processes pub/sub messages gets stuck on this call [and will never unblock].

Unbounded queue in ThresholdBundler.closedBundles

Copying over some possible issues found in googleapis/google-cloud-java#1432:

  1. com.google.api.gax.bundling.ThresholdBundler has an unbounded queue for closedBundles that will fill endlessly if an application is publishing faster than the queue can be drained, or if draining/publishing can't occur at all for some reason. We've seen on a few instances (3-5 applications out of 1000s) that this eventually leads to a OutOfMemoryError as the heap space fills up.

  2. It seems like if the thread that ThresholdBundlingForwarder starts dies for any reason, it won't be restarted, and the messages accumulating in the Bundler will not be processed at all (eventually leading to the OOM above).

I am only familiar with the bundling behavior as it is used in google-cloud-pubsub, but for the first issue I think it may make sense for the Bundler to allow for specifying a maximum number of bundles/items that it will hold onto, and then either reject new items from being added or drop the oldest bundles/items when this limit is hit.

API Docs are out of date

The docs for gax-java are out of date. They seem to be stuck on version 1.9.1 while the library is on 1.14.0.

Missing required properties: totalTimeout even though the value is set

When creating a PubSub's PublisherApi object I am getting the following IllegalStateException error:

java.io.IOException: java.lang.IllegalStateException: Missing required properties: totalTimeout
    at com.google.cloud.pubsub.spi.DefaultPubSubRpc.<init>(DefaultPubSubRpc.java:87)
    at com.google.cloud.pubsub.PubSubOptions$DefaultPubSubRpcFactory.create(PubSubOptions.java:57)
    ... 23 more
Caused by: java.lang.IllegalStateException: Missing required properties: totalTimeout
    at com.google.api.gax.core.AutoValue_RetrySettings$Builder.autoBuild(AutoValue_RetrySettings.java:264)
    at com.google.api.gax.core.RetrySettings$Builder.build(RetrySettings.java:220)
    at com.google.api.gax.grpc.SimpleCallSettings$Builder.build(SimpleCallSettings.java:73)
    at com.google.cloud.pubsub.spi.v1.PublisherSettings.<init>(PublisherSettings.java:219)
    at com.google.cloud.pubsub.spi.v1.PublisherSettings.<init>(PublisherSettings.java:103)
    at com.google.cloud.pubsub.spi.v1.PublisherSettings$Builder.build(PublisherSettings.java:556)
    at com.google.cloud.pubsub.spi.DefaultPubSubRpc.<init>(DefaultPubSubRpc.java:78)

However we do set the totalTimeout value: see here.

If I understood it correctly this might be caused by RetrySettings.Builder.merge which does not merge the totalTimeout field.

Tag versions

In the source tree, we don't have version tags. Given an gax-java version, it's pretty hard or near to impossible to find the source associated w/ that version in the source tree.

ServiceApiSettings.applyToAllApiMethods always overrides retryable codes

ServiceApiSettings.applyToAllApiMethods(Iterable<ApiCallSettings.Builder> methodSettingsBuilders, ApiCallSettings.Builder newSettingsBuilder) sets newSettingsBuilder.getRetryableCodes() and newSettingsBuilder.getRetrySettingsBuilder() for all API method settings in methodSettingsBuilders.

applyToAllApiMethods avoids using newSettingsBuilder.getRetryableCodes() if its null, however, there's no way to create an ApiCallSettings.Builder with null retryable codes (always initialized to empty set).

The result is that if I want to use applyToAllApiMethods to set common RetrySettings I am forced to override also retryable codes. Could you add a way to just set RetrySettings for all methods?

/cc @shinfan @garrettjonesgoogle

Switch to Apache 2.0 License

Both the upstream dependency gRPC, and downstream consumer google-cloud-java are Apache 2.0 license. This one in the middle glueing the two is BSD.

Unable to print `StatusCode` from `ApiException`

ApiFutures.addCallback(future, new ApiFutureCallback<String>() {
          @Override
          public void onFailure(Throwable throwable) {
                   if (throwable instanceof ApiException) {
                     ApiException e = (ApiException) throwable;
                     System.out.println("Api Error Code : " + e.getStatusCode());
                   }
                   System.out.println("Error publishing message : " + message);
          }

e.getStatusCode() currently retrieves :

com.google.api.gax.grpc.GrpcStatusCode@3fce1ed0

Users should be able to not have to perform the following cast to retrieve the status code:

((GrpcStatusCode)e.getStatusCode()).getCode()

Create Gradle build task to perform automatic release process

Still manual:

  • Update version.txt

Full process:

  • verify that there are no local changes before starting the process
  • update docs (there is already a task for this step - updateDocsWithCurrentVersion)
  • commit generated gh-pages (updateDocsWithCurrentVersion puts this under tmp_gh-pages/)
  • upload built archives (uploadArchives is the command that needs to be invoked when being performed manually)
  • close & release the archive on Sonatype
  • commit the auto-generated doc updates
  • push the auto-generated doc updates to github

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.