use of java.util.prefs.BackingStoreException in project org.alloytools.alloy by AlloyTools.
the class MailBug method prepareCrashReport.
/**
* This method prepares the crash report.
*/
private static String prepareCrashReport(Thread thread, Throwable ex, String email, String problem) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
pw.printf("Alloy Analyzer %s crash report (Build Date = %s) (Commit = %s)\n", Version.version(), Version.commit);
pw.printf("\n========================= Email ============================\n%s\n", Util.convertLineBreak(email).trim());
pw.printf("\n========================= Problem ==========================\n%s\n", Util.convertLineBreak(problem).trim());
pw.printf("\n========================= Thread Name ======================\n%s\n", thread.getName().trim());
if (ex != null)
pw.printf("\n========================= Stack Trace ======================\n%s\n", dump(ex));
pw.printf("\n========================= Preferences ======================\n");
try {
for (String key : Preferences.userNodeForPackage(Util.class).keys()) {
String value = Preferences.userNodeForPackage(Util.class).get(key, "");
pw.printf("%s = %s\n", key.trim(), value.trim());
}
} catch (BackingStoreException bse) {
pw.printf("BackingStoreException occurred: %s\n", bse.toString().trim());
}
pw.printf("\n========================= System Properties ================\n");
pw.println("Runtime.freeMemory() = " + Runtime.getRuntime().freeMemory());
pw.println("nRuntime.totalMemory() = " + Runtime.getRuntime().totalMemory());
for (Map.Entry<Object, Object> e : System.getProperties().entrySet()) {
String k = String.valueOf(e.getKey()), v = String.valueOf(e.getValue());
pw.printf("%s = %s\n", k.trim(), v.trim());
}
pw.printf("\n========================= The End ==========================\n\n");
pw.close();
sw.flush();
return sw.toString();
}
use of java.util.prefs.BackingStoreException in project energy3d by concord-consortium.
the class OneInstance method setActivePort.
/**
* Remembers an active port number in the preferences.
*
* @param mainClass
* The main class of the application.
* @param port
* The port number.
*/
private void setActivePort(final Class<?> mainClass, final int port) {
final Preferences prefs = Preferences.userNodeForPackage(mainClass);
prefs.putInt(PORT_KEY, port);
try {
prefs.flush();
} catch (final BackingStoreException e) {
e.printStackTrace();
}
}
use of java.util.prefs.BackingStoreException in project energy3d by concord-consortium.
the class OneInstance method unregister.
/**
* Unregisters this instance of the application. If this is the first instance then the server is closed and the port is removed from the preferences. If this is not the first instance then this method does nothing.
*
* This method should be called when the application exits. But it is not a requirement. When you don't do this then the port number will stay in the preferences so on next start of the application this port number must be validated. So by calling this method on application exit you just save the time for this port validation.
*
* @param mainClass
* The main class of the application. Must not be null. This is used as the user node key for the preferences.
*/
public void unregister(final Class<?> mainClass) {
if (mainClass == null)
throw new IllegalArgumentException("mainClass must be set");
// Nothing to do when no server socket is present
if (server == null)
return;
// Close the server socket
server.stop();
server = null;
// Remove the port from the preferences
final Preferences prefs = Preferences.userNodeForPackage(mainClass);
prefs.remove(PORT_KEY);
try {
prefs.flush();
} catch (final BackingStoreException e) {
e.printStackTrace();
}
}
use of java.util.prefs.BackingStoreException in project hale by halestudio.
the class WMSConfiguration method load.
/**
* Load a WMS configuration with the given name
*
* @param name the configuration name
*
* @return if loading the configuration succeeded
*/
public boolean load(String name) {
Preferences preferences = getPreferences();
try {
if (preferences.nodeExists(name)) {
Preferences node = preferences.node(name);
setName(name);
loadProperties(node);
return true;
} else {
// $NON-NLS-1$ //$NON-NLS-2$
log.warn("No configuration named " + name + " found");
return false;
}
} catch (BackingStoreException e) {
// $NON-NLS-1$
log.error("Error loading WMS configuration");
return false;
}
}
use of java.util.prefs.BackingStoreException in project hale by halestudio.
the class WMSConfiguration method save.
/**
* Save the configuration
*
* @param overwrite if old settings/servers with the same name shall be
* overridden
*/
public void save(boolean overwrite) {
Preferences preferences = getPreferences();
try {
String name = getName();
if (!overwrite) {
int i = 1;
// find unique name
while (preferences.nodeExists(name)) {
// $NON-NLS-1$
name = getName() + "_" + i;
i++;
}
}
Preferences node = preferences.node(name);
setName(name);
saveProperties(node);
node.flush();
} catch (BackingStoreException e) {
// $NON-NLS-1$
log.error("Error saving map server preferences", e);
}
}
Aggregations