inital check-in of cache replicator
This commit is contained in:
parent
2ff4f8e2e8
commit
e886594f30
1 changed files with 139 additions and 0 deletions
139
src/helma/objectmodel/db/Replicator.java
Normal file
139
src/helma/objectmodel/db/Replicator.java
Normal file
|
@ -0,0 +1,139 @@
|
|||
// Replicator.java
|
||||
// Copyright (c) Hannes Wallnöfer 2001
|
||||
|
||||
package helma.objectmodel.db;
|
||||
|
||||
import helma.framework.IRemoteApp;
|
||||
import java.rmi.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class replicates the updates of transactions to other applications via RMI
|
||||
*/
|
||||
|
||||
public class Replicator implements Runnable {
|
||||
|
||||
String url;
|
||||
Vector add, delete, currentAdd, currentDelete;
|
||||
Thread runner;
|
||||
|
||||
public Replicator (String url) {
|
||||
this.url = url;
|
||||
add = new Vector ();
|
||||
delete = new Vector ();
|
||||
runner = new Thread (this);
|
||||
runner.start ();
|
||||
}
|
||||
|
||||
|
||||
public void run () {
|
||||
while (Thread.currentThread () == runner) {
|
||||
try {
|
||||
if (prepareReplication ()) {
|
||||
IRemoteApp app = (IRemoteApp) Naming.lookup (url);
|
||||
app.replicateCache (currentAdd, currentDelete);
|
||||
}
|
||||
} catch (Exception x) {
|
||||
System.err.println ("ERROR REPLICATING CACHE: "+x);
|
||||
}
|
||||
|
||||
try {
|
||||
if (runner != null)
|
||||
runner.sleep (1000l);
|
||||
} catch (InterruptedException ir) {
|
||||
runner = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addNewNode (Node n) {
|
||||
add.addElement (n);
|
||||
}
|
||||
|
||||
public synchronized void addModifiedNode (Node n) {
|
||||
add.addElement (n);
|
||||
}
|
||||
|
||||
public synchronized void addDeletedNode (Node n) {
|
||||
delete.addElement (n);
|
||||
}
|
||||
|
||||
private synchronized boolean prepareReplication () {
|
||||
if (add.size() == 0 && delete.size() == 0)
|
||||
return false;
|
||||
currentAdd = add;
|
||||
currentDelete = delete;
|
||||
add = new Vector ();
|
||||
delete = new Vector ();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue