Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[1151441] JON server was unexpectedly stopped
Browse files Browse the repository at this point in the history
Only resolve the identity of the running server (i.e. the SERVER_NAME) one
time and cache it as a static for ServerManagerBean.  This is more efficient
as the server name can not change at runtime, and actually should not change
for a defined server, ever, in general.  Moreover, for server where
rhq.server.high-availability.name is not set, it prevents repeated calls to
InetAddress.getLocalhost(), which can fail if there is a temporary DNS
issue, and the localhost can not be resolved.
  • Loading branch information
jshaughn committed Oct 13, 2014
1 parent 546cf53 commit 4e66a36
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,17 @@
public class ServerManagerBean implements ServerManagerLocal {
private final Log log = LogFactory.getLog(ServerManagerBean.class);

static private final String RHQ_SERVER_NAME_PROPERTY = "rhq.server.high-availability.name";

static private Server.OperationMode lastEstablishedServerMode = null;

static private final String RHQ_SERVER_NAME_PROPERTY;

static private final String SERVER_NAME;

static {
RHQ_SERVER_NAME_PROPERTY = "rhq.server.high-availability.name";
SERVER_NAME = getServerName();
}

@Resource
private TimerService timerService;

Expand Down Expand Up @@ -135,7 +142,10 @@ public int create(Server server) {
}

public String getIdentity() {
return SERVER_NAME;
}

private static String getServerName() {
// The property may return "" so also use "" as the default to ensure we set it to something useful
String result = System.getProperty(RHQ_SERVER_NAME_PROPERTY, "");

Expand All @@ -150,19 +160,17 @@ public String getIdentity() {
}

public List<Agent> getAgents() {
String identity = getIdentity();
List<Agent> results = topologyManager.getAgentsByServerName(identity);
List<Agent> results = topologyManager.getAgentsByServerName(SERVER_NAME);
return results;
}

public List<Integer> getAndClearAgentsWithStatus() {
List<Integer> results = agentStatusManager.getAndClearAgentsWithStatusForServer(getIdentity());
List<Integer> results = agentStatusManager.getAndClearAgentsWithStatusForServer(SERVER_NAME);
return results;
}

public boolean getAndClearServerStatus() {
String identity = getIdentity();
Server server = topologyManager.getServerByName(identity);
Server server = topologyManager.getServerByName(SERVER_NAME);
if (server == null) {
return false; // don't reload caches if we don't know who we are
}
Expand All @@ -174,10 +182,9 @@ public boolean getAndClearServerStatus() {
}

public Server getServer() throws ServerNotFoundException {
String identity = getIdentity();
Server result = topologyManager.getServerByName(identity);
Server result = topologyManager.getServerByName(SERVER_NAME);
if (result == null) {
throw new ServerNotFoundException("Could not find server name [" + identity
throw new ServerNotFoundException("Could not find server name [" + SERVER_NAME
+ "]. If the rhq-server.properties property [" + RHQ_SERVER_NAME_PROPERTY
+ "] is unset the server name defaults to the host name (via InetAddress.getLocalHost()). "
+ "If this value, possibly an IP address, has changed it can cause this issue.");
Expand Down

0 comments on commit 4e66a36

Please sign in to comment.