Skip to content

Commit 4c4e658

Browse files
committed
Updated pom with new sc-cluster/commons/reactor/parent-pom
1 parent dd30d65 commit 4c4e658

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<parent>
99
<groupId>io.scalecube</groupId>
1010
<artifactId>scalecube-parent-pom</artifactId>
11-
<version>0.1.1</version>
11+
<version>0.1.2-RC3</version>
1212
</parent>
1313
<packaging>pom</packaging>
1414

@@ -23,11 +23,11 @@
2323

2424
<properties>
2525
<jackson.version>2.11.0</jackson.version>
26-
<scalecube-cluster.version>2.6.0-RC2</scalecube-cluster.version>
27-
<scalecube-commons.version>1.0.4</scalecube-commons.version>
26+
<scalecube-cluster.version>2.6.0-RC3</scalecube-cluster.version>
27+
<scalecube-commons.version>1.0.7</scalecube-commons.version>
2828
<scalecube-benchmarks.version>1.2.2</scalecube-benchmarks.version>
2929
<scalecube-config.version>0.4.3</scalecube-config.version>
30-
<reactor.version>Dysprosium-SR8</reactor.version>
30+
<reactor.version>Dysprosium-SR9</reactor.version>
3131
<rsocket.version>1.0.1</rsocket.version>
3232
<protostuff.version>1.6.0</protostuff.version>
3333
<netty.version>4.1.50.Final</netty.version>

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public static Builder builder() {
4848
return new Builder();
4949
}
5050

51+
public static Builder from(ServiceEndpoint serviceEndpoint) {
52+
return new Builder(serviceEndpoint);
53+
}
54+
5155
public String id() {
5256
return id;
5357
}
@@ -163,6 +167,14 @@ public static class Builder {
163167

164168
private Builder() {}
165169

170+
private Builder(ServiceEndpoint other) {
171+
this.id = other.id;
172+
this.address = other.address;
173+
this.contentTypes = new HashSet<>(other.contentTypes);
174+
this.tags = new HashMap<>(other.tags);
175+
this.serviceRegistrations = new ArrayList<>(other.serviceRegistrations);
176+
}
177+
166178
public Builder id(String id) {
167179
this.id = Objects.requireNonNull(id, "id");
168180
return this;
@@ -174,12 +186,12 @@ public Builder address(Address address) {
174186
}
175187

176188
public Builder contentTypes(Set<String> contentTypes) {
177-
this.contentTypes = Objects.requireNonNull(contentTypes, "contentTypes");
189+
this.contentTypes = new HashSet<>(Objects.requireNonNull(contentTypes, "contentTypes"));
178190
return this;
179191
}
180192

181193
public Builder tags(Map<String, String> tags) {
182-
this.tags = Objects.requireNonNull(tags, "tags");
194+
this.tags = new HashMap<>(Objects.requireNonNull(tags, "tags"));
183195
return this;
184196
}
185197

@@ -204,7 +216,7 @@ public Builder appendServiceRegistrations(
204216
*/
205217
public Builder serviceRegistrations(Collection<ServiceRegistration> serviceRegistrations) {
206218
this.serviceRegistrations =
207-
Objects.requireNonNull(serviceRegistrations, "serviceRegistrations");
219+
new ArrayList<>(Objects.requireNonNull(serviceRegistrations, "serviceRegistrations"));
208220
return this;
209221
}
210222

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.lang.management.ManagementFactory;
3232
import java.util.ArrayList;
3333
import java.util.Arrays;
34+
import java.util.Collections;
3435
import java.util.HashMap;
3536
import java.util.List;
3637
import java.util.Map;
@@ -143,9 +144,11 @@ public final class Microservices {
143144
private final MonoProcessor<Void> shutdown = MonoProcessor.create();
144145
private final MonoProcessor<Void> onShutdown = MonoProcessor.create();
145146
private ServiceEndpoint serviceEndpoint;
147+
private String containerHost;
148+
private Integer containerPort;
146149

147150
private Microservices(Builder builder) {
148-
this.tags = new HashMap<>(builder.tags);
151+
this.tags = Collections.unmodifiableMap(new HashMap<>(builder.tags));
149152
this.serviceProviders = new ArrayList<>(builder.serviceProviders);
150153
this.serviceRegistry = builder.serviceRegistry;
151154
this.methodRegistry = builder.methodRegistry;
@@ -157,6 +160,8 @@ private Microservices(Builder builder) {
157160
this.dataDecoder = builder.dataDecoder;
158161
this.contentType = builder.contentType;
159162
this.principalMapper = builder.principalMapper;
163+
this.containerHost = builder.containerHost;
164+
this.containerPort = builder.containerPort;
160165

161166
// Setup cleanup
162167
shutdown
@@ -217,7 +222,7 @@ private Mono<Microservices> start() {
217222
LOGGER.warn("[{}] ServiceTransport is not set", this.id());
218223
}
219224

220-
serviceEndpoint = serviceEndpointBuilder.build();
225+
serviceEndpoint = newServiceEndpoint(serviceEndpointBuilder.build());
221226

222227
return createDiscovery(
223228
this, new ServiceDiscoveryOptions().serviceEndpoint(serviceEndpoint))
@@ -236,6 +241,20 @@ this, new ServiceDiscoveryOptions().serviceEndpoint(serviceEndpoint))
236241
.doOnTerminate(scheduler::dispose);
237242
}
238243

244+
private ServiceEndpoint newServiceEndpoint(ServiceEndpoint serviceEndpoint) {
245+
ServiceEndpoint.Builder builder = ServiceEndpoint.from(serviceEndpoint);
246+
247+
int port = Optional.ofNullable(containerPort).orElse(serviceEndpoint.address().port());
248+
249+
// calculate local service endpoint address
250+
Address newAddress =
251+
Optional.ofNullable(containerHost)
252+
.map(host -> Address.create(host, port))
253+
.orElseGet(() -> Address.create(serviceEndpoint.address().host(), port));
254+
255+
return builder.address(newAddress).build();
256+
}
257+
239258
private Mono<GatewayBootstrap> startGateway(GatewayOptions options) {
240259
return gatewayBootstrap.start(this, options);
241260
}
@@ -373,6 +392,8 @@ public static final class Builder {
373392
.orElse((message, dataType) -> message);
374393
private String contentType = ServiceMessage.DEFAULT_DATA_FORMAT;
375394
private PrincipalMapper<Object, Object> principalMapper = authData -> authData;
395+
private String containerHost;
396+
private Integer containerPort;
376397

377398
public Mono<Microservices> start() {
378399
return Mono.defer(() -> new Microservices(this).start());
@@ -411,6 +432,16 @@ public Builder services(ServiceProvider serviceProvider) {
411432
return this;
412433
}
413434

435+
public Builder containerHost(String containerHost) {
436+
this.containerHost = containerHost;
437+
return this;
438+
}
439+
440+
public Builder containerPort(Integer containerPort) {
441+
this.containerPort = containerPort;
442+
return this;
443+
}
444+
414445
public Builder serviceRegistry(ServiceRegistry serviceRegistry) {
415446
this.serviceRegistry = serviceRegistry;
416447
return this;

0 commit comments

Comments
 (0)