Changeset 97
- Timestamp:
- 08/02/06 07:08:46 (2 years ago)
- Files:
-
- streamservice/trunk/lib/streamservice/Loopback.js (copied) (copied from streamservice/trunk/tests/dispatch_testilities.js) (2 diffs)
- streamservice/trunk/lib/streamservice/dispatch.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
streamservice/trunk/lib/streamservice/Loopback.js
r6 r97 1 1 /****************************************************************************** 2 2 3 Utilities to assist testing & developmet of dispatch.js 3 Loopback protocol implementation. 4 5 Provided both as an example and to support testing. 4 6 5 7 ***/ 8 if (typeof(streamservice) == 'undefined') { 9 streamservice = {}; 10 } 11 if (typeof(streamservice.Loopback) == 'undefined') { 12 streamservice.Loopback = {}; 13 } 6 14 15 streamservice.Loopback.VERSION = "0.9.0"; 16 streamservice.Loopback.NAME = "Loopback"; 17 streamservice.Loopback.EXPORT = [ 18 "Protocol", 19 "Observer" 20 ]; 21 streamservice.Loopback.EXPORT_OK = []; 7 22 8 LoopbackProtocol = function (23 streamservice.Loopback.Protocol = function ( 9 24 manualmode, latency, ignoreemulatedbackendresponses){ 10 bindMethods(this); 25 /*** LoopbackProtocol is a streamservice protocol implementation. 26 27 It is used, together with LoopbackObserver, to support the streamservice 28 self test suite. 29 30 ***/ 31 32 MochiKit.Base.bindMethods(this); 11 33 if(typeof(manualmode)=="undefined" || manualmode == null){ 12 34 this.manualmode = true; … … 19 41 this.ignoreemulatedbackendresponses = ignoreemulatedbackendresponses; 20 42 this.emulatedbackendpollresult=[]; 21 }22 LoopbackProtocol.prototype.response_error = function(err) {23 throw err;24 }25 26 27 LoopbackProtocol.prototype.emulate_backendquery = function(querydata){28 this.emulatedbackendpollresult.push(querydata);29 }30 LoopbackProtocol.prototype.poll = function(queryitems, replyitems){31 if(this.manualmode==true){32 /*log("protcol.poll: manualpoll == true");*/33 return new Deferred().addCallbacks(34 split_json, this.response_error);35 }36 /*log("protocol.poll: " + queryitems);37 log("protocol.poll: " + replyitems);*/38 var data = join_json(queryitems, replyitems);39 /*log("protocol.poll: " + data);*/40 var emulatedbackendpollresult = null;41 if(this.emulatedbackendpollresult.length > 0)42 emulatedbackendpollresult = this.emulatedbackendpollresult.shift();43 return poll_loopback_json.apply(44 this, [data,45 this.latency,46 emulatedbackendpollresult,47 this.ignoreemulatedbackendresponses]).addCallbacks(48 split_json, this.response_error);49 43 }; 50 44 51 LoopbackObserver = function(onnewquery){ 45 streamservice.Loopback.Protocol.prototype = { 46 response_error : function(err) { 47 throw err; 48 }, 49 emulate_backendquery : function(querydata){ 50 this.emulatedbackendpollresult.push(querydata); 51 }, 52 poll : function(queryitems, replyitems){ 53 if(this.manualmode==true){ 54 /*log("protcol.poll: manualpoll == true");*/ 55 return new Deferred().addCallbacks( 56 split_json, this.response_error); 57 } 58 /*log("protocol.poll: " + queryitems); 59 log("protocol.poll: " + replyitems);*/ 60 var data = join_json(queryitems, replyitems); 61 /*log("protocol.poll: " + data);*/ 62 var emulatedbackendpollresult = null; 63 if(this.emulatedbackendpollresult.length > 0){ 64 emulatedbackendpollresult = 65 this.emulatedbackendpollresult.shift(); 66 } 67 return poll_loopback_json.apply( 68 this, [data, 69 this.latency, 70 emulatedbackendpollresult, 71 this.ignoreemulatedbackendresponses]).addCallbacks( 72 split_json, this.response_error); 73 } 74 }; 75 76 streamservice.Loopback.Observer = function(onnewquery){ 52 77 bindMethods(this); 53 78 this.backendqueries=[] 54 this.onnewquery = typeof(onnewquery)=="undefined" || onnewquery == null ? null : onnewquery; 79 this.onnewquery = 80 typeof(onnewquery)=="undefined" || onnewquery == null ? 81 null : onnewquery; 55 82 /*log("***!: " + typeof(this.onnewquery));*/ 56 } 57 LoopbackObserver.prototype.handle_queryitems = function( 58 dispatcher, queryitems){ 59 /*log("***!: LoopbackObserver.handle_queryitems"); 60 log("***!: queryitems = " + serializeJSON(queryitems));*/ 61 extend(this.backendqueries, queryitems); 62 if(this.onnewquery != null){ 63 this.onnewquery(dispatcher, queryitems); 83 }; 84 85 streamservice.Loopback.Observer.prototype = { 86 handle_queryitems : function( 87 dispatcher, queryitems){ 88 /*log("***!: streamservice.Loopback.Observer.handle_queryitems"); 89 log("***!: queryitems = " + serializeJSON(queryitems));*/ 90 extend(this.backendqueries, queryitems); 91 if(this.onnewquery != null){ 92 this.onnewquery(dispatcher, queryitems); 93 } 64 94 } 65 } 95 }; streamservice/trunk/lib/streamservice/dispatch.js
r6 r97 104 104 if (typeof(responseitems) == "undefined" || responseitems == null) 105 105 var responseitems = []; 106 return "[" + serializeJSON(queryitems) + "," +107 serializeJSON(responseitems) + "]";106 return "[" + MochiKit.Base.serializeJSON(queryitems) + "," + 107 MochiKit.Base.serializeJSON(responseitems) + "]"; 108 108 } 109 109 … … 483 483 /*** 484 484 485 Service allows multiple observers to share the same dispatcher/protocol instance. 485 Service allows multiple observers to share the same dispatcher/protocol 486 instance. 486 487 487 488 ***/ … … 505 506 }, 506 507 strip_tag_inplace: function(item){ 507 return strip_tag_inplace(this.TAG_SEPERATOR, this.dispatcher.strip_tag_inplace(item)); 508 return strip_tag_inplace(this.TAG_SEPERATOR, 509 this.dispatcher.strip_tag_inplace(item)); 508 510 }, 509 511 strip_tag : function(tag){ … … 557 559 this.service = service; 558 560 this.idinservice = idinservice; 559 this.client_dispatcher = typeof(client_dispatcher) == 'function' ? client_dispatcher : null; 561 this.client_dispatcher = 562 typeof(client_dispatcher) == 'function' ? 563 client_dispatcher : null; 560 564 } 561 565 … … 648 652 return latency <= 0 ? fail(result) : waitfail(latency, result); 649 653 } 650 } 654 };