Skip to content

Commit

Permalink
Java: remove URL
Browse files Browse the repository at this point in the history
  • Loading branch information
dkropachev committed Nov 14, 2024
1 parent 3b89842 commit a3661de
Showing 1 changed file with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Arrays;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.net.URISyntaxException;
import java.net.MalformedURLException;
import java.net.HttpURLConnection;
import java.util.logging.Logger;
import java.util.logging.Level;
Expand Down Expand Up @@ -80,17 +76,15 @@ public URI nextAsURI() {
try {
return new URI(alternatorScheme, null, nextNode(), alternatorPort, "", null, null);
} catch (URISyntaxException e) {
// Can't happen with the empty path and other nulls we used above...
logger.log(Level.WARNING, "nextAsURI", e);
return null;
}
}

public URL nextAsURL(String file) {
public URI nextAsURI(String file) {
try {
return new URL(alternatorScheme, nextNode(), alternatorPort, file);
} catch (MalformedURLException e) {
// Can only happen if alternatorScheme is an unknown one.
return new URI(alternatorScheme, "", nextNode(), alternatorPort, file, "", "");
} catch (URISyntaxException e) {
logger.log(Level.WARNING, "nextAsURL", e);
return null;
}
Expand All @@ -105,11 +99,11 @@ private static String streamToString(java.io.InputStream is) {

private void updateLiveNodes() {
List<String> newHosts = new ArrayList<String>();
URL url = nextAsURL("/localnodes");
URI uri = nextAsURI("/localnodes");
try {
// Note that despite this being called HttpURLConnection, it actually
// supports HTTPS as well.
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
HttpURLConnection conn = (HttpURLConnection) uri.toURL().openConnection();
conn.setRequestMethod("GET");
int responseCode = conn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
Expand All @@ -125,14 +119,14 @@ private void updateLiveNodes() {
}
}
} catch (IOException e) {
logger.log(Level.FINE, "Request failed: " + url, e);
logger.log(Level.FINE, "Request failed: " + uri, e);
}
if (!newHosts.isEmpty()) {
synchronized(this) {
this.liveNodes = newHosts;
this.nextLiveNodeIndex = 0;
}
logger.log(Level.FINE, "Updated hosts to " + this.liveNodes.toString());
logger.log(Level.FINE, "Updated hosts to " + this.liveNodes);
}
}
}

0 comments on commit a3661de

Please sign in to comment.