* Added NodeManager.init() to separate initialization from the constructor.
* Added ObjectCache.shutdown() to allow object caches to be closed. * Catch exceptions and errors thrown by NodeChangeListeners.
This commit is contained in:
parent
9d53d33ef9
commit
4e073785ab
4 changed files with 35 additions and 14 deletions
|
@ -359,7 +359,8 @@ public final class Application implements IPathElement, Runnable {
|
||||||
userRootMapping.update();
|
userRootMapping.update();
|
||||||
|
|
||||||
// create the node manager
|
// create the node manager
|
||||||
nmgr = new NodeManager(this, dbDir.getAbsolutePath(), props);
|
nmgr = new NodeManager(this);
|
||||||
|
nmgr.init(dbDir.getAbsolutePath(), props);
|
||||||
|
|
||||||
// reset the classloader to the parent/system/server classloader.
|
// reset the classloader to the parent/system/server classloader.
|
||||||
Thread.currentThread().setContextClassLoader(typemgr.getClassLoader().getParent());
|
Thread.currentThread().setContextClassLoader(typemgr.getClassLoader().getParent());
|
||||||
|
|
|
@ -33,6 +33,11 @@ public interface ObjectCache {
|
||||||
*/
|
*/
|
||||||
void init(Application app);
|
void init(Application app);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the application holding the cache is stopped.
|
||||||
|
*/
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the application's properties have been updated to let
|
* Called when the application's properties have been updated to let
|
||||||
* the cache implementation update its settings.
|
* the cache implementation update its settings.
|
||||||
|
|
|
@ -47,21 +47,26 @@ public final class NodeManager {
|
||||||
public final WrappedNodeManager safe;
|
public final WrappedNodeManager safe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new NodeManager for Application app. An embedded database will be
|
* Create a new NodeManager for Application app.
|
||||||
|
*/
|
||||||
|
public NodeManager(Application app) {
|
||||||
|
this.app = app;
|
||||||
|
safe = new WrappedNodeManager(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the NodeManager for the given dbHome and
|
||||||
|
* application properties. An embedded database will be
|
||||||
* created in dbHome if one doesn't already exist.
|
* created in dbHome if one doesn't already exist.
|
||||||
*/
|
*/
|
||||||
public NodeManager(Application app, String dbHome, Properties props)
|
public void init(String dbHome, Properties props)
|
||||||
throws DatabaseException, ClassNotFoundException,
|
throws DatabaseException, ClassNotFoundException,
|
||||||
IllegalAccessException, InstantiationException {
|
IllegalAccessException, InstantiationException {
|
||||||
this.app = app;
|
|
||||||
|
|
||||||
String cacheImpl = props.getProperty("cacheimpl", "helma.util.CacheMap");
|
String cacheImpl = props.getProperty("cacheimpl", "helma.util.CacheMap");
|
||||||
|
|
||||||
cache = (ObjectCache) Class.forName(cacheImpl).newInstance();
|
cache = (ObjectCache) Class.forName(cacheImpl).newInstance();
|
||||||
cache.init(app);
|
cache.init(app);
|
||||||
|
|
||||||
safe = new WrappedNodeManager(this);
|
|
||||||
|
|
||||||
logSql = "true".equalsIgnoreCase(props.getProperty("logsql"));
|
logSql = "true".equalsIgnoreCase(props.getProperty("logsql"));
|
||||||
logReplication = "true".equalsIgnoreCase(props.getProperty("logReplication"));
|
logReplication = "true".equalsIgnoreCase(props.getProperty("logReplication"));
|
||||||
|
|
||||||
|
@ -162,17 +167,15 @@ public final class NodeManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shut down this node manager. This is called when the application using this
|
* Shut down this node manager. This is called when the application
|
||||||
* node manager is stopped.
|
* using this node manager is stopped.
|
||||||
*/
|
*/
|
||||||
public void shutdown() throws DatabaseException {
|
public void shutdown() throws DatabaseException {
|
||||||
db.shutdown();
|
db.shutdown();
|
||||||
|
|
||||||
if (cache != null) {
|
if (cache != null) {
|
||||||
synchronized (cache) {
|
cache.shutdown();
|
||||||
cache.clear();
|
cache = null;
|
||||||
cache = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1830,7 +1833,13 @@ public final class NodeManager {
|
||||||
int l = listeners.size();
|
int l = listeners.size();
|
||||||
|
|
||||||
for (int i=0; i<l; i++) {
|
for (int i=0; i<l; i++) {
|
||||||
((NodeChangeListener) listeners.get(i)).nodesChanged(inserted, updated, deleted);
|
try {
|
||||||
|
((NodeChangeListener) listeners.get(i)).nodesChanged(inserted, updated, deleted);
|
||||||
|
} catch (Error e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -275,6 +275,12 @@ public class CacheMap implements ObjectCache {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Called when the application using this cache is stopped. We
|
||||||
|
// simply clear out our cache contents.
|
||||||
|
public synchronized void shutdown() {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
/// Set the application to use for debug and profiling output
|
/// Set the application to use for debug and profiling output
|
||||||
public void init(Application app) {
|
public void init(Application app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
Loading…
Add table
Reference in a new issue