/** * Gets the host, as either hostname or IP address, on which the Server was bound and running. An * attempt is made to get the canonical hostname for IP address to which the Server was bound for * accepting client requests. If the server bind address is null or localhost is unknown, then a * default String value of "localhost/127.0.0.1" is returned. * * Note, this information is purely information and should not be used to re-construct state or * for other purposes. * * @return the hostname or IP address of the host running the Server, based on the bind-address, * or 'localhost/127.0.0.1' if the bind address is null and localhost is unknown. * @see java.net.InetAddress * @see #getServerBindAddress() */ public String getServerBindAddressAsString() { try { if (getServerBindAddress() != null) { return getServerBindAddress().getCanonicalHostName(); } final InetAddress localhost = SocketCreator.getLocalHost(); return localhost.getCanonicalHostName(); } catch (UnknownHostException handled) { // Returning localhost/127.0.0.1 implies the serverBindAddress was null and no IP address // for localhost could be found return "localhost/127.0.0.1"; } }
private static String getServerLocation(ServerLauncher launcher) { if (launcher.getServerPort() == null) { return launcher.getId(); } if (launcher.getServerBindAddress() == null) { return HostUtils.getLocatorId(HostUtils.getLocalHost(), launcher.getServerPort()); } return HostUtils.getServerId(launcher.getServerBindAddress().getCanonicalHostName(), launcher.getServerPort()); }
if (launcher.getServerBindAddress() != null) { commandLine .add("--server-bind-address=" + launcher.getServerBindAddress().getCanonicalHostName());
@Test public void buildCreatesServerLauncherWithBuilderValues() throws UnknownHostException { ServerLauncher launcher = new Builder().setCommand(Command.STOP).setAssignBuckets(true) .setForce(true).setMemberName("serverOne").setRebalance(true) .setServerBindAddress(InetAddress.getLocalHost().getHostAddress()).setServerPort(11235) .setCriticalHeapPercentage(90.0f).setEvictionHeapPercentage(75.0f).setMaxConnections(100) .setMaxMessageCount(512).setMaxThreads(8).setMessageTimeToLive(120000) .setSocketBufferSize(32768).setRedirectOutput(Boolean.TRUE).build(); assertThat(launcher.getCommand()).isEqualTo(Command.STOP); assertThat(launcher.getMemberName()).isEqualTo("serverOne"); assertThat(launcher.getServerBindAddress()).isEqualTo(InetAddress.getLocalHost()); assertThat(launcher.getServerPort().intValue()).isEqualTo(11235); assertThat(launcher.getCriticalHeapPercentage().floatValue()).isEqualTo(90.0f); assertThat(launcher.getEvictionHeapPercentage().floatValue()).isEqualTo(75.0f); assertThat(launcher.getMaxConnections().intValue()).isEqualTo(100); assertThat(launcher.getMaxMessageCount().intValue()).isEqualTo(512); assertThat(launcher.getMaxThreads().intValue()).isEqualTo(8); assertThat(launcher.getMessageTimeToLive().intValue()).isEqualTo(120000); assertThat(launcher.getSocketBufferSize().intValue()).isEqualTo(32768); assertThat(launcher.isAssignBuckets()).isTrue(); assertThat(launcher.isDebugging()).isFalse(); assertThat(launcher.isDisableDefaultServer()).isFalse(); assertThat(launcher.isForcing()).isTrue(); assertThat(launcher.isHelping()).isFalse(); assertThat(launcher.isRebalancing()).isTrue(); assertThat(launcher.isRedirectingOutput()).isTrue(); assertThat(launcher.isRunning()).isFalse(); }
if (isDefaultServerEnabled(cache)) { final String serverBindAddress = getServerBindAddress() == null ? null : getServerBindAddress().getHostAddress(); final Integer serverPort = getServerPort(); final CacheServer cacheServer = cache.addCacheServer();
assertPortAvailable(getServerBindAddress(), getServerPort());