-
Notifications
You must be signed in to change notification settings - Fork 4k
api: Implement custom events framework in gRPC-Java server #12980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
45b5af1
e37245c
2636ebb
5caf237
2158b97
605cc03
dd549f3
d5f0182
542f840
958fddc
feeab1e
b9e1e2b
e832422
48aee63
1b8a230
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,6 +100,20 @@ public void onComplete() {} | |
| * <em>another</em> {@code onReady()} callback. | ||
| */ | ||
| public void onReady() {} | ||
|
|
||
| /** | ||
| * A custom event has been triggered by the call. | ||
| * | ||
| * <p>This callback is guaranteed to run on the call's executor, serialized with other | ||
| * callbacks (like {@link #onMessage}, {@link #onHalfClose}). This means the implementation | ||
| * does not need internal synchronization to access call-specific state. | ||
| * | ||
| * @param event the triggered event. | ||
|
sauravzg marked this conversation as resolved.
|
||
| */ | ||
| @ExperimentalApi("https://github.com/grpc/grpc-java/issues/12979") | ||
| public void onEvent(Object event) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any invariants on this ? Can this be called after cancellation(I assume no)?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The framework code (
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The expected behavior should be documented on the interface on if it's callable after cancellation/completion , if yes, what's the expected behavior. |
||
| // Default no-op | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -262,6 +276,20 @@ public String getAuthority() { | |
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Triggers a custom event to be processed by the listener. | ||
| * The event will be delivered to {@link Listener#onEvent(Object)} on the call's executor. | ||
| * | ||
| * <p>This method is thread-safe and can be called from any thread. No events will be delivered | ||
| * after the RPC is cancelled or completed. | ||
| * | ||
| * @param event the event to trigger. | ||
| */ | ||
| @ExperimentalApi("https://github.com/grpc/grpc-java/issues/12979") | ||
| public void triggerEvent(Object event) { | ||
| // Default no-op | ||
| } | ||
|
|
||
| /** | ||
| * The {@link MethodDescriptor} for the call. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -289,6 +289,7 @@ public ListenableFuture<Status> checkAuthorizationAsync(int uid) { | |
| ListenableFuture<Status> authFuture = asyncPolicy.checkAuthorizationAsync(SOME_UID); | ||
| assertThat(awaitResult(settableUid)).isEqualTo(SOME_UID); | ||
| authFuture.cancel(false); | ||
| executor.submit(() -> {}).get(10, TimeUnit.SECONDS); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what are we doing here? Seems like no-op to me.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is causing a wait for the cancellation task submitted to the executor to be complete before the assertion in the next statement.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and why did we need it now and not before this PR? or is this an unrelated change? |
||
|
|
||
| assertThat(delegateAuthFuture.isCancelled()).isTrue(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -254,6 +254,14 @@ public MethodDescriptor<ReqT, RespT> getMethodDescriptor() { | |
| return method; | ||
| } | ||
|
|
||
| @Override | ||
| public void triggerEvent(Object event) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need a cancellation and close check here? other methods seem to have it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A check in
The
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am less worried about races since we can fix and address them and more worried about the expected behavior. Right now it seems like we don't check cancellation or closure status here when triggering operations which may be okay if our interface contract is "you should not call after cancellation" . If our contract allows or specifies the behavior after cancellation , I'd assume we check and enforce it here in the implementation.
sauravzg marked this conversation as resolved.
|
||
| try (TaskCloseable ignore = PerfMark.traceTask("ServerCall.triggerEvent")) { | ||
| PerfMark.attachTag(tag); | ||
| stream.triggerEvent(event); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public SecurityLevel getSecurityLevel() { | ||
| final Attributes attributes = getAttributes(); | ||
|
|
@@ -395,5 +403,16 @@ public void onReady() { | |
| listener.onReady(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void triggerEvent(Object event) { | ||
| try (TaskCloseable ignore = PerfMark.traceTask("ServerStreamListener.triggerEvent")) { | ||
| PerfMark.attachTag(call.tag); | ||
| if (call.cancelled) { | ||
| return; | ||
| } | ||
| listener.onEvent(event); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.