New fly support clusters
This commit is contained in:
parent
ca6a88798a
commit
719f87c558
69
Dragonfly.js
69
Dragonfly.js
@ -1,4 +1,4 @@
|
|||||||
var util = require('util');
|
var util = require( "util" );
|
||||||
|
|
||||||
/*{{{ Private methods */
|
/*{{{ Private methods */
|
||||||
// Months
|
// Months
|
||||||
@ -22,28 +22,11 @@ function logDate( date )
|
|||||||
}
|
}
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
// Logger
|
// Logger
|
||||||
function Dragonfly()
|
function Dragonfly( logHandler )
|
||||||
{
|
{
|
||||||
// Static properties
|
this.currentSphere = Dragonfly.defaultSphere;
|
||||||
Dragonfly.currentSphere = 10;
|
this.Visibility = Dragonfly.Visibility;
|
||||||
|
this.Spheres = Dragonfly.Spheres;
|
||||||
Dragonfly.Spheres = {
|
|
||||||
// Debug
|
|
||||||
THERMO: 30
|
|
||||||
// Inspect
|
|
||||||
, STRATO: 20
|
|
||||||
// Production
|
|
||||||
, HYDRO: 10
|
|
||||||
, LITHO: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
Dragonfly.Visibility = {
|
|
||||||
VISIBLE: 9
|
|
||||||
, VH8: 8, VH7: 7, VH6: 6
|
|
||||||
, HIDDEN: 5
|
|
||||||
, HU4: 4, HU3: 3, HU2: 2
|
|
||||||
, UNSEEN: 1
|
|
||||||
};
|
|
||||||
|
|
||||||
// Bind prototype functions
|
// Bind prototype functions
|
||||||
for( var i in Dragonfly.prototype )
|
for( var i in Dragonfly.prototype )
|
||||||
@ -51,6 +34,23 @@ function Dragonfly()
|
|||||||
Dragonfly[i] = this[i].bind( this );
|
Dragonfly[i] = this[i].bind( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cluster = require( "cluster" );
|
||||||
|
if( cluster.isMaster )
|
||||||
|
{
|
||||||
|
this.logHandler = logHandler || { write: console.log };
|
||||||
|
this.messageBus = function( msg )
|
||||||
|
{
|
||||||
|
if( msg.cmd == "dragonLog" )
|
||||||
|
{
|
||||||
|
this.logHandler.write( msg.data );
|
||||||
|
}
|
||||||
|
}.bind( this );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.logHandler = { write: function( e ) { process.send({ cmd: "dragonLog", data: e }); } };
|
||||||
|
}
|
||||||
|
|
||||||
var cluster = require("cluster");
|
var cluster = require("cluster");
|
||||||
this.ptag = "[ " + ( cluster.isMaster ? "M" : "S" ) + ":" + process.pid + " ] ";
|
this.ptag = "[ " + ( cluster.isMaster ? "M" : "S" ) + ":" + process.pid + " ] ";
|
||||||
|
|
||||||
@ -117,9 +117,28 @@ Dragonfly.prototype.writeLine = function ()
|
|||||||
|
|
||||||
Dragonfly.prototype.__log = function ( line )
|
Dragonfly.prototype.__log = function ( line )
|
||||||
{
|
{
|
||||||
console.log( this.ptag + logDate( new Date() ) + line );
|
this.logHandler.write( this.ptag + logDate( new Date() ) + util.format( line ) + "\n" );
|
||||||
};
|
};
|
||||||
|
|
||||||
new Dragonfly();
|
// Static properties
|
||||||
|
Dragonfly.defaultSphere = 10;
|
||||||
|
|
||||||
global.Dragonfly = Dragonfly;
|
Dragonfly.Spheres = {
|
||||||
|
// Debug
|
||||||
|
THERMO: 30
|
||||||
|
// Inspect
|
||||||
|
, STRATO: 20
|
||||||
|
// Production
|
||||||
|
, HYDRO: 10
|
||||||
|
, LITHO: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
Dragonfly.Visibility = {
|
||||||
|
VISIBLE: 9
|
||||||
|
, VH8: 8, VH7: 7, VH6: 6
|
||||||
|
, HIDDEN: 5
|
||||||
|
, HU4: 4, HU3: 3, HU2: 2
|
||||||
|
, UNSEEN: 1
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Dragonfly;
|
||||||
|
Loading…
Reference in New Issue
Block a user