Skip to content
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

add judgement for SimpleForwardingServerCall in method ServerStreamHelper.getServerStream #1044

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
*/
package io.grpc.internal;

import io.grpc.ServerCall;

import com.alipay.sofa.jraft.util.internal.ReferenceFieldUpdater;
import com.alipay.sofa.jraft.util.internal.Updaters;
import io.grpc.ForwardingServerCall;
import io.grpc.ServerCall;

/**
* Get grpc's server stream.
Expand All @@ -28,14 +28,23 @@
*/
public class ServerStreamHelper {

private static final ReferenceFieldUpdater<ServerCallImpl<?, ?>, ServerStream> STREAM_GETTER = Updaters
.newReferenceFieldUpdater(
ServerCallImpl.class,
"stream");
private static final ReferenceFieldUpdater<ServerCallImpl<?, ?>, ServerStream> STREAM_GETTER = Updaters
.newReferenceFieldUpdater(
ServerCallImpl.class,
"stream");

private static final ReferenceFieldUpdater<ForwardingServerCall.SimpleForwardingServerCall<?, ?>, ServerCall<?, ?>> SERVER_CALL_GETTER = Updaters
.newReferenceFieldUpdater(
ForwardingServerCall.SimpleForwardingServerCall.class,
"delegate");

public static ServerStream getServerStream(final ServerCall<?, ?> call) {
if (call instanceof ServerCallImpl) {
return STREAM_GETTER.get((ServerCallImpl<?, ?>) call);
ServerCall<?, ?> lastServerCall = call;
if (call instanceof ForwardingServerCall.SimpleForwardingServerCall) {
lastServerCall = SERVER_CALL_GETTER.get((ForwardingServerCall.SimpleForwardingServerCall<?, ?>) call);
}
if (lastServerCall instanceof ServerCallImpl) {
return STREAM_GETTER.get((ServerCallImpl<?, ?>) lastServerCall);
}
return null;
}
Expand Down
Loading