Skip to content

Commit

Permalink
Fix the MODCLUSTER-380.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfclere committed Feb 6, 2014
1 parent 87250ed commit 45be692
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 8 additions & 0 deletions core/src/main/java/org/jboss/modcluster/ModClusterLogger.java
Expand Up @@ -153,4 +153,12 @@ public interface ModClusterLogger {
@LogMessage(level = ERROR)
@Message(id = 43, value = "Failed to send %s to %s")
void sendFailed(@Cause Throwable cause, MCMPRequestType type, InetSocketAddress proxy);

@LogMessage(level = WARN)
@Message(id = 44, value = "%s requires com.sun.management.OperatingSystemMXBean.")
void missingOSBean(String classname);

@LogMessage(level = WARN)
@Message(id = 45, value = "%s is not supported on this system and will be disabled.")
void notSupportedOnSystem(String classname);
}
Expand Up @@ -25,6 +25,7 @@
import java.lang.management.OperatingSystemMXBean;

import org.jboss.logging.Logger;
import org.jboss.modcluster.ModClusterLogger;
import org.jboss.modcluster.container.Engine;

/**
Expand All @@ -33,8 +34,6 @@
* @author Paul Ferraro
*/
public class AverageSystemLoadMetric extends AbstractLoadMetric {
private static final Logger logger = Logger.getLogger(AverageSystemLoadMetric.class);

private final OperatingSystemMXBean bean;

public AverageSystemLoadMetric() {
Expand All @@ -49,7 +48,7 @@ public AverageSystemLoadMetric(OperatingSystemMXBean bean) {
public double getLoad(Engine engine) throws Exception {
double load = this.bean.getSystemLoadAverage();
if (load < 0) {
logger.warnf("%s is not supported on this system and will be disabled.", this.getClass().getSimpleName());
ModClusterLogger.LOGGER.notSupportedOnSystem(this.getClass().getSimpleName());
this.setWeight(0);
return 0;
}
Expand Down
Expand Up @@ -28,6 +28,7 @@
import javax.management.ObjectName;

import org.jboss.logging.Logger;
import org.jboss.modcluster.ModClusterLogger;
import org.jboss.modcluster.container.Engine;
import org.jboss.modcluster.load.metric.LoadMetric;

Expand All @@ -40,8 +41,6 @@ public class SystemMemoryUsageLoadMetric extends AbstractLoadMetric {
public static final String FREE_MEMORY = "FreePhysicalMemorySize";
public static final String TOTAL_MEMORY = "TotalPhysicalMemorySize";

private Logger logger = Logger.getLogger(this.getClass());

private volatile MBeanServer server = ManagementFactory.getPlatformMBeanServer();

public void setMBeanServer(MBeanServer server) {
Expand All @@ -61,7 +60,7 @@ public double getLoad(Engine engine) throws Exception {
double total = ((Number) this.server.getAttribute(name, TOTAL_MEMORY)).doubleValue();
return (total - free) / total;
} catch (AttributeNotFoundException e) {
this.logger.warn(this.getClass().getSimpleName() + " requires com.sun.management.OperatingSystemMXBean.");
ModClusterLogger.LOGGER.missingOSBean(this.getClass().getSimpleName());
this.setWeight(0);
return 0;
}
Expand Down

0 comments on commit 45be692

Please sign in to comment.