Handle library loading issues gracefully

This commit is contained in:
Simon Pamies committed 2013-01-10 10:55:49 +01:00
1 parent c1c96dd607
commit d37bae806f
2 files changed
+30 -7

No files matched your search

@@ -41,8 +41,12 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
}
@Override
public void handleFailure(Endpoint endpoint) {
public void handleFailure(Endpoint endpoint) {
boolean sysinfo_available = true;
SystemInformation info = SystemInformationImpl.getInstance();
if (info == null) {
sysinfo_available = false;
}
Bundle bundle = getBundleByName(endpoint.getBundleName());
if (bundle == null) {
@@ -55,7 +59,10 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
log.throwing(getClass().getName(), "handleFailure", e);
}
} else {
final String info_before_restart = info.toString();
String info_before_restart = "";
if (sysinfo_available) {
info_before_restart = info.toString();
}
if (bundle.getState() == BundleEvent.STARTED || bundle.getState() == BundleEvent.STOPPED) {
try {
bundle.stop();
@@ -78,8 +85,13 @@ public class OSGiRestartingPortMonitor extends AbstractPortMonitor {
String content = "The Bundle " + endpoint.getBundleName() + " has been restarted - check on "
+ endpoint + " didn't respond!\n"
+ "This Mail won't be sent again if service continues to fail.";
content += "\nSystem Information BEFORE restart:\n" + info_before_restart;
content += "\n\nSystem information AFTER restart:\n" + info.toString();
if (sysinfo_available) {
content += "\nSystem Information BEFORE restart:\n" + info_before_restart;
content += "\n\nSystem information AFTER restart:\n" + info.toString();
} else {
content += "\nSystem information NOT available due to an error in the library";
}
sendMail(endpoint, subject, content);
} catch (Throwable ex) {
ex.printStackTrace();
@@ -12,6 +12,7 @@ import org.hyperic.sigar.FileSystem;
import org.hyperic.sigar.NetConnection;
import org.hyperic.sigar.NetFlags;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
/**
* @see SystemInformation
@@ -29,13 +30,23 @@ public class SystemInformationImpl implements SystemInformation {
private long allocated_tcp_connections = -1;
private long used_tcp_connections = -1;
/**
* @return An instance in case SIGAR can be activated. You always have to check
* for a null value.
*/
public synchronized static SystemInformation getInstance() {
if (singleton == null)
singleton = new SystemInformationImpl();
if (singleton == null) {
try {
singleton = new SystemInformationImpl();
} catch (SigarException ex) {
singleton = null;
}
}
return singleton;
}
public SystemInformationImpl() {
public SystemInformationImpl() throws SigarException {
this.sigar_manager = new Sigar();
this.java_manager = ManagementFactory.getOperatingSystemMXBean();
}