@@ -54,21 +54,36 @@ public String get(@Nullable HeadersAccessor carrier, @NonNull String key) {
5454
5555 private final Endpoint endpoint ;
5656 private final EndpointManifest deploymentManifest ;
57+ private final boolean deprecatedSupportsBidirectionalStreaming ;
5758
5859 private EndpointRequestHandler (
59- EndpointManifestSchema .ProtocolMode protocolMode , Endpoint endpoint ) {
60+ EndpointManifestSchema .@ Nullable ProtocolMode protocolMode , Endpoint endpoint ) {
6061 this .endpoint = endpoint ;
6162 this .deploymentManifest =
6263 new EndpointManifest (
63- protocolMode ,
64- this .endpoint . getServiceDefinitions (),
65- this . endpoint . isExperimentalContextEnabled ()) ;
64+ this . endpoint . getServiceDefinitions (), this . endpoint . isExperimentalContextEnabled ());
65+ this .deprecatedSupportsBidirectionalStreaming =
66+ protocolMode != EndpointManifestSchema . ProtocolMode . REQUEST_RESPONSE ;
6667 }
6768
69+ public static EndpointRequestHandler create (Endpoint endpoint ) {
70+ return new EndpointRequestHandler (null , endpoint );
71+ }
72+
73+ /**
74+ * @deprecated The protocol mode is now established on request basis, use {@link
75+ * #create(Endpoint)} instead.
76+ */
77+ @ Deprecated
6878 public static EndpointRequestHandler forBidiStream (Endpoint endpoint ) {
6979 return new EndpointRequestHandler (EndpointManifestSchema .ProtocolMode .BIDI_STREAM , endpoint );
7080 }
7181
82+ /**
83+ * @deprecated The protocol mode is now established on request basis, use {@link
84+ * #create(Endpoint)} instead.
85+ */
86+ @ Deprecated
7287 public static EndpointRequestHandler forRequestResponse (Endpoint endpoint ) {
7388 return new EndpointRequestHandler (
7489 EndpointManifestSchema .ProtocolMode .REQUEST_RESPONSE , endpoint );
@@ -93,17 +108,37 @@ public interface LoggingContextSetter {
93108 void set (String key , String value );
94109 }
95110
111+ /**
112+ * @deprecated Use {@link #processorForRequest(String, HeadersAccessor, LoggingContextSetter,
113+ * Executor, boolean)} instead.
114+ */
115+ @ Deprecated
116+ public RequestProcessor processorForRequest (
117+ String path ,
118+ HeadersAccessor headersAccessor ,
119+ LoggingContextSetter loggingContextSetter ,
120+ Executor coreExecutor )
121+ throws ProtocolException {
122+ return processorForRequest (
123+ path ,
124+ headersAccessor ,
125+ loggingContextSetter ,
126+ coreExecutor ,
127+ this .deprecatedSupportsBidirectionalStreaming );
128+ }
129+
96130 /**
97131 * @param coreExecutor This executor MUST serialize the execution of all scheduled tasks. For
98132 * example {@link Executors#newSingleThreadExecutor()} can be used.
133+ * @param supportsBidirectionalStreaming true if the server supports bidirectional streaming.
99134 * @return The request processor
100- * @throws ProtocolException in
101135 */
102136 public RequestProcessor processorForRequest (
103137 String path ,
104138 HeadersAccessor headersAccessor ,
105139 LoggingContextSetter loggingContextSetter ,
106- Executor coreExecutor )
140+ Executor coreExecutor ,
141+ boolean supportsBidirectionalStreaming )
107142 throws ProtocolException {
108143 if (path .endsWith (HEALTH_PATH )) {
109144 return new StaticResponseRequestProcessor (200 , "text/plain" , Slice .wrap ("OK" ));
@@ -120,7 +155,7 @@ public RequestProcessor processorForRequest(
120155
121156 // Discovery request
122157 if (path .endsWith (DISCOVER_PATH )) {
123- return this .handleDiscoveryRequest (headersAccessor );
158+ return this .handleDiscoveryRequest (supportsBidirectionalStreaming , headersAccessor );
124159 }
125160
126161 // Parse request
@@ -142,7 +177,6 @@ public RequestProcessor processorForRequest(
142177 StateMachine stateMachine = StateMachine .init (headersAccessor , loggingContextSetter );
143178
144179 // Resolve the service method definition
145- @ SuppressWarnings ("unchecked" )
146180 ServiceDefinition svc = this .endpoint .resolveService (serviceName );
147181 if (svc == null ) {
148182 throw ProtocolException .methodNotFound (serviceName , handlerName );
@@ -182,7 +216,8 @@ public RequestProcessor processorForRequest(
182216 coreExecutor );
183217 }
184218
185- StaticResponseRequestProcessor handleDiscoveryRequest (HeadersAccessor headersAccessor )
219+ StaticResponseRequestProcessor handleDiscoveryRequest (
220+ boolean supportsBidirectionalStreaming , HeadersAccessor headersAccessor )
186221 throws ProtocolException {
187222 String acceptContentType = headersAccessor .get (ACCEPT );
188223
@@ -195,7 +230,12 @@ StaticResponseRequestProcessor handleDiscoveryRequest(HeadersAccessor headersAcc
195230 ProtocolException .UNSUPPORTED_MEDIA_TYPE_CODE );
196231 }
197232
198- EndpointManifestSchema response = this .deploymentManifest .manifest (version );
233+ EndpointManifestSchema response =
234+ this .deploymentManifest .manifest (
235+ version ,
236+ supportsBidirectionalStreaming
237+ ? EndpointManifestSchema .ProtocolMode .BIDI_STREAM
238+ : EndpointManifestSchema .ProtocolMode .REQUEST_RESPONSE );
199239 LOG .info (
200240 "Replying to discovery request with services [{}]" ,
201241 response .getServices ().stream ().map (Service ::getName ).collect (Collectors .joining ("," )));
0 commit comments