My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Module("Japache", function() {
Class("Server", {

has: {
cometClient: {
is: "rw"
},
wp: {
is: "rw",
required: true
},
config: {
is: "rw",
init: function () { return {} }
},
motherId: {
is: "rw",
required: true
},
requestHandler: {
is: "rw"
}
},

after: {
initialize: function () {
var self = this;
this.setCometClient(new Japache.CometClient({
url: "/listen",
callback: function (data) { self.handleRequest(data) },
log: function (msg) {
self.log(msg)
}
}))
}
},

methods: {
handleRequest: function (request) {
var self = this;
var client = this.getCometClient();
var url = request.url;
var requestId = request.requestId;

this.log("Start: "+new Date()+" - "+url + " - Request: "+requestId+" Thread "+this.config.id)

var responseData = this.getRequestHandler().handleRequest(request);

var json = JSON.stringify(responseData)

var response = {
requestId: requestId,
header: "Content-Type: text/html",
body: json
}

client.ajaxRequest("POST", "/response", response, function () {
self.log("Done: "+new Date()+" - "+url + " - Request: "+requestId+" Thread "+self.config.id)
}, function onError (err) {
self.log(""+err)
})
},

listen: function () {
this.log("Starting thread "+this.config.id)
this.getCometClient().listen();
this.log("Started thread "+this.config.id)
},

stop: function () {
this.log("Stopping server "+this.config.id)
this.getCometClient().disconnect()
this.log("Sent stop signal "+this.config.id)
},

log: function (msg) {
this.getWp().sendMessage({ action: "log", message: msg }, this.getMotherId())
}
}

})
})
Show details Hide details

Change log

r367 by malte.ubl on Dec 24, 2008   Diff
Make apps pluggable
Go to: 
Sign in to write a code review

Older revisions

r365 by malte.ubl on Dec 06, 2008   Diff
Only allow JSON for app responses
r364 by malte.ubl on Dec 06, 2008   Diff
Why? Because you can!

A massively parallel crowd-sourced
JavaScript application server cloud
based on Google AppEngine and Google
...
All revisions of this file

File info

Size: 2653 bytes, 82 lines
Hosted by Google Code