Skip to content

Commit

Permalink
add alive control to drpc servers
Browse files Browse the repository at this point in the history
  • Loading branch information
ldsimonassi committed Mar 25, 2012
1 parent b7f6bb3 commit 09ff367
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 36 deletions.
83 changes: 47 additions & 36 deletions node-js-server/node-drpc-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,46 +179,57 @@ http.createServer(function (request, response) {
// Server to be used for requesting pending tasks
http.createServer(function (request, response) {
var parsed_url= parser.parse(request.url, true);
var max= parsed_url.query.max;
if(max==null || typeof(max)=="undefined")
max=1;
var waiter = { "request": request, "response": response, "max": max };
waiting_workers.store(waiter);
check_queues();
var query = request.url;
if(query=="/isAlive")
response.end("YES!");
else {
var max= parsed_url.query.max;
if(max==null || typeof(max)=="undefined")
max=1;
var waiter = { "request": request, "response": response, "max": max };
waiting_workers.store(waiter);
check_queues();
}
}).listen(base_port+1);

// Response receiver server
http.createServer(function (request, response) {
if(request.method=="POST") {

var parsed_url= parser.parse(request.url, true);
var id= parsed_url.query.id;

if(id==null || typeof(id)=="undefined" ||
active_tasks[id]==null ||
typeof(active_tasks[id])=="undefined") {

response.writeHead(404);
response.end("Error ["+id+"] is not a waiting task in this server");
console.log("Error ["+id+"] is not a waiting task in this server");
} else {

var data='';
request.on("data", function(chunk) {
data += chunk;
});

request.on("end", function() {
active_tasks[id].response.writeHead(200, {
'Content-Type' : content_type
});

active_tasks[id].response.end(data);
delete active_tasks[id]
total_active_tasks = total_active_tasks - 1;
response.end("OK!\n");
total_requests_answered = total_requests_answered + 1;
});
var query = request.url;
if(query=="/isAlive")
response.end("YES!");
else {
if(request.method=="POST") {

var parsed_url= parser.parse(request.url, true);
var id= parsed_url.query.id;


if(id==null || typeof(id)=="undefined" ||
active_tasks[id]==null ||
typeof(active_tasks[id])=="undefined") {

response.writeHead(404);
response.end("Error ["+id+"] is not a waiting task in this server");
console.log("Error ["+id+"] is not a waiting task in this server");
} else {

var data='';
request.on("data", function(chunk) {
data += chunk;
});

request.on("end", function() {
active_tasks[id].response.writeHead(200, {
'Content-Type' : content_type
});

active_tasks[id].response.end(data);
delete active_tasks[id]
total_active_tasks = total_active_tasks - 1;
response.end("OK!\n");
total_requests_answered = total_requests_answered + 1;
});
}
}
}
}).listen(base_port+2);
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/search/RandomItemsPopulator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package search;

public class RandomItemsPopulator {
public static String[] possibleWords= new String[] {
"dvd", "laptop", "usb", "home", "theater", "sound",
"notebook", "17", "15", "14", "ipod", "iphone",
"mac", "pava", "mate", "bombilla",
"aire", "acondicionado", "departamento",
"casa", "cochera", "silla", "sillon", "mesa", "cable",
"cortina", "lavarropa", "lavavajilla",
"televisor", "led", "lcd", "ambientes",
"cuadro", "decoracion", "pintura", "jarron", "escultura",
"ventana", "vidrio", "aluminio", "pvc",
"nokia", "1100", "blackberry", "curve",
"android", "samsung", "galaxy", "sII", "windows", "mobile",
"aeromodelismo", "automodelismo", "bateria",
"motor", "control", "remoto", "alas", "avion", "pilas",
"combustible", "autos", "peugeot", "206", "207",
"307", "308", "407", "408", "fiat", "uno", "palio",
"siena", "linea", "stilo", "idea",
"chevrolet", "corsa", "agile", "aveo", "vecra",
"astra", "cruze", "captiva", "volkswagen", "gol", "trend",
"power", "fox", "suran", "bora", "vento", "passat", "cc",
"tiguan", "touareg", "ford", "fiesta", "ka", "kinetic",
"design", "focus", "mondeo", "ecosport", "kuga"
};


public static int MAX_WORDS= 10;


public static String getRandomTitle(){
int cantWords= (int)(Math.random()*(MAX_WORDS-1))+1;
String res= "";
for(int i= 0; i< cantWords; i++){
int ind= (int)(Math.random()*(possibleWords.length-1));
res+=possibleWords[ind]+" ";
}
return res;
}
}

0 comments on commit 09ff367

Please sign in to comment.