Skip to content

Commit

Permalink
Merge pull request payara#4699 from MeroRai/CUSTCOM-14
Browse files Browse the repository at this point in the history
CUSTCOM-14 Improvements in stop-domain process
  • Loading branch information
MeroRai committed Jun 29, 2020
1 parent d294a5e commit 26ff977
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
import com.sun.enterprise.util.SystemPropertyConstants;
import com.sun.enterprise.util.io.FileUtils;
import com.sun.enterprise.util.io.ServerDirs;
import java.net.InetAddress;
import java.net.InetSocketAddress;

import org.glassfish.api.ActionReport;
import org.glassfish.api.admin.CommandException;
Expand Down Expand Up @@ -96,6 +98,7 @@ public abstract class LocalServerCommand extends CLICommand {
////////////////////////////////////////////////////////////////
private ServerDirs serverDirs;
private static final LocalStringsImpl STRINGS = new LocalStringsImpl(LocalDomainCommand.class);
private final static int IS_RUNNING_DEFAULT_TIMEOUT = 2000;

////////////////////////////////////////////////////////////////
/// Section: protected variables
Expand Down Expand Up @@ -356,24 +359,18 @@ protected final int getServerPid() {
* @return boolean indicating whether the server is running
*/
protected final boolean isRunning(String host, int port) {
Socket server = null;
try {
server = new Socket(host, port);

try(Socket server = new Socket()) {
if (host == null) {
host = InetAddress.getByName(null).getHostName();
}

server.connect( new InetSocketAddress(host, port), IS_RUNNING_DEFAULT_TIMEOUT);
return true;
}
catch (Exception ex) {
}catch (Exception ex) {
logger.log(Level.FINER, "\nisRunning got exception: {0}", ex);
return false;
}
finally {
if (server != null) {
try {
server.close();
}
catch (IOException ex) {
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.sun.enterprise.admin.cli.remote.RemoteCLICommand;
import com.sun.enterprise.universal.process.ProcessUtils;
import com.sun.enterprise.util.io.FileUtils;
import com.sun.enterprise.util.net.NetUtils;
import java.io.File;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -95,10 +96,7 @@ protected void validate()
protected void initDomain() throws CommandException {
// only initialize local domain information if it's a local operation

// TODO Byron said in April 2013 that we should probably just check if
// NetUtils says that the getHost() --> isThisMe() rather than merely
// checking for the magic "localhost" string. Too risky to fool with it today.
if (programOpts.getHost().equals(CLIConstants.DEFAULT_HOSTNAME)) {
if (NetUtils.isThisHostLocal(programOpts.getHost())) {
super.initDomain();
} else if (userArgDomainName != null) { // remote case
throw new CommandException(Strings.get("StopDomain.noDomainNameAllowed"));
Expand Down

0 comments on commit 26ff977

Please sign in to comment.