GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — request: return ListenableFutures in PubSub async methods rather than bare Futures · Issue #1148 · googleapis/google-cloud-java

request: return ListenableFutures in PubSub async methods rather than bare Futures  #1148

New issue
Copy link
New issue
Copy link
Closed
#1168
Closed
request: return ListenableFutures in PubSub async methods rather than bare Futures #1148
#1168
Copy link
Assignees
mziccard

Description

@mattnworb
mattnworb
opened on Aug 10, 2016
Issue body actions

The com.google.cloud.pubsub.PubSub interface defines async operations which return java.util.concurrent.Future values.

For anyone who uses the ListenableFuture concept from Guava (or CompletableFutures in Java 8), these Futures have to be adapted into ListenableFutures by spawning a thread that blocks on the Future.get() return.

It would be much more convenient if the Futures returned from PubSub were actually ListenableFuture instances (even if the interface did not define the return value to be ListenableFuture) - then it would not be necessary for users to block one thread per future they wish to adapt into a ListenableFuture.

For instance, internally PubSubImpl.pullAsync(final String subscription, int maxMessages) is implemented by using the listenable-like com.google.cloud.pubsub.spi.PubSubRpc.PullFuture and attaching callbacks to it, but the returned Future is an anonymous subclass of Future created by Futures.lazyTransform(..).

Is it a conscious decision to avoid using ListenableFutures in the interfaces defined in gcloud-java-pubsub and other clients?

It seems like the com.google.cloud.pubsub.spi layer has access to ListenableFuture instances via the generated grpc client code (like subscriberApi.acknowledgeCallable().futureCall(request)) but then these are discarded in the PubSubImpl layer.

Activity

  1. mziccard commented on Aug 10, 2016

    @mziccard
    mziccard
    on Aug 10, 2016
    Contributor
    More actions

    Is it a conscious decision to avoid using ListenableFutures in the interfaces defined in gcloud-java-pubsub and other clients?

    Yes, it's a conscious decision. We don't want to expose Guava-related classes in our interfaces and we still want to support Java 7 (for GAE and Android, mainly).

    Could MessageConsumer pullAsync(String subscription, MessageProcessor callback, PullOption... options) help? If not, what is it missing that you need (I would be happy to add more features)?

  2. mattnworb commented on Aug 10, 2016

    @mattnworb
    mattnworb
    on Aug 10, 2016
    Author
    More actions

    Thanks @mziccard for the fast reply.

    MessageConsumer is great - it perfectly fits my needs for consuming messages. It is awesome to not have to implement something that pulls messages in a loop and processes them in our own code.

    The (minor) pain point comes more in code that deals with methods like Future<String> publishAsync(String topic, Message msg), when I would like to be able to transform the returned future to some other type or combine it with another future. We are heavy users of ListenableFuture and find it natural to transform and otherwise chain ListenableFutures together, so it is a small annoyance to have to use JdkFutureAdapters.listenInPoolThread and create a thread that blocks on Future.get() to be able to adapt this response to a ListenableFuture.

    I understand not wanting to return Guava types in the PubSub interface, but wouldn't it be possible to return ListenableFuture implementations (SettableFuture, etc) in the PubSub implementation? This way adapters like JdkFutureAdapters would avoid having to spawn a blocked thread since the returned future would pass a if (future instanceof ListenableFuture) ... check.

  3. mziccard commented on Aug 11, 2016

    @mziccard
    mziccard
    on Aug 11, 2016
    Contributor
    More actions

    I understand not wanting to return Guava types in the PubSub interface, but wouldn't it be possible to return ListenableFuture implementations (SettableFuture, etc) in the PubSub implementation?

    I will look into this, I'll keep you posted!

  4. mziccard
    closed this as completedin #1168on Aug 21, 2016
  5. JustinBeckwith
    assigned
    mziccard
    on Feb 1, 2021
  6. github-actions
    added 2 commits that reference this issue on Jun 29, 2022

    chore: remove All rights reserved clause from java.header (googleapis…

    57d7cd7

    chore: remove All rights reserved clause from java.header (#1148) (#292)

    d701fed
  7. chingor13
    added a commit that references this issue on Jan 6, 2026

    deps: update dependency com.google.cloud:google-cloud-shared-dependen…

    a51611f
  8. chingor13
    added a commit that references this issue on Jan 22, 2026

    chore(deps): update dependency com.google.cloud:libraries-bom to v26.…

    59c5215
  9. chingor13
    added 2 commits that reference this issue on Feb 24, 2026

    fix: Java doc for DefaultPKCEProvider.java (#1148)

    154c127

    chore(main): release 1.16.0 (#1139)

    ebf2b6b
  10. lqiu96
    added a commit that references this issue on Feb 26, 2026

    chore(main): release 1.80.0 (#11952)

    3caee36
  11. chingor13
    added 2 commits that reference this issue on Mar 12, 2026

    fix: Java doc for DefaultPKCEProvider.java (#1148)

    5347450

    chore(main): release 1.16.0 (#1139)

    ddebe66
  12. lqiu96
    added a commit that references this issue on Mar 20, 2026

    chore(main): release 1.80.0 (#11952)

    b06b3d1
  13. suztomo
    added a commit that references this issue on Mar 23, 2026

    chore(main): release 2.9.9-SNAPSHOT (googleapis#1148)

    04be110
  14. suztomo
    added a commit that references this issue on Mar 30, 2026

    chore(main): release 0.126.11 (#1148)

    d4c5de8
  15. lqiu96
    added a commit that references this issue on Apr 1, 2026

    chore(main): release 0.126.11 (#1148)

    0290d3e
  16. meltsufin
    added 4 commits that reference this issue on Apr 29, 2026

    deps: update dependency com.google.cloud:google-cloud-shared-dependen…

    b5b004b

    chore(main): release 1.119.0 (#1144)

    e15ef6c

    deps: update dependency com.google.cloud:google-cloud-shared-dependen…

    977d1e2

    chore(main): release 1.119.0 (#1144)

    67440b3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @mziccard
    mziccard

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.