Last active
October 28, 2020 20:29
-
-
Save nsivabalan/e90f3e923bd76284bd3c651b21d111e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Since every interceptor needs to register as listener to next in chain, and on getting notified | |
* should notify previous listener in the chain. This class will be the new listener which holds | |
* reference to previous listener and gets registered to next interceptor in the chain. | |
* | |
* @param <ReqT> request msg of generic type ReqT. | |
* @param <RespT> response msg of generic type RespT. | |
* @param <T> methodInfo of generic type T. | |
*/ | |
public class InternalListener<ReqT, RespT, T> extends UberNetworkListener<RespT> { | |
private static final Logger LOGGER = Logger.getLogger(InternalListener.class.getName()); | |
public String identifier; | |
@Nullable private UberCallListener<RespT> prevListener; | |
@Nullable private UberInternalCallOptions callOptions; | |
@Nullable private MethodInfo<T> methodInfo; | |
private UberInterceptor<ReqT, RespT, T> interceptor; | |
public InternalListener( | |
String identifier, | |
@Nullable UberInternalCallOptions callOptions, | |
MethodInfo<T> methodInfo, | |
@Nullable UberCallListener<RespT> prevListener, | |
UberInterceptor<ReqT, RespT, T> interceptor) { | |
super(); | |
this.identifier = identifier; | |
this.callOptions = callOptions; | |
this.methodInfo = methodInfo; | |
this.prevListener = prevListener; | |
this.interceptor = interceptor; | |
} | |
/** On response headers. */ | |
@Override | |
public void onHeaders(UberCallHeaders headers) { | |
interceptor.onResponseHeaders(headers); | |
if (prevListener != null) { | |
prevListener.onHeaders(headers); | |
} | |
} | |
/** On response msg. */ | |
@Override | |
public void onMessage(RespT message) { | |
if (methodInfo != null) { | |
interceptor.onResponseMsg(message); | |
if (prevListener != null) { | |
prevListener.onMessage(message); | |
} | |
} | |
} | |
/** | |
* Invoked on closing a request. Refer | |
* https://grpc.github.io/grpc-java/javadoc/io/grpc/ClientCall.Listener.html for more details. | |
*/ | |
@Override | |
public void onClose(UberNetworkRequestStatus status, UberCallHeaders trailers) { | |
interceptor.onComplete(status, trailers); | |
if (prevListener != null) { | |
prevListener.onClose(status, trailers); | |
} | |
} | |
/** | |
* Refer https://grpc.github.io/grpc-java/javadoc/io/grpc/ClientCall.Listener.html for more | |
* details. | |
*/ | |
@Override | |
public void onReady() { | |
if (prevListener != null) { | |
prevListener.onReady(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment