Bläddra i källkod

"Eventual" changes

Added propagate.
moved hci-http to core-http
Luis Figueiredo 8 år sedan
förälder
incheckning
0be26de958

+ 16 - 16
test/hci-usecase/bundles/hci-http/index.js

@@ -5,22 +5,24 @@ var activator = {
 
 	start(context) {
 		this.server = http.createServer((req,res) => {
-			// Global emmit
-			context.emit('req',req,res) //??
-						 .done((evt) => {
-							 // Array of results
-							 if(res.statusCode == 404 || evt.count == 0) {
-									res.writeHead(404,"Not found");
-									res.end("Not found");
-								}	
-							});
-
-			// Setup stuff here to routing
+			var lurl = req.url.replace(/^\/|\/$/g,'');  // Replace all starting "/" or ending "/"
+			// New
+			context
+				.channel(context.name).channel(req.method)
+				.propagate(lurl,req,res)
+				.done((e) => {
+					if(e.count == 0) {
+						res.writeHead(404,"Not found");
+						res.end("Not found");
+						console.log("Every thing is done");
+					}
+				});
+			// Different way
 		});
 		// 
 		log.info("Server started at: " + 3500);
 		this.server.listen(3500);
-		
+
 		this.clients = {};
 		this.server.on('connection',(conn) => {
 			var key = conn.remoteAddress + ':' + conn.remotePort;
@@ -29,7 +31,7 @@ var activator = {
 				delete this.clients[key];
 			});
 		});
-		
+
 		this.server.on('close',() => {
 			log.info("Http server went down");
 			for(var k in this.clients) {
@@ -40,11 +42,9 @@ var activator = {
 
 	stop(context) {
 		log.info("Server shutting down");
-		context.toggleOff('serverStart');
-		context.emit('serverStop');		
 		this.server.close()		// Shutdown clients
 		for(var k in this.clients) {
-				this.clients[k].destroy();
+			this.clients[k].destroy();
 		};
 
 		//this.server.emit('user:close');

+ 5 - 9
bundles/core-installer/index.js

@@ -10,20 +10,18 @@ var HitCounter = require('./hit-counter');
 var installerActivator = {
 
 	start(context) {
-
+		
 		// With config
 		this.deployPath = context.manager.config.deployPath; 
 		this.runPath = context.manager.config.runPath;
 		if(this.deployPath == undefined) {
 			log.warn("There is no deploy path configured");
-			context.set("installed",true);
+			context.channel(context.name).set("installed",true);
 			//context.emit('installed');
 			return;
 		}
 		if(this.runPath == undefined) {
-			log.warn("There is no bundlePath configured");
-			this.installed = true;
-			context.state("installed",true);
+			context.channel(context.name).set("installed",true);
 			return;
 		}
 
@@ -33,9 +31,7 @@ var installerActivator = {
 		var mods = fs.readdirSync(this.deployPath);
 
 		var hitCounter = new HitCounter(mods.length, () => {
-			log.info("Emitting installed");
-			this.installed = true;
-			context.state('installed',true);	
+			context.channel(context.name).set("installed",true);
 		});
 
 		for(var v of mods) {
@@ -48,7 +44,7 @@ var installerActivator = {
 		}
 	},
 	stop(context) {
-		context.unset('installed');	
+		context.channel(context.name).unset('installed');	
 	},
 	installPlugin(fullPath,cb) {
 		log.info("Intalling: " + fullPath);

+ 60 - 64
bundles/core-loader/index.js

@@ -17,12 +17,14 @@ var loaderActivator = {
 			log.warn("There is no runPath configured in manager");
 			return;
 		}
-		context.watch('core-installer:installed',(value) => {
-			console.log("core-installer:installed is:",value);
-			if(value == true) {
-				process.nextTick(() => { this.loadBundles()});
-			}
-		});
+		context
+			.channel('core-installer')
+			.watch('installed',(value) => {
+				console.log("core-installer:installed is:",value);
+				if(value == true) {
+					process.nextTick(() => { this.loadBundles()});
+				}
+			});
 		//this.loadBundles();	
 		// Check this out its wrong!?
 	
@@ -45,30 +47,32 @@ var loaderActivator = {
 
 	registerShell(context) {
 		//var prefix = context.prefix(".*:cmd"); // Any cmd sender
-		context.on('core-shell:cmd:lb',(req,res) => {
-			var tbl = [];
-			for(var k in context.manager.registry) {
-				var v = context.manager.registry[k];
-				if(v == undefined) {
-					continue;
-				}		
-				var modPath = v.modulePath;
-				if(modPath) {
-					modPath = modPath.replace(new RegExp("^" + process.env.PWD + "/"),"");
+		context
+			.channel('core-shell').channel('cmd')
+			.on('lb',(req,res) => {
+				var tbl = [];
+				for(var k in context.manager.registry) {
+					var v = context.manager.registry[k];
+					if(v == undefined) {
+						continue;
+					}		
+					var modPath = v.modulePath;
+					if(modPath) {
+						modPath = modPath.replace(new RegExp("^" + process.env.PWD + "/"),"");
+					}
+					tbl.push({
+						id: v.id,
+						name:v.name,
+						state: v.info.state,
+						package: (v.info.pkgInfo)?v.info.pkgInfo.name:"",
+						version: (v.info.pkgInfo)?v.info.pkgInfo.version:"",
+						author: (v.info.pkgInfo)?v.info.pkgInfo.author.name:"",
+						modulePath: modPath,
+					});
 				}
-				tbl.push({
-					id: v.id,
-					name:v.name,
-					state: v.info.state,
-					package: (v.info.pkgInfo)?v.info.pkgInfo.name:"",
-					version: (v.info.pkgInfo)?v.info.pkgInfo.version:"",
-					author: (v.info.pkgInfo)?v.info.pkgInfo.author.name:"",
-					modulePath: modPath,
-				});
-			}
-			tbl = tbl.sort((a,b) => { return a.id - b.id});
-			res.write(clitable(tbl));
-			//log.info("\n"+clitable(tbl));
+				tbl = tbl.sort((a,b) => { return a.id - b.id});
+				res.write(clitable(tbl));
+				//log.info("\n"+clitable(tbl));
 		});
 
 		function commonGetBundle(req,res,nargs) {
@@ -82,42 +86,34 @@ var loaderActivator = {
 			}
 			return bcontext;
 		}
-		context.on('core-shell:cmd:stop',(req,res) => {
-			var bcontext = commonGetBundle(req,res,1);
-			if(bcontext == null) { return; }
-			bcontext.stop();
-
-		});
-		context.on('core-shell:cmd:start',(req,res) => {
-			var bcontext = commonGetBundle(req,res,1);
-			if(bcontext == null) { return; }
-			bcontext.start();
-		});
-
-		context.on('core-shell:cmd:reload',(req,res) => {
-			var bcontext = commonGetBundle(req,res,1);
-			if(bcontext == null) { return; }
-			var modulePath = bcontext.modulePath;
-			context.manager.unregister(bcontext);
-			context.manager.register({id:bcontext.id, name:bcontext.name, bundle:bcontext.modulePath});
-		});
-		context.on('core-shell:cmd:unload',(req,res) => {
-			var bcontext = commonGetBundle(req,res,1);
-			if(bcontext == null) { return; }
-			context.manager.unregister(bcontext);
-		});
-		
-		context.on('core-shell:cmd:load',(req,res) => {
-			if(req.args.length < 1) {
-				res.write("Not enough parameters\n");
-				return;
-			}
-			res.write("Loading module from: " + process.env.PWD +"\n");
-			context.manager.load(process.env.PWD + "/" + req.args[0]);
+		context.channel('core-shell').channel('cmd')
+			.on('stop',(req,res) => {
+				var bcontext = commonGetBundle(req,res,1);
+				if(bcontext == null) { return; }
+				bcontext.stop();
+			}).on('start',(req,res) => {
+				var bcontext = commonGetBundle(req,res,1);
+				if(bcontext == null) { return; }
+				bcontext.start();
+			}).on('reload',(req,res) => {
+				var bcontext = commonGetBundle(req,res,1);
+				if(bcontext == null) { return; }
+				var modulePath = bcontext.modulePath;
+				context.manager.unregister(bcontext);
+				context.manager.register({id:bcontext.id, name:bcontext.name, bundle:bcontext.modulePath});
+			}).on('unload',(req,res) => {
+				var bcontext = commonGetBundle(req,res,1);
+				if(bcontext == null) { return; }
+				context.manager.unregister(bcontext);
+			}).on('load',(req,res) => {
+				if(req.args.length < 1) {
+					res.write("Not enough parameters\n");
+					return;
+				}
+				res.write("Loading module from: " + process.env.PWD +"\n");
+				context.manager.load(process.env.PWD + "/" + req.args[0]);
 			//context.manager.register({name:args[1], bundle:path.resolve(path.join(process.env.PWD, args[2]))});
-		});
-	
-
+			});
 	}
 	
 

+ 0 - 5
bundles/core-monitor/index.js

@@ -18,11 +18,6 @@ var monitor = {
 		this.context = context;
 		log.info("Bundle monitor started");
 		this.registerCommands(context);
-		context.on('hci-config', (config) => {
-			context.on(config,"start",function() {
-				config.test();
-			});	
-		});
 	},
 
 	registerCommands(context) {

+ 5 - 2
bundles/core-shell/index.js

@@ -21,10 +21,13 @@ var shellActivator = {
 			var req = { cmd:cmd, args:args }
 			var res = this.stdout;
 			context
-				.emit("cmd:" + cmd,req,res)
+				.channel(context.name).channel('cmd')
+				.emit(cmd,req,res)
 				.done((evt)=> {
 					if(evt.count == 0) {
-						context.emit("cmd",req,res).done(() => { this.cli.prompt() });
+						context
+							.channel(context.name)
+							.emit("cmd",req,res).done(() => { this.cli.prompt() });
 					}
 					this.cli.prompt();	
 				});

+ 14 - 0
doc/eventual/ideas.md

@@ -1,4 +1,18 @@
 
+### Propagation
+
+context.emit("channel:sub:test");
+Propagation should fire 3 events: as in
+
+
+context.on("channel:sub",(e) => {
+	e.stopPropagation();
+});
+
+
+
+
+
 Object storage can be simplified as in
 
 disable channel complexity?

+ 0 - 2
index.js

@@ -1,4 +1,2 @@
-
-
 module.exports = require('./lib/bundle-manager');
 

+ 14 - 28
lib/bundle-context.js

@@ -102,7 +102,7 @@ class BundleContext /*extends XEventEmitter*/ {
 	stop() {
 		if(this.info.state == 0) return;
 		//this.toggleOff("start");
-		this.emit("stop");
+		this.events.channel(this.name).emit("stop");
 		try {
 			this._bundleContext.instanceStop(this);
 		} catch( e) {
@@ -117,20 +117,25 @@ class BundleContext /*extends XEventEmitter*/ {
 		this.info.state = 0;
 	}
 
-	emit(name,...args) {
-		return this.events.emit(this.name + ":" +name,...args);
-	}
-
 	channel(name) {
 		return this.events.channel(name);
 	}
+	/*emit(name,...args) {
+		return this.events.emit(this.name + ":" +name,...args);
+	}
+	propagate(name,nameto,...args) {
+		return this.events.propagate(this.name + ":" + name, this.name + ":" + nameto,...args);
+	}
+
 	on(name,cb) {
 		// Only create events if does not exists, maybe with a getter
 		this.events.on(name,cb);
 		return this;
 	}
-
-
+	after(name,cb) { // Priorities
+		this.events.on(name,cb,1000);
+		return this;
+	}
 	// Watcher
 	watch(name,cb) {
 		this.events.watch(name,cb);
@@ -141,18 +146,9 @@ class BundleContext /*extends XEventEmitter*/ {
 	unset(name) {
 		this.events.unset(this.name + ":" + name);
 	}
+	*/
 
-	/*on(...args) {
-		var cb = args.pop();
-		var evtName = args.join(":");
-		this.manager.events.on(this,evtName ,cb);
-		return this;
-	}*/
-	after(name,cb) { // Priorities
-		this.events.on(name,cb,1000);
-		return this;
-	}
-	// Wrappers
+	// manager Wrappers
 	
 	/**
 	 * @param {array} args 
@@ -170,16 +166,6 @@ class BundleContext /*extends XEventEmitter*/ {
 		return this.manager.call(name,args);
 	}
 
-	/*
-	get(name) {
-		var ctx = this.manager.get(name);
-		if(ctx == null || ctx.info.state != 1) { 
-			// Early bail
-			return null;
-		}
-		return ctx.instance;
-	}*/
-
 	// Auto clear helpers
 	//
 	setInterval(cb,n) {

+ 0 - 15
lib/eventual/lib/context-flat-map/channel.js

@@ -1,15 +0,0 @@
-class Channel {
-	constructor(context,name) {
-		this.context = context;
-		this.name = name; // Full name
-	}
-	channel(name) {
-		return new Channel(this.context,this.name + ":" + name);
-	}
-	on(name,cb,order) {
-		this.context.on(this.name + ":" + name,cb,order);
-		return this;
-	}
-}
-
-module.exports = Channel;

+ 53 - 0
lib/eventual/lib/context/channel.js

@@ -0,0 +1,53 @@
+
+const chs = "/"; // Channel separator
+
+
+class Channel {
+	constructor(context,name) {
+		this.context = context;
+		this._name = name; // Full name
+	}
+	name(name) {
+		if(name == undefined) return this._name;
+		return this._name + chs + name;
+	}
+	channel(...names) { // Sub channel
+		var name = names.join("/");
+		return new Channel(this.context,this.name(name));
+	}
+	on(sname,callback,order) {
+		var name = this.name(sname);
+		var listener = this.context.get(name,true);
+		listener.callbacks.push({name,callback,order});
+		//this.context.on(this.name(name),cb,order);
+		
+		return this;
+	}
+	after(name,cb) {
+		this.on(this.name(name),cb,1000);
+		return this;
+	}
+	emit(name,...args){
+		return this.context.eventual.emit(this.name(name),...args);
+	}
+	propagate(name,...args) {
+		// special case
+		return this.context.eventual.propagate(this.name(name),this._name,...args);
+	}
+	set(name,value) {
+		this.context.eventual.set(this.name(name),value);
+		return this;
+	}
+	watch(sname,callback) {
+		var name = this.name(sname);
+		if(this.context.watchers[name]== undefined) this.context.watchers[name]= [];
+		this.context.watchers[name].push(callback);
+		callback(this.context.eventual._events.store[name]);
+
+		//this.context.watch(this.name + ":" + name,cb);
+	}
+
+
+}
+
+module.exports = Channel;

+ 1 - 22
lib/eventual/lib/context-flat-map/context.js

@@ -1,6 +1,5 @@
 var Channel = require("./channel");
 
-const chs = ":"; // Channel separator
 
 class EventualContext {
 
@@ -23,6 +22,7 @@ class EventualContext {
 			this.listeners[name]= o;
 			return o;
 		}
+		// Should return copy
 		return this.listeners[name];
 
 		/*var nodes = name.split(chs);
@@ -45,27 +45,6 @@ class EventualContext {
 	getWatchers(name) {
 		return this.watchers[name] || [];
 	}
-		on(name,callback,order = 0) {
-		var listener = this.get(name,true);
-		listener.callbacks.push({name,callback:callback,order});
-	}
-	emit(name,...args) {
-		return this.eventual.emit(name,...args);
-	}
-	// Watcher features
-	watch(name,callback) {
-		if(this.watchers[name]== undefined) this.watchers[name]= [];
-		this.watchers[name].push(callback);
-
-		callback(this.eventual._events.store[name]);
-	}
-	set(name,value) {
-		this.eventual.set(name,value);
-	}
-	unset(name) {
-		this.eventual.unset(name);
-	}
-
 }
 
 module.exports = EventualContext;

lib/eventual/lib/context-flat-map/index.js → lib/eventual/lib/context/index.js


+ 6 - 3
lib/eventual/lib/event-param.js

@@ -2,14 +2,17 @@
 class Event {
 	constructor(donecb,args) {
 		this.count = 0;
-		this.dowait = 0;
-		
+		this._dowait = 0;
+		this._dostop = 0;
 		this.done= donecb; // Callback
 		this.errors = [];
 		this.params = args;
 	}
 	wait() {
-		this.dowait = 1;
+		this._dowait = 1;
+	}
+	stop() {
+		this._dostop = 1;
 	}
 }
 

+ 48 - 24
lib/eventual/lib/eventual.js

@@ -2,7 +2,7 @@
  * Substitute for xeventx
  * */
 
-const EventualContext = require('./context-flat-map');
+const EventualContext = require('./context');
 const EventParam = require('./event-param');
 
 class Eventual {
@@ -12,6 +12,14 @@ class Eventual {
 			store: {}
 		};
 	}
+	createContext() {
+		var ret = new EventualContext(this);
+		this._events.ctx.add(ret);
+		return ret;
+	}
+	destroyContext(ctx) {
+		this._events.ctx.delete(ctx);
+	}
 
 	set(name,value) {
 		if(value == undefined) {
@@ -34,15 +42,40 @@ class Eventual {
 	unset(name) {
 		this.set(name,undefined);
 	}
+
 	emit(name,...args) {
 		// Special send to all eventual contexts
+		var tocall = this.callbacks(name);
+
+		return this.process(tocall,args)
+	}
+	propagate(name,nameto,...args) {
+		var nparts = name.split("/");
+		var tocall = [];
+
+		var sname = name;
+		while(nparts.length && sname != nameto)  {
+			var localCall = this.callbacks(sname);
+			console.log("Found: " + localCall.length + " in : " + sname);
+			// Limitation on argument size
+			tocall.push(...localCall);
+			nparts.pop();
+			sname = nparts.join("/");
+		}
+		var localCall = this.callbacks(sname);
+		console.log("Found: " + tocall.length + " in : " + sname);
+		tocall.push(...localCall);
+		return this.process(tocall,args);	
+	}
+
+
+	callbacks(name) {
 		var tocall = [];		
 		this._events.ctx.forEach((c) => {
 			var callbacks = c.getCallbacks(name);
-			//tocall.push(...callbacks); // Oh too many will break
 			callbacks.forEach((l) => { tocall.push(l); });
 		});
-		return this.process(tocall,args)
+		return tocall;
 	}
 
 	processsimple(tocall,nargs) {
@@ -53,14 +86,14 @@ class Eventual {
 	// process should be handled here
 	process(tocall,nargs) {
 		var args = nargs || [];	 // or empty
-		var evt = new EventParam(next,args);
+		var evt = new EventParam(next,args); // Travel between events
+		
 		var callback,dotrigger = 0;
-		//Inner trigger	
-		// Finish	
 		function triggerDone() {
 			if(callback) callback(evt);
 			dotrigger = 1;
 		}
+
 		var ret = {
 			done: function(cb) {
 				if(dotrigger) { cb(evt); }
@@ -74,7 +107,8 @@ class Eventual {
 		var iter = tocall[Symbol.iterator]();
 		
 		function next() {
-			process.nextTick(() => chain(iter));
+			// prevent stack overflowing by defering function
+			process.nextTick(() => chain(iter))
 		}
 
 		// Internal thing
@@ -92,35 +126,25 @@ class Eventual {
 				evt.args = args;
 				evt.name = entry.name;
 				entry.callback(...args,evt);
+
+				if(evt._dostop == 1) {
+					triggerDone();
+					return;	
+				}
 				evt.count++;
 			}catch(e) {
 				console.log(e);
 				evt.errors.push(e);
 				// Should we stop??
 			}
-			if(!evt.dowait) next();
-			evt.dowait=0; // reset wait?
+			if(!evt._dowait) next();
+			evt._dowait=0; // reset wait?
 		}
 		next();
 
 		return ret;
 	}
 
-
-	createContext() {
-		var ret = new EventualContext(this);
-		this._events.ctx.add(ret);
-		return ret;
-	}
-	destroyContext(ctx) {
-		this._events.ctx.delete(ctx);
-	}
-	state(name,args) {
-		// Should do this per context
-		this._events.state[name] = args;
-	}
-
-
 	
 }
 

+ 30 - 0
test/eventual-test/propagation.js

@@ -0,0 +1,30 @@
+var Eventual = require('../../lib/eventual');
+
+var events = new Eventual();
+
+var ctx = events.createContext();
+
+
+ctx.on('hello:from:the',(e) => {
+	e.wait();
+	console.log("Will be done in a sec");
+	setTimeout(() => {
+		console.log("Continue");
+		e.done();
+	},1000);
+});
+
+ctx.on('hello:from',(e) => {
+	console.log("The other side");
+	e.stop();
+});
+
+
+ctx.on('hello',(e) => {
+	console.log("Worked");
+});
+
+ctx.propagate('hello:from:the:other:side')
+	 .done(() => {
+			console.log("Events called");
+	 });

+ 9 - 8
test/hci-usecase/bundles/hci-http-monitor/index.js

@@ -4,6 +4,7 @@ var mime = require('mime-types'),
 
 var log = require('hlogger').createLogger('hci-http-test');
 
+
 function loadControllers() {
 	var targetPath = __dirname + "/controllers";
 	var files = fs.readdirSync(targetPath);
@@ -20,15 +21,14 @@ function loadControllers() {
 
 function bundleStart(context) {
 	var controllers = loadControllers();
-
-	context.on('hci-http:stop',() => {
-		console.log("Stopping http monitor");
-		context.stop();
-	});
-
 	var channel = context
-		.channel('hci-http')
-		.on('req',(req,res,e) => {
+		.channel('core-http')
+		.on('stop',()=> {
+			console.log("Stopping http monitor");
+			context.stop();
+		})
+		.on('GET/monitor/api',(req,res,e) => {
+			e.stop();
 			// Manual router
 			var re = new RegExp("/monitor/api/(.*)");
 			var match = req.url.match(re);
@@ -36,6 +36,7 @@ function bundleStart(context) {
 				api(match,req,res,e);
 				return;
 			}
+		}).on('GET/monitor', (req,res,e) => {
 			re = new RegExp("/monitor/?(.*)");
 			match =	req.url.match(re);
 			if(match!=null) {

+ 9 - 8
test/hci-usecase/bundles/shell-test/index.js

@@ -6,14 +6,15 @@ function bundleStart(context) {
 	log.info("Command provider installed");
 
 	// Create a bash and transport commands
-	context.after('core-shell:cmd',(req,res,e) => {
-		e.wait();	
-		var shcmd = req.cmd + " " + req.args.join(" ");
-		var proc = child.exec(shcmd);
-		res.write("\n");
-		proc.stdout.pipe(res);
-		proc.stderr.pipe(process.stderr);
-		proc.on('close',function() {
+	context.channel('core-shell')
+		.after('cmd',(req,res,e) => {
+			e.wait();	
+			var shcmd = req.cmd + " " + req.args.join(" ");
+			var proc = child.exec(shcmd);
+			res.write("\n");
+			proc.stdout.pipe(res);
+			proc.stderr.pipe(process.stderr);
+			proc.on('close',function() {
 			e.done();
 		});			
 	});

+ 4 - 3
test/hci-usecase/bundles/stress-test/http-test/index.js

@@ -1,9 +1,10 @@
 
 var activator = {
 	start(context) {
-		context.on('hci-http:req:/test',(req,res) => {
-			res.end('Hello word');
-		});
+		context.channel('core-http')
+			.on('hci-http:req:/test',(req,res) => {
+				res.end('Hello word');
+			});
 	}
 }
 

+ 27 - 25
test/hci-usecase/bundles/stress-test/index.js

@@ -18,39 +18,41 @@ module.exports.bundleActivator = {
 	start(context) {
 		context.manager.load(__dirname + "/http-test");
 		this.context = context;
-		context.channel('core-shell:cmd')
-				.on('test',(req,res,e) => {
-					var cmds = ["events","cpu","mem","ping","siege"]; 
-					var [subcmd,...args] = req.args;
-					if(cmds.indexOf(subcmd) == -1) {
-						res.write("Wrong\n");	
-						res.write("Available tests:" + cmds + "\n");
-						return;
-					};
-
-					this[subcmd](req,res,e);
-				});
+		context
+			.channel('core-shell').channel('cmd')
+			.on('test',(req,res,e) => {
+				var cmds = ["events","cpu","mem","ping","siege"]; 
+				var [subcmd,...args] = req.args;
+				if(cmds.indexOf(subcmd) == -1) {
+					res.write("Wrong\n");	
+					res.write("Available tests:" + cmds + "\n");
+					return;
+				};
+
+				this[subcmd](req,res,e);
+			});
 
 		var lastPing; 
-		context.on('stress-test:ping',(e) => {
-			lastPing = process.hrtime();
-			context.emit('pong')
-			e.done();
-		});
-		context.on('stress-test:pong',(e) => {
-			var now = hrToStr(process.hrtime(lastPing));
-			console.log("Time taken to poing: " + now);
-		});
+
+		var lchannel = context.channel('stress-test');
+		lchannel
+			.on('ping',(e) => {
+				lastPing = process.hrtime();
+				lchannel.emit('pong')
+			})
+			.on('pong',(e) => {
+				var now = hrToStr(process.hrtime(lastPing));
+				console.log("Time taken to poing: " + now);
+			});
 	},
 	ping(req,res,e) {
-		e.wait();
-		this.context.emit('ping',e);
+		this.context.channel(this.context.name).emit('ping',e);
 	},
 	events(req,res,e) {
-		res.write("Adding 1 million events\n");
+		res.write("Adding 1 million listeners\n");
 		var count = 1000000; 
 		for(;count;count--) {
-			this.context.on('stress-test:'+Math.random().toString(36).substring(7) + ':test:event',() => { var arr = new Array(5);	});
+			this.context.channel('stress-test').on('stress-test:'+Math.random().toString(36).substring(7) + ':test:event',() => { var arr = new Array(5);	});
 		}
 	},