-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #766 from scalecube/cleanup-service-discovery-inte…
…rface Cleanup service discovery interface
- Loading branch information
Showing
37 changed files
with
607 additions
and
318 deletions.
There are no files selected for viewing
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
20 changes: 2 additions & 18 deletions
20
services-api/src/main/java/io/scalecube/services/discovery/api/ServiceDiscovery.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
72 changes: 72 additions & 0 deletions
72
services-api/src/main/java/io/scalecube/services/discovery/api/ServiceDiscoveryContext.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,72 @@ | ||
package io.scalecube.services.discovery.api; | ||
|
||
import io.scalecube.net.Address; | ||
import java.util.Objects; | ||
import java.util.StringJoiner; | ||
import reactor.core.publisher.Flux; | ||
|
||
public final class ServiceDiscoveryContext { | ||
|
||
private final String id; | ||
private final Address address; | ||
private final ServiceDiscovery discovery; | ||
|
||
private ServiceDiscoveryContext(Builder builder) { | ||
this.id = Objects.requireNonNull(builder.id, "discoveryContext.id"); | ||
this.address = Objects.requireNonNull(builder.address, "discoveryContext.address"); | ||
this.discovery = Objects.requireNonNull(builder.discovery, "discoveryContext.discovery"); | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public String id() { | ||
return id; | ||
} | ||
|
||
public Address address() { | ||
return address; | ||
} | ||
|
||
public Flux<ServiceDiscoveryEvent> listen() { | ||
return discovery.listen(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new StringJoiner(", ", ServiceDiscoveryContext.class.getSimpleName() + "[", "]") | ||
.add("id='" + id + "'") | ||
.add("address=" + address) | ||
.add("discovery=" + discovery) | ||
.toString(); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private String id; | ||
private Address address; | ||
private ServiceDiscovery discovery; | ||
|
||
private Builder() {} | ||
|
||
public Builder id(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public Builder address(Address address) { | ||
this.address = address; | ||
return this; | ||
} | ||
|
||
public Builder discovery(ServiceDiscovery discovery) { | ||
this.discovery = discovery; | ||
return this; | ||
} | ||
|
||
public ServiceDiscoveryContext build() { | ||
return new ServiceDiscoveryContext(this); | ||
} | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
services-api/src/main/java/io/scalecube/services/discovery/api/ServiceDiscoveryFactory.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,9 @@ | ||
package io.scalecube.services.discovery.api; | ||
|
||
import io.scalecube.services.ServiceEndpoint; | ||
|
||
@FunctionalInterface | ||
public interface ServiceDiscoveryFactory { | ||
|
||
ServiceDiscovery createServiceDiscovery(ServiceEndpoint serviceEndpoint); | ||
} |
65 changes: 65 additions & 0 deletions
65
services-api/src/main/java/io/scalecube/services/discovery/api/ServiceDiscoveryOptions.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,65 @@ | ||
package io.scalecube.services.discovery.api; | ||
|
||
import io.scalecube.services.ServiceEndpoint; | ||
import java.util.StringJoiner; | ||
import java.util.UUID; | ||
import java.util.function.Consumer; | ||
|
||
public final class ServiceDiscoveryOptions { | ||
|
||
private String id = UUID.randomUUID().toString(); | ||
private ServiceEndpoint serviceEndpoint; | ||
private ServiceDiscoveryFactory discoveryFactory; | ||
|
||
public ServiceDiscoveryOptions() {} | ||
|
||
/** | ||
* ServiceDiscoveryOptions copy constructor. | ||
* | ||
* @param other ServiceDiscoveryOptions to copy | ||
*/ | ||
public ServiceDiscoveryOptions(ServiceDiscoveryOptions other) { | ||
this.id = other.id; | ||
this.serviceEndpoint = other.serviceEndpoint; | ||
this.discoveryFactory = other.discoveryFactory; | ||
} | ||
|
||
private ServiceDiscoveryOptions set(Consumer<ServiceDiscoveryOptions> c) { | ||
ServiceDiscoveryOptions s = new ServiceDiscoveryOptions(this); | ||
c.accept(s); | ||
return s; | ||
} | ||
|
||
public ServiceDiscoveryOptions id(String id) { | ||
return set(o -> o.id = id); | ||
} | ||
|
||
public String id() { | ||
return id; | ||
} | ||
|
||
public ServiceDiscoveryOptions serviceEndpoint(ServiceEndpoint serviceEndpoint) { | ||
return set(o -> o.serviceEndpoint = serviceEndpoint); | ||
} | ||
|
||
public ServiceEndpoint serviceEndpoint() { | ||
return serviceEndpoint; | ||
} | ||
|
||
public ServiceDiscoveryOptions discoveryFactory(ServiceDiscoveryFactory discoveryFactory) { | ||
return set(o -> o.discoveryFactory = discoveryFactory); | ||
} | ||
|
||
public ServiceDiscoveryFactory discoveryFactory() { | ||
return discoveryFactory; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new StringJoiner(", ", ServiceDiscoveryOptions.class.getSimpleName() + "[", "]") | ||
.add("id='" + id + "'") | ||
.add("serviceEndpoint=" + serviceEndpoint) | ||
.add("discoveryFactory=" + discoveryFactory) | ||
.toString(); | ||
} | ||
} |
File renamed without changes.
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
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 |
---|---|---|
|
@@ -66,5 +66,4 @@ public int hashCode() { | |
return Objects.hash(name); | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.