some generalization in the Cache Replicator. Not finished,

but should be usable.
This commit is contained in:
hns 2001-07-29 20:12:42 +00:00
parent f5923016c6
commit cd6ee8ccbf
2 changed files with 43 additions and 13 deletions

View file

@ -55,9 +55,10 @@ public final class NodeManager {
// nullNode = new Node ("nullNode", "nullNode", null, safe); // nullNode = new Node ("nullNode", "nullNode", null, safe);
String replicationUrl = props.getProperty ("replicationUrl"); String replicationUrl = props.getProperty ("replicationUrl");
if (replicationUrl != null) if (replicationUrl != null) {
replicator = new Replicator (replicationUrl); replicator = new Replicator ();
else replicator.addUrl (replicationUrl);
} else
replicator = null; replicator = null;
// get the initial id generator value // get the initial id generator value
@ -647,6 +648,10 @@ public final class NodeManager {
*/ */
public List getNodes (Node home, Relation rel) throws Exception { public List getNodes (Node home, Relation rel) throws Exception {
// This does not apply for groupby nodes - use getNodeIDs instead
if (rel.groupby != null)
return getNodeIDs (home, rel);
Transactor tx = (Transactor) Thread.currentThread (); Transactor tx = (Transactor) Thread.currentThread ();
// tx.timer.beginEvent ("getNodes "+home); // tx.timer.beginEvent ("getNodes "+home);
@ -982,6 +987,12 @@ public final class NodeManager {
return replicator; return replicator;
} }
public void registerReplicatedApp (helma.framework.IReplicatedApp rapp) {
if (replicator == null)
replicator = new Replicator ();
replicator.addApp (rapp);
}
public void replicateCache (Vector add, Vector delete) { public void replicateCache (Vector add, Vector delete) {
synchronized (cache) { synchronized (cache) {
for (Enumeration en=add.elements(); en.hasMoreElements(); ) { for (Enumeration en=add.elements(); en.hasMoreElements(); ) {

View file

@ -3,7 +3,7 @@
package helma.objectmodel.db; package helma.objectmodel.db;
import helma.framework.IRemoteApp; import helma.framework.IReplicatedApp;
import java.rmi.*; import java.rmi.*;
import java.util.*; import java.util.*;
@ -13,28 +13,47 @@ import java.util.*;
public class Replicator implements Runnable { public class Replicator implements Runnable {
String url; Vector urls;
Vector apps;
Vector add, delete, currentAdd, currentDelete; Vector add, delete, currentAdd, currentDelete;
Thread runner; Thread runner;
public Replicator (String url) { public Replicator () {
this.url = url; urls = new Vector ();
apps = new Vector ();
add = new Vector (); add = new Vector ();
delete = new Vector (); delete = new Vector ();
runner = new Thread (this); runner = new Thread (this);
runner.start (); runner.start ();
} }
public void addUrl (String url) {
urls.addElement (url);
}
public void addApp (IReplicatedApp app) {
apps.addElement (app);
}
public void run () { public void run () {
while (Thread.currentThread () == runner) { while (Thread.currentThread () == runner) {
try { if (prepareReplication ()) {
if (prepareReplication ()) { for (int i=0; i<urls.size(); i++) {
IRemoteApp app = (IRemoteApp) Naming.lookup (url); try {
app.replicateCache (currentAdd, currentDelete); IReplicatedApp app = (IReplicatedApp) Naming.lookup ((String) urls.elementAt (i));
app.replicateCache (currentAdd, currentDelete);
} 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);
}
} }
} catch (Exception x) {
System.err.println ("ERROR REPLICATING CACHE: "+x);
} }
try { try {