diff options
author | Mark Spruiell <mes@zeroc.com> | 2014-03-19 12:45:55 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2014-03-19 12:45:55 -0700 |
commit | cdcffbcc3c3c052afdeb772ff0167e7a90b525bb (patch) | |
tree | 4f16ee41ef7d33394c44e9db81e4d6cd89908250 /js/src/Ice/RetryQueue.js | |
parent | fixing testicedist.py for 5487 (diff) | |
download | ice-cdcffbcc3c3c052afdeb772ff0167e7a90b525bb.tar.bz2 ice-cdcffbcc3c3c052afdeb772ff0167e7a90b525bb.tar.xz ice-cdcffbcc3c3c052afdeb772ff0167e7a90b525bb.zip |
merging javascript branch
Diffstat (limited to 'js/src/Ice/RetryQueue.js')
-rw-r--r-- | js/src/Ice/RetryQueue.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/js/src/Ice/RetryQueue.js b/js/src/Ice/RetryQueue.js new file mode 100644 index 00000000000..5462933c15f --- /dev/null +++ b/js/src/Ice/RetryQueue.js @@ -0,0 +1,83 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +(function(global){ + require("Ice/Class"); + require("Ice/Debug"); + require("Ice/LocalException"); + + var Ice = global.Ice || {}; + + var Debug = Ice.Debug; + + var Class = Ice.Class; + + var RetryQueue = Class({ + __init__: function(instance) + { + this._instance = instance; + this._requests = []; + }, + add: function(outAsync, interval) + { + var task = new RetryTask(this, outAsync); + this._instance.timer().schedule(function() + { + task.run(); + }, interval); + this._requests.push(task); + }, + destroy: function() + { + for(var i = 0; i < this._requests.length; ++i) + { + this._requests[i].destroy(); + } + this._requests = []; + }, + remove: function(task) + { + var idx = this._requests.indexOf(task); + if(idx >= 0) + { + this._requests.splice(idx, 1); + return true; + } + return false; + } + }); + Ice.RetryQueue = RetryQueue; + + var RetryTask = Class({ + __init__: function(queue, outAsync, interval) + { + this.queue = queue; + this.outAsync = outAsync; + }, + run: function() + { + if(this.queue.remove(this)) + { + try + { + this.outAsync.__send(); + } + catch(ex) + { + this.outAsync.__exception(ex); + } + } + }, + destroy: function() + { + this.outAsync.__exception(new Ice.CommunicatorDestroyedException()); + } + }); + global.Ice = Ice; +}(typeof (global) === "undefined" ? window : global)); |