this.protocol = protocol;
this.access = access;
int dash = range.indexOf('-');
- if(dash<0) {
+ if (dash<0) {
startPort = endPort = Integer.parseInt(range);
} else {
startPort = Integer.parseInt(range.substring(0,dash));
public DNSLocator(Access access, String aaf_locate) throws LocatorException {
this.access = access;
- if(aaf_locate==null) {
+ if (aaf_locate==null) {
throw new LocatorException("Null passed into DNSLocator constructor");
}
int start, port;
- if(aaf_locate.startsWith("https:")) {
+ if (aaf_locate.startsWith("https:")) {
protocol = "https:";
start = 9; // https://
port = 443;
- } else if(aaf_locate.startsWith("http:")) {
+ } else if (aaf_locate.startsWith("http:")) {
protocol = "http:";
start = 8; // http://
port = 80;
@Override
public boolean hasItems() {
- for(Host h : hosts) {
- if(h.status==Status.OK) {
+ for (Host h : hosts) {
+ if (h.status==Status.OK) {
return true;
}
}
@Override
public Item best() throws LocatorException {
// not a good "best"
- for(int i=0;i<hosts.length;++i) {
+ for (int i=0;i<hosts.length;++i) {
switch(hosts[i].status) {
case OK:
return new DLItem(i);
break;
case UNTRIED:
try {
- if(hosts[i].ia.isReachable(CHECK_TIME)) {
+ if (hosts[i].ia.isReachable(CHECK_TIME)) {
hosts[i].status = Status.OK;
return new DLItem(i);
}
@Override
public Item next(Item item) throws LocatorException {
DLItem di = (DLItem)item;
- if(++di.cnt<hosts.length) {
+ if (++di.cnt<hosts.length) {
return di;
} else {
return null;
InetAddress[] ias = InetAddress.getAllByName(host);
Host[] temp = new Host[ias.length * (1 + endPort - startPort)];
int cnt = -1;
- for(int j=startPort; j<=endPort; ++j) {
- for(int i=0;i<ias.length;++i) {
+ for (int j=startPort; j<=endPort; ++j) {
+ for (int i=0;i<ias.length;++i) {
temp[++cnt] = new Host(ias[i], j, suffix);
}
}
private void parsePorts(String aaf_locate, int defaultPort) throws LocatorException {
int slash, start;
int colon = aaf_locate.indexOf(':');
- if(colon > 0) {
+ if (colon > 0) {
start = colon + 1;
int left = aaf_locate.indexOf('[', start);
- if(left > 0) {
+ if (left > 0) {
int right = aaf_locate.indexOf(']', left + 1);
if (right < 0) {
throw new LocatorException("Missing closing bracket in DNSLocator constructor. (requested URL " + aaf_locate + ')');
if (dash == (right - 1) || dash == (left + 1)) {
throw new LocatorException("Missing ports in brackets in DNSLocator constructor. (requested URL " + aaf_locate + ')');
}
- if(dash < 0) {
+ if (dash < 0) {
startPort = endPort = Integer.parseInt(aaf_locate.substring(left + 1, right));
} else {
startPort = Integer.parseInt(aaf_locate.substring(left + 1, dash));
if (slash == start) {
throw new LocatorException("Missing port before '/' in DNSLocator constructor. (requested URL " + aaf_locate + ')');
}
- if(slash < 0) {
+ if (slash < 0) {
startPort = endPort = Integer.parseInt(aaf_locate.substring(start));
} else {
startPort = endPort = Integer.parseInt(aaf_locate.substring(start, slash));