Rename onPayload to onMessage

This commit is contained in:
Carl Mastrangelo 2015-07-31 13:53:46 -07:00
parent 8fe667676c
commit 14e774130d
6 changed files with 29 additions and 15 deletions

View File

@ -63,7 +63,7 @@ public abstract class ClientCall<RequestT, ResponseT> {
public abstract static class Listener<T> {
/**
* The response headers have been received. Headers always precede payloads.
* The response headers have been received. Headers always precede messages.
* This method is always called, if no headers were received then an empty {@link Metadata}
* is passed.
*
@ -75,9 +75,23 @@ public abstract class ClientCall<RequestT, ResponseT> {
* A response payload has been received. May be called zero or more times depending on whether
* the call response is empty, a single message or a stream of messages.
*
* @param payload returned by the server
* @param payload returned by the server
* @deprecated use {@link #onMessage}
*/
public abstract void onPayload(T payload);
@Deprecated
public void onPayload(T payload) {
throw new UnsupportedOperationException();
}
/**
* A response message has been received. May be called zero or more times depending on whether
* the call response is empty, a single message or a stream of messages.
*
* @param message returned by the server
*/
public void onMessage(T message) {
onPayload(message);
}
/**
* The ClientCall has been closed. Any additional calls to the {@code ClientCall} will not be
@ -113,7 +127,7 @@ public abstract class ClientCall<RequestT, ResponseT> {
/**
* Requests up to the given number of messages from the call to be delivered to
* {@link Listener#onPayload(Object)}. No additional messages will be delivered.
* {@link Listener#onMessage(Object)}. No additional messages will be delivered.
*
* <p>Message delivery is guaranteed to be sequential in the order received. In addition, the
* listener methods will not be accessed concurrently. While it is not guaranteed that the same

View File

@ -253,7 +253,7 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
}
try {
observer.onPayload(method.parseResponse(message));
observer.onMessage(method.parseResponse(message));
} finally {
message.close();
}

View File

@ -47,8 +47,8 @@ public abstract class ForwardingClientCallListener<RespT> extends ClientCall.Lis
}
@Override
public void onPayload(RespT payload) {
delegate().onPayload(payload);
public void onMessage(RespT message) {
delegate().onMessage(message);
}
@Override

View File

@ -449,8 +449,8 @@ public abstract class AbstractTransportTest {
public void onHeaders(Metadata.Headers headers) {}
@Override
public void onPayload(final StreamingOutputCallResponse payload) {
queue.add(payload);
public void onMessage(final StreamingOutputCallResponse message) {
queue.add(message);
}
@Override

View File

@ -241,14 +241,14 @@ public class ClientCalls {
}
@Override
public void onPayload(RespT payload) {
public void onMessage(RespT message) {
if (firstResponseReceived && !streamingResponse) {
throw Status.INTERNAL
.withDescription("More than one responses received for unary or client-streaming call")
.asRuntimeException();
}
firstResponseReceived = true;
observer.onValue(payload);
observer.onValue(message);
if (streamingResponse) {
// Request delivery of the next inbound message.
@ -282,7 +282,7 @@ public class ClientCalls {
}
@Override
public void onPayload(RespT value) {
public void onMessage(RespT value) {
if (this.value != null) {
throw Status.INTERNAL.withDescription("More than one value received for unary call")
.asRuntimeException();
@ -397,7 +397,7 @@ public class ClientCalls {
}
@Override
public void onPayload(T value) {
public void onMessage(T value) {
Preconditions.checkState(!done, "ClientCall already closed");
buffer.add(value);
}

View File

@ -73,7 +73,7 @@ public class ClientCallsTest {
ClientCall.Listener<String> listener = listenerCaptor.getValue();
verify(call).sendPayload(req);
verify(call).halfClose();
listener.onPayload("bar");
listener.onMessage("bar");
listener.onClose(Status.OK, new Metadata.Trailers());
assertEquals("bar", future.get());
}
@ -102,7 +102,7 @@ public class ClientCallsTest {
ClientCall.Listener<String> listener = listenerCaptor.getValue();
future.cancel(true);
verify(call).cancel();
listener.onPayload("bar");
listener.onMessage("bar");
listener.onClose(Status.OK, new Metadata.Trailers());
try {
future.get();