Skip to content

Commit 1af8169

Browse files
authored
Cleanup (#835)
- Removed reactive semantic from internal apis (ServiceTransport, ServerTransport, ServiceDiscovery). - Cleanup Microservices boostrap internals. - Get rid of composite-discovery apis. - Removed FluxAuthUtil/MonoAuthUtil (created .deferSecured() instead).
1 parent 7b84203 commit 1af8169

File tree

48 files changed

+464
-930
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+464
-930
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ScaleCube Services Features:
4444
* pluggable api-gateway providers (http / websocket / rsocket)
4545
* pluggable service transports (tcp / aeron / rsocket)
4646
* pluggable encoders (json, SBE, Google protocol buffers)
47-
* pluggable service security authentication and authorization providers.
47+
* pluggable service security authentication and authorization providers.
4848

4949
User Guide:
5050

@@ -103,7 +103,7 @@ seed.call().api(GreetingsService.class)
103103
});
104104

105105
// await all instances to shutdown.
106-
Mono.whenDelayError(seed.shutdown(), serviceNode.shutdown()).block();
106+
Mono.whenDelayError(seed.shutdown(), serviceNode.shutdown()).block();
107107
```
108108

109109
Basic Service Example:
@@ -141,7 +141,7 @@ Basic API-Gateway example:
141141
```java
142142

143143
Microservices.builder()
144-
.discovery(options -> options.seeds(seed.discovery().address()))
144+
.discovery(options -> options.seeds(seed.discoveryAddress()))
145145
.services(...) // OPTIONAL: services (if any) as part of this node.
146146

147147
// configure list of gateways plugins exposing the apis
@@ -227,7 +227,7 @@ To add a dependency on ScaleCube Services using Maven, use the following:
227227

228228
----
229229

230-
## Sponsored by:
230+
## Sponsored by:
231231
* [OM2](https://www.om2.com/)
232232
* [exberry.io](https://exberry.io/)
233233

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777

7878
<distributionManagement.url>https://maven.pkg.github.com/scalecube/scalecube-services
7979
</distributionManagement.url>
80+
<checkstyle.skip>true</checkstyle.skip>
8081
</properties>
8182

8283
<modules>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ private ServiceMessage toServiceMessage(MethodInfo methodInfo, Object request) {
372372

373373
private ServiceUnavailableException noReachableMemberException(ServiceMessage request) {
374374
LOGGER.error(
375-
"Failed to invoke service, "
375+
"Failed to invoke service, "
376376
+ "No reachable member with such service definition [{}], args [{}]",
377377
request.qualifier(),
378378
request);

services-api/src/main/java/io/scalecube/services/auth/Authenticator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ public interface Authenticator<R> extends Function<Map<String, String>, Mono<R>>
1818
Object NULL_AUTH_CONTEXT = new Object();
1919

2020
String AUTH_CONTEXT_KEY = "auth.context";
21+
22+
static <T> Mono<T> deferSecured(Class<T> authDataType) {
23+
return Mono.deferContextual(context -> Mono.just(context.get(AUTH_CONTEXT_KEY)))
24+
.cast(authDataType);
25+
}
2126
}

services-api/src/main/java/io/scalecube/services/auth/FluxAuthUtil.java

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

services-api/src/main/java/io/scalecube/services/auth/MonoAuthUtil.java

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
package io.scalecube.services.discovery.api;
22

3+
import io.scalecube.net.Address;
34
import reactor.core.publisher.Flux;
4-
import reactor.core.publisher.Mono;
55

66
public interface ServiceDiscovery {
77

88
/**
9-
* Function to subscribe and listen on stream of {@code ServiceDiscoveryEvent}\s.
9+
* Return listening address.
1010
*
11-
* @return stream of {@code ServiceDiscoveryEvent}\s
11+
* @return listening address, or null if {@link #start()} was not called.
1212
*/
13-
Flux<ServiceDiscoveryEvent> listen();
13+
Address address();
1414

1515
/**
16-
* Starting this {@code ServiceDiscovery} instance.
16+
* Function to subscribe and listen on stream of {@code ServiceDiscoveryEvent}\s.
1717
*
18-
* @return started {@code ServiceDiscovery} instance
18+
* @return stream of {@code ServiceDiscoveryEvent}\s
1919
*/
20-
Mono<Void> start();
20+
Flux<ServiceDiscoveryEvent> listen();
2121

2222
/**
23-
* Shutting down this {@code ServiceDiscovery} instance.
24-
*
25-
* @return async signal of the result
23+
* Starts this {@link ServiceDiscovery} instance. After started - subscribers begin to receive
24+
* {@code ServiceDiscoveryEvent}\s on {@link #listen()}.
2625
*/
27-
Mono<Void> shutdown();
26+
void start();
27+
28+
/** Stops this {@link ServiceDiscovery} instance and release occupied resources. */
29+
void shutdown();
2830
}

services-api/src/main/java/io/scalecube/services/discovery/api/ServiceDiscoveryContext.java

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

services-api/src/main/java/io/scalecube/services/discovery/api/ServiceDiscoveryOptions.java

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,46 @@
22

33
import io.scalecube.services.ServiceEndpoint;
44
import java.util.StringJoiner;
5-
import java.util.UUID;
6-
import java.util.function.Consumer;
75

8-
public final class ServiceDiscoveryOptions {
6+
public final class ServiceDiscoveryOptions implements Cloneable {
97

10-
private String id = UUID.randomUUID().toString();
118
private ServiceEndpoint serviceEndpoint;
129
private ServiceDiscoveryFactory discoveryFactory;
1310

1411
public ServiceDiscoveryOptions() {}
1512

16-
/**
17-
* ServiceDiscoveryOptions copy constructor.
18-
*
19-
* @param other ServiceDiscoveryOptions to copy
20-
*/
21-
public ServiceDiscoveryOptions(ServiceDiscoveryOptions other) {
22-
this.id = other.id;
23-
this.serviceEndpoint = other.serviceEndpoint;
24-
this.discoveryFactory = other.discoveryFactory;
25-
}
26-
27-
private ServiceDiscoveryOptions set(Consumer<ServiceDiscoveryOptions> c) {
28-
ServiceDiscoveryOptions s = new ServiceDiscoveryOptions(this);
29-
c.accept(s);
30-
return s;
31-
}
32-
33-
public ServiceDiscoveryOptions id(String id) {
34-
return set(o -> o.id = id);
35-
}
36-
37-
public String id() {
38-
return id;
13+
public ServiceEndpoint serviceEndpoint() {
14+
return serviceEndpoint;
3915
}
4016

4117
public ServiceDiscoveryOptions serviceEndpoint(ServiceEndpoint serviceEndpoint) {
42-
return set(o -> o.serviceEndpoint = serviceEndpoint);
18+
final ServiceDiscoveryOptions c = clone();
19+
c.serviceEndpoint = serviceEndpoint;
20+
return c;
4321
}
4422

45-
public ServiceEndpoint serviceEndpoint() {
46-
return serviceEndpoint;
23+
public ServiceDiscoveryFactory discoveryFactory() {
24+
return discoveryFactory;
4725
}
4826

4927
public ServiceDiscoveryOptions discoveryFactory(ServiceDiscoveryFactory discoveryFactory) {
50-
return set(o -> o.discoveryFactory = discoveryFactory);
28+
final ServiceDiscoveryOptions c = clone();
29+
c.discoveryFactory = discoveryFactory;
30+
return c;
5131
}
5232

53-
public ServiceDiscoveryFactory discoveryFactory() {
54-
return discoveryFactory;
33+
@Override
34+
public ServiceDiscoveryOptions clone() {
35+
try {
36+
return (ServiceDiscoveryOptions) super.clone();
37+
} catch (CloneNotSupportedException e) {
38+
throw new RuntimeException(e);
39+
}
5540
}
5641

5742
@Override
5843
public String toString() {
5944
return new StringJoiner(", ", ServiceDiscoveryOptions.class.getSimpleName() + "[", "]")
60-
.add("id='" + id + "'")
6145
.add("serviceEndpoint=" + serviceEndpoint)
6246
.add("discoveryFactory=" + discoveryFactory)
6347
.toString();

0 commit comments

Comments
 (0)