Skip to content

Instantly share code, notes, and snippets.

View nsivabalan's full-sized avatar

Sivabalan Narayanan nsivabalan

View GitHub Profile
/**
* Interface representing Request/Response headers. This is a common interface for all network
* transports and each transport is expected to have its own implementation.
*
* @param <T> represents the actual transport header object of generic type T.
*/
public interface UberCallHeaders<T> {
/**
* Fetch value corresponding to the given key.
/**
* Generic interface to represent MethodInfo fo type <T>. Used to hold method info like url path,
* call type etc.
*
* @param <T>
*/
public interface MethodInfo<T> {
/** @return the methodInfo object as is. */
T getTransportMethodInfo();
/**
* Grpc's implementation of {@link MethodInfo}.
*
* @param <ReqT> reqeust object of generic Type ReqT.
* @param <RespT> response object of generic Type RespT.
*/
public class GrpcMethodInfo<ReqT, RespT> implements MethodInfo<MethodDescriptor> {
private MethodDescriptor<ReqT, RespT> methodDescriptor;
private MethodType methodType;
public class UberClientCall<ReqT, RespT> {
@Nullable private ClientCall<ReqT, RespT> delegate;
public UberClientCall() {}
public UberClientCall(ClientCall<ReqT, RespT> delegate) {
this.delegate = delegate;
}
/**
* A virtual connection to a conceptual endpoint, to perform RPCs. A channel is free to have zero or
* many actual connections to the endpoint based on configuration, load, etc. A channel is also free
* to determine which actual endpoints to use and may change it every RPC, permitting client-side
* load balancing. Applications are generally expected to use stubs instead of calling this class
* directly.
*
* <p>Every new request will return an instance of {@link UberClientCall} and all further
* processing, monitoring, manipulations are done with the UberClientCall instance.
*
/**
* Call router interceptor which routes calls to corresponding transport adaptors.
*
* @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 UberCallRouterInterceptor<ReqT, RespT, T> extends UberInterceptor<ReqT, RespT, T> {
// Adaptors will the next in the chain of interceptors.
/**
* Adaptor for Grpc which does all the translation from generic uber types to grpc entities and
* places the call to a grpc ManagedChannel. This class manages multiple channels and routes new
* calls based on host fetched from UberInternalCallOptions.
*/
public class UbergRPCAdaptor implements UberChannel {
private static final Logger LOGGER = Logger.getLogger(UbergRPCAdaptor.class.getName());
// static variable singleInstance of type Singleton
/**
* Adaptor for Grpc which does all the translation from generic uber types to grpc entities and
* places the call to a grpc ManagedChannel. This class manages multiple channels and routes new
* calls based on host fetched from UberInternalCallOptions.
*/
public class UbergRPCAdaptor implements UberChannel {
private static final Logger LOGGER = Logger.getLogger(UbergRPCAdaptor.class.getName());
// static variable singleInstance of type Singleton
/**
* 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> {
/**
* Public interface for Realtime clients, ramen and other clients to send and receive network
* requests. Clients need to instantiate {@link UberNetworkingClient} once using singleton method
* {@link #getInstance(List)} and then for new grpc calls, can call the following.
* uberNetworkingClient.newCall(MethodInfo, UberInternalCallOptions) This will return an instance of
* {@link UberClientCall} and any further interaction to the request will be done in via {@link
* UberClientCall}.
*
* <p>For every new call, UberNetworkingClient will instantiate a new chain of {@link
* UberInterceptor}s and attachs them to the {@link UbergRPCAdaptor} at the end. {@link