lib/tycho.js
function handleControlConnection(connection) {
		connection.on('data', function (data) {
			console.log('Got command:', data.toString().trim());
			var request = data.toString().trim().split(' '),
				cmd = request[0],
				target = request[1],
				newline = '\r\n',
				response;
			console.log('Command is:', cmd);
			switch (cmd) {
				case 'start':
					console.log('got here');
					self.store.broadcast('worker:start', target);
					response = lib.format('Starting {0} servers.', (target || 'all'));
					break;
				case 'pause':
					self.store.broadcast('worker:pause', target);
					response = lib.format('Pausing {0} servers.', (target || 'all'));
					break;
				case 'stop':
					self.store.broadcast('worker:stop', target);
					response = lib.format('Stopping {0} servers.', (target || 'all'));
					break;
				case 'resume':
					self.store.broadcast('worker:resume', target);
					response = lib.format('Resuming {0} servers.', (target || 'all'));
					break;
				case 'heartbeat':
					var id = lib.guid();
					self.store.broadcast('worker:heartbeat', id);
					wait(id, function () {
						var args = Array.prototype.slice.call(arguments),
							response = {};
						lib.each(args, function (data) {
							var message = data[0],
								worker = data[1];
							response[worker] = message;
						});
						connection.write(JSON.stringify(response));
						connection.end(newline);
					});
					break;
				case 'stats':
					var id = lib.guid();
					self.store.broadcast('worker:stats', id);
					wait(id, function () {
						var args = Array.prototype.slice.call(arguments),
							response = {};
						lib.each(args, function (data) {
							var message = data[0],
								worker = data[1];
							response[worker] = message;
						});
						connection.write(JSON.stringify(response));
						connection.end(newline);
					});
					break;
				default:
					response = lib.format('Unknown command: {0}.', cmd);
					break;
			}
			if (response) {
				connection.write(response);
				connection.end(newline);
			}
		});
	}
function handleControlConnection(connection) {
		connection.on('data', function (data) {
			console.log('Got command:', data.toString().trim());
			var request = data.toString().trim().split(' '),
				cmd = request[0],
				target = request[1],
				newline = '\r\n',
				response;
			console.log('Command is:', cmd);
			switch (cmd) {
				case 'start':
					console.log('got here');
					self.store.broadcast('worker:start', target);
					response = lib.format('Starting {0} servers.', (target || 'all'));
					break;
				case 'pause':
					self.store.broadcast('worker:pause', target);
					response = lib.format('Pausing {0} servers.', (target || 'all'));
					break;
				case 'stop':
					self.store.broadcast('worker:stop', target);
					response = lib.format('Stopping {0} servers.', (target || 'all'));
					break;
				case 'resume':
					self.store.broadcast('worker:resume', target);
					response = lib.format('Resuming {0} servers.', (target || 'all'));
					break;
				case 'heartbeat':
					var id = lib.guid();
					self.store.broadcast('worker:heartbeat', id);
					wait(id, function () {
						var args = Array.prototype.slice.call(arguments),
							response = {};
						lib.each(args, function (data) {
							var message = data[0],
								worker = data[1];
							response[worker] = message;
						});
						connection.write(JSON.stringify(response));
						connection.end(newline);
					});
					break;
				case 'stats':
					var id = lib.guid();
					self.store.broadcast('worker:stats', id);
					wait(id, function () {
						var args = Array.prototype.slice.call(arguments),
							response = {};
						lib.each(args, function (data) {
							var message = data[0],
								worker = data[1];
							response[worker] = message;
						});
						connection.write(JSON.stringify(response));
						connection.end(newline);
					});
					break;
				default:
					response = lib.format('Unknown command: {0}.', cmd);
					break;
			}
			if (response) {
				connection.write(response);
				connection.end(newline);
			}
		});
	}
function handleControlConnection ( connection ) { connection . on ( 'data' , function ( data ) { console . log ( 'Got command:' , data . toString ( ) . trim ( ) ) ; var request = data . toString ( ) . trim ( ) . split ( ' ' ) , cmd = request [ 0 ] , target = request [ 1 ] , newline = '\r\n' , response ; console . log ( 'Command is:' , cmd ) ; switch ( cmd ) { case 'start' : console . log ( 'got here' ) ; self . store . broadcast ( 'worker:start' , target ) ; response = lib . format ( 'Starting {0} servers.' , ( target || 'all' ) ) ; break ; case 'pause' : self . store . broadcast ( 'worker:pause' , target ) ; response = lib . format ( 'Pausing {0} servers.' , ( target || 'all' ) ) ; break ; case 'stop' : self . store . broadcast ( 'worker:stop' , target ) ; response = lib . format ( 'Stopping {0} servers.' , ( target || 'all' ) ) ; break ; case 'resume' : self . store . broadcast ( 'worker:resume' , target ) ; response = lib . format ( 'Resuming {0} servers.' , ( target || 'all' ) ) ; break ; case 'heartbeat' : var id = lib . guid ( ) ; self . store . broadcast ( 'worker:heartbeat' , id ) ; wait ( id , function ( ) { var args = Array . prototype . slice . call ( arguments ) , response = { } ; lib . each ( args , function ( data ) { var message = data [ 0 ] , worker = data [ 1 ] ; response [ worker ] = message ; } ) ; connection . write ( JSON . stringify ( response ) ) ; connection . end ( newline ) ; } ) ; break ; case 'stats' : var id = lib . guid ( ) ; self . store . broadcast ( 'worker:stats' , id ) ; wait ( id , function ( ) { var args = Array . prototype . slice . call ( arguments ) , response = { } ; lib . each ( args , function ( data ) { var message = data [ 0 ] , worker = data [ 1 ] ; response [ worker ] = message ; } ) ; connection . write ( JSON . stringify ( response ) ) ; connection . end ( newline ) ; } ) ; break ; default : response = lib . format ( 'Unknown command: {0}.' , cmd ) ; break ; } if ( response ) { connection . write ( response ) ; connection . end ( newline ) ; } } ) ; }
Handler for new connections to the control server
Also defines the valid commands that can be issued to workers
Handler for new connections to the control server Also defines the valid commands that can be issued to workers