Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection modification #31

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"semi": [
"error",
"always"
]
],
"no-console" : "off"
}
}
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/test\\testrunner.js",
"args" : ["-i","local","clientaffinity"]
}
]
}
22 changes: 11 additions & 11 deletions examples/voter/voter/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,38 @@
* client code.
*/

var express = require('express'),
routes = require('./routes'), volt = require('./models/volt'),
votes = require('./jsons/votes'), util = require('util'),
cluster = require('cluster'), numCPUs = require('os').cpus().length;
var express = require("express"),
routes = require("./routes"), volt = require("./models/volt"),
votes = require("./jsons/votes"), util = require("util"),
cluster = require("cluster"), numCPUs = require("os").cpus().length;

function webserverProcess() {
var app = module.exports = express.createServer();

// Configuration

app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.set("views", __dirname + "/views");
app.set("view engine", "jade");
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
app.use(express.static(__dirname + "/public"));
});

app.configure('production', function() {
app.configure("production", function() {
app.use(express.errorHandler({
dumpExceptions : true,
showStack : true
}));
});

app.configure('production', function() {
app.configure("production", function() {
app.use(express.errorHandler());
});
// Routes
app.get('/', routes.index);
app.get('/results', votes.votes);
app.get("/", routes.index);
app.get("/results", votes.votes);

app.listen(3000);

Expand Down
8 changes: 4 additions & 4 deletions examples/voter/voter/jsons/votes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
*/

var volt = require("../models/volt"),
VoltConstants = require(__dirname + '/../../../../lib/voltconstants');
VoltConstants = require(__dirname + "/../../../../lib/voltconstants");

exports.votes = function(req, res) {
return volt.getVoteResults(function displayResults(code, event, results) {
if(code == VoltConstants.STATUS_CODES.SUCCESS) {
res.json({
'rows' : results.table[0]
"rows" : results.table[0]
});
} else {
res.json({
'critical fault, database down': 500
"critical fault, database down": 500
});
}
});
}
};
102 changes: 51 additions & 51 deletions examples/voter/voter/models/volt.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,37 @@
* 3. Invokes stored procedures and processes the results.
*/

var util = require('util');
var cluster = require('cluster');
var util = require("util");
var cluster = require("cluster");

// VoltClient manages all communication with VoltDB
var VoltClient = require(__dirname + '/../../../../lib/client');
var VoltClient = require(__dirname + "/../../../../lib/client");

// VoltConstants has all the event types, codes and other constants
// that the client and your code will rely upon
var VoltConstants = require(__dirname + '/../../../../lib/voltconstants');
var VoltConstants = require(__dirname + "/../../../../lib/voltconstants");

// VoltConfiguration sets up the configuration for each VoltDB server
// in your cluster. If you have ten Volt nodes in the cluster, then you should
// create ten configurations. These configurations are used in the construction
// of the client.
var VoltConfiguration = require(__dirname + '/../../../../lib/configuration');
var VoltConfiguration = require(__dirname + "/../../../../lib/configuration");

// VoltProcedure is a static representation of the stored procedure and
// specifies the procedure's name and the parameter types. The parameter types
// are especially important since they define how the client will marshal the
// the parameters.
var VoltProcedure = require(__dirname + '/../../../../lib/query');
var VoltProcedure = require(__dirname + "/../../../../lib/query");

// VoltQuery is a specific instance of a VoltProcedure. Your code will
// always call stored procedures using a VoltQuery object.
var VoltQuery = require(__dirname + '/../../../../lib/query');
var VoltQuery = require(__dirname + "/../../../../lib/query");

// These are a set of stored procedure definitions.
// See VoltConstants to see the data types supported by the driver.
var resultsProc = new VoltProcedure('Results');
var initProc = new VoltProcedure('Initialize', ['int', 'string']);
var voteProc = new VoltProcedure('Vote', ['long', 'int', 'long']);
var resultsProc = new VoltProcedure("Results");
var initProc = new VoltProcedure("Initialize", ["int", "string"]);
var voteProc = new VoltProcedure("Vote", ["long", "int", "long"]);

// The following is just application specific data
var client = null;
Expand All @@ -69,29 +69,29 @@ var transactionCounter = 0;
var statsLoggingInterval = 10000;

var area_codes = [907, 205, 256, 334, 251, 870, 501, 479, 480, 602, 623, 928,
520, 341, 764, 628, 831, 925, 909, 562, 661, 510, 650, 949, 760, 415, 951, 209,
669, 408, 559, 626, 442, 530, 916, 627, 714, 707, 310, 323, 213, 424, 747, 818,
858, 935, 619, 805, 369, 720, 303, 970, 719, 860, 203, 959, 475, 202, 302, 689,
407, 239, 850, 727, 321, 754, 954, 927, 352, 863, 386, 904, 561, 772, 786, 305,
941, 813, 478, 770, 470, 404, 762, 706, 678, 912, 229, 808, 515, 319, 563, 641,
712, 208, 217, 872, 312, 773, 464, 708, 224, 847, 779, 815, 618, 309, 331, 630,
317, 765, 574, 260, 219, 812, 913, 785, 316, 620, 606, 859, 502, 270, 504, 985,
225, 318, 337, 774, 508, 339, 781, 857, 617, 978, 351, 413, 443, 410, 301, 240,
207, 517, 810, 278, 679, 313, 586, 947, 248, 734, 269, 989, 906, 616, 231, 612,
320, 651, 763, 952, 218, 507, 636, 660, 975, 816, 573, 314, 557, 417, 769, 601,
662, 228, 406, 336, 252, 984, 919, 980, 910, 828, 704, 701, 402, 308, 603, 908,
848, 732, 551, 201, 862, 973, 609, 856, 575, 957, 505, 775, 702, 315, 518, 646,
347, 212, 718, 516, 917, 845, 631, 716, 585, 607, 914, 216, 330, 234, 567, 419,
440, 380, 740, 614, 283, 513, 937, 918, 580, 405, 503, 541, 971, 814, 717, 570,
878, 835, 484, 610, 267, 215, 724, 412, 401, 843, 864, 803, 605, 423, 865, 931,
615, 901, 731, 254, 325, 713, 940, 817, 430, 903, 806, 737, 512, 361, 210, 979,
936, 409, 972, 469, 214, 682, 832, 281, 830, 956, 432, 915, 435, 801, 385, 434,
804, 757, 703, 571, 276, 236, 540, 802, 509, 360, 564, 206, 425, 253, 715, 920,
262, 414, 608, 304, 307];

var voteCandidates = 'Edwina Burnam,Tabatha Gehling,Kelly Clauss,' +
'Jessie Alloway,Alana Bregman,Jessie Eichman,Allie Rogalski,Nita Coster,' +
'Kurt Walser,Ericka Dieter,Loraine NygrenTania Mattioli';
520, 341, 764, 628, 831, 925, 909, 562, 661, 510, 650, 949, 760, 415, 951, 209,
669, 408, 559, 626, 442, 530, 916, 627, 714, 707, 310, 323, 213, 424, 747, 818,
858, 935, 619, 805, 369, 720, 303, 970, 719, 860, 203, 959, 475, 202, 302, 689,
407, 239, 850, 727, 321, 754, 954, 927, 352, 863, 386, 904, 561, 772, 786, 305,
941, 813, 478, 770, 470, 404, 762, 706, 678, 912, 229, 808, 515, 319, 563, 641,
712, 208, 217, 872, 312, 773, 464, 708, 224, 847, 779, 815, 618, 309, 331, 630,
317, 765, 574, 260, 219, 812, 913, 785, 316, 620, 606, 859, 502, 270, 504, 985,
225, 318, 337, 774, 508, 339, 781, 857, 617, 978, 351, 413, 443, 410, 301, 240,
207, 517, 810, 278, 679, 313, 586, 947, 248, 734, 269, 989, 906, 616, 231, 612,
320, 651, 763, 952, 218, 507, 636, 660, 975, 816, 573, 314, 557, 417, 769, 601,
662, 228, 406, 336, 252, 984, 919, 980, 910, 828, 704, 701, 402, 308, 603, 908,
848, 732, 551, 201, 862, 973, 609, 856, 575, 957, 505, 775, 702, 315, 518, 646,
347, 212, 718, 516, 917, 845, 631, 716, 585, 607, 914, 216, 330, 234, 567, 419,
440, 380, 740, 614, 283, 513, 937, 918, 580, 405, 503, 541, 971, 814, 717, 570,
878, 835, 484, 610, 267, 215, 724, 412, 401, 843, 864, 803, 605, 423, 865, 931,
615, 901, 731, 254, 325, 713, 940, 817, 430, 903, 806, 737, 512, 361, 210, 979,
936, 409, 972, 469, 214, 682, 832, 281, 830, 956, 432, 915, 435, 801, 385, 434,
804, 757, 703, 571, 276, 236, 540, 802, 509, 360, 564, 206, 425, 253, 715, 920,
262, 414, 608, 304, 307];

var voteCandidates = "Edwina Burnam,Tabatha Gehling,Kelly Clauss," +
"Jessie Alloway,Alana Bregman,Jessie Eichman,Allie Rogalski,Nita Coster," +
"Kurt Walser,Ericka Dieter,Loraine NygrenTania Mattioli";

function getCandidate() {
return Math.floor(Math.random() * 6) + 1;
Expand All @@ -105,7 +105,7 @@ function getAreaCode() {

// This will initialize the Voter database by invoking a stored procedure.
function voltInit() {
util.log('voltInit');
util.log("voltInit");
// Start by creating a query instance from the VoltProcedure
var query = initProc.getQuery();

Expand All @@ -123,7 +123,7 @@ function voltInit() {
// VoltTable array
client.callProcedure(query, function initVoter(code, event, results) {
var val = results.table[0][0];
util.log('Initialized app for ' + val[''] + ' candidates.');
util.log("Initialized app for " + val[""] + " candidates.");
});
}

Expand All @@ -133,7 +133,7 @@ function voltInit() {
// for trapping all the various error conditions, like connections being
// dropped.
function eventListener(code, event, message) {
util.log(util.format( 'Event %s\tcode: %d\tMessage: %s', event, code,
util.log(util.format( "Event %s\tcode: %d\tMessage: %s", event, code,
message));
}

Expand All @@ -155,9 +155,9 @@ function getConfiguration(host) {
// Connect to the server
exports.initClient = function(startLoop) {
if(client == null) {
var configs = []
var configs = [];

configs.push(getConfiguration('localhost'));
configs.push(getConfiguration("localhost"));
// The client is only configured at this point. The connection
// is not made until the call to client.connect().
client = new VoltClient(configs);
Expand All @@ -180,7 +180,7 @@ exports.initClient = function(startLoop) {
// The second handler is more for catastrophic failures.
client.connect(function startup(code, event,results) {
if(code == VoltConstants.STATUS_CODES.SUCCESS) {
util.log('Node connected to VoltDB');
util.log("Node connected to VoltDB");
if(startLoop) {
setInterval(logResults, statsLoggingInterval);
voteInsertLoop();
Expand All @@ -192,10 +192,10 @@ exports.initClient = function(startLoop) {
process.exit(1);
}
}, function loginError(code, event, results) {
util.log('Node did not connect to VoltDB');
util.log("Node did not connect to VoltDB");
});
}
}
};

// This method will vote several times and will run in the background.
function voteInsertLoop() {
Expand All @@ -221,12 +221,12 @@ function voteInsertLoop() {
client.callProcedure(query,
function displayResults(code, event, results) {
transactionCounter++;
}, function readyToWrite(code, event, results) {
}, function readyToWrite(code, event, results) {

});
});
}
setImmediate(innerLoop);
}
setImmediate(innerLoop);
};
process.nextTick(innerLoop);

}
Expand All @@ -239,13 +239,13 @@ function logResults() {
}

function logTime(operation, totalTime, count) {
util.log(util.format('%d: %s %d times in %d milliseconds. %d TPS',
process.pid, operation, count, totalTime,
Math.floor((count / totalTime) * 1000)));
util.log(util.format("%d: %s %d times in %d milliseconds. %d TPS",
process.pid, operation, count, totalTime,
Math.floor((count / totalTime) * 1000)));
}

// Call the stored proc to collect all votes.
exports.getVoteResults = function(callback) {
var query = resultsProc.getQuery();
client.callProcedure(query, callback);
}
var query = resultsProc.getQuery();
client.callProcedure(query, callback);
};
6 changes: 3 additions & 3 deletions examples/voter/voter/public/javascripts/jquery-1.7.1.min.js

Large diffs are not rendered by default.

Loading