Skip to content

Commit abcbce8

Browse files
authored
Merge pull request #701 from scalecube/update/scalecube-cluster
Update/scalecube cluster on RC5
2 parents 79d9053 + 207a844 commit abcbce8

File tree

12 files changed

+355
-192
lines changed

12 files changed

+355
-192
lines changed

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
<properties>
2525
<jackson.version>2.10.0.pr1</jackson.version>
26-
<scalecube-cluster.version>2.4.10-RC1</scalecube-cluster.version>
26+
<scalecube-cluster.version>2.4.10-RC5</scalecube-cluster.version>
2727
<scalecube-commons.version>1.0.1</scalecube-commons.version>
2828
<scalecube-benchmarks.version>1.2.2</scalecube-benchmarks.version>
2929
<scalecube-config.version>0.3.11</scalecube-config.version>
@@ -69,6 +69,11 @@
6969
<artifactId>scalecube-cluster</artifactId>
7070
<version>${scalecube-cluster.version}</version>
7171
</dependency>
72+
<dependency>
73+
<groupId>io.scalecube</groupId>
74+
<artifactId>scalecube-codec-jackson</artifactId>
75+
<version>${scalecube-cluster.version}</version>
76+
</dependency>
7277

7378
<!-- Scalecube Config -->
7479
<dependency>

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

Lines changed: 85 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
package io.scalecube.services;
22

33
import io.scalecube.net.Address;
4+
import java.io.Externalizable;
5+
import java.io.IOException;
6+
import java.io.ObjectInput;
7+
import java.io.ObjectOutput;
48
import java.util.ArrayList;
59
import java.util.Collection;
610
import java.util.Collections;
711
import java.util.HashMap;
812
import java.util.HashSet;
13+
import java.util.List;
914
import java.util.Map;
15+
import java.util.Map.Entry;
16+
import java.util.Objects;
1017
import java.util.Set;
1118
import java.util.StringJoiner;
1219
import java.util.stream.Collectors;
1320

14-
public class ServiceEndpoint {
21+
public class ServiceEndpoint implements Externalizable {
22+
23+
private static final long serialVersionUID = 1L;
1524

1625
private String id;
1726
private Address address;
@@ -27,12 +36,12 @@ public class ServiceEndpoint {
2736
public ServiceEndpoint() {}
2837

2938
private ServiceEndpoint(Builder builder) {
30-
this.id = builder.id;
39+
this.id = Objects.requireNonNull(builder.id, "ServiceEndpoint.id is required");
3140
this.address = builder.address;
3241
this.contentTypes = Collections.unmodifiableSet(new HashSet<>(builder.contentTypes));
33-
this.tags = new HashMap<>(builder.tags);
42+
this.tags = Collections.unmodifiableMap(new HashMap<>(builder.tags));
3443
this.serviceRegistrations =
35-
Collections.unmodifiableCollection(new ArrayList<>(builder.serviceRegistrations));
44+
Collections.unmodifiableList(new ArrayList<>(builder.serviceRegistrations));
3645
}
3746

3847
public static Builder builder() {
@@ -55,19 +64,14 @@ public Map<String, String> tags() {
5564
return tags;
5665
}
5766

58-
/**
59-
* Return collection of service registratrions.
60-
*
61-
* @return collection of {@link ServiceRegistration}
62-
*/
6367
public Collection<ServiceRegistration> serviceRegistrations() {
6468
return serviceRegistrations;
6569
}
6670

6771
/**
68-
* Creates collection of service references from this service endpoint.
72+
* Creates collection of service references from {@code serviceRegistrations}.
6973
*
70-
* @return collection of {@link ServiceReference}
74+
* @return {@link ServiceReference} collection
7175
*/
7276
public Collection<ServiceReference> serviceReferences() {
7377
return serviceRegistrations.stream()
@@ -86,6 +90,76 @@ public String toString() {
8690
.toString();
8791
}
8892

93+
@Override
94+
public void writeExternal(ObjectOutput out) throws IOException {
95+
// id
96+
out.writeUTF(id);
97+
98+
// address
99+
boolean addressExists = address != null;
100+
out.writeBoolean(addressExists);
101+
if (addressExists) {
102+
out.writeUTF(address.toString());
103+
}
104+
105+
// contentTypes
106+
out.writeInt(contentTypes.size());
107+
for (String contentType : contentTypes) {
108+
out.writeUTF(contentType);
109+
}
110+
111+
// tags
112+
out.writeInt(tags.size());
113+
for (Entry<String, String> entry : tags.entrySet()) {
114+
out.writeUTF(entry.getKey());
115+
out.writeUTF(entry.getValue());
116+
}
117+
118+
// serviceRegistrations
119+
out.writeInt(serviceRegistrations.size());
120+
for (ServiceRegistration registration : serviceRegistrations) {
121+
out.writeObject(registration);
122+
}
123+
}
124+
125+
@Override
126+
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
127+
// id
128+
id = in.readUTF();
129+
130+
// address
131+
boolean addressExists = in.readBoolean();
132+
if (addressExists) {
133+
address = Address.from(in.readUTF());
134+
}
135+
136+
// contentTypes
137+
int contentTypesSize = in.readInt();
138+
Set<String> contentTypes = new HashSet<>(contentTypesSize);
139+
for (int i = 0; i < contentTypesSize; i++) {
140+
contentTypes.add(in.readUTF());
141+
}
142+
this.contentTypes = Collections.unmodifiableSet(contentTypes);
143+
144+
// tags
145+
int tagsSize = in.readInt();
146+
Map<String, String> tags = new HashMap<>(tagsSize);
147+
for (int i = 0; i < tagsSize; i++) {
148+
String key = in.readUTF();
149+
String value = in.readUTF();
150+
tags.put(key, value);
151+
}
152+
this.tags = Collections.unmodifiableMap(tags);
153+
154+
// serviceRegistrations
155+
int serviceRegistrationsSize = in.readInt();
156+
List<ServiceRegistration> serviceRegistrations = new ArrayList<>(serviceRegistrationsSize);
157+
for (int i = 0; i < serviceRegistrationsSize; i++) {
158+
serviceRegistrations.add((ServiceRegistration) in.readObject());
159+
}
160+
this.serviceRegistrations = Collections.unmodifiableList(serviceRegistrations);
161+
}
162+
89163
public static class Builder {
90164

91165
private String id;
Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
package io.scalecube.services;
22

3+
import java.io.Externalizable;
4+
import java.io.IOException;
5+
import java.io.ObjectInput;
6+
import java.io.ObjectOutput;
37
import java.util.Collections;
8+
import java.util.HashMap;
49
import java.util.Map;
10+
import java.util.Map.Entry;
11+
import java.util.Objects;
512
import java.util.StringJoiner;
613

714
/**
815
* A Service Method Definition is a single method definition of a service inside service
916
* registration.
1017
*/
11-
public class ServiceMethodDefinition {
18+
public class ServiceMethodDefinition implements Externalizable {
19+
20+
private static final long serialVersionUID = 1L;
1221

1322
private String action;
1423
private Map<String, String> tags;
@@ -38,43 +47,23 @@ public ServiceMethodDefinition(String action) {
3847
* @param auth is method protected by authentication
3948
*/
4049
public ServiceMethodDefinition(String action, Map<String, String> tags, boolean auth) {
41-
this.action = action;
42-
this.tags = tags;
50+
this.action = Objects.requireNonNull(action, "ServiceMethodDefinition.action is required");
51+
this.tags = Collections.unmodifiableMap(new HashMap<>(tags));
4352
this.auth = auth;
4453
}
4554

46-
/**
47-
* a generic definition for method name.
48-
*
49-
* @return the method name
50-
*/
51-
public String getAction() {
55+
public String action() {
5256
return action;
5357
}
5458

55-
public ServiceMethodDefinition setAction(String action) {
56-
this.action = action;
57-
return this;
58-
}
59-
60-
public Map<String, String> getTags() {
59+
public Map<String, String> tags() {
6160
return tags;
6261
}
6362

64-
public ServiceMethodDefinition setTags(Map<String, String> tags) {
65-
this.tags = tags;
66-
return this;
67-
}
68-
6963
public boolean isAuth() {
7064
return auth;
7165
}
7266

73-
public ServiceMethodDefinition setAuth(boolean auth) {
74-
this.auth = auth;
75-
return this;
76-
}
77-
7867
@Override
7968
public String toString() {
8069
return new StringJoiner(", ", ServiceMethodDefinition.class.getSimpleName() + "[", "]")
@@ -83,4 +72,39 @@ public String toString() {
8372
.add("auth=" + auth)
8473
.toString();
8574
}
75+
76+
@Override
77+
public void writeExternal(ObjectOutput out) throws IOException {
78+
// action
79+
out.writeUTF(action);
80+
81+
// tags
82+
out.writeInt(tags.size());
83+
for (Entry<String, String> entry : tags.entrySet()) {
84+
out.writeUTF(entry.getKey());
85+
out.writeUTF(entry.getValue());
86+
}
87+
88+
// auth
89+
out.writeBoolean(auth);
90+
}
91+
92+
@Override
93+
public void readExternal(ObjectInput in) throws IOException {
94+
// namespace
95+
action = in.readUTF();
96+
97+
// tags
98+
int tagsSize = in.readInt();
99+
Map<String, String> tags = new HashMap<>(tagsSize);
100+
for (int i = 0; i < tagsSize; i++) {
101+
String key = in.readUTF();
102+
String value = in.readUTF();
103+
tags.put(key, value);
104+
}
105+
this.tags = Collections.unmodifiableMap(tags);
106+
107+
// auth
108+
this.auth = in.readBoolean();
109+
}
86110
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public ServiceReference(
3838
this.namespace = serviceRegistration.namespace();
3939
this.contentTypes = Collections.unmodifiableSet(serviceEndpoint.contentTypes());
4040
this.tags = mergeTags(serviceMethodDefinition, serviceRegistration, serviceEndpoint);
41-
this.action = serviceMethodDefinition.getAction();
41+
this.action = serviceMethodDefinition.action();
4242
this.qualifier = Qualifier.asString(namespace, action);
4343
this.address = serviceEndpoint.address();
4444
this.auth = serviceMethodDefinition.isAuth();
@@ -83,7 +83,7 @@ private Map<String, String> mergeTags(
8383
Map<String, String> tags = new HashMap<>();
8484
tags.putAll(serviceEndpoint.tags());
8585
tags.putAll(serviceRegistration.tags());
86-
tags.putAll(serviceMethodDefinition.getTags());
86+
tags.putAll(serviceMethodDefinition.tags());
8787
return tags;
8888
}
8989

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

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

3+
import java.io.Externalizable;
4+
import java.io.IOException;
5+
import java.io.ObjectInput;
6+
import java.io.ObjectOutput;
7+
import java.util.ArrayList;
38
import java.util.Collection;
9+
import java.util.Collections;
10+
import java.util.HashMap;
11+
import java.util.List;
412
import java.util.Map;
13+
import java.util.Map.Entry;
14+
import java.util.Objects;
515
import java.util.StringJoiner;
616

7-
public class ServiceRegistration {
17+
public class ServiceRegistration implements Externalizable {
18+
19+
private static final long serialVersionUID = 1L;
820

921
private String namespace;
1022
private Map<String, String> tags;
@@ -26,9 +38,9 @@ public ServiceRegistration() {}
2638
*/
2739
public ServiceRegistration(
2840
String namespace, Map<String, String> tags, Collection<ServiceMethodDefinition> methods) {
29-
this.namespace = namespace;
30-
this.tags = tags;
31-
this.methods = methods;
41+
this.namespace = Objects.requireNonNull(namespace, "ServiceRegistration.namespace is required");
42+
this.tags = Collections.unmodifiableMap(new HashMap<>(tags));
43+
this.methods = Collections.unmodifiableList(new ArrayList<>(methods));
3244
}
3345

3446
public String namespace() {
@@ -43,11 +55,6 @@ public Collection<ServiceMethodDefinition> methods() {
4355
return methods;
4456
}
4557

46-
public ServiceRegistration setTags(Map<String, String> tags) {
47-
this.tags = tags;
48-
return this;
49-
}
50-
5158
@Override
5259
public String toString() {
5360
return new StringJoiner(", ", ServiceRegistration.class.getSimpleName() + "[", "]")
@@ -56,4 +63,47 @@ public String toString() {
5663
.add("methods(" + methods.size() + ")")
5764
.toString();
5865
}
66+
67+
@Override
68+
public void writeExternal(ObjectOutput out) throws IOException {
69+
// namespace
70+
out.writeUTF(namespace);
71+
72+
// tags
73+
out.writeInt(tags.size());
74+
for (Entry<String, String> entry : tags.entrySet()) {
75+
out.writeUTF(entry.getKey());
76+
out.writeUTF(entry.getValue());
77+
}
78+
79+
// methods
80+
out.writeInt(methods.size());
81+
for (ServiceMethodDefinition method : methods) {
82+
out.writeObject(method);
83+
}
84+
}
85+
86+
@Override
87+
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
88+
// namespace
89+
namespace = in.readUTF();
90+
91+
// tags
92+
int tagsSize = in.readInt();
93+
Map<String, String> tags = new HashMap<>(tagsSize);
94+
for (int i = 0; i < tagsSize; i++) {
95+
String key = in.readUTF();
96+
String value = in.readUTF();
97+
tags.put(key, value);
98+
}
99+
this.tags = Collections.unmodifiableMap(tags);
100+
101+
// methods
102+
int methodsSize = in.readInt();
103+
List<ServiceMethodDefinition> methods = new ArrayList<>(methodsSize);
104+
for (int i = 0; i < methodsSize; i++) {
105+
methods.add((ServiceMethodDefinition) in.readObject());
106+
}
107+
this.methods = Collections.unmodifiableList(methods);
108+
}
59109
}

0 commit comments

Comments
 (0)