Added logReplication option (works like logSql) to log events regarding cache

replication. Errors in replication are now logged to the application event log.
This commit is contained in:
hns 2002-09-26 16:36:29 +00:00
parent dbd45f573c
commit be021b25ea
2 changed files with 26 additions and 33 deletions

View file

@ -32,6 +32,7 @@ public final class NodeManager {
private long idBaseValue = 1l; private long idBaseValue = 1l;
private boolean logSql; private boolean logSql;
protected boolean logReplication;
// a wrapper that catches some Exceptions while accessing this NM // a wrapper that catches some Exceptions while accessing this NM
public final WrappedNodeManager safe; public final WrappedNodeManager safe;
@ -53,12 +54,19 @@ public final class NodeManager {
safe = new WrappedNodeManager (this); safe = new WrappedNodeManager (this);
// nullNode = new Node (); // nullNode = new Node ();
logSql = "true".equalsIgnoreCase(props.getProperty ("logsql"));
logReplication = "true".equalsIgnoreCase(props.getProperty ("logReplication"));
String replicationUrl = props.getProperty ("replicationUrl"); String replicationUrl = props.getProperty ("replicationUrl");
if (replicationUrl != null) { if (replicationUrl != null) {
replicator = new Replicator (); if (logReplication)
app.logEvent ("Setting up replication listener at "+replicationUrl);
replicator = new Replicator (this);
replicator.addUrl (replicationUrl); replicator.addUrl (replicationUrl);
} else } else {
replicator = null; replicator = null;
}
// get the initial id generator value // get the initial id generator value
String idb = props.getProperty ("idBaseValue"); String idb = props.getProperty ("idBaseValue");
@ -69,8 +77,6 @@ public final class NodeManager {
db = new XmlDatabase (dbHome, null, this); db = new XmlDatabase (dbHome, null, this);
initDb (); initDb ();
logSql = "true".equalsIgnoreCase(props.getProperty ("logsql"));
} }
/** /**
@ -80,6 +86,7 @@ public final class NodeManager {
int cacheSize = Integer.parseInt (props.getProperty ("cachesize", "1000")); int cacheSize = Integer.parseInt (props.getProperty ("cachesize", "1000"));
cache.setCapacity (cacheSize); cache.setCapacity (cacheSize);
logSql = "true".equalsIgnoreCase(props.getProperty ("logsql")); logSql = "true".equalsIgnoreCase(props.getProperty ("logsql"));
logReplication = "true".equalsIgnoreCase(props.getProperty ("logReplication"));
} }
/** /**
@ -1170,20 +1177,14 @@ public final class NodeManager {
return replicator; return replicator;
} }
/**
* Register a remote application as listener to updates in this cache.
*/
public void registerReplicatedApp (helma.framework.IReplicatedApp rapp) {
if (replicator == null)
replicator = new Replicator ();
replicator.addApp (rapp);
}
/** /**
* Receive notification from a remote app that objects in its cache have been * Receive notification from a remote app that objects in its cache have been
* modified. * modified.
*/ */
public void replicateCache (Vector add, Vector delete) { public void replicateCache (Vector add, Vector delete) {
if (logReplication)
app.logEvent ("Received cache replication event: "+add.size()+" added, "+delete.size()+" deleted");
synchronized (cache) { synchronized (cache) {
for (Enumeration en=add.elements(); en.hasMoreElements(); ) { for (Enumeration en=add.elements(); en.hasMoreElements(); ) {
Node n = (Node) en.nextElement (); Node n = (Node) en.nextElement ();

View file

@ -3,7 +3,6 @@
package helma.objectmodel.db; package helma.objectmodel.db;
import helma.framework.IReplicatedApp;
import java.rmi.*; import java.rmi.*;
import java.util.*; import java.util.*;
@ -14,25 +13,23 @@ import java.util.*;
public class Replicator implements Runnable { public class Replicator implements Runnable {
Vector urls; Vector urls;
Vector apps;
Vector add, delete, currentAdd, currentDelete; Vector add, delete, currentAdd, currentDelete;
Thread runner; Thread runner;
NodeManager nmgr;
public Replicator () { public Replicator (NodeManager nmgr) {
urls = new Vector (); urls = new Vector ();
apps = new Vector ();
add = new Vector (); add = new Vector ();
delete = new Vector (); delete = new Vector ();
this.nmgr = nmgr;
runner = new Thread (this); runner = new Thread (this);
runner.start (); runner.start ();
} }
public void addUrl (String url) { public void addUrl (String url) {
urls.addElement (url); urls.addElement (url);
} if (nmgr.logReplication)
nmgr.app.logEvent ("Adding replication listener: "+url);
public void addApp (IReplicatedApp app) {
apps.addElement (app);
} }
public void run () { public void run () {
@ -40,18 +37,13 @@ public class Replicator implements Runnable {
if (prepareReplication ()) { if (prepareReplication ()) {
for (int i=0; i<urls.size(); i++) { for (int i=0; i<urls.size(); i++) {
try { try {
IReplicatedApp app = (IReplicatedApp) Naming.lookup ((String) urls.elementAt (i)); String url = (String) urls.elementAt (i);
app.replicateCache (currentAdd, currentDelete); IReplicationListener listener = (IReplicationListener) Naming.lookup (url);
listener.replicateCache (currentAdd, currentDelete);
if (nmgr.logReplication)
nmgr.app.logEvent ("Sent cache replication event: "+add.size()+" added, "+delete.size()+" deleted");
} catch (Exception x) { } catch (Exception x) {
System.err.println ("ERROR REPLICATING CACHE: "+x); nmgr.app.logEvent ("Error sending cache replication event: "+x);
}
}
for (int i=0; i<apps.size(); i++) {
try {
IReplicatedApp app = (IReplicatedApp) apps.elementAt (i);
app.replicateCache (currentAdd, currentDelete);
} catch (Exception x) {
System.err.println ("ERROR REPLICATING CACHE: "+x);
} }
} }
} }