Skip to content

Commit

Permalink
adding examples
Browse files Browse the repository at this point in the history
  • Loading branch information
evantahler committed Jan 25, 2012
1 parent c3bf8c8 commit f43601b
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 37 deletions.
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

4 changes: 1 addition & 3 deletions actionHero
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ params.configChanges = {
"password" : null,
"port" : "3306",
"consoleLogging" : false
},
"flatFileDirectory":"./public/"
}
}

// any additional functions you might wish to define to be globally accessable can be added as part of params.initFunction. The api object will be availalbe.
params.initFunction = function(api, next){
api.randomNumberGenerator = Math.random() * 100;
next();
}

Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Key" : "4ijhaijhm43yjnawhja43jaj",
"ReConnectToLostPeersMS" : 1000,
"CycleCheckTimeMS" : 100,
"RemoteTimeoutWaitMS" : 10000,
"remoteTimeoutWaitMS" : 10000,
"nodeDuplication" : 2,
"StartingPeer" : {
"host": null,
Expand Down
51 changes: 51 additions & 0 deletions examples/actionHero_cluster_peer_1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// load in the actionHero class
var actionHero = require(__dirname + "/../api.js").actionHero; // normally if installed by npm: var actionHero = require("actionHero").actionHero;

// if there is no config.js file in the application's root, then actionHero will load in a collection of default params. You can overwrite them with params.configChanges
var params = {};
params.configChanges = {

"webServerPort" : 8080,
"socketServerPort" : 5000,

"logFile" : "api_peer_1.log",

"actionCluster": {
"Key" : "4ijhaijhm43yjnawhja43jaj",
"ReConnectToLostPeersMS" : 1000,
"CycleCheckTimeMS" : 100,
"remoteTimeoutWaitMS" : 10000,
"nodeDuplication" : 2,
"StartingPeer" : {
"host": null,
"port": null
}
},

"database" : {
"type":"mySQL",
"host" : "127.0.0.1",
"database" : "action_hero_api",
"username" : "root",
"password" : null,
"port" : "3306",
"consoleLogging" : false
}
}

// any additional functions you might wish to define to be globally accessable can be added as part of params.initFunction. The api object will be availalbe.
params.initFunction = function(api, next){
api.showCacheData = function(api){
api.log("--------- CACHE --------");
api.log(JSON.stringify(api.cache.data));
setTimeout(api.showCacheData, 5000, api);
}
setTimeout(api.showCacheData, 5000, api);

next();
}

// start the server!
actionHero.start(params, function(api){
api.log("Boot Sucessful!");
});
20 changes: 12 additions & 8 deletions actionHero2 → examples/actionHero_cluster_peer_2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env node

// load in the actionHero class
var actionHero = require(__dirname + "/api.js").actionHero; // normally if installed by npm: var actionHero = require("actionHero").actionHero;
var actionHero = require(__dirname + "/../api.js").actionHero; // normally if installed by npm: var actionHero = require("actionHero").actionHero;

// if there is no config.js file in the application's root, then actionHero will load in a collection of default params. You can overwrite them with params.configChanges
var params = {};
Expand All @@ -10,13 +8,13 @@ params.configChanges = {
"webServerPort" : 8081,
"socketServerPort" : 5001,

"logFile" : "api2.log",
"logFile" : "api_peer_2.log",

"actionCluster": {
"Key" : "4ijhaijhm43yjnawhja43jaj",
"ReConnectToLostPeersMS" : 1000,
"CycleCheckTimeMS" : 100,
"RemoteTimeoutWaitMS" : 10000,
"remoteTimeoutWaitMS" : 10000,
"nodeDuplication" : 2,
"StartingPeer" : {
"host": "127.0.0.1",
Expand All @@ -32,16 +30,22 @@ params.configChanges = {
"password" : null,
"port" : "3306",
"consoleLogging" : false
},
"flatFileDirectory":"./public/"
}
}

// any additional functions you might wish to define to be globally accessable can be added as part of params.initFunction. The api object will be availalbe.
params.initFunction = function(api, next){
api.randomNumberGenerator = Math.random() * 100;
api.showCacheData = function(api){
api.log("--------- CACHE --------");
api.log(JSON.stringify(api.cache.data));
setTimeout(api.showCacheData, 5000, api);
}
setTimeout(api.showCacheData, 5000, api);

next();
}


// start the server!
actionHero.start(params, function(api){
api.log("Boot Sucessful!");
Expand Down
20 changes: 12 additions & 8 deletions actionHero3 → examples/actionHero_cluster_peer_3.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env node

// load in the actionHero class
var actionHero = require(__dirname + "/api.js").actionHero; // normally if installed by npm: var actionHero = require("actionHero").actionHero;
var actionHero = require(__dirname + "/../api.js").actionHero; // normally if installed by npm: var actionHero = require("actionHero").actionHero;

// if there is no config.js file in the application's root, then actionHero will load in a collection of default params. You can overwrite them with params.configChanges
var params = {};
Expand All @@ -10,13 +8,13 @@ params.configChanges = {
"webServerPort" : 8082,
"socketServerPort" : 5002,

"logFile" : "api3.log",
"logFile" : "api_peer_3.log",

"actionCluster": {
"Key" : "4ijhaijhm43yjnawhja43jaj",
"ReConnectToLostPeersMS" : 1000,
"CycleCheckTimeMS" : 100,
"RemoteTimeoutWaitMS" : 10000,
"remoteTimeoutWaitMS" : 10000,
"nodeDuplication" : 2,
"StartingPeer" : {
"host": "127.0.0.1",
Expand All @@ -32,16 +30,22 @@ params.configChanges = {
"password" : null,
"port" : "3306",
"consoleLogging" : false
},
"flatFileDirectory":"./public/"
}
}

// any additional functions you might wish to define to be globally accessable can be added as part of params.initFunction. The api object will be availalbe.
params.initFunction = function(api, next){
api.randomNumberGenerator = Math.random() * 100;
api.showCacheData = function(api){
api.log("--------- CACHE --------");
api.log(JSON.stringify(api.cache.data));
setTimeout(api.showCacheData, 5000, api);
}
setTimeout(api.showCacheData, 5000, api);

next();
}


// start the server!
actionHero.start(params, function(api){
api.log("Boot Sucessful!");
Expand Down
52 changes: 52 additions & 0 deletions examples/actionHero_cluster_peer_4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// load in the actionHero class
var actionHero = require(__dirname + "/../api.js").actionHero; // normally if installed by npm: var actionHero = require("actionHero").actionHero;

// if there is no config.js file in the application's root, then actionHero will load in a collection of default params. You can overwrite them with params.configChanges
var params = {};
params.configChanges = {

"webServerPort" : 8083,
"socketServerPort" : 5003,

"logFile" : "api_peer_4.log",

"actionCluster": {
"Key" : "4ijhaijhm43yjnawhja43jaj",
"ReConnectToLostPeersMS" : 1000,
"CycleCheckTimeMS" : 100,
"remoteTimeoutWaitMS" : 10000,
"nodeDuplication" : 2,
"StartingPeer" : {
"host": "127.0.0.1",
"port": "5000"
}
},

"database" : {
"type":"mySQL",
"host" : "127.0.0.1",
"database" : "action_hero_api",
"username" : "root",
"password" : null,
"port" : "3306",
"consoleLogging" : false
}
}

// any additional functions you might wish to define to be globally accessable can be added as part of params.initFunction. The api object will be availalbe.
params.initFunction = function(api, next){
api.showCacheData = function(api){
api.log("--------- CACHE --------");
api.log(JSON.stringify(api.cache.data));
setTimeout(api.showCacheData, 5000, api);
}
setTimeout(api.showCacheData, 5000, api);

next();
}


// start the server!
actionHero.start(params, function(api){
api.log("Boot Sucessful!");
});
26 changes: 26 additions & 0 deletions examples/actionHero_single_node_with_database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// load in the actionHero class
var actionHero = require(__dirname + "/../api.js").actionHero; // normally if installed by npm: var actionHero = require("actionHero").actionHero;

// if there is no config.js file in the application's root, then actionHero will load in a collection of default params. You can overwrite them with params.configChanges
var params = {};
params.configChanges = {
"database" : {
"type":"mySQL",
"host" : "127.0.0.1",
"database" : "action_hero_api",
"username" : "root",
"password" : null,
"port" : "3306",
"consoleLogging" : false
}
}

// any additional functions you might wish to define to be globally accessable can be added as part of params.initFunction. The api object will be availalbe.
params.initFunction = function(api, next){
next();
}

// start the server!
actionHero.start(params, function(api){
api.log("Boot Sucessful!");
});
18 changes: 18 additions & 0 deletions examples/actionHero_single_node_without_database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// load in the actionHero class
var actionHero = require(__dirname + "/../api.js").actionHero; // normally if installed by npm: var actionHero = require("actionHero").actionHero;

// if there is no config.js file in the application's root, then actionHero will load in a collection of default params. You can overwrite them with params.configChanges
var params = {};
params.configChanges = {
"database" : null
}

// any additional functions you might wish to define to be globally accessable can be added as part of params.initFunction. The api object will be availalbe.
params.initFunction = function(api, next){
next();
}

// start the server!
actionHero.start(params, function(api){
api.log("Boot Sucessful!");
});
10 changes: 5 additions & 5 deletions initializers/initActionCluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,15 @@ var initActionCluster= function(api, next){
if(api.actionCluster.cache.results[requestID].complete == false){
if(typeof next == "function"){ next(api.actionCluster.cache.results[requestID]["peerResponses"]); }
}
},api.configData.actionCluster.RemoteTimeoutWaitMS);
},api.configData.actionCluster.remoteTimeoutWaitMS);
}

// clear result set data
if(api.actionCluster.cache.results[requestID].dataClearTimer == null){
api.actionCluster.cache.results[requestID].dataClearTimer = setTimeout(function(){
clearTimeout(api.actionCluster.cache.results[requestID].timeoutTimer);
delete api.actionCluster.cache.results[requestID];
}, (api.configData.actionCluster.RemoteTimeoutWaitMS * 2))
}, (api.configData.actionCluster.remoteTimeoutWaitMS * 2))
}
}
}
Expand All @@ -288,7 +288,7 @@ var initActionCluster= function(api, next){
if(counter > 0){
api.log(counter + " cache objects on this server do not have corresponding duplicates in peers; Attempting to re-duplicate", "red");
}
setTimeout(api.actionCluster.cache.ensureObjectDuplication, api.configData.actionCluster.RemoteTimeoutWaitMS, api);
setTimeout(api.actionCluster.cache.ensureObjectDuplication, api.configData.actionCluster.remoteTimeoutWaitMS, api);
}else{
setTimeout(completeAndRestart, 1000);
}
Expand All @@ -299,7 +299,7 @@ var initActionCluster= function(api, next){
var value = cacheObj.value;
var expireTimestamp = cacheObj.expireTimestamp;
var expireTimeSeconds = (expireTimestamp - (new Date().getTime())) / 1000;
if(expireTimestamp - (new Date().getTime()) > api.configData.actionCluster.RemoteTimeoutWaitMS){
if(expireTimestamp - (new Date().getTime()) > api.configData.actionCluster.remoteTimeoutWaitMS){
api.actionCluster.cache.load(api, key, function(resp){
var truthyResponses = 0;
for (var i in resp){
Expand Down Expand Up @@ -331,7 +331,7 @@ var initActionCluster= function(api, next){
}

}
setTimeout(api.actionCluster.cache.ensureObjectDuplication, api.configData.actionCluster.RemoteTimeoutWaitMS, api);
setTimeout(api.actionCluster.cache.ensureObjectDuplication, api.configData.actionCluster.remoteTimeoutWaitMS, api);


// connect to first peer
Expand Down
Loading

0 comments on commit f43601b

Please sign in to comment.