ipv6 formatting fixed. #121

pull/139/head
Nikita 10 years ago
parent a400717b12
commit fee63b39bc

@ -20,6 +20,8 @@ import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.redisson.misc.URIBuilder;
public class ClusterServersConfig extends BaseMasterSlaveServersConfig<ClusterServersConfig> {
/**
@ -49,11 +51,7 @@ public class ClusterServersConfig extends BaseMasterSlaveServersConfig<ClusterSe
*/
public ClusterServersConfig addNodeAddress(String ... addresses) {
for (String address : addresses) {
try {
nodeAddresses.add(new URI("//" + address));
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Can't parse " + address);
}
nodeAddresses.add(URIBuilder.create(address));
}
return this;
}

@ -16,10 +16,11 @@
package org.redisson;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.redisson.misc.URIBuilder;
public class MasterSlaveServersConfig extends BaseMasterSlaveServersConfig<MasterSlaveServersConfig> {
/**
@ -48,17 +49,13 @@ public class MasterSlaveServersConfig extends BaseMasterSlaveServersConfig<Maste
* @param masterAddress
*/
public MasterSlaveServersConfig setMasterAddress(String masterAddress) {
try {
this.masterAddress = new URI("//" + masterAddress);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Can't parse " + masterAddress);
}
this.masterAddress = URIBuilder.create(masterAddress);
return this;
}
public URI getMasterAddress() {
return masterAddress;
}
void setMasterAddress(URI masterAddress) {
public void setMasterAddress(URI masterAddress) {
this.masterAddress = masterAddress;
}
@ -70,7 +67,7 @@ public class MasterSlaveServersConfig extends BaseMasterSlaveServersConfig<Maste
*/
public MasterSlaveServersConfig addSlaveAddress(String ... sAddresses) {
for (String address : sAddresses) {
slaveAddresses.add(URI.create("//" + address));
slaveAddresses.add(URIBuilder.create(address));
}
return this;
}

@ -20,6 +20,8 @@ import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.redisson.misc.URIBuilder;
public class SentinelServersConfig extends BaseMasterSlaveServersConfig<SentinelServersConfig> {
private List<URI> sentinelAddresses = new ArrayList<URI>();
@ -45,11 +47,7 @@ public class SentinelServersConfig extends BaseMasterSlaveServersConfig<Sentinel
public SentinelServersConfig addSentinelAddress(String ... addresses) {
for (String address : addresses) {
try {
sentinelAddresses.add(new URI("//" + address));
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Can't parse " + address);
}
sentinelAddresses.add(URIBuilder.create(address));
}
return this;
}

@ -18,6 +18,8 @@ package org.redisson;
import java.net.URI;
import java.net.URISyntaxException;
import org.redisson.misc.URIBuilder;
public class SingleServerConfig extends BaseConfig<SingleServerConfig> {
/**
@ -82,11 +84,7 @@ public class SingleServerConfig extends BaseConfig<SingleServerConfig> {
* @param address
*/
public SingleServerConfig setAddress(String address) {
try {
this.address = new URI("//" + address);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Can't parse " + address);
}
this.address = URIBuilder.create(address);
return this;
}
public URI getAddress() {

@ -117,8 +117,8 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
if (!newMasterPart.getMasterAddress().equals(part.getMasterAddress())) {
log.debug("changing master from {} to {} for {}",
part.getMasterAddress(), newMasterPart.getMasterAddress(), newMasterPart.getEndSlot());
URI newUri = toURI(newMasterPart.getMasterAddress());
URI oldUri = toURI(part.getMasterAddress());
URI newUri = newMasterPart.getMasterAddress();
URI oldUri = part.getMasterAddress();
changeMaster(newMasterPart.getEndSlot(), newUri.getHost(), newUri.getPort());
slaveDown(newMasterPart.getEndSlot(), oldUri.getHost(), oldUri.getPort());

@ -15,15 +15,18 @@
*/
package org.redisson.connection;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.redisson.misc.URIBuilder;
public class ClusterNodeInfo {
public enum Flag {SLAVE, MASTER, MYSELF, FAIL};
private String nodeId;
private String address;
private URI address;
private List<Flag> flags = new ArrayList<Flag>();
private String slaveOf;
@ -37,11 +40,11 @@ public class ClusterNodeInfo {
this.nodeId = nodeId;
}
public String getAddress() {
public URI getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
this.address = URIBuilder.create(address);
}
public List<Flag> getFlags() {

@ -15,16 +15,19 @@
*/
package org.redisson.connection;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.redisson.misc.URIBuilder;
public class ClusterPartition {
private int startSlot;
private int endSlot;
private boolean masterFail;
private String masterAddress;
private List<String> slaveAddresses = new ArrayList<String>();
private URI masterAddress;
private List<URI> slaveAddresses = new ArrayList<URI>();
public void setMasterFail(boolean masterFail) {
this.masterFail = masterFail;
@ -47,17 +50,20 @@ public class ClusterPartition {
this.endSlot = endSlot;
}
public String getMasterAddress() {
public URI getMasterAddress() {
return masterAddress;
}
public void setMasterAddress(String masterAddress) {
setMasterAddress(URIBuilder.create(masterAddress));
}
public void setMasterAddress(URI masterAddress) {
this.masterAddress = masterAddress;
}
public void addSlaveAddress(String address) {
public void addSlaveAddress(URI address) {
slaveAddresses.add(address);
}
public List<String> getSlaveAddresses() {
public List<URI> getSlaveAddresses() {
return slaveAddresses;
}

@ -25,7 +25,6 @@ import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map.Entry;
@ -646,14 +645,6 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
return getEntry(slot).nextPubSubConnection();
}
protected URI toURI(String url) {
try {
return new URI("//" + url);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Can't parse " + url);
}
}
protected void returnSubscribeConnection(int slot, PubSubConnectionEntry entry) {
this.getEntry(slot).returnSubscribeConnection(entry);
}

@ -0,0 +1,17 @@
package org.redisson.misc;
import java.net.URI;
public class URIBuilder {
public static URI create(String uri) {
String[] parts = uri.split(":");
if (parts.length-1 >= 3) {
String port = parts[parts.length-1];
uri = "[" + uri.replace(":" + port, "") + "]:" + port;
}
return URI.create("//" + uri);
}
}
Loading…
Cancel
Save