Changeset 97

Show
Ignore:
Timestamp:
08/02/06 07:08:46 (2 years ago)
Author:
robin
Message:

interim comit

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • streamservice/trunk/lib/streamservice/Loopback.js

    r6 r97  
    11/****************************************************************************** 
    22 
    3 Utilities to assist testing & developmet of dispatch.js 
     3Loopback protocol implementation. 
     4 
     5Provided both as an example and to support testing. 
    46 
    57***/ 
     8if (typeof(streamservice) == 'undefined') { 
     9    streamservice = {}; 
     10} 
     11if (typeof(streamservice.Loopback) == 'undefined') { 
     12    streamservice.Loopback = {}; 
     13} 
    614 
     15streamservice.Loopback.VERSION = "0.9.0"; 
     16streamservice.Loopback.NAME = "Loopback"; 
     17streamservice.Loopback.EXPORT = [ 
     18    "Protocol", 
     19    "Observer" 
     20]; 
     21streamservice.Loopback.EXPORT_OK = []; 
    722 
    8 LoopbackProtocol = function ( 
     23streamservice.Loopback.Protocol = function ( 
    924    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); 
    1133    if(typeof(manualmode)=="undefined" || manualmode == null){ 
    1234        this.manualmode = true; 
     
    1941        this.ignoreemulatedbackendresponses = ignoreemulatedbackendresponses; 
    2042    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); 
    4943}; 
    5044 
    51 LoopbackObserver = function(onnewquery){ 
     45streamservice.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 
     76streamservice.Loopback.Observer = function(onnewquery){ 
    5277    bindMethods(this); 
    5378    this.backendqueries=[] 
    54     this.onnewquery = typeof(onnewquery)=="undefined" || onnewquery == null ? null : onnewquery; 
     79    this.onnewquery =  
     80        typeof(onnewquery)=="undefined" || onnewquery == null ?  
     81            null : onnewquery; 
    5582    /*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 
     85streamservice.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        } 
    6494    } 
    65 } 
     95}; 
  • streamservice/trunk/lib/streamservice/dispatch.js

    r6 r97  
    104104    if (typeof(responseitems) == "undefined" || responseitems == null) 
    105105        var responseitems = []; 
    106     return "[" + serializeJSON(queryitems) + "," + 
    107                  serializeJSON(responseitems) + "]"; 
     106    return "[" + MochiKit.Base.serializeJSON(queryitems) + "," + 
     107                 MochiKit.Base.serializeJSON(responseitems) + "]"; 
    108108} 
    109109 
     
    483483    /*** 
    484484     
    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. 
    486487 
    487488    ***/ 
     
    505506    }, 
    506507    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)); 
    508510    }, 
    509511    strip_tag : function(tag){ 
     
    557559    this.service = service; 
    558560    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; 
    560564} 
    561565 
     
    648652        return latency <= 0 ? fail(result) : waitfail(latency, result); 
    649653    } 
    650 } 
     654};