src/main/java/org/embulk/executor/remoteserver/Host.java in embulk-executor-remoteserver-0.1.1 vs src/main/java/org/embulk/executor/remoteserver/Host.java in embulk-executor-remoteserver-0.2.0
- old
+ new
@@ -1,32 +1,37 @@
package org.embulk.executor.remoteserver;
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
import java.net.InetSocketAddress;
class Host {
private String name;
private int port;
- @JsonCreator
- Host(@JsonProperty("name") String name,
- @JsonProperty("port") int port) {
+ Host(String name, int port) {
this.name = name;
this.port = port;
}
- @JsonProperty
String getName() {
return name;
}
- @JsonProperty
int getPort() {
return port;
}
InetSocketAddress toAddress() {
return new InetSocketAddress(name, port);
+ }
+
+ static Host of(String host) {
+ String[] split = host.split(":");
+ if (split.length > 2) {
+ throw new IllegalArgumentException("Host must be the format 'hostname(:port)' but " + host);
+ }
+ if (split.length == 1) {
+ return new Host(split[0], 30001);
+ } else {
+ return new Host(split[0], Integer.parseInt(split[1]));
+ }
}
}