Skip to content

Commit

Permalink
Introduce new hudson.TcpSlaveAgentListener.getAdvertisedHost() method (
Browse files Browse the repository at this point in the history
…#4227)

* Introduced hudson.TcpSlaveAgentListener.getAdvertisedHost()

* review feedback

* better error message
  • Loading branch information
alxsap authored and oleg-nenashev committed Sep 28, 2019
1 parent f5385ea commit 694764e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions core/src/main/java/hudson/TcpSlaveAgentListener.java
Expand Up @@ -43,6 +43,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketAddress;
import java.net.URL;
import java.util.Arrays;
import java.util.Base64;
import jenkins.AgentProtocol;
Expand All @@ -55,6 +56,7 @@
import java.io.PrintWriter;
import java.net.BindException;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Socket;
import java.nio.channels.ServerSocketChannel;
import java.util.logging.Level;
Expand Down Expand Up @@ -131,6 +133,21 @@ public int getAdvertisedPort() {
return CLI_PORT != null ? CLI_PORT : getPort();
}

/**
* Gets the host name that we advertise protocol clients to connect to.
* @since TODO
*/
public String getAdvertisedHost() {
if (CLI_HOST_NAME != null) {
return CLI_HOST_NAME;
}
try {
return new URL(Jenkins.get().getRootUrl()).getHost();
} catch (MalformedURLException | NullPointerException e) {
throw new IllegalStateException("Could not get TcpSlaveAgentListener host name", e);
}
}

/**
* Gets the Base64 encoded public key that forms part of this instance's identity keypair.
* @return the Base64 encoded public key
Expand Down

0 comments on commit 694764e

Please sign in to comment.