Permalink
Browse files

V037

  • Loading branch information...
1 parent 839789c commit efedcf30dbc5f7e4731b0ab5c8d37516f25b7808 @mrohad committed Aug 29, 2010
Showing with 144 additions and 76 deletions.
  1. +17 −0 .project
  2. BIN AlligatorV037.tar.gz
  3. +1 −0 ChangeLog
  4. +5 −5 lib/application.js
  5. +4 −4 lib/asemaphore.js
  6. +44 −41 lib/engine.js
  7. +22 −16 lib/log.js
  8. +9 −9 lib/session.js
  9. +36 −0 lib/utils.js
  10. +6 −1 settings.json
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Alligator</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
+ </natures>
+</projectDescription>
View
Binary file not shown.
View
@@ -5,6 +5,7 @@ Features:
2) ability to write code outside the page() function using the <?!code?> tag
3) add examples to README
4) commands has been change to context
+5) improvements to the logs module.
Change LOG 0.35
View
@@ -11,9 +11,9 @@ var applicationScope = function(webAppName,mcOptions){
applicationScope.prototype.get = function(seprator,key,cb){
if(this.mcOptions.enable){
var connection = new Memcache(this.mcOptions.server, this.mcOptions.port);
- log.debug("connectin memcache for get key("+seprator+this.webAppName+key+")");
+ log.debug("Application","connectin memcache for get key("+seprator+this.webAppName+key+")");
connection.get(seprator+this.webAppName+key, function(response) {
- log.debug("Memecahe GET results("+response.success+") - "+response.data);
+ log.debug("Application","Memecahe GET results("+response.success+") - "+response.data);
if (cb){
if(response.success)
try{
@@ -34,7 +34,7 @@ applicationScope.prototype.get = function(seprator,key,cb){
applicationScope.prototype.set = function(seprator,key,value,cb){
if(this.mcOptions.enable){
var connection = new Memcache(this.mcOptions.server, this.mcOptions.port);
- log.debug("connectin memcache for get key("+seprator+this.webAppName+key+")");
+ log.debug("Application","connectin memcache for get key("+seprator+this.webAppName+key+")");
connection.set(seprator+this.webAppName+key, JSON.stringify(value), {expires:0,flags:0,callback: function () {
if (cb) cb();
}});
@@ -47,7 +47,7 @@ applicationScope.prototype.set = function(seprator,key,value,cb){
applicationScope.prototype.remove = function(seprator,key,cb){
if(this.mcOptions.enable){
var connection = new Memcache(this.mcOptions.server, this.mcOptions.port);
- log.debug("connectin memcache for get "+this.mcOptions.server+" " +this.mcOptions.port);
+ log.debug("Application","connectin memcache for get "+this.mcOptions.server+" " +this.mcOptions.port);
connection.del(seprator+this.webAppName+key, {callback: function () {
if (cb) cb();
}});
@@ -58,7 +58,7 @@ applicationScope.prototype.remove = function(seprator,key,cb){
var instance = undefined;
exports.start = function(webAppName,mcOptions){
- log.info("Starting application scope for "+webAppName+" memcahecOptions - "+mcOptions);
+ log.info("Application","Starting application scope for "+webAppName+" memcahecOptions - "+mcOptions);
if(instance == undefined)
instance = new applicationScope(webAppName,mcOptions);
return instance;
View
@@ -4,21 +4,21 @@ var log = require('./log');
var ASemaphore = function(semaphore,fireFunc){
this.semaphore = (semaphore==undefined?0:semaphore);
this.fire = fireFunc;
- //log.debug("Starting Asemaphore with semaphore:" +this.semaphore);
+ log.debug("ASemaphore","Starting Asemaphore with semaphore:" +this.semaphore);
};
ASemaphore.prototype.v = function(){
++this.semaphore;
- //log.debug("Asemaphore semaphore after v(): " +this.semaphore);
+ log.debug("ASemaphore","Asemaphore semaphore after v(): " +this.semaphore);
return this.semaphore;
};
ASemaphore.prototype.p = function(){
if((--this.semaphore)<1){
- //log.debug("Asemaphore fire() after p()");
+ log.debug("ASemaphore","Asemaphore fire() after p()");
this.fire.apply(this,arguments);
}
- //log.debug("Asemaphore counter after p(): " +this.counter);
+ log.debug("ASemaphore","Asemaphore counter after p(): " +this.counter);
return this.counter;
};
View
@@ -17,13 +17,13 @@ var cachedJssp = [];
var pageObjCache = new Object();
pageObjCache.get = function(key){
var val = pageObjCache[key];
- //log.debug("===CACHE-GET by key - "+key);
+ //log.debug("Engine","===CACHE-GET by key - "+key);
//if(val != undefined)
- // log.debug("val.page - "+val.page.toString());
+ // log.debug("Engine","val.page - "+val.page.toString());
return val;
};
pageObjCache.set = function(key,val){
- //log.debug("===CACHE-SET by key - "+key + " val.page - " + val.page.toString());
+ //log.debug("Engine","===CACHE-SET by key - "+key + " val.page - " + val.page.toString());
pageObjCache[key] = val;
};
@@ -34,11 +34,14 @@ var sessionScope;
exports.start = function(settings) {
globalSettings = defaultSettings(settings);
- if(globalSettings.debug_mode)
- log.level = log.levels.DEBUG;
- else
- log.level = log.levels.WARN;
- log.info("Starting Web App - " +globalSettings.web_app_name);
+ var logObj = globalSettings.logs;
+ for (property in logObj)
+ log.setLevel(property,logObj[property]);
+// if(globalSettings.debug_mode)
+// log.level = log.levels.DEBUG;
+// else
+// log.level = log.levels.WARN;
+ log.info("Engine","Starting Web App - " +globalSettings.web_app_name);
//setting up sessionScope and applicationScope:
applicationScope = applicationManager.start(globalSettings.web_app_name,globalSettings.server_script.memcached);
sessionScope = sessionManager.start(globalSettings.server_script.session_minutes,globalSettings.web_app_name);
@@ -47,9 +50,9 @@ exports.start = function(settings) {
if(globalSettings.path.lib != undefined)
fs.stat(globalSettings.path.lib, function (err, stats) {
if (err)
- log.error("Loading lib error:"+err);
+ log.error("Engine","Loading lib error:"+err);
else if(!stats.isDirectory())
- log.error("Loading lib error: path must be a directory");
+ log.error("Engine","Loading lib error: path must be a directory");
else{
var files = fs.readdirSync(globalSettings.path.lib);
for(i=0;i<files.length;i++){
@@ -58,14 +61,14 @@ exports.start = function(settings) {
var fileNoJs = file.substring(0,files[i].length-3);
var path = pathlib.join(globalSettings.path.lib,fileNoJs);
eval("lib."+fileNoJs+" = require(path)");
- log.info("Loading lib file:" + path);
+ log.info("Engine","Loading lib file:" + path);
}
}
}
});
//END util loading
var server = http.createServer(function (req, res) {
- log.debug("request arrived!");
+ log.debug("Engine","request arrived!");
var url = uri.parse(req.url,true);
var pathname = (url.pathname || '/');
var cleanPathname = pathname
@@ -80,7 +83,7 @@ exports.start = function(settings) {
}
else if (req.method == "POST"){
incomingForm.parse(req, function(err, fields, files) {
- //log.debug("POST fields:" + utils.arrayToString(fields));
+ //log.debug("Engine","POST fields:" + utils.arrayToString(fields));
params = new Object();
req.parameters = fields;
handleRequest(req,res,cleanPathname);
@@ -96,17 +99,17 @@ exports.start = function(settings) {
nodes: globalSettings.nodes
}, server);
- log.warn('Server running at port '+globalSettings.port);
+ log.warn("Engine",'Server running at port '+globalSettings.port);
};
function handleRequest(req,res,cleanPathname,newSessionId){
var root = globalSettings.path.root;
var path = pathlib.join(root, cleanPathname);
if(newSessionId==undefined)
- log.info("Handling request to: " +path + " pid("+process.pid+")");
+ log.info("Engine","Handling request to: " +path + " pid("+process.pid+")");
else
- log.info("Forwarding request to: " +path + " pid("+process.pid+")");
- //log.debug("Request headers: "+utils.arrayToString(req.headers));
+ log.info("Engine","Forwarding request to: " +path + " pid("+process.pid+")");
+ //log.debug("Engine","Request headers: "+utils.arrayToString(req.headers));
fs.stat(path, function (err, stats) {
if (err) {
// ENOENT is normal on 'file not found'
@@ -129,27 +132,27 @@ function handleRequest(req,res,cleanPathname,newSessionId){
sessionScope.hello(sessionId);
}
if(!(path.endsWith("."+globalSettings.server_script.template_ext) || path.endsWith("."+globalSettings.server_script.script_ext))){
- log.info("Static request");
+ log.info("Engine","Static request");
sendHeaders(req, res,undefined, stats.size, mime.mimeType(path), stats.mtime);
var readStream = fs.createReadStream(path);
sys.pump(readStream,res);
}else{
- log.info("Dyanmic request");
+ log.info("Engine","Dyanmic request");
if(path.endsWith("."+globalSettings.server_script.template_ext) && (cachedJssp[path] == undefined || cachedJssp[path+"#date"] != stats.mtime.toUTCString())){
var readStream = fs.createReadStream(path);
var script = [];
readStream.addListener("data", function (chunk) {
script.push(chunk.toString());
});
readStream.addListener("end", function () {
- log.info("STARTING PROCESSING JSSP");
+ log.info("Engine","STARTING PROCESSING JSSP");
SSJSWriter(script.join(""),req,res,path,stats.mtime,sessionId);
- log.info("END OF JSSP PROCESSING");
+ log.info("Engine","END OF JSSP PROCESSING");
});
req.connection.addListener('timeout', function() {
/* dont destroy it when the fd's already closed */
if (readStream.readable) {
- log.debug('timed out. destroying file read stream');
+ log.debug("Engine",'timed out. destroying file read stream');
readStream.destroy();
}
});
@@ -158,7 +161,7 @@ function handleRequest(req,res,cleanPathname,newSessionId){
readStream.destroy();
});
readStream.addListener('fd', function(fd) {
- log.debug("opened",path,"on fd",fd);
+ log.debug("Engine","opened",path,"on fd",fd);
});
readStream.addListener('error', function (err) {
@@ -168,7 +171,7 @@ function handleRequest(req,res,cleanPathname,newSessionId){
}
else{
- log.info("RUN JSSP FROM CACHE");
+ log.info("Engine","RUN JSSP FROM CACHE");
var currentFileNameToRead = cachedJssp[path];
if(path.endsWith("."+globalSettings.server_script.script_ext))
currentFileNameToRead = path.substring(0,path.length-globalSettings.server_script.script_ext.length-1);;
@@ -192,7 +195,7 @@ function serverSideRunning(newfileName,request,response,file,lastMod,sessionId,i
responseHead.status = 200;
responseHead.headers = {};
var afterEval = [];
- //log.debug(asemaphore);
+ //log.debug("Engine",asemaphore);
var currentAsemaphore = asemaphore.ctor(1,function(){
if(!error)
result.html = afterEval.join("");
@@ -221,7 +224,7 @@ function serverSideRunning(newfileName,request,response,file,lastMod,sessionId,i
lib:lib,
log:log,
write : function(text){
- //log.debug("WRITE afterEval : "+ afterEval);
+ //log.debug("Engine","WRITE afterEval : "+ afterEval);
afterEval.push(text);
},
writeEscapedText :function(text){
@@ -237,25 +240,25 @@ function serverSideRunning(newfileName,request,response,file,lastMod,sessionId,i
}
};
//=============================================
- //log.debug(typeof functoRun.page);
- log.debug("READING pageObject from cache, key - "+file );
+ //log.debug("Engine",typeof functoRun.page);
+ log.debug("Engine","READING pageObject from cache, key - "+file );
var pageObjFromCache = pageObjCache.get(file);
if(pageObjFromCache == undefined || isForceEval){//not in cache
- log.debug("....and....cache is EMPTY for key - "+file);
+ log.debug("Engine","....and....cache is EMPTY for key - "+file);
var pageObjFunc = new Function(functoRun.toString() + " ; return this;");
pageObjFromCache = new pageObjFunc(context);
pageObjCache.set(file,pageObjFromCache);
}
else
- log.debug("....and....cache is FULL for key - "+file);
+ log.debug("Engine","....and....cache is FULL for key - "+file);
if(request.parameters.serverFunction == undefined){
pageObjFromCache.page(context);
}else{//Server command
serverFunction = request.parameters.serverFunction;
pageObjFromCache[serverFunction](context);
}
currentAsemaphore.p();
- //log.debug("sessionId - "+result.sessionId);
+ //log.debug("Engine","sessionId - "+result.sessionId);
}catch(err){
log.error("parse problem:"+err+" stack:"+err.stack);
flushResponse = true;
@@ -274,11 +277,11 @@ function serverSideRunning(newfileName,request,response,file,lastMod,sessionId,i
};
if(cachedJssp[file]!= undefined && !isForceEval){//funcCaching
- log.debug("SSJS RUN: bring file from CACHE: "+file);
+ log.debug("Engine","SSJS RUN: bring file from CACHE: "+file);
executeTheSJSFile(undefined,undefined);
}else{
var fileNameToRead = [newfileName,".",globalSettings.server_script.script_ext].join("");
- log.debug("SSJS RUN: reading file from FS: "+fileNameToRead);
+ log.debug("Engine","SSJS RUN: reading file from FS: "+fileNameToRead);
fs.readFile(fileNameToRead,executeTheSJSFile);
}
}
@@ -348,17 +351,17 @@ function SSJSWriter(str,request,response,file,lastMod,sessionId){
var finalFunction = ["this.page = function (context){",parsedTextArray.join(""),"};",externalParsedTextArray.join("")].join("");
var newfileName = file.substring(0,file.length-globalSettings.server_script.template_ext.length-1);
fs.writeFile([newfileName,".",globalSettings.server_script.script_ext].join(""), finalFunction, function (err) {
- //log.debug("Error writin cache file: "+err);
+ //log.debug("Engine","Error writin cache file: "+err);
cachedJssp[file] = newfileName;
cachedJssp[file + "#date"] = lastMod.toUTCString();
- log.info("Caching - "+file + ",last mod - "+ lastMod.toUTCString());
+ log.info("Engine","Caching - "+file + ",last mod - "+ lastMod.toUTCString());
serverSideRunning(newfileName,request,response,file,lastMod,sessionId,true);
});
}
function sendHeaders(req, res,responseHead, length, content_type, modified_time,sessionId) {
- //log.debug("send headers: sessionId - "+sessionId);
+ //log.debug("Engine","send headers: sessionId - "+sessionId);
if(responseHead==undefined)
responseHead = new Object();
if(responseHead.status==undefined)
@@ -378,13 +381,13 @@ function sendHeaders(req, res,responseHead, length, content_type, modified_time,
responseHead.headers["Content-Type"] = content_type || "application/octet-stream";
if (modified_time)
responseHead.headers["Last-Modified"] = modified_time.toUTCString();
- //log.debug("RESPONSE Headers :"+utils.arrayToString(responseHead.headers)+" +++ RESPONSE Status :"+responseHead.status);
+ //log.debug("Engine","RESPONSE Headers :"+utils.arrayToString(responseHead.headers)+" +++ RESPONSE Status :"+responseHead.status);
res.writeHead(responseHead.status, responseHead.headers);
- log.info(req.connection.remoteAddress,req.method,responseHead.status,length);
+ log.info("Engine",req.connection.remoteAddress,req.method,responseHead.status,length);
}
function fileNotFound(req,res,path) {
- log.debug("404 opening path: '"+path+"'");
+ log.debug("Engine","404 opening path: '"+path+"'");
var body = "404: " + req.url + " not found.\n";
var responseHead= new Object();
responseHead.status = 404;
@@ -428,8 +431,8 @@ function defaultSettings(settings){
if(settings.server_script.memcached.port == undefined)
settings.server_script.memcached.port = 11211;
- if(settings.debug_mode == undefined)
- settings.debug_mode = 1;
+ if(settings.logs == undefined)
+ settings.logs = new Object();
if(settings.nodes == undefined)
settings.nodes = 1;
return settings;
Oops, something went wrong.

0 comments on commit efedcf3

Please sign in to comment.