Skip to content

Commit 113886d

Browse files
authored
Merged ServiceMethodRegistry into ServiceRegistry (#841)
1 parent 24dff0f commit 113886d

File tree

11 files changed

+145
-184
lines changed

11 files changed

+145
-184
lines changed

services-api/src/main/java/io/scalecube/services/ServiceCall.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import io.scalecube.services.exceptions.ServiceUnavailableException;
88
import io.scalecube.services.methods.MethodInfo;
99
import io.scalecube.services.methods.ServiceMethodInvoker;
10-
import io.scalecube.services.methods.ServiceMethodRegistry;
1110
import io.scalecube.services.registry.api.ServiceRegistry;
1211
import io.scalecube.services.routing.Router;
1312
import io.scalecube.services.routing.Routers;
@@ -34,7 +33,6 @@ public class ServiceCall {
3433
private static final Logger LOGGER = LoggerFactory.getLogger(ServiceCall.class);
3534

3635
private ClientTransport transport;
37-
private ServiceMethodRegistry methodRegistry;
3836
private ServiceRegistry serviceRegistry;
3937
private Router router;
4038
private ServiceClientErrorMapper errorMapper = DefaultErrorMapper.INSTANCE;
@@ -45,7 +43,6 @@ public ServiceCall() {}
4543

4644
private ServiceCall(ServiceCall other) {
4745
this.transport = other.transport;
48-
this.methodRegistry = other.methodRegistry;
4946
this.serviceRegistry = other.serviceRegistry;
5047
this.router = other.router;
5148
this.errorMapper = other.errorMapper;
@@ -77,18 +74,6 @@ public ServiceCall serviceRegistry(ServiceRegistry serviceRegistry) {
7774
return target;
7875
}
7976

80-
/**
81-
* Setter for {@code methodRegistry}.
82-
*
83-
* @param methodRegistry method registry.
84-
* @return new {@link ServiceCall} instance.
85-
*/
86-
public ServiceCall methodRegistry(ServiceMethodRegistry methodRegistry) {
87-
ServiceCall target = new ServiceCall(this);
88-
target.methodRegistry = methodRegistry;
89-
return target;
90-
}
91-
9277
/**
9378
* Setter for {@code routerType}.
9479
*
@@ -180,8 +165,8 @@ public Mono<ServiceMessage> requestOne(ServiceMessage request, Type responseType
180165
return Mono.defer(
181166
() -> {
182167
ServiceMethodInvoker methodInvoker;
183-
if (methodRegistry != null
184-
&& (methodInvoker = methodRegistry.getInvoker(request.qualifier())) != null) {
168+
if (serviceRegistry != null
169+
&& (methodInvoker = serviceRegistry.getInvoker(request.qualifier())) != null) {
185170
// local service
186171
return methodInvoker.invokeOne(request).map(this::throwIfError);
187172
} else {
@@ -219,8 +204,8 @@ public Flux<ServiceMessage> requestMany(ServiceMessage request, Type responseTyp
219204
return Flux.defer(
220205
() -> {
221206
ServiceMethodInvoker methodInvoker;
222-
if (methodRegistry != null
223-
&& (methodInvoker = methodRegistry.getInvoker(request.qualifier())) != null) {
207+
if (serviceRegistry != null
208+
&& (methodInvoker = serviceRegistry.getInvoker(request.qualifier())) != null) {
224209
// local service
225210
return methodInvoker.invokeMany(request).map(this::throwIfError);
226211
} else {
@@ -262,8 +247,8 @@ public Flux<ServiceMessage> requestBidirectional(
262247
if (first.hasValue()) {
263248
ServiceMessage request = first.get();
264249
ServiceMethodInvoker methodInvoker;
265-
if (methodRegistry != null
266-
&& (methodInvoker = methodRegistry.getInvoker(request.qualifier())) != null) {
250+
if (serviceRegistry != null
251+
&& (methodInvoker = serviceRegistry.getInvoker(request.qualifier())) != null) {
267252
// local service
268253
return methodInvoker.invokeBidirectional(messages).map(this::throwIfError);
269254
} else {

services-api/src/main/java/io/scalecube/services/methods/ServiceMethodRegistry.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

services-api/src/main/java/io/scalecube/services/registry/api/ServiceRegistry.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package io.scalecube.services.registry.api;
22

33
import io.scalecube.services.ServiceEndpoint;
4+
import io.scalecube.services.ServiceInfo;
45
import io.scalecube.services.ServiceReference;
56
import io.scalecube.services.api.ServiceMessage;
7+
import io.scalecube.services.methods.ServiceMethodInvoker;
68
import java.util.List;
79

810
/**
@@ -20,4 +22,10 @@ public interface ServiceRegistry {
2022
boolean registerService(ServiceEndpoint serviceEndpoint);
2123

2224
ServiceEndpoint unregisterService(String endpointId);
25+
26+
void registerService(ServiceInfo serviceInfo);
27+
28+
List<ServiceInfo> listServices();
29+
30+
ServiceMethodInvoker getInvoker(String qualifier);
2331
}

services-api/src/main/java/io/scalecube/services/transport/api/ServiceTransport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.scalecube.services.transport.api;
22

3-
import io.scalecube.services.methods.ServiceMethodRegistry;
3+
import io.scalecube.services.registry.api.ServiceRegistry;
44

55
public interface ServiceTransport {
66

@@ -14,10 +14,10 @@ public interface ServiceTransport {
1414
/**
1515
* Provider for {@link ServerTransport}.
1616
*
17-
* @param methodRegistry methodRegistry
17+
* @param serviceRegistry serviceRegistry
1818
* @return {@code ServerTransport} instance
1919
*/
20-
ServerTransport serverTransport(ServiceMethodRegistry methodRegistry);
20+
ServerTransport serverTransport(ServiceRegistry serviceRegistry);
2121

2222
/**
2323
* Starts {@link ServiceTransport} instance.

services-transport-parent/services-transport-rsocket/src/main/java/io/scalecube/services/transport/rsocket/RSocketServerTransport.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import io.rsocket.transport.netty.server.CloseableChannel;
66
import io.scalecube.net.Address;
77
import io.scalecube.services.auth.Authenticator;
8-
import io.scalecube.services.methods.ServiceMethodRegistry;
8+
import io.scalecube.services.registry.api.ServiceRegistry;
99
import io.scalecube.services.transport.api.DataCodec;
1010
import io.scalecube.services.transport.api.HeadersCodec;
1111
import io.scalecube.services.transport.api.ServerTransport;
@@ -18,7 +18,7 @@ public class RSocketServerTransport implements ServerTransport {
1818
private static final Logger LOGGER = LoggerFactory.getLogger(RSocketServerTransport.class);
1919

2020
private final Authenticator<Object> authenticator;
21-
private final ServiceMethodRegistry methodRegistry;
21+
private final ServiceRegistry serviceRegistry;
2222
private final ConnectionSetupCodec connectionSetupCodec;
2323
private final HeadersCodec headersCodec;
2424
private final Collection<DataCodec> dataCodecs;
@@ -30,21 +30,21 @@ public class RSocketServerTransport implements ServerTransport {
3030
* Constructor for this server transport.
3131
*
3232
* @param authenticator authenticator
33-
* @param methodRegistry methodRegistry
33+
* @param serviceRegistry serviceRegistry
3434
* @param connectionSetupCodec connectionSetupCodec
3535
* @param headersCodec headersCodec
3636
* @param dataCodecs dataCodecs
3737
* @param serverTransportFactory serverTransportFactory
3838
*/
3939
public RSocketServerTransport(
4040
Authenticator<Object> authenticator,
41-
ServiceMethodRegistry methodRegistry,
41+
ServiceRegistry serviceRegistry,
4242
ConnectionSetupCodec connectionSetupCodec,
4343
HeadersCodec headersCodec,
4444
Collection<DataCodec> dataCodecs,
4545
RSocketServerTransportFactory serverTransportFactory) {
4646
this.authenticator = authenticator;
47-
this.methodRegistry = methodRegistry;
47+
this.serviceRegistry = serviceRegistry;
4848
this.connectionSetupCodec = connectionSetupCodec;
4949
this.headersCodec = headersCodec;
5050
this.dataCodecs = dataCodecs;
@@ -64,7 +64,7 @@ public ServerTransport bind() {
6464
RSocketServer.create()
6565
.acceptor(
6666
new RSocketServiceAcceptor(
67-
connectionSetupCodec, headersCodec, dataCodecs, authenticator, methodRegistry))
67+
connectionSetupCodec, headersCodec, dataCodecs, authenticator, serviceRegistry))
6868
.payloadDecoder(PayloadDecoder.DEFAULT)
6969
.bind(serverTransportFactory.serverTransport())
7070
.doOnSuccess(channel -> serverChannel = channel)

services-transport-parent/services-transport-rsocket/src/main/java/io/scalecube/services/transport/rsocket/RSocketServiceAcceptor.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import io.scalecube.services.exceptions.ServiceUnavailableException;
1818
import io.scalecube.services.exceptions.UnauthorizedException;
1919
import io.scalecube.services.methods.ServiceMethodInvoker;
20-
import io.scalecube.services.methods.ServiceMethodRegistry;
20+
import io.scalecube.services.registry.api.ServiceRegistry;
2121
import io.scalecube.services.transport.api.DataCodec;
2222
import io.scalecube.services.transport.api.HeadersCodec;
2323
import java.util.Collection;
@@ -36,7 +36,7 @@ public class RSocketServiceAcceptor implements SocketAcceptor {
3636
private final HeadersCodec headersCodec;
3737
private final Collection<DataCodec> dataCodecs;
3838
private final Authenticator<Object> authenticator;
39-
private final ServiceMethodRegistry methodRegistry;
39+
private final ServiceRegistry serviceRegistry;
4040

4141
/**
4242
* Constructor.
@@ -45,19 +45,19 @@ public class RSocketServiceAcceptor implements SocketAcceptor {
4545
* @param headersCodec headersCodec
4646
* @param dataCodecs dataCodecs
4747
* @param authenticator authenticator
48-
* @param methodRegistry methodRegistry
48+
* @param serviceRegistry serviceRegistry
4949
*/
5050
public RSocketServiceAcceptor(
5151
ConnectionSetupCodec connectionSetupCodec,
5252
HeadersCodec headersCodec,
5353
Collection<DataCodec> dataCodecs,
5454
Authenticator<Object> authenticator,
55-
ServiceMethodRegistry methodRegistry) {
55+
ServiceRegistry serviceRegistry) {
5656
this.connectionSetupCodec = connectionSetupCodec;
5757
this.headersCodec = headersCodec;
5858
this.dataCodecs = dataCodecs;
5959
this.authenticator = authenticator;
60-
this.methodRegistry = methodRegistry;
60+
this.serviceRegistry = serviceRegistry;
6161
}
6262

6363
@Override
@@ -99,7 +99,7 @@ private Mono<Object> authenticate(RSocket rsocket, ConnectionSetup connectionSet
9999

100100
private RSocket newRSocket(Object authData) {
101101
return new RSocketImpl(
102-
authData, new ServiceMessageCodec(headersCodec, dataCodecs), methodRegistry);
102+
authData, new ServiceMessageCodec(headersCodec, dataCodecs), serviceRegistry);
103103
}
104104

105105
private UnauthorizedException toUnauthorizedException(Throwable th) {
@@ -115,13 +115,13 @@ private static class RSocketImpl implements RSocket {
115115

116116
private final Object authData;
117117
private final ServiceMessageCodec messageCodec;
118-
private final ServiceMethodRegistry methodRegistry;
118+
private final ServiceRegistry serviceRegistry;
119119

120120
private RSocketImpl(
121-
Object authData, ServiceMessageCodec messageCodec, ServiceMethodRegistry methodRegistry) {
121+
Object authData, ServiceMessageCodec messageCodec, ServiceRegistry serviceRegistry) {
122122
this.authData = authData;
123123
this.messageCodec = messageCodec;
124-
this.methodRegistry = methodRegistry;
124+
this.serviceRegistry = serviceRegistry;
125125
}
126126

127127
@Override
@@ -130,7 +130,8 @@ public Mono<Payload> requestResponse(Payload payload) {
130130
.doOnNext(this::validateRequest)
131131
.flatMap(
132132
message -> {
133-
ServiceMethodInvoker methodInvoker = methodRegistry.getInvoker(message.qualifier());
133+
ServiceMethodInvoker methodInvoker =
134+
serviceRegistry.getInvoker(message.qualifier());
134135
validateMethodInvoker(methodInvoker, message);
135136
return methodInvoker
136137
.invokeOne(message)
@@ -147,7 +148,8 @@ public Flux<Payload> requestStream(Payload payload) {
147148
.doOnNext(this::validateRequest)
148149
.flatMapMany(
149150
message -> {
150-
ServiceMethodInvoker methodInvoker = methodRegistry.getInvoker(message.qualifier());
151+
ServiceMethodInvoker methodInvoker =
152+
serviceRegistry.getInvoker(message.qualifier());
151153
validateMethodInvoker(methodInvoker, message);
152154
return methodInvoker
153155
.invokeMany(message)
@@ -168,7 +170,7 @@ public Flux<Payload> requestChannel(Publisher<Payload> payloads) {
168170
ServiceMessage message = first.get();
169171
validateRequest(message);
170172
ServiceMethodInvoker methodInvoker =
171-
methodRegistry.getInvoker(message.qualifier());
173+
serviceRegistry.getInvoker(message.qualifier());
172174
validateMethodInvoker(methodInvoker, message);
173175
return methodInvoker
174176
.invokeBidirectional(messages)

services-transport-parent/services-transport-rsocket/src/main/java/io/scalecube/services/transport/rsocket/RSocketServiceTransport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import io.scalecube.services.auth.Authenticator;
1010
import io.scalecube.services.auth.CredentialsSupplier;
1111
import io.scalecube.services.exceptions.ConnectionClosedException;
12-
import io.scalecube.services.methods.ServiceMethodRegistry;
12+
import io.scalecube.services.registry.api.ServiceRegistry;
1313
import io.scalecube.services.transport.api.ClientTransport;
1414
import io.scalecube.services.transport.api.DataCodec;
1515
import io.scalecube.services.transport.api.HeadersCodec;
@@ -195,10 +195,10 @@ public ClientTransport clientTransport() {
195195
}
196196

197197
@Override
198-
public ServerTransport serverTransport(ServiceMethodRegistry methodRegistry) {
198+
public ServerTransport serverTransport(ServiceRegistry serviceRegistry) {
199199
return new RSocketServerTransport(
200200
authenticator,
201-
methodRegistry,
201+
serviceRegistry,
202202
connectionSetupCodec,
203203
headersCodec,
204204
dataCodecs,

services/src/main/java/io/scalecube/services/Microservices.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import io.scalecube.services.exceptions.ServiceProviderErrorMapper;
1616
import io.scalecube.services.gateway.Gateway;
1717
import io.scalecube.services.gateway.GatewayOptions;
18-
import io.scalecube.services.methods.ServiceMethodRegistry;
19-
import io.scalecube.services.methods.ServiceMethodRegistryImpl;
2018
import io.scalecube.services.registry.ServiceRegistryImpl;
2119
import io.scalecube.services.registry.api.ServiceRegistry;
2220
import io.scalecube.services.routing.RoundRobinServiceRouter;
@@ -124,7 +122,6 @@ public final class Microservices implements AutoCloseable {
124122
private final Map<String, String> tags;
125123
private final List<ServiceProvider> serviceProviders;
126124
private final ServiceRegistry serviceRegistry;
127-
private final ServiceMethodRegistry methodRegistry;
128125
private final Authenticator<Object> defaultAuthenticator;
129126
private final ServiceTransportBootstrap transportBootstrap;
130127
private final GatewayBootstrap gatewayBootstrap;
@@ -143,7 +140,6 @@ private Microservices(Builder builder) {
143140
this.tags = Collections.unmodifiableMap(new HashMap<>(builder.tags));
144141
this.serviceProviders = new ArrayList<>(builder.serviceProviders);
145142
this.serviceRegistry = builder.serviceRegistry;
146-
this.methodRegistry = builder.methodRegistry;
147143
this.defaultAuthenticator = builder.defaultAuthenticator;
148144
this.gatewayBootstrap = builder.gatewayBootstrap;
149145
this.discoveryBootstrap = builder.discoveryBootstrap;
@@ -241,7 +237,7 @@ private Mono<ServiceDiscoveryBootstrap> concludeDiscovery(
241237
}
242238

243239
private void registerService(ServiceInfo serviceInfo) {
244-
methodRegistry.registerService(
240+
serviceRegistry.registerService(
245241
ServiceInfo.from(serviceInfo)
246242
.errorMapperIfAbsent(defaultErrorMapper)
247243
.dataDecoderIfAbsent(defaultDataDecoder)
@@ -258,7 +254,6 @@ public ServiceCall call() {
258254
return new ServiceCall()
259255
.transport(transportBootstrap.clientTransport)
260256
.serviceRegistry(serviceRegistry)
261-
.methodRegistry(methodRegistry)
262257
.contentType(defaultContentType)
263258
.errorMapper(DefaultErrorMapper.INSTANCE)
264259
.router(Routers.getRouter(RoundRobinServiceRouter.class));
@@ -288,10 +283,6 @@ public ServiceRegistry serviceRegistry() {
288283
return serviceRegistry;
289284
}
290285

291-
public ServiceMethodRegistry methodRegistry() {
292-
return methodRegistry;
293-
}
294-
295286
public Address discoveryAddress() {
296287
return discoveryBootstrap.serviceDiscovery != null
297288
? discoveryBootstrap.serviceDiscovery.address()
@@ -350,7 +341,7 @@ private Mono<Void> applyBeforeDestroy() {
350341
return Mono.defer(
351342
() ->
352343
Mono.whenDelayError(
353-
methodRegistry.listServices().stream()
344+
serviceRegistry.listServices().stream()
354345
.map(ServiceInfo::serviceInstance)
355346
.map(s -> Mono.fromRunnable(() -> Injector.processBeforeDestroy(this, s)))
356347
.collect(Collectors.toList())));
@@ -370,7 +361,6 @@ public static final class Builder {
370361
private Map<String, String> tags = new HashMap<>();
371362
private final List<ServiceProvider> serviceProviders = new ArrayList<>();
372363
private ServiceRegistry serviceRegistry = new ServiceRegistryImpl();
373-
private ServiceMethodRegistry methodRegistry = new ServiceMethodRegistryImpl();
374364
private Authenticator<Object> defaultAuthenticator = null;
375365
private final ServiceDiscoveryBootstrap discoveryBootstrap = new ServiceDiscoveryBootstrap();
376366
private ServiceTransportBootstrap transportBootstrap = new ServiceTransportBootstrap();
@@ -436,11 +426,6 @@ public Builder serviceRegistry(ServiceRegistry serviceRegistry) {
436426
return this;
437427
}
438428

439-
public Builder methodRegistry(ServiceMethodRegistry methodRegistry) {
440-
this.methodRegistry = methodRegistry;
441-
return this;
442-
}
443-
444429
public Builder discovery(ServiceDiscoveryFactory discoveryFactory) {
445430
this.discoveryBootstrap.operator(options -> options.discoveryFactory(discoveryFactory));
446431
return this;
@@ -717,7 +702,7 @@ private ServiceTransportBootstrap start(Microservices microservices) {
717702
try {
718703
try {
719704
serviceTransport = serviceTransport.start();
720-
serverTransport = serviceTransport.serverTransport(microservices.methodRegistry).bind();
705+
serverTransport = serviceTransport.serverTransport(microservices.serviceRegistry).bind();
721706
} catch (Exception e) {
722707
throw new RuntimeException(e);
723708
}

0 commit comments

Comments
 (0)