Future-Completable RPC Call

I have an RPC method that can take a while to complete. I have no issues completing the task asynchronously purely on the Gateway; but when calling the method from an RPC, I can't serialize a CompletableFuture so I'm stuck blocking the client.

What are my options for giving the client/designer a CompletableFuture-type-thing that eventually gets completed by the Gateway?

I've found the ClientProgressManager and GatewayProgressManager, but I'm having a hard time determining what's required/optional (I'm also not interested in displaying a progress bar in the client). My task already manages its own threading and lifecycle, in case that matters.

You need to use messaging. Return a handle from the initial call. Maintain a map in the client of incomplete Futures by handle. The gateway's implementation then sends a message to that client with handle and result. Your client/designer message handler looks up and completes the future.

Your gateway RPC hook method needs to create and cache implementations that retain the client session supplied, so that your implementation has the session needed to send back to the specific client.


Thanks Phil.

Some notes for my future self and others:

  1. To push to a designer/client from the gateway, add a notification to the session received from the RPC call using:
  1. To listen for this notification in the designer/client, you first need a GatewayConnection object. Don't make a new connection, get one from the GatewayConnectionManager.
new DesignerGatewayConnection(context.getLaunchContext()) # incorrect
GatewayConnectionManager.getInstance() # correct
  1. In the designer/client, add a push notification listener to the GatewayConnection to handle the notification:
GatewayConnection connection = GatewayConnectionManager.getInstance();