Skip to content

Commit

Permalink
proper dispose if ide plugins
Browse files Browse the repository at this point in the history
Conflicts:

	server/cloud9/ide.js
  • Loading branch information
fjakobs committed Jan 17, 2011
1 parent 1d5d8a7 commit e91b299
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 21 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -90,6 +90,14 @@ If you get an error about unable to load o3-xml or an architecture error, you wi

after this you can start cloud9 manually using node bin/cloud9.js

## How to compile a custom node.js binary

There is a known V8 bug in the 0.2.x banch of node, which prevents the debugger from working under Linux. To work around this bug the node binary has to be compiled with gcc 4.4:

$ export GCC_VERSION=44
$ configure
$ make

## Documentation

Documentation is in the making.
Expand Down
36 changes: 23 additions & 13 deletions server/cloud9/ext/debugger/index.js
Expand Up @@ -88,19 +88,7 @@ sys.inherits(DebuggerPlugin, Plugin);
this.ide.broadcast('{"type": "node-debug-ready"}');
break;
case "kill":
var child = this.child;
if (!child)
break;
try {
child.kill();
// check after 2sec if the process is really dead
// If not kill it harder
setTimeout(function() {
if (child.pid > 0)
child.kill("SIGKILL");
}, 2000)
}
catch(e) {}
this.$kill();
break;
default:
res = false;
Expand All @@ -109,6 +97,22 @@ sys.inherits(DebuggerPlugin, Plugin);
return res;
};

this.$kill = function() {
var child = this.child;
if (!child)
return;
try {
child.kill();
// check after 2sec if the process is really dead
// If not kill it harder
setTimeout(function() {
if (child.pid > 0)
child.kill("SIGKILL");
}, 2000)
}
catch(e) {}
};

this.$run = function(message, client) {
var _self = this;

Expand Down Expand Up @@ -205,4 +209,10 @@ sys.inherits(DebuggerPlugin, Plugin);

this.nodeDebugProxy.connect();
};

this.dispose = function(callback) {
this.$kill();
callback();
};

}).call(DebuggerPlugin.prototype);
6 changes: 6 additions & 0 deletions server/cloud9/ext/shell-git/index.js
Expand Up @@ -75,4 +75,10 @@ sys.inherits(ShellGitPlugin, Plugin);

return true;
};

this.dispose = function(callback) {
// TODO kill all running processes!
callback();
};

}).call(ShellGitPlugin.prototype);
5 changes: 5 additions & 0 deletions server/cloud9/ext/shell/index.js
Expand Up @@ -163,4 +163,9 @@ sys.inherits(ShellPlugin, Plugin);
callback(tail, matches);
});
};

this.dispose = function(callback) {
// TODO kill all running processes!
callback();
}
}).call(ShellPlugin.prototype);
20 changes: 14 additions & 6 deletions server/cloud9/ext/watcher/index.js
Expand Up @@ -10,20 +10,21 @@ var fs = require("fs"),
function cloud9WatcherPlugin(ide) {
this.ide = ide;
this.hooks = ["disconnect", "command"];
this.filenames = {};
}

(function() {
var filenames = {};

function unwatchFile(filename) {
// console.log("No longer watching file " + filename);
delete filenames[filename];
delete this.filenames[filename];
fs.unwatchFile(filename);
return true;
}

// TODO: this does not look correct. There could be more than one client be
// attached. There needs to be a per client list with ref counting
this.disconnect = function() {
for (var filename in filenames)
for (var filename in this.filenames)
unwatchFile(filename);
return true;
};
Expand All @@ -39,7 +40,7 @@ function cloud9WatcherPlugin(ide) {
filename = path.replace(/\/workspace/, this.ide.workspaceDir);
switch (type) {
case "watchFile":
if (filenames[filename])
if (this.filenames[filename])
; // console.log("Already watching file " + filename);
else {
// console.log("Watching file " + filename);
Expand Down Expand Up @@ -73,7 +74,7 @@ function cloud9WatcherPlugin(ide) {
}));
// console.log("Sent " + subtype + " notification for file " + filename);
});
filenames[filename] = filename;
this.filenames[filename] = filename;
}
return true;
case "unwatchFile":
Expand All @@ -83,6 +84,13 @@ function cloud9WatcherPlugin(ide) {
}
}
};

this.dispose = function(callback) {
for (filename in this.filenames)
unwatchFile(this.filenames[filename]);
callback();
};

}).call(cloud9WatcherPlugin.prototype = new plugin());

module.exports = cloud9WatcherPlugin;
23 changes: 21 additions & 2 deletions server/cloud9/ide.js
Expand Up @@ -130,6 +130,7 @@ sys.inherits(Ide, EventEmitter);
this.addClientConnection = function(client, message) {
var _self = this;
this.clients[client.sessionId] = client;
this.onClientCountChange();

client.on("message", function(message) {
_self.onClientMessage(message, client);
Expand All @@ -138,11 +139,16 @@ sys.inherits(Ide, EventEmitter);
client.on("disconnect", function() {
_self.execHook("disconnect");
delete _self.clients[client.sessionId];
_self.onClientCountChange();
});

if (message)
_self.onClientMessage(message, client);
};

this.onClientCountChange = function() {
this.emit("clientCountChange", Object.keys(this.clients).length);
};

this.onClientMessage = function(message, client) {
try {
Expand Down Expand Up @@ -187,8 +193,8 @@ sys.inherits(Ide, EventEmitter);
// if we get here, no hook function was successfully delegated to an
// extension.

this.error("Error: no handler found for hook '" + hook + "'. Arguments: "
+ sys.inspect(args), 9, args[0]);
//this.error("Error: no handler found for hook '" + hook + "'. Arguments: "
// + sys.inspect(args), 9, args[0]);
};

this.error = function(description, code, message, client) {
Expand All @@ -205,4 +211,17 @@ sys.inherits(Ide, EventEmitter);
else
this.broadcast(error);
};

this.dispose = function(callback) {
var count;
for (var name in this.exts) {
count++;
var ext = this.exts[name];
ext.dispose(function() {
count--;
if (count == 0)
callback();
});
}
};
}).call(Ide.prototype);
5 changes: 5 additions & 0 deletions server/cloud9/plugin.js
Expand Up @@ -58,6 +58,11 @@ function cloud9Plugin() {}

return child;
};

this.dispose = function(callback) {
callback();
};

}).call(cloud9Plugin.prototype = new Events.EventEmitter());

module.exports = cloud9Plugin;

0 comments on commit e91b299

Please sign in to comment.