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:
parent
dbd45f573c
commit
be021b25ea
2 changed files with 26 additions and 33 deletions
|
@ -32,6 +32,7 @@ public final class NodeManager {
|
|||
private long idBaseValue = 1l;
|
||||
|
||||
private boolean logSql;
|
||||
protected boolean logReplication;
|
||||
|
||||
// a wrapper that catches some Exceptions while accessing this NM
|
||||
public final WrappedNodeManager safe;
|
||||
|
@ -53,12 +54,19 @@ public final class NodeManager {
|
|||
safe = new WrappedNodeManager (this);
|
||||
// nullNode = new Node ();
|
||||
|
||||
logSql = "true".equalsIgnoreCase(props.getProperty ("logsql"));
|
||||
logReplication = "true".equalsIgnoreCase(props.getProperty ("logReplication"));
|
||||
|
||||
|
||||
String replicationUrl = props.getProperty ("replicationUrl");
|
||||
if (replicationUrl != null) {
|
||||
replicator = new Replicator ();
|
||||
if (logReplication)
|
||||
app.logEvent ("Setting up replication listener at "+replicationUrl);
|
||||
replicator = new Replicator (this);
|
||||
replicator.addUrl (replicationUrl);
|
||||
} else
|
||||
} else {
|
||||
replicator = null;
|
||||
}
|
||||
|
||||
// get the initial id generator value
|
||||
String idb = props.getProperty ("idBaseValue");
|
||||
|
@ -69,8 +77,6 @@ public final class NodeManager {
|
|||
|
||||
db = new XmlDatabase (dbHome, null, this);
|
||||
initDb ();
|
||||
|
||||
logSql = "true".equalsIgnoreCase(props.getProperty ("logsql"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,6 +86,7 @@ public final class NodeManager {
|
|||
int cacheSize = Integer.parseInt (props.getProperty ("cachesize", "1000"));
|
||||
cache.setCapacity (cacheSize);
|
||||
logSql = "true".equalsIgnoreCase(props.getProperty ("logsql"));
|
||||
logReplication = "true".equalsIgnoreCase(props.getProperty ("logReplication"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1170,20 +1177,14 @@ public final class NodeManager {
|
|||
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
|
||||
* modified.
|
||||
*/
|
||||
public void replicateCache (Vector add, Vector delete) {
|
||||
if (logReplication)
|
||||
app.logEvent ("Received cache replication event: "+add.size()+" added, "+delete.size()+" deleted");
|
||||
synchronized (cache) {
|
||||
for (Enumeration en=add.elements(); en.hasMoreElements(); ) {
|
||||
Node n = (Node) en.nextElement ();
|
||||
|
|
|
@ -3,36 +3,33 @@
|
|||
|
||||
package helma.objectmodel.db;
|
||||
|
||||
import helma.framework.IReplicatedApp;
|
||||
import java.rmi.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class replicates the updates of transactions to other applications via RMI
|
||||
*/
|
||||
|
||||
|
||||
public class Replicator implements Runnable {
|
||||
|
||||
Vector urls;
|
||||
Vector apps;
|
||||
Vector add, delete, currentAdd, currentDelete;
|
||||
Thread runner;
|
||||
NodeManager nmgr;
|
||||
|
||||
public Replicator () {
|
||||
public Replicator (NodeManager nmgr) {
|
||||
urls = new Vector ();
|
||||
apps = new Vector ();
|
||||
add = new Vector ();
|
||||
delete = new Vector ();
|
||||
this.nmgr = nmgr;
|
||||
runner = new Thread (this);
|
||||
runner.start ();
|
||||
}
|
||||
|
||||
public void addUrl (String url) {
|
||||
urls.addElement (url);
|
||||
}
|
||||
|
||||
public void addApp (IReplicatedApp app) {
|
||||
apps.addElement (app);
|
||||
if (nmgr.logReplication)
|
||||
nmgr.app.logEvent ("Adding replication listener: "+url);
|
||||
}
|
||||
|
||||
public void run () {
|
||||
|
@ -40,18 +37,13 @@ public class Replicator implements Runnable {
|
|||
if (prepareReplication ()) {
|
||||
for (int i=0; i<urls.size(); i++) {
|
||||
try {
|
||||
IReplicatedApp app = (IReplicatedApp) Naming.lookup ((String) urls.elementAt (i));
|
||||
app.replicateCache (currentAdd, currentDelete);
|
||||
String url = (String) urls.elementAt (i);
|
||||
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) {
|
||||
System.err.println ("ERROR REPLICATING CACHE: "+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);
|
||||
nmgr.app.logEvent ("Error sending cache replication event: "+x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue