Changeset 100
- Timestamp:
- 08/03/06 03:03:25 (2 years ago)
- Files:
-
- streamservice/trunk/lib/streamservice/Dispatch.include.js (added)
- streamservice/trunk/lib/streamservice/Dispatch.js (modified) (21 diffs)
- streamservice/trunk/lib/streamservice/Dispatch.js.json (added)
- streamservice/trunk/lib/streamservice/Dispatch.pkg.js (added)
- streamservice/trunk/lib/streamservice/Loopback.include.js (added)
- streamservice/trunk/lib/streamservice/Loopback.js (modified) (1 diff)
- streamservice/trunk/lib/streamservice/Loopback.js.json (added)
- streamservice/trunk/scripts/json-provides.py (added)
- streamservice/trunk/tests/test-Dispatch.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
streamservice/trunk/lib/streamservice/Dispatch.js
r98 r100 1 if (typeof(streamservice) == 'undefined') { 2 streamservice = {}; 3 } 4 5 update(streamservice, { 1 /*** 2 3 streamservice.Dispatch 0.9.0 4 5 (c) 2006 Wiretooth Ltd. All rights Reserverd. 6 7 ***/ 8 9 MochiKit.Base.update(streamservice, { 6 10 strip_tag_inplace : function(seperator, item){ 7 11 item[0] = item[0].slice(item[0].split(seperator,1)[0].length + 1); … … 26 30 27 31 if(typeof(names) == "undefined" || names==null){ 28 self.queryparameters=parseQueryString( 29 queryString([self.dispatchparametername],["[[],[]]"]), true); 30 /*log("***: self.queryparameters = " + 31 serializeJSON(self.queryparameters));*/ 32 self.queryparameters=MochiKit.Base.parseQueryString( 33 MochiKit.Base.queryString( 34 [self.dispatchparametername],["[[],[]]"]), true); 32 35 } else { 33 36 /* normalize parameter representation */ 34 self.queryparameters=parseQueryString(queryString( 35 names, values), true); 36 log("***: self.queryparameters = " + serializeJSON( 37 self.queryparameters)); 37 self.queryparameters=MochiKit.Base.parseQueryString( 38 MochiKit.Base.queryString( 39 names, values), true); 38 40 /* if there is a collision the first element of user specified 39 41 value is clobbered */ … … 106 108 } 107 109 try{ 108 /*log("***:" + clientdata);*/109 110 var sent = streamservice.split_json(clientdata); 110 111 var recvd = [null,null]; 111 112 if( typeof(emulatedbackendpollresult)!="undefined" && 112 113 emulatedbackendpollresult != null){ 113 /*log("***:" + emulatedbackendpollresult);114 log("***:" + typeof(emulatedbackendpollresult));*/115 114 recvd = streamservice.split_json(emulatedbackendpollresult); 116 115 if(ignoreemulatedresponses != false) 117 116 recvd = [recvd[0],null]; 118 117 } 119 /* log("***:" + serializeJSON(recvd)); */120 118 var result = streamservice.join_json(recvd[0], sent[0]); 121 119 if(recvd[1] != null){ … … 130 128 log("loopback raised:" + result); 131 129 waitfail = function(seconds, value){ 132 var d = wait(seconds); 133 d.addBoth(partial(function (value){throw value;}, value)); 130 var d = MochiKit.Async.wait(seconds); 131 d.addBoth(MochiKit.Base.partial( 132 function (value){throw value;}, value)); 134 133 return d; 135 134 } … … 342 341 streamservice.XMLHttpRequestProtocol = function (servicepath, 343 342 dispatchparametername, names, values, sdpp){ 344 bindMethods(this);343 MochiKit.Base.bindMethods(this); 345 344 streamservice.prepare_protocol( 346 345 this, servicepath, 347 346 dispatchparametername, names, values, sdpp); 348 this.req = getXMLHttpRequest();347 this.req = MochiKit.Async.getXMLHttpRequest(); 349 348 } 350 349 streamservice.XMLHttpRequestProtocol.prototype = { … … 371 370 method="POST"; 372 371 this.queryparameters[this.dispatchparametername][0]=data 373 var url = this.baseurl + "?" + queryString(this.queryparameters); 374 375 log("###: POLLING = " + 376 this.queryparameters[this.dispatchparametername][0]); 377 378 /*log("###: queryitems = " + serializeJSON(queryitems)); 379 log("###: url = " + url);*/ 372 var url = this.baseurl + "?" + MochiKit.Base.queryString( 373 this.queryparameters); 374 380 375 this.queryparameters[this.dispatchparametername][0]="[[][]]"; 381 376 … … 384 379 385 380 var getresult = function(req){ 386 log("***: req.responseText = " + req.responseText);387 /*388 log("***: evalJSONRequest(req) = " + evalJSONRequest(req));389 log("***: split_json(req.responseText) = " + split_json(390 req.responseText));*/391 381 /*return split_json(req.responseText);*/ 392 return evalJSONRequest(req);393 } 394 return sendXMLHttpRequest(this.req).addCallbacks(382 return MochiKit.Base.evalJSONRequest(req); 383 } 384 return MochiKit.Async.sendXMLHttpRequest(this.req).addCallbacks( 395 385 getresult, this.response_error); 396 386 } catch (e){ 397 log("***: error polling " + repr(e));387 log("***: error polling " + MochiKit.Base.repr(e)); 398 388 return fail(e).addBoth(this.response_error); 399 389 } … … 402 392 403 393 streamservice.Dispatcher = function () { 404 bindMethods(this);394 MochiKit.Base.bindMethods(this); 405 395 this.initialize.apply(this, arguments); 406 396 }; … … 424 414 425 415 if( typeof(d)=="undefined" || d == null){ 426 d = new Deferred();416 d = new MochiKit.Async.Deferred(); 427 417 } 428 418 tag = [this.nextresponsetag, tag].join(this.TAG_SEPERATOR); … … 443 433 444 434 dispatch_result : function (result) { 445 /*log("result: " + result);446 log("typeof(result): " + typeof(result));447 log("serializeJSON(result): " + serializeJSON(result));*/448 435 try{ 449 forEach(iter(result[1]),436 MochiKit.Iter.forEach(iter(result[1]), 450 437 function(item){ 451 438 452 /*log("query/reply: " + repr(item));*/453 454 439 /* each item is [tag, body] */ 455 440 dresponse=this.replypending[item[0]]; … … 461 446 462 447 } else { 463 log("unexpected response:" + serializeJSON(item)); 448 log("*** unexpected response:" + 449 MochiKit.Base.serializeJSON(item)); 464 450 } 465 451 }, this); 466 452 /* returns the new queries from the backend to the client. */ 467 453 return result[0]; 468 } catch(e){ log("dispatch_result exception:" + repr(e)); throw e;} 454 } catch(e){ log("dispatch_result exception:" + 455 MochiKit.Base.repr(e)); throw e;} 469 456 }, 470 457 … … 496 483 this.responsepending.splice(0, this.responsepending.length); 497 484 d.addCallbacks( 498 bind(this.dispatch_result, this),499 bind(this.dispatch_err, this));485 MochiKit.Base.bind(this.dispatch_result, this), 486 MochiKit.Base.bind(this.dispatch_err, this)); 500 487 return d; 501 488 }, … … 546 533 547 534 if(this.dpolling==null || this.dpolling.fired != -1){ 548 callLater(this.polling_interval,549 bind(function(){535 MochiKit.Async.callLater(this.polling_interval, 536 MochiKit.Base.bind(function(){ 550 537 this.dpolling = this.poll().addBoth( 551 538 this._continue_polling) … … 562 549 this.dpolling.cancel(); 563 550 } catch (e){ 564 if(!(e instanceof AlreadyCalledError))551 if(!(e instanceof MochiKit.Async.AlreadyCalledError)) 565 552 throw e; 566 553 } … … 577 564 ***/ 578 565 579 bindMethods(this);566 MochiKit.Base.bindMethods(this); 580 567 this.id = streamservice.Service.prototype.NEXT_SERVICE_ID; 581 568 streamservice.Service.prototype.NEXT_SERVICE_ID += 1; … … 594 581 this.observers[idinservice] = observer; 595 582 }, 596 strip_tag_inplace : function(item){583 strip_tag_inplace : function(item){ 597 584 return streamservice.strip_tag_inplace(this.TAG_SEPERATOR, 598 585 this.dispatcher.strip_tag_inplace(item)); … … 609 596 610 597 handle_query : function(item){ 611 log("*** serverquery ***" + repr(item));612 598 613 599 observertag = this.dispatcher.strip_tag(item[0]); … … 624 610 observer.handle_query.call(observer, item[1], tag, responseback); 625 611 } else { 626 log(" UNTARGETED SERVER QUERY:" + item);612 log("*** UNTARGETED SERVER QUERY:" + item); 627 613 } 628 614 }, 629 615 630 616 handle_queryitems : function(dispatcher, queryitems){ 631 /*log("***!: Observer.handle_queryitems");*/ 632 /*log("***!: queryitems = " + serializeJSON(queryitems));*/ 633 forEach(iter(queryitems), partial(this.handle_query)); 617 MochiKit.Iter.forEach(iter(queryitems), MochiKit.Base.partial( 618 this.handle_query)); 634 619 }, 635 620 … … 638 623 '' + observerid : 639 624 [observerid, tag].join(this.TAG_SEPERATOR); 640 d = (typeof(d)=='undefined' || !d) ? new Deferred() : d; 625 d = (typeof(d)=='undefined' || !d) ? 626 new MochiKit.Async.Deferred() : d; 641 627 d.addCallback(this.strip_tag_inplace); 642 628 return this.dispatcher.query(body, id, d); … … 645 631 646 632 streamservice.Observer = function(service, idinservice, client_dispatcher){ 647 bindMethods(this);633 MochiKit.Base.bindMethods(this); 648 634 this.service = service; 649 635 this.idinservice = idinservice; … … 659 645 660 646 handle_query : function(body, tag, responseback){ 661 /*log("*** Observer.handle_query ***" + repr(body) + ' ' + repr(tag));*/662 647 if (this.client_dispatcher){ 663 648 this.client_dispatcher(body, tag).addBoth(responseback); streamservice/trunk/lib/streamservice/Loopback.js
r98 r100 6 6 7 7 ***/ 8 if (typeof(streamservice) == 'undefined') {9 streamservice = {};10 }11 if (typeof(streamservice.Loopback) == 'undefined') {12 streamservice.Loopback = {};13 }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 = [];22 8 23 9 streamservice.Loopback.Protocol = function ( streamservice/trunk/tests/test-Dispatch.html
r98 r100 8 8 src="../lib/SimpleTest/SimpleTest.js"></script> 9 9 <script type="text/javascript" 10 src="../lib/streamservice/ Loopback.js"></script>10 src="../lib/streamservice/Dispatch.include.js"></script> 11 11 <script type="text/javascript" 12 12 src="../lib/streamservice/Dispatch.js"></script> 13 <script type="text/javascript" 14 src="../lib/streamservice/Loopback.include.js"></script> 15 <script type="text/javascript" 16 src="../lib/streamservice/Loopback.js"></script> 13 17 <script type="text/javascript" 14 18 src="test_Dispatch.js"></script>