diff options
Diffstat (limited to 'js/src/Ice/ConnectRequestHandler.js')
-rw-r--r-- | js/src/Ice/ConnectRequestHandler.js | 180 |
1 files changed, 82 insertions, 98 deletions
diff --git a/js/src/Ice/ConnectRequestHandler.js b/js/src/Ice/ConnectRequestHandler.js index eb38f0945d2..3c6c99f5d41 100644 --- a/js/src/Ice/ConnectRequestHandler.js +++ b/js/src/Ice/ConnectRequestHandler.js @@ -7,39 +7,27 @@ // // ********************************************************************** -var Ice = require("../Ice/ModuleRegistry").Ice; -Ice.__M.require(module, +const Ice = require("../Ice/ModuleRegistry").Ice; +Ice._ModuleRegistry.require(module, [ - "../Ice/Class", - "../Ice/AsyncResult", "../Ice/AsyncStatus", - "../Ice/BasicStream", "../Ice/ConnectionRequestHandler", "../Ice/Debug", - "../Ice/ExUtil", "../Ice/RetryException", - "../Ice/OutgoingAsync", - "../Ice/Protocol", "../Ice/ReferenceMode", "../Ice/Exception", - "../Ice/Promise" ]); -var AsyncResult = Ice.AsyncResult; -var AsyncStatus = Ice.AsyncStatus; -var BasicStream = Ice.BasicStream; -var ConnectionRequestHandler = Ice.ConnectionRequestHandler; -var Debug = Ice.Debug; -var ExUtil = Ice.ExUtil; -var RetryException = Ice.RetryException; -var OutgoingAsync = Ice.OutgoingAsync; -var Protocol = Ice.Protocol; -var ReferenceMode = Ice.ReferenceMode; -var LocalException = Ice.LocalException; -var Promise = Ice.Promise; +const AsyncStatus = Ice.AsyncStatus; +const ConnectionRequestHandler = Ice.ConnectionRequestHandler; +const Debug = Ice.Debug; +const RetryException = Ice.RetryException; +const ReferenceMode = Ice.ReferenceMode; +const LocalException = Ice.LocalException; -var ConnectRequestHandler = Ice.Class({ - __init__: function(ref, proxy) +class ConnectRequestHandler +{ + constructor(ref, proxy) { this._reference = ref; this._response = ref.getMode() === ReferenceMode.ModeTwoway; @@ -48,27 +36,29 @@ var ConnectRequestHandler = Ice.Class({ this._initialized = false; this._connection = null; - this._compress = false; this._exception = null; this._requests = []; - }, - connect: function(proxy) + } + + connect(proxy) { if(!this.initialized()) { this._proxies.push(proxy); } return this._requestHandler ? this._requestHandler : this; - }, - update: function(previousHandler, newHandler) + } + + update(previousHandler, newHandler) { return previousHandler === this ? newHandler : this; - }, - sendAsyncRequest: function(out) + } + + sendAsyncRequest(out) { if(!this._initialized) { - out.__cancelable(this); // This will throw if the request is canceled + out.cancelable(this); // This will throw if the request is canceled } if(!this.initialized()) @@ -76,9 +66,10 @@ var ConnectRequestHandler = Ice.Class({ this._requests.push(out); return AsyncStatus.Queued; } - return out.__invokeRemote(this._connection, this._compress, this._response); - }, - asyncRequestCanceled: function(out, ex) + return out.invokeRemote(this._connection, this._response); + } + + asyncRequestCanceled(out, ex) { if(this._exception !== null) { @@ -87,11 +78,11 @@ var ConnectRequestHandler = Ice.Class({ if(!this.initialized()) { - for(var i = 0; i < this._requests.length; i++) + for(let i = 0; i < this._requests.length; i++) { if(this._requests[i] === out) { - out.__completedEx(ex); + out.completedEx(ex); this._requests.splice(i, 1); return; } @@ -99,12 +90,14 @@ var ConnectRequestHandler = Ice.Class({ Debug.assert(false); // The request has to be queued if it timed out and we're not initialized yet. } this._connection.asyncRequestCanceled(out, ex); - }, - getReference: function() + } + + getReference() { return this._reference; - }, - getConnection: function() + } + + getConnection() { if(this._exception !== null) { @@ -114,37 +107,30 @@ var ConnectRequestHandler = Ice.Class({ { return this._connection; } - }, + } + // // Implementation of Reference_GetConnectionCallback // - setConnection: function(connection, compress) + setConnection(connection) { Debug.assert(this._exception === null && this._connection === null); this._connection = connection; - this._compress = compress; // // If this proxy is for a non-local object, and we are using a router, then // add this proxy to the router info object. // - var ri = this._reference.getRouterInfo(); + let ri = this._reference.getRouterInfo(); if(ri !== null) { - var self = this; - ri.addProxy(this._proxy).then(function() - { - // - // The proxy was added to the router info, we're now ready to send the - // queued requests. - // - self.flushRequests(); - }, - function(ex) - { - self.setException(ex); - }); + // + ri.addProxy(this._proxy).then(() => this.flushRequests(), // The proxy was added to the router + // info, we're now ready to send the + // queued requests. + // + ex => this.setException(ex)); return; // The request handler will be initialized once addProxy completes. } @@ -152,8 +138,9 @@ var ConnectRequestHandler = Ice.Class({ // We can now send the queued requests. // this.flushRequests(); - }, - setException: function(ex) + } + + setException(ex) { Debug.assert(!this._initialized && this._exception === null); @@ -176,17 +163,17 @@ var ConnectRequestHandler = Ice.Class({ // Ignore } - for(var i = 0; i < this._requests.length; ++i) - { - var request = this._requests[i]; - if(request !== null) + this._requests.forEach(request => { - request.__completedEx(this._exception); - } - } + if(request !== null) + { + request.completedEx(this._exception); + } + }); this._requests.length = 0; - }, - initialized: function() + } + + initialized() { if(this._initialized) { @@ -214,47 +201,44 @@ var ConnectRequestHandler = Ice.Class({ return this._initialized; } } - }, - flushRequests: function() + } + + flushRequests() { Debug.assert(this._connection !== null && !this._initialized); - var exception = null; - for(var i = 0; i < this._requests.length; ++i) - { - var request = this._requests[i]; - try - { - request.__invokeRemote(this._connection, this._compress, this._response); - } - catch(ex) + let exception = null; + this._requests.forEach(request => { - if(ex instanceof RetryException) + try { - exception = ex.inner; - - // Remove the request handler before retrying. - this._reference.getInstance().requestHandlerFactory().removeRequestHandler(this._reference, this); - - request.__retryException(ex.inner); + request.invokeRemote(this._connection, this._response); } - else + catch(ex) { - Debug.assert(ex instanceof LocalException); - exception = ex; - request.out.__completedEx(ex); + if(ex instanceof RetryException) + { + exception = ex.inner; + + // Remove the request handler before retrying. + this._reference.getInstance().requestHandlerFactory().removeRequestHandler(this._reference, this); + + request.retryException(ex.inner); + } + else + { + Debug.assert(ex instanceof LocalException); + exception = ex; + request.out.completedEx(ex); + } } - } - } + }); this._requests.length = 0; if(this._reference.getCacheConnection() && exception === null) { - this._requestHandler = new ConnectionRequestHandler(this._reference, this._connection, this._compress); - for(var k = 0; k < this._proxies.length; ++k) - { - this._proxies[k].__updateRequestHandler(this, this._requestHandler); - } + this._requestHandler = new ConnectionRequestHandler(this._reference, this._connection); + this._proxies.forEach(proxy => proxy._updateRequestHandler(this, this._requestHandler)); } Debug.assert(!this._initialized); @@ -270,7 +254,7 @@ var ConnectRequestHandler = Ice.Class({ this._proxies.length = 0; this._proxy = null; // Break cyclic reference count. } -}); +} Ice.ConnectRequestHandler = ConnectRequestHandler; module.exports.Ice = Ice; |