/** * Single VDC constructor. */ public ObjectConfig(Protocol protocol, int port, String... hosts) { this(protocol, port, new Vdc(hosts)); }
@Override public Object valueFromString(String param) { if (param == null) return null; return new Vdc(param.split(",")); }
/** * Sets a single server host */ public void setHost(String host) { setVdcs(Collections.singletonList(new Vdc(host))); }
@Override public void setAsText(String text) throws IllegalArgumentException { Matcher matcher = Pattern.compile(VDC_PATTERN).matcher(text); if (!matcher.matches()) throw new IllegalArgumentException("invalid VDC format"); String name = matcher.group(1); List<Host> hosts = new ArrayList<>(); for (int i = 2; i <= matcher.groupCount() && matcher.group(i) != null; i++) { hosts.add(new Host(matcher.group(i).replaceFirst("^,", ""))); } if (name == null) setValue(new Vdc(hosts)); else setValue(new Vdc(name, hosts)); } }
/** * Cloning constructor. */ public ObjectConfig(ObjectConfig<T> other) { this.protocol = other.protocol; // deep copy the VDCs to avoid two clients referencing the same host lists (SDK-122) this.vdcs = new ArrayList<Vdc>(); for (Vdc vdc : other.getVdcs()) { this.vdcs.add(new Vdc(vdc.getName(), vdc.getHosts())); } this.port = other.port; this.smartClient = other.smartClient; this.rootContext = other.rootContext; this.namespace = other.namespace; this.identity = other.identity; this.secretKey = other.secretKey; this.serverClockSkew = other.serverClockSkew; this.userAgent = other.userAgent; this.geoPinningEnabled = other.geoPinningEnabled; this.geoReadRetryFailover = other.geoReadRetryFailover; this.chunkedEncodingSize = other.chunkedEncodingSize; this.properties = new HashMap<String, Object>(other.properties); }