forked from spring-projects/spring-framework
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prior to this commit, the `RSocketRequester.Builder` would allow to configure directly annotated handlers for processing server requests. This lead to a package tangle where the `o.s.messaging.rsocket` would use classes from `o.s.messaging.rsocket.annotation.support` package. This commit introduces the `ClientResponder` interface for configuring a responder on the client requester. This is compatible with future changes with a parallel implementation of a functional variant for RSocket handlers. Closes spring-projectsgh-23170
- Loading branch information
Showing
6 changed files
with
146 additions
and
22 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
spring-messaging/src/main/java/org/springframework/messaging/rsocket/ClientResponder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2002-2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.messaging.rsocket; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
import io.rsocket.ConnectionSetupPayload; | ||
import io.rsocket.RSocket; | ||
|
||
import org.springframework.util.RouteMatcher; | ||
|
||
/** | ||
* Handle requests sent by the RSocket server to the client. | ||
* @author Brian Clozel | ||
* @since 5.2 | ||
*/ | ||
public interface ClientResponder { | ||
|
||
/** | ||
* Create a client Socket acceptor for handling server requests. | ||
* @param matcher the route matcher for routing incoming requests | ||
* @param strategies the codecs strategies for (de)serializing messages | ||
* @return a client Socket acceptor | ||
*/ | ||
BiFunction<ConnectionSetupPayload, RSocket, RSocket> toSocketAcceptor( | ||
RouteMatcher matcher, RSocketStrategies strategies); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...java/org/springframework/messaging/rsocket/annotation/support/DefaultClientResponder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2002-2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.messaging.rsocket.annotation.support; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.function.BiFunction; | ||
|
||
import io.rsocket.ConnectionSetupPayload; | ||
import io.rsocket.RSocket; | ||
|
||
import org.springframework.messaging.rsocket.ClientResponder; | ||
import org.springframework.messaging.rsocket.RSocketStrategies; | ||
import org.springframework.util.Assert; | ||
import org.springframework.util.RouteMatcher; | ||
|
||
/** | ||
* Default implementation of {@link ClientResponder} for annotated handlers. | ||
* @author Brian Clozel | ||
*/ | ||
class DefaultClientResponder implements ClientResponder { | ||
|
||
private final List<Object> handlers; | ||
|
||
DefaultClientResponder(Object... handlers) { | ||
Assert.notEmpty(handlers, "handlers should not be empty"); | ||
this.handlers = Arrays.asList(handlers); | ||
} | ||
|
||
@Override | ||
public BiFunction<ConnectionSetupPayload, RSocket, RSocket> toSocketAcceptor(RouteMatcher routeMatcher, RSocketStrategies strategies) { | ||
RSocketMessageHandler messageHandler = new RSocketMessageHandler(); | ||
messageHandler.setHandlers(this.handlers); | ||
messageHandler.setRSocketStrategies(strategies); | ||
messageHandler.setRouteMatcher(routeMatcher); | ||
messageHandler.afterPropertiesSet(); | ||
return messageHandler.clientAcceptor(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters