Commit c49be272 authored by Andre Freyssinet's avatar Andre Freyssinet

Adds dumpServerState method.

parent 9d3b9ce9
...@@ -86,6 +86,46 @@ public class SCServer implements SCServerMBean { ...@@ -86,6 +86,46 @@ public class SCServer implements SCServerMBean {
return servers; return servers;
} }
@Override
public void dumpServerState(String path) {
dumpServerState(path, null);
}
public static void dumpServerState(String path, String cause) {
FileWriter writer = null;
try {
writer = new FileWriter(path, true);
final StringBuffer strbuf = new StringBuffer();
if (cause != null) {
writer.write("\n===== Dump cause =====\n\n");
writer.write(cause);
writer.write("\n");
}
writer.write("\n===== MBean's attributes =====\n\n");
DumpAttributes.dumpAttributes("*:*", strbuf);
writer.write(strbuf.toString());
writer.flush();
strbuf.setLength(0);
writer.write("\n===== Thread's stack traces =====\n\n");
DumpAttributes.dumpAllStackTraces(strbuf);
writer.write(strbuf.toString());
writer.flush();
strbuf.setLength(0);
} catch (IOException exc) {
logger.log(BasicLevel.ERROR,
"MqttCheckActivator.dumpServerState, cannot open dump file \"" + path + "\"", exc);
} finally {
if (writer != null)
try {
writer.close();
} catch (IOException e) {}
}
}
public void dumpAttributes(String name, String path, boolean threaddump) { public void dumpAttributes(String name, String path, boolean threaddump) {
FileWriter writer = null; FileWriter writer = null;
try { try {
...@@ -95,6 +135,7 @@ public class SCServer implements SCServerMBean { ...@@ -95,6 +135,7 @@ public class SCServer implements SCServerMBean {
DumpAttributes.dumpAttributes(name, strbuf); DumpAttributes.dumpAttributes(name, strbuf);
if (threaddump) if (threaddump)
DumpAttributes.dumpAllStackTraces(strbuf); DumpAttributes.dumpAllStackTraces(strbuf);
writer.write(strbuf.toString());
writer.close(); writer.close();
} catch (IOException exc) { } catch (IOException exc) {
logger.log(BasicLevel.ERROR, logger.log(BasicLevel.ERROR,
......
...@@ -33,5 +33,6 @@ public interface SCServerMBean { ...@@ -33,5 +33,6 @@ public interface SCServerMBean {
public String[] getServers(); public String[] getServers();
public void dumpServerState(String path);
public void dumpAttributes(String name, String path, boolean threaddump); public void dumpAttributes(String name, String path, boolean threaddump);
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment