Some cleanup, fixed bug where a zip file with entries for a prototype

would prevent stuff in the prototype's directory to be ignored.  (use
getLastCheck() instead of getLastUpdate() to find out if we should
look for new files in directory)
This commit is contained in:
hns 2002-07-04 18:31:11 +00:00
parent 894c544174
commit fab876e2e7

View file

@ -23,7 +23,6 @@ public final class TypeManager {
HashMap prototypes; HashMap prototypes;
HashMap zipfiles; HashMap zipfiles;
long lastCheck = 0; long lastCheck = 0;
long idleSeconds = 120; // if idle for longer than 5 minutes, slow down
boolean rewire; boolean rewire;
static String[] standardTypes = {"user", "global", "root", "hopobject"}; static String[] standardTypes = {"user", "global", "root", "hopobject"};
@ -124,7 +123,6 @@ public final class TypeManager {
app.rewireDbMappings (); app.rewireDbMappings ();
rewire = false; rewire = false;
} }
// app.logEvent (" ...done @ "+ (System.currentTimeMillis () - now)+ "--- "+idleSeconds);
} }
@ -152,11 +150,6 @@ public final class TypeManager {
Prototype p = getPrototype (typename); Prototype p = getPrototype (typename);
if (p == null) { if (p == null) {
p = new Prototype (typename, app); p = new Prototype (typename, app);
p.templates = new HashMap ();
p.functions = new HashMap ();
p.actions = new HashMap ();
p.skins = new HashMap ();
p.updatables = new HashMap ();
prototypes.put (typename, p); prototypes.put (typename, p);
} }
return p; return p;
@ -170,26 +163,11 @@ public final class TypeManager {
// System.err.println ("REGISTER PROTO: "+app.getName()+"/"+name); // System.err.println ("REGISTER PROTO: "+app.getName()+"/"+name);
// app.logEvent ("registering prototype "+name); // app.logEvent ("registering prototype "+name);
// show the type checker thread that there has been type activity
idleSeconds = 0;
HashMap ntemp = new HashMap ();
HashMap nfunc = new HashMap ();
HashMap nact = new HashMap ();
HashMap nskins = new HashMap ();
HashMap updatables = new HashMap ();
// Create and register type properties file // Create and register type properties file
File propfile = new File (dir, "type.properties"); File propfile = new File (dir, "type.properties");
SystemProperties props = new SystemProperties (propfile.getAbsolutePath ()); SystemProperties props = new SystemProperties (propfile.getAbsolutePath ());
DbMapping dbmap = new DbMapping (app, name, props); DbMapping dbmap = new DbMapping (app, name, props);
updatables.put ("type.properties", dbmap); proto.updatables.put ("type.properties", dbmap);
proto.templates = ntemp;
proto.functions = nfunc;
proto.actions = nact;
proto.skins = nskins;
proto.updatables = updatables;
// app.scriptingEngine.updatePrototype (proto); // app.scriptingEngine.updatePrototype (proto);
} }
@ -214,7 +192,8 @@ public final class TypeManager {
boolean needsUpdate = false; boolean needsUpdate = false;
HashSet updatables = null; HashSet updatables = null;
// our plan is to do as little as possible, so first check if anything has changed at all... // our plan is to do as little as possible, so first check if
// anything the prototype knows about has changed on disk
for (Iterator i = proto.updatables.values().iterator(); i.hasNext(); ) { for (Iterator i = proto.updatables.values().iterator(); i.hasNext(); ) {
Updatable upd = (Updatable) i.next(); Updatable upd = (Updatable) i.next();
if (upd.needsUpdate ()) { if (upd.needsUpdate ()) {
@ -225,8 +204,14 @@ public final class TypeManager {
} }
} }
// check if file have been created since last update // fetch previous last-check timestamp and update it on prototype
if (proto.lastUpdate < dir.lastModified ()) { // we do this here for the (not very likely but possible) case
// where files are created in the exact moment we are doing this check.
long lastcheck = proto.getLastCheck ();
proto.markChecked ();
// next we check if files have been created since last update
if (lastcheck < dir.lastModified ()) {
String[] list = dir.list(); String[] list = dir.list();
for (int i=0; i<list.length; i++) { for (int i=0; i<list.length; i++) {
String fn = list[i]; String fn = list[i];
@ -241,13 +226,10 @@ public final class TypeManager {
} }
} }
if (!needsUpdate) { // if nothing needs to be updated, return now
proto.markChecked (); if (!needsUpdate)
return; return;
}
// let the thread know we had to do something.
idleSeconds = 0;
// app.logEvent ("TypeManager: Updating prototypes for "+app.getName()+": "+updatables); // app.logEvent ("TypeManager: Updating prototypes for "+app.getName()+": "+updatables);
// first go through new files and create new items // first go through new files and create new items