Skip to content

Instantly share code, notes, and snippets.

@nsivabalan
Created August 21, 2020 14:10
Show Gist options
  • Save nsivabalan/43debc98eb1e4042ff385516a7bf2f92 to your computer and use it in GitHub Desktop.
Save nsivabalan/43debc98eb1e4042ff385516a7bf2f92 to your computer and use it in GitHub Desktop.
public class UberClientCall<ReqT, RespT> {
@Nullable private ClientCall<ReqT, RespT> delegate;
public UberClientCall() {}
public UberClientCall(ClientCall<ReqT, RespT> delegate) {
this.delegate = delegate;
}
public void start(UberNetworkListener<RespT> responseListener, UberNetworkHeaders headers) {
if (delegate != null) {
delegate.start(responseListener),
(Metadata) headers.getNetworkTransportHeaders());
} else {
throw new IllegalStateException("Delegate can't be null");
}
}
public void request(int numMessages) {
if (delegate != null) {
delegate.request(numMessages);
} else {
throw new IllegalStateException("Delegate can't be null");
}
}
public void cancel(@Nullable String message, @Nullable Throwable cause) {
if (delegate != null) {
delegate.cancel(message, cause);
} else {
throw new IllegalStateException("Delegate can't be null");
}
}
public void halfClose() {
if (delegate != null) {
delegate.halfClose();
} else {
throw new IllegalStateException("Delegate can't be null");
}
}
public void sendMessage(ReqT message) {
if (delegate != null) {
delegate.sendMessage(message);
} else {
throw new IllegalStateException("Delegate can't be null");
}
}
public boolean isReady() {
if (delegate != null) {
return delegate.isReady();
} else {
throw new IllegalStateException("Delegate can't be null");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment