From be021b25ea16b150670e665a1237319eb2df3ac9 Mon Sep 17 00:00:00 2001 From: hns Date: Thu, 26 Sep 2002 16:36:29 +0000 Subject: [PATCH] Added logReplication option (works like logSql) to log events regarding cache replication. Errors in replication are now logged to the application event log. --- src/helma/objectmodel/db/NodeManager.java | 27 ++++++++++--------- src/helma/objectmodel/db/Replicator.java | 32 +++++++++-------------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/helma/objectmodel/db/NodeManager.java b/src/helma/objectmodel/db/NodeManager.java index c15a70c6..48029c43 100644 --- a/src/helma/objectmodel/db/NodeManager.java +++ b/src/helma/objectmodel/db/NodeManager.java @@ -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 (); diff --git a/src/helma/objectmodel/db/Replicator.java b/src/helma/objectmodel/db/Replicator.java index a949704c..8877c52e 100644 --- a/src/helma/objectmodel/db/Replicator.java +++ b/src/helma/objectmodel/db/Replicator.java @@ -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