r9856 - in helma/helma/trunk/src/helma: framework/core main objectmodel objectmodel/db

[email protected] Tue, 8 Sep 2009 21:48:08 +0200 (CEST)
Newsgroups gmane.comp.java.helma.cvs
Message-ID <20090908194808.0C4C23D0E3@mia>
Author: hannes
Date: 2009-09-08 21:48:08 +0200 (Tue, 08 Sep 2009)
New Revision: 9856

Added:
   helma/helma/trunk/src/helma/objectmodel/TransientNode.java
   helma/helma/trunk/src/helma/objectmodel/TransientProperty.java
Removed:
   helma/helma/trunk/src/helma/framework/core/RemoteApplication.java
   helma/helma/trunk/src/helma/objectmodel/db/IReplicationListener.java
   helma/helma/trunk/src/helma/objectmodel/db/Replicator.java
Modified:
   helma/helma/trunk/src/helma/framework/core/Session.java
   helma/helma/trunk/src/helma/main/ApplicationManager.java
   helma/helma/trunk/src/helma/main/Server.java
   helma/helma/trunk/src/helma/main/ServerConfig.java
   helma/helma/trunk/src/helma/objectmodel/db/DbMapping.java
   helma/helma/trunk/src/helma/objectmodel/db/Node.java
   helma/helma/trunk/src/helma/objectmodel/db/NodeManager.java
Log:
Remove cache replication functionality including the underlying RMI networking code, make Node not serializable and Node.nmgr final, and resurrect TransientNode for use in sessions.


Details at http://dev.helma.org/trac/helma/changeset/9856

Deleted: helma/helma/trunk/src/helma/framework/core/RemoteApplication.java

Modified: helma/helma/trunk/src/helma/framework/core/Session.java
===================================================================
--- helma/helma/trunk/src/helma/framework/core/Session.java	2009-09-08 13:51:39 UTC (rev 9855)
+++ helma/helma/trunk/src/helma/framework/core/Session.java	2009-09-08 19:48:08 UTC (rev 9856)
@@ -67,7 +67,7 @@
         this.app = app;
         this.uid = null;
         this.userHandle = null;
-        cacheNode = new Node("session", null, app.getWrappedNodeManager());
+        cacheNode = new TransientNode("session");
         onSince = System.currentTimeMillis();
         lastTouched = lastModified = onSince;
     }

Modified: helma/helma/trunk/src/helma/main/ApplicationManager.java
===================================================================
--- helma/helma/trunk/src/helma/main/ApplicationManager.java	2009-09-08 13:51:39 UTC (rev 9855)
+++ helma/helma/trunk/src/helma/main/ApplicationManager.java	2009-09-08 19:48:08 UTC (rev 9856)
@@ -29,7 +29,6 @@
 import org.mortbay.jetty.servlet.ServletHolder;
 
 import java.io.*;
-import java.rmi.*;
 import java.util.*;
 import helma.util.ResourceProperties;
 import helma.servlet.EmbeddedServletClient;
@@ -41,7 +40,6 @@
     private Hashtable descriptors;
     private Hashtable applications;
     private Hashtable xmlrpcHandlers;
-    private int rmiPort;
     private ResourceProperties props;
     private Server server;
     private long lastModified;
@@ -54,23 +52,9 @@
      * @param props the properties defining the running apps
      * @param server the server instance
      */
-    public ApplicationManager(ResourceProperties props,
-                              Server server) {
-        this(props, server, 0);
-    }
-
-    /**
-     * Creates a new ApplicationManager object.
-     *
-     * @param props the properties defining the running apps
-     * @param server the server instance
-     * @param port The RMI port we're binding to
-     */
-    public ApplicationManager(ResourceProperties props,
-                              Server server, int port) {
+    public ApplicationManager(ResourceProperties props, Server server) {
         this.props = props;
         this.server = server;
-        this.rmiPort = port;
         descriptors = new Hashtable();
         applications = new Hashtable();
         xmlrpcHandlers = new Hashtable();
@@ -488,11 +472,6 @@
             try {
                 getLogger().info("Binding application " + appName + " :: " + app.hashCode() + " :: " + this.hashCode());
 
-                // bind to RMI server
-                if (rmiPort > 0) {
-                    Naming.rebind("//:" + rmiPort + "/" + appName, new RemoteApplication(app));
-                }
-
                 // set application URL prefix if it isn't set in app.properties
                 if (!app.hasExplicitBaseURI()) {
                     app.setBaseURI(mountpoint);
@@ -594,11 +573,6 @@
             getLogger().info("Unbinding application " + appName);
 
             try {
-               // unbind from RMI server
-                if (rmiPort > 0) {
-                    Naming.unbind("//:" + rmiPort + "/" + appName);
-                }
-
                 // unbind from Jetty HTTP server
                 if (jetty != null) {
                     if (appContext != null) {

Modified: helma/helma/trunk/src/helma/main/Server.java
===================================================================
--- helma/helma/trunk/src/helma/main/Server.java	2009-09-08 13:51:39 UTC (rev 9855)
+++ helma/helma/trunk/src/helma/main/Server.java	2009-09-08 19:48:08 UTC (rev 9856)
@@ -59,7 +59,7 @@
     // server start time
     public final long starttime;
 
-    // if paranoid == true we only accept RMI and XML-RPC connections from
+    // if paranoid == true we only accept XML-RPC connections from
     // explicitly listed hosts.
     public boolean paranoid;
     private ApplicationManager appManager;
@@ -205,14 +205,6 @@
             }
         }
 
-        if (!config.hasRmiPort() && sysProps.getProperty("rmiPort") != null) {
-            try {
-                config.setRmiPort(getInetSocketAddress(sysProps.getProperty("rmiPort")));
-            } catch (Exception portx) {
-                throw new Exception("Error parsing RMI server port property from server.properties: " + portx);
-            }
-        }
-
         if (!config.hasXmlrpcPort() && sysProps.getProperty("xmlrpcPort") != null) {
             try {
                 config.setXmlrpcPort(getInetSocketAddress(sysProps.getProperty("xmlrpcPort")));
@@ -238,12 +230,6 @@
                 config.setPropFile(new File(args[++i]));
             } else if (args[i].equals("-a") && ((i + 1) < args.length)) {
                 config.setApps(StringUtils.split(args[++i]));
-            } else if (args[i].equals("-p") && ((i + 1) < args.length)) {
-                try {
-                    config.setRmiPort(getInetSocketAddress(args[++i]));
-                } catch (Exception portx) {
-                    throw new Exception("Error parsing RMI server port property: " + portx);
-                }
             } else if (args[i].equals("-x") && ((i + 1) < args.length)) {
                 try {
                     config.setXmlrpcPort(getInetSocketAddress(args[++i]));
@@ -335,7 +321,6 @@
         System.out.println("  -w [ip:]port      Specify embedded web server address/port");
         System.out.println("  -x [ip:]port      Specify XML-RPC address/port");
         System.out.println("  -jk [ip:]port     Specify AJP13 address/port");
-        System.out.println("  -p [ip:]port      Specify RMI address/port");
         System.out.println("");
         System.out.println("Supported formats for server ports:");
         System.out.println("   <port-number>");
@@ -359,10 +344,6 @@
                 checkPort(config.getWebsrvPort());
             }
 
-            if (config.hasRmiPort()) {
-                checkPort(config.getRmiPort());
-            }
-
             if (config.hasXmlrpcPort()) {
                 checkPort(config.getXmlrpcPort());
             }
@@ -588,35 +569,8 @@
                 logger.info("Starting XML-RPC server on port " + (xmlrpcPort));
             }
 
-            if (config.hasRmiPort()) {
-                InetSocketAddress rmiPort = config.getRmiPort();
-                if (paranoid) {
-                    HelmaSocketFactory factory = new HelmaSocketFactory();
-                    String rallow = sysProps.getProperty("allowWeb");
-                    if (rallow == null) {
-                        rallow = sysProps.getProperty("allowRMI");
-                    }
+            appManager = new ApplicationManager(appsProps, this);
 
-                    if (rallow != null) {
-                        StringTokenizer st = new StringTokenizer(rallow, " ,;");
-
-                        while (st.hasMoreTokens())
-                            factory.addAddress(st.nextToken());
-                    }
-
-                    RMISocketFactory.setSocketFactory(factory);
-                }
-
-                logger.info("Starting RMI server on port " + rmiPort);
-                LocateRegistry.createRegistry(rmiPort.getPort());
-
-                // create application manager which binds to the given RMI port
-                appManager = new ApplicationManager(appsProps, this, rmiPort.getPort());
-            } else {
-                // create application manager without RMI port
-                appManager = new ApplicationManager(appsProps, this);
-            }
-
             if (xmlrpc != null) {
                 xmlrpc.addHandler("$default", appManager);
             }

Modified: helma/helma/trunk/src/helma/main/ServerConfig.java
===================================================================
--- helma/helma/trunk/src/helma/main/ServerConfig.java	2009-09-08 13:51:39 UTC (rev 9855)
+++ helma/helma/trunk/src/helma/main/ServerConfig.java	2009-09-08 19:48:08 UTC (rev 9856)
@@ -25,7 +25,6 @@
  
 public class ServerConfig {
 
-    private InetSocketAddress rmiPort    = null;
     private InetSocketAddress xmlrpcPort = null;
     private InetSocketAddress websrvPort = null;
     private InetSocketAddress ajp13Port  = null;
@@ -46,10 +45,6 @@
         return (homeDir != null);
     }
 
-    public boolean hasRmiPort() {
-        return (rmiPort != null);
-    }
-
     public boolean hasXmlrpcPort() {
         return (xmlrpcPort != null);
     }
@@ -66,14 +61,6 @@
         return (apps != null);
     }
 
-    public InetSocketAddress getRmiPort() {
-        return rmiPort;
-    }
-
-    public void setRmiPort(InetSocketAddress rmiPort) {
-        this.rmiPort = rmiPort;
-    }
-
     public InetSocketAddress getXmlrpcPort() {
         return xmlrpcPort;
     }

Added: helma/helma/trunk/src/helma/objectmodel/TransientNode.java

Added: helma/helma/trunk/src/helma/objectmodel/TransientProperty.java

Modified: helma/helma/trunk/src/helma/objectmodel/db/DbMapping.java
===================================================================
--- helma/helma/trunk/src/helma/objectmodel/db/DbMapping.java	2009-09-08 13:51:39 UTC (rev 9855)
+++ helma/helma/trunk/src/helma/objectmodel/db/DbMapping.java	2009-09-08 19:48:08 UTC (rev 9856)
@@ -117,9 +117,6 @@
     // timestamp of last modification of an object of this type
     long lastDataChange = 0;
 
-    // evict objects of this type when received via replication
-    private boolean evictOnReplication;
-
     // Set of mappings that depend on us and should be forwarded last data change events
     HashSet dependentMappings = new HashSet();
 
@@ -229,7 +226,6 @@
         idField = props.getProperty("_id");
         nameField = props.getProperty("_name");
         protoField = props.getProperty("_prototype");
-        evictOnReplication = "true".equals(props.getProperty("_evictOnReplication"));
 
         parentSetting = props.getProperty("_parent");
         if (parentSetting != null) {
@@ -595,14 +591,6 @@
     }
 
     /**
-     * Should objects of this type be evicted/discarded/reloaded when received via
-     * cache replication?
-     */
-    public boolean evictOnReplication() {
-        return evictOnReplication;
-    }
-
-    /**
      * Translate a database column name to an object property name according to this mapping.
      */
     public String columnNameToProperty(String columnName) {

Deleted: helma/helma/trunk/src/helma/objectmodel/db/IReplicationListener.java

Modified: helma/helma/trunk/src/helma/objectmodel/db/Node.java
===================================================================
--- helma/helma/trunk/src/helma/objectmodel/db/Node.java	2009-09-08 13:51:39 UTC (rev 9855)
+++ helma/helma/trunk/src/helma/objectmodel/db/Node.java	2009-09-08 19:48:08 UTC (rev 9856)
@@ -34,8 +34,7 @@
  * An implementation of INode that can be stored in the internal database or
  * an external relational database.
  */
-public final class Node implements INode, Serializable {
-    static final long serialVersionUID = -3740339688506633675L;
+public final class Node implements INode {
 
     // The handle to the node's parent
     protected NodeHandle parentHandle;
@@ -60,7 +59,7 @@
     private transient String prototype;
     private transient NodeHandle handle;
     private transient INode cacheNode;
-    transient volatile WrappedNodeManager nmgr;
+    transient final WrappedNodeManager nmgr;
     transient DbMapping dbmap;
     transient Key primaryKey = null;
     transient String subnodeRelation = null;
@@ -71,32 +70,41 @@
     private static long idgen = 0;
 
     /**
-     * Creates an empty, uninitialized Node. The init() method must be called on the
-     * Node before it can do anything useful.
-     */
-    protected Node() {
-        created = lastmodified = System.currentTimeMillis();
-    }
-
-    /**
      * Creates an empty, uninitialized Node with the given create and modify time.
      * This is used for null-node references in the node cache.
      * @param timestamp
      */
     protected Node(long timestamp) {
         created = lastmodified = timestamp;
+        this.nmgr = null;
     }
 
     /**
+     * Creates an empty, uninitialized Node. The init() method must be called on the
+     * Node before it can do anything useful.
+     */
+    protected Node(WrappedNodeManager nmgr) {
+        if (nmgr == null) {
+            throw new NullPointerException("nmgr");
+        }
+        this.nmgr = nmgr;
+        created = lastmodified = System.currentTimeMillis();
+    }
+
+    /**
      * Creates a new Node with the given name. Used by NodeManager for creating "root nodes"
      * outside of a Transaction context, which is why we can immediately mark it as CLEAN.
      * Also used by embedded database to re-create an existing Node.
      */
     public Node(String name, String id, String prototype, WrappedNodeManager nmgr) {
+        if (nmgr == null) {
+            throw new NullPointerException("nmgr");
+        }
+        this.nmgr = nmgr;
         if (prototype == null) {
             prototype = "HopObject";
         }
-        init(nmgr.getDbMapping(prototype), id, name, prototype, null, nmgr);
+        init(nmgr.getDbMapping(prototype), id, name, prototype, null);
     }
 
     /**
@@ -162,12 +170,8 @@
     /**
      * Initializer used for nodes being instanced from an embedded or relational database.
      */
-    public synchronized void init(DbMapping dbm, String id, String name, String prototype,
-                Hashtable propMap, WrappedNodeManager nmgr) {
-        if (nmgr == null) {
-            throw new NullPointerException("nmgr");
-        }
-        this.nmgr = nmgr;
+    public synchronized void init(DbMapping dbm, String id, String name,
+                                  String prototype, Hashtable propMap) {
         this.dbmap = dbm;
         this.prototype = prototype;
         this.id = id;
@@ -188,67 +192,6 @@
     }
 
     /**
-     * Read this object instance from a stream. This does some smart conversion to
-     * update from previous serialization formats.
-     */
-    private void readObject(ObjectInputStream in) throws IOException {
-        try {
-            // as a general rule of thumb, if a string can be null use read/writeObject,
-            // if not it's save to use read/writeUTF.
-            // version indicates the serialization version
-            version = in.readShort();
-
-            if (version < 9) {
-                throw new IOException("Can't read pre 1.3.0 HopObject");
-            }
-
-            id = (String) in.readObject();
-            name = (String) in.readObject();
-            state = in.readInt();
-            parentHandle = (NodeHandle) in.readObject();
-            created = in.readLong();
-            lastmodified = in.readLong();
-
-            subnodes = (SubnodeList) in.readObject();
-            // left-over from links vector
-            in.readObject();
-            propMap = (Hashtable) in.readObject();
-            anonymous = in.readBoolean();
-            prototype = (String) in.readObject();
-
-        } catch (ClassNotFoundException x) {
-            throw new IOException(x.toString());
-        }
-    }
-
-    /**
-     * Write out this instance to a stream
-     */
-    private void writeObject(ObjectOutputStream out) throws IOException {
-        out.writeShort(9); // serialization version
-        out.writeObject(id);
-        out.writeObject(name);
-        out.writeInt(state);
-        out.writeObject(parentHandle);
-        out.writeLong(created);
-        out.writeLong(lastmodified);
-
-        DbMapping smap = (dbmap == null) ? null : dbmap.getSubnodeMapping();
-
-        if (smap != null && smap.isRelational()) {
-            out.writeObject(null);
-        } else {
-            out.writeObject(subnodes);
-        }
-
-        // left-over from links vector
-        out.writeObject(null);
-        out.writeObject(propMap);
-        out.writeBoolean(anonymous);
-        out.writeObject(prototype);
-    }
-
-    /**
      * used by Xml deserialization
      */
     public synchronized void setPropMap(Hashtable propMap) {
@@ -1710,9 +1653,6 @@
                     if (n != null) {
                         // do set DbMapping for embedded db collection nodes
                         n.setDbMapping(rel.getVirtualMapping());
-                        // also set node manager in case this is a mountpoint node
-                        // that came in through replication
-                        n.nmgr = nmgr;
                     }
                 }
             }

Modified: helma/helma/trunk/src/helma/objectmodel/db/NodeManager.java
===================================================================
--- helma/helma/trunk/src/helma/objectmodel/db/NodeManager.java	2009-09-08 13:51:39 UTC (rev 9855)
+++ helma/helma/trunk/src/helma/objectmodel/db/NodeManager.java	2009-09-08 19:48:08 UTC (rev 9856)
@@ -42,7 +42,6 @@
     protected IDGenerator idgen;
     private boolean logSql;
     private Log sqlLog = null;
-    protected boolean logReplication;
     private ArrayList listeners = new ArrayList();
 
     // a wrapper that catches some Exceptions while accessing this NM
@@ -77,20 +76,7 @@
         }
 
         logSql = "true".equalsIgnoreCase(props.getProperty("logsql"));
-        logReplication = "true".equalsIgnoreCase(props.getProperty("logReplication"));
 
-        String replicationUrl = props.getProperty("replicationUrl");
-
-        if (replicationUrl != null) {
-            if (logReplication) {
-                app.logEvent("Setting up replication listener at " + replicationUrl);
-            }
-
-            Replicator replicator = new Replicator(this);
-            replicator.addUrl(replicationUrl);
-            addNodeChangeListener(replicator);
-        }
-
         db = new XmlDatabase();
         db.init(dbHome, app);
     }
@@ -123,7 +109,6 @@
         // notify the cache about the properties update
         cache.updateProperties(props);
         logSql = "true".equalsIgnoreCase(props.getProperty("logsql"));
-        logReplication = "true".equalsIgnoreCase(props.getProperty("logReplication"));
     }
 
     /**
@@ -1311,8 +1296,6 @@
 
         if ((dbm == null) || !dbm.isRelational()) {
             node = (Node) db.getNode(txn, kstr);
-            node.nmgr = safe;
-
             if ((node != null) && (dbm != null)) {
                 node.setDbMapping(dbm);
             }
@@ -1388,15 +1371,11 @@
 
             if (node == null && (dbm == null || !dbm.isRelational())) {
                 node = (Node) db.getNode(txn, kstr);
-                node.nmgr = safe;
             }
-
             return node;
         } else if (rel == null || dbm == null || !dbm.isRelational()) {
             node = (Node) db.getNode(txn, kstr);
-            node.nmgr = safe;
             node.setDbMapping(dbm);
-
             return node;
         } else {
             Statement stmt = null;
@@ -1476,7 +1455,7 @@
         String protoName = dbm.getTypeName();
         DbMapping dbmap = dbm;
 
-        Node node = new Node();
+        Node node = new Node(safe);
 
         for (int i = 0; i < columns.length; i++) {
 
@@ -1683,7 +1662,7 @@
             }
         }
 
-        node.init(dbmap, id, name, protoName, propMap, safe);
+        node.init(dbmap, id, name, protoName, propMap);
         return node;
     }
 
@@ -1776,65 +1755,6 @@
         }
     }
     
-
-    /**
-     *  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) {
-            // long now = System.currentTimeMillis();
-
-            for (Enumeration en = add.elements(); en.hasMoreElements();) {
-                Node n = (Node) en.nextElement();
-                DbMapping dbm = app.getDbMapping(n.getPrototype());
-
-                if (dbm != null) {
-                    dbm.setLastDataChange();
-                }
-
-                n.setDbMapping(dbm);
-                n.nmgr = safe;
-
-                if (dbm != null && dbm.evictOnReplication()) {
-                    Node oldNode = (Node) cache.get(n.getKey());
-
-                    if (oldNode != null) {
-                        evictNode(oldNode);
-                    }
-                } else {
-                    n.lastParentSet = -1;
-                    cache.put(n.getKey(), n);
-                }
-            }
-
-            for (Enumeration en = delete.elements(); en.hasMoreElements();) {
-                // NOTE: it would be more efficient to transfer just the keys
-                // of nodes that are to be deleted.
-                Node n = (Node) en.nextElement();
-                DbMapping dbm = app.getDbMapping(n.getPrototype());
-
-                if (dbm != null) {
-                    dbm.setLastDataChange();
-                }
-
-                n.setDbMapping(dbm);
-                n.nmgr = safe;
-
-                Node oldNode = (Node) cache.get(n.getKey());
-
-                if (oldNode != null) {
-                    evictNode(oldNode);
-                }
-            }
-        }
-    }
-
     private void setStatementValue(PreparedStatement stmt, int columnNumber, String value, DbColumn col)
             throws SQLException {
         if (value == null) {

Deleted: helma/helma/trunk/src/helma/objectmodel/db/Replicator.java