Use DaprChannel instead of closeable ActorProxyBuilder.#451
Conversation
| */ | ||
| public static void main(String[] args) throws InterruptedException { | ||
| try (ActorProxyBuilder<DemoActor> builder = new ActorProxyBuilder(DemoActor.class)) { | ||
| try (DaprChannel channel = new DaprChannel()) { |
There was a problem hiding this comment.
This is why this is a breaking change. This is only applicable for Actors because the proxy is per actor instance, so there must be a "client" shared some how. I think having this separate class is more intuitive then making the ActorProxyBuilder to own the channel behind the scenes.
There was a problem hiding this comment.
Two questions about this approach...
I assume that it's not feasible to make the generated proxies (actor in this example) implement Closable because it's an interface that the user provided and may not include it.
So having the user do the equivalent of (my Java is rusty, be nice!):
if (actor instanceof Closable) {
((Closable)actor).Close()
}Just sounds terrible from a usability standpoint. A beginner would not understand what to do.
Equally bad is requiring the actor interface to implement Closable because then they end up with a do-nothing implementation of that interface on the server, since the proxy interface is shared.
Second question.
Have you considered using a static instance of DaprChannel and making the constructor arg optional via overloading? This way by default users that are not bothered about resource management can share a single channel instance that's process-scoped and can opt-in to more complexity if they want eager resource cleanup.
I also considered the approach of returning a handle type, which would not only be a massive breaking change, but it would also require ref-counting (yuck).
There was a problem hiding this comment.
First question, making the proxy or the class user provided to be closeable does not make sense because the resource to be closed (grpcChannel) is shared and reused. So a single instance of ActorProxy cannot close it because there might be other ActorProxies still using it.
The idea is to give users freedom of where to create and when to close the managed resource. If I create one for them. Having a static instance will also load it even when users don't use it. Imagine having this managed channel created for the application that just serves the actor runtime without calling into other actors? Users are also used to do this in Springboot - actually being opinionated about resource management probably belongs to the springboot package we have instead of here.
No ref counting :)
There was a problem hiding this comment.
Users are also used to do this in Springboot - actually being opinionated about resource management probably belongs to the springboot package we have instead of here.
So does this mean we have a recipe for using these types in a DI-enabled way? Or is that up the user to figure out?
rynowak
left a comment
There was a problem hiding this comment.
Actual code changes look straightforward, left a few questions ...
|
I made ActorClient not implement the DaprClient interface anymore since we don't want to expose that method to applications but made it implement a method with same signature and delegate to DaprClient instead. Now, apps only see the |
mukundansundar
left a comment
There was a problem hiding this comment.
left some comments.
…er.java Co-authored-by: Mukundan Sundararajan <musundar@microsoft.com>
…erTest.java Co-authored-by: Mukundan Sundararajan <musundar@microsoft.com>
Codecov Report
@@ Coverage Diff @@
## master #451 +/- ##
============================================
+ Coverage 82.80% 82.94% +0.13%
- Complexity 899 903 +4
============================================
Files 76 77 +1
Lines 2640 2644 +4
Branches 263 264 +1
============================================
+ Hits 2186 2193 +7
+ Misses 325 321 -4
- Partials 129 130 +1
Continue to review full report at Codecov.
|
Description
This change creates a class called
DaprChannelfor actor communication in Dapr. It will avoid makingActorProxyBuildera closeable class - it was odd to have a builder class that could not be disposed. Now,DaprChannelis the class where users must keep a reference and close in the end. If we decide to use HTTP instead of gRPC, the DaprChannel still holds the Client reference, making it an effective singleton.Summary:
ActorProxyBuilderis now disposable and does not need to exist while DaprClient is being used.DaprChannelholds the "channel" to Dapr and must be referenced while app is using Dapr Actor APIs.DaprChannelis closeable, so users must close it after done with using Dapr Actor APIs.DaprChannelis encourage to be a singleton in the app, creating many instances can trash the application.DaprChannelis specific to Actor APIs becauseDaprClientin the regular SDKs is already closeable and must be reused.Issue reference
We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.
Please reference the issue this PR will close: None
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list:
RELEASE NOTE: REFACTOR Created
DaprChannelfor actor APIs, makingActorProxyBuildernot closeable anymore.