mirror of https://github.com/grpc/grpc-java.git
Clarifying the InputStream ownership contract in Call.Listener and StreamListener.
------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=70334261
This commit is contained in:
parent
46fea97a63
commit
ad1ee03104
|
@ -31,13 +31,19 @@ public abstract class Call<RequestT, ResponseT> {
|
|||
public abstract static class Listener<T> {
|
||||
/**
|
||||
* A response context has been received. Any context messages will precede payload messages.
|
||||
*
|
||||
* <p>The {@code value} {@link InputStream} will be closed when the returned future completes.
|
||||
* If no future is returned, the stream will be closed immediately after returning from this
|
||||
* method.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract ListenableFuture<Void> onContext(String name, InputStream value);
|
||||
|
||||
/**
|
||||
* A response payload has been received. For streaming calls, there may be zero payload
|
||||
* messages.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract ListenableFuture<Void> onPayload(T payload);
|
||||
|
||||
/**
|
||||
|
|
|
@ -224,6 +224,7 @@ public final class ChannelImpl extends AbstractService implements Channel {
|
|||
}, MoreExecutors.sameThreadExecutor());
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
ours.set(null);
|
||||
CallImpl.this.cancel();
|
||||
Throwables.propagate(t);
|
||||
}
|
||||
|
|
|
@ -17,14 +17,20 @@ public interface StreamListener {
|
|||
* Called upon receiving context information from the remote end-point. The {@link InputStream} is
|
||||
* non-blocking and contains the entire context.
|
||||
*
|
||||
* <p>The method optionally returns a future that can be observed by flow control to determine
|
||||
* when the context has been processed by the application. If {@code null} is returned, processing
|
||||
* of this context is assumed to be complete upon returning from this method.
|
||||
*
|
||||
* <p>The {@code value} {@link InputStream} will be closed when the returned future completes. If
|
||||
* no future is returned, the stream will be closed immediately after returning from this method.
|
||||
*
|
||||
* <p>This method should return quickly, as the same thread may be used to process other streams.
|
||||
*
|
||||
* @param name the unique name of the context
|
||||
* @param value the value of the context.
|
||||
* @param length the length of the value {@link InputStream}.
|
||||
* @return a future that can be observed by flow control to determine when the context has been
|
||||
* processed by the application. If {@code null}, processing of this context is assumed to
|
||||
* be complete upon returning from this method.
|
||||
* @return a processing completion future, or {@code null} to indicate that processing of the
|
||||
* context is immediately complete.
|
||||
*/
|
||||
@Nullable
|
||||
ListenableFuture<Void> contextRead(String name, InputStream value, int length);
|
||||
|
@ -33,13 +39,20 @@ public interface StreamListener {
|
|||
* Called upon receiving a message from the remote end-point. The {@link InputStream} is
|
||||
* non-blocking and contains the entire message.
|
||||
*
|
||||
* <p>The method optionally returns a future that can be observed by flow control to determine
|
||||
* when the message has been processed by the application. If {@code null} is returned, processing
|
||||
* of this message is assumed to be complete upon returning from this method.
|
||||
*
|
||||
* <p>The {@code message} {@link InputStream} will be closed when the returned future completes.
|
||||
* If no future is returned, the stream will be closed immediately after returning from this
|
||||
* method.
|
||||
*
|
||||
* <p>This method should return quickly, as the same thread may be used to process other streams.
|
||||
*
|
||||
* @param message the bytes of the message.
|
||||
* @param length the length of the message {@link InputStream}.
|
||||
* @return a future that can be observed by flow control to determine when the message has been
|
||||
* processed by the application. If {@code null}, processing of this message is assumed to
|
||||
* be complete upon returning from this method.
|
||||
* @return a processing completion future, or {@code null} to indicate that processing of the
|
||||
* message is immediately complete.
|
||||
*/
|
||||
@Nullable
|
||||
ListenableFuture<Void> messageRead(InputStream message, int length);
|
||||
|
|
Loading…
Reference in New Issue