-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathGrpcServerResponse.java
More file actions
94 lines (79 loc) · 2.85 KB
/
GrpcServerResponse.java
File metadata and controls
94 lines (79 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright (c) 2011-2022 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*/
package io.vertx.grpc.server;
import io.vertx.codegen.annotations.Fluent;
import io.vertx.codegen.annotations.Nullable;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.MultiMap;
import io.vertx.core.streams.ReadStream;
import io.vertx.grpc.common.GrpcStatus;
import io.vertx.grpc.common.GrpcWriteStream;
import io.vertx.grpc.common.WireFormat;
@VertxGen
public interface GrpcServerResponse<Req, Resp> extends GrpcWriteStream<Resp> {
/**
* Set the grpc status response
*
* @param status the status
* @return a reference to this, so the API can be used fluently
*/
@Fluent
GrpcServerResponse<Req, Resp> status(GrpcStatus status);
/**
* Set the grpc status response message
*
* @param msg the message
* @return a reference to this, so the API can be used fluently
*/
@Fluent
GrpcServerResponse<Req, Resp> statusMessage(String msg);
@Fluent
GrpcServerResponse<Req, Resp> encoding(String encoding);
@Fluent
GrpcServerResponse<Req, Resp> format(WireFormat format);
/**
* @return the {@link MultiMap} to write metadata trailers
*/
MultiMap trailers();
@Override
GrpcServerResponse<Req, Resp> exceptionHandler(@Nullable Handler<Throwable> handler);
@Override
GrpcServerResponse<Req, Resp> setWriteQueueMaxSize(int maxSize);
@Override
GrpcServerResponse<Req, Resp> drainHandler(@Nullable Handler<Void> handler);
/**
* Send the response headers.
*
* @return a future notified by the success or failure of the write
*/
Future<Void> writeHead();
default Future<Void> send(Resp item) {
return end(item);
}
default Future<Void> send(ReadStream<Resp> body) {
return body.pipeTo(this);
}
/**
* End the stream with an appropriate status message, when {@code failure} is
*
* <ul>
* <li>{@link StatusException}, set status to {@link StatusException#status()}, status message to {@link StatusException#message()} and associated metadata to {@link StatusException#trailers()}</li>
* <li>Use any exception implementing {@link GrpcErrorInfoProvider} to propagate meaningful and rich error context to gRPC clients without coupling to a specific exception class.</li>
* <li>{@link UnsupportedOperationException} returns {@link GrpcStatus#UNIMPLEMENTED}</li>
* <li>otherwise returns {@link GrpcStatus#UNKNOWN}</li>
* </ul>
*
* @param failure the failure
*/
void fail(Throwable failure);
}