-
-
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.
* Removed RetryNonSerializedEmitFailureHandler * Removed dependency on commons * Added `Address` (copied from commons)
- Loading branch information
Showing
50 changed files
with
241 additions
and
130 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
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
139 changes: 139 additions & 0 deletions
139
services-api/src/main/java/io/scalecube/services/Address.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,139 @@ | ||
package io.scalecube.services; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.Objects; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class Address { | ||
|
||
public static final Address NULL_ADDRESS = Address.create("nullhost", 0); | ||
|
||
public static final Pattern ADDRESS_FORMAT = Pattern.compile("(?<host>^.*):(?<port>\\d+$)"); | ||
|
||
private String host; | ||
private int port; | ||
|
||
Address() {} | ||
|
||
private Address(String host, int port) { | ||
this.host = host; | ||
this.port = port; | ||
} | ||
|
||
/** | ||
* Parses given host:port string to create Address instance. | ||
* | ||
* @param hostandport must come in form {@code host:port} | ||
*/ | ||
public static Address from(String hostandport) { | ||
if (hostandport == null || hostandport.isEmpty()) { | ||
throw new IllegalArgumentException("host-and-port string must be present"); | ||
} | ||
|
||
Matcher matcher = ADDRESS_FORMAT.matcher(hostandport); | ||
if (!matcher.find()) { | ||
throw new IllegalArgumentException("can't parse host-and-port string from: " + hostandport); | ||
} | ||
|
||
String host = matcher.group(1); | ||
if (host == null || host.isEmpty()) { | ||
throw new IllegalArgumentException("can't parse host from: " + hostandport); | ||
} | ||
|
||
int port; | ||
try { | ||
port = Integer.parseInt(matcher.group(2)); | ||
} catch (NumberFormatException ex) { | ||
throw new IllegalArgumentException("can't parse port from: " + hostandport, ex); | ||
} | ||
|
||
return new Address(host, port); | ||
} | ||
|
||
/** | ||
* Create address from host and port. | ||
* | ||
* @param host host | ||
* @param port port | ||
* @return address | ||
*/ | ||
public static Address create(String host, int port) { | ||
return new Address(host, port); | ||
} | ||
|
||
/** | ||
* Getting local IP address by the address of local host. <b>NOTE:</b> returned IP address is | ||
* expected to be a publicly visible IP address. | ||
* | ||
* @throws RuntimeException wrapped {@link UnknownHostException} | ||
*/ | ||
public static InetAddress getLocalIpAddress() { | ||
try { | ||
return InetAddress.getLocalHost(); | ||
} catch (UnknownHostException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Returns host. | ||
* | ||
* @return host | ||
*/ | ||
public String host() { | ||
return host; | ||
} | ||
|
||
/** | ||
* Returns port. | ||
* | ||
* @return port | ||
*/ | ||
public int port() { | ||
return port; | ||
} | ||
|
||
/** | ||
* Returns new address instance with the specified port. | ||
* | ||
* @param port port | ||
* @return address instance | ||
*/ | ||
public Address port(int port) { | ||
return Address.create(host, port); | ||
} | ||
|
||
/** | ||
* Returns new address instance with applied port offset. | ||
* | ||
* @param portOffset portOffset | ||
* @return address instance | ||
*/ | ||
public Address withPortOffset(int portOffset) { | ||
return Address.create(host, port + portOffset); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
Address that = (Address) other; | ||
return Objects.equals(host, that.host) && Objects.equals(port, that.port); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(host, port); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return host + ":" + port; | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
services-api/src/main/java/io/scalecube/services/ServiceEndpoint.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
1 change: 0 additions & 1 deletion
1
services-api/src/main/java/io/scalecube/services/ServiceReference.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
2 changes: 1 addition & 1 deletion
2
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
2 changes: 1 addition & 1 deletion
2
services-api/src/main/java/io/scalecube/services/gateway/Gateway.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
2 changes: 1 addition & 1 deletion
2
services-api/src/main/java/io/scalecube/services/transport/api/ServerTransport.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
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
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
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
2 changes: 1 addition & 1 deletion
2
...ces-examples/src/main/java/io/scalecube/services/examples/gateway/HttpGatewayExample.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
2 changes: 1 addition & 1 deletion
2
...xamples/src/main/java/io/scalecube/services/examples/gateway/WebsocketGatewayExample.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
Oops, something went wrong.