summaryrefslogtreecommitdiff
path: root/js/src
diff options
context:
space:
mode:
Diffstat (limited to 'js/src')
-rw-r--r--js/src/Ice/ConnectRequestHandler.js134
-rw-r--r--js/src/Ice/ConnectionRequestHandler.js8
-rw-r--r--js/src/Ice/Instance.js25
-rw-r--r--js/src/Ice/Makefile1
-rw-r--r--js/src/Ice/Makefile.mak1
-rw-r--r--js/src/Ice/ObjectPrx.js10
-rw-r--r--js/src/Ice/Operation.js1
-rw-r--r--js/src/Ice/Promise.js11
-rw-r--r--js/src/Ice/RequestHandlerFactory.js60
9 files changed, 158 insertions, 93 deletions
diff --git a/js/src/Ice/ConnectRequestHandler.js b/js/src/Ice/ConnectRequestHandler.js
index 22bfb213581..5ad7ae6cdc6 100644
--- a/js/src/Ice/ConnectRequestHandler.js
+++ b/js/src/Ice/ConnectRequestHandler.js
@@ -44,42 +44,40 @@ var ConnectRequestHandler = Ice.Class({
this._reference = ref;
this._response = ref.getMode() === ReferenceMode.ModeTwoway;
this._proxy = proxy;
+ this._proxies = [];
this._batchAutoFlush = ref.getInstance().initializationData().properties.getPropertyAsIntWithDefault(
"Ice.BatchAutoFlush", 1) > 0 ? true : false;
this._initialized = false;
- this._flushing = false;
this._batchRequestInProgress = false;
this._batchRequestsSize = Protocol.requestBatchHdr.length;
this._batchStream =
new BasicStream(ref.getInstance(), Protocol.currentProtocolEncoding, this._batchAutoFlush);
- this._updateRequestHandler = false;
this._connection = null;
this._compress = false;
this._exception = null;
this._requests = [];
- this._updateRequestHandler = false;
},
- connect: function()
+ connect: function(proxy)
{
var self = this;
- var proxy = this._proxy;
- try
+ if(proxy === this._proxy)
{
- this._reference.getConnection().then(
- function(connection, compress)
- {
- self.setConnection(connection, compress);
- }).exception(
- function(ex)
- {
- self.setException(ex);
- });
+ this._reference.getConnection().then(function(connection, compress)
+ {
+ self.setConnection(connection, compress);
+ },
+ function(ex)
+ {
+ self.setException(ex);
+ });
+ }
+ try
+ {
if(!this.initialized())
{
- // The proxy request handler will be updated when the connection is set.
- this._updateRequestHandler = true;
+ this._proxies.push(proxy);
return this;
}
}
@@ -89,11 +87,15 @@ var ConnectRequestHandler = Ice.Class({
throw ex;
}
- Debug.Assert(this._connection !== null);
-
- var handler = new ConnectionRequestHandler(this._reference, this._connection, this._compress);
- proxy.setRequestHandler__(this, handler);
- return handler;
+ if(this._connectionRequestHandler)
+ {
+ proxy.__setRequestHandler(this, this._connectionRequestHandler);
+ return this._connectionRequestHandler;
+ }
+ else
+ {
+ return this;
+ }
},
update: function(previousHandler, newHandler)
{
@@ -148,7 +150,6 @@ var ConnectRequestHandler = Ice.Class({
this._batchAutoFlush);
this._batchStream.swap(dummy);
this._batchRequestsSize = Protocol.requestBatchHdr.length;
-
return;
}
this._connection.abortBatchRequest();
@@ -218,7 +219,6 @@ var ConnectRequestHandler = Ice.Class({
setConnection: function(connection, compress)
{
Debug.assert(this._exception === null && this._connection === null);
- Debug.assert(this._updateRequestHandler || this._requests.length === 0);
this._connection = connection;
this._compress = compress;
@@ -231,24 +231,19 @@ var ConnectRequestHandler = Ice.Class({
if(ri !== null)
{
var self = this;
- var promise = 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();
- }).exception(
- function(ex)
- {
- self.setException(ex);
- });
-
- if(!promise.completed())
- {
- return; // The request handler will be initialized once addProxy completes.
- }
+ 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);
+ });
+ return; // The request handler will be initialized once addProxy completes.
}
//
@@ -259,19 +254,21 @@ var ConnectRequestHandler = Ice.Class({
setException: function(ex)
{
Debug.assert(!this._initialized && this._exception === null);
- Debug.assert(this._updateRequestHandler || this._requests.length === 0);
this._exception = ex;
+ this._proxies.length = 0;
this._proxy = null; // Break cyclic reference count.
- //
- // If some requests were queued, we notify them of the failure.
- //
- if(this._requests.length > 0)
+ this.flushRequestsWithException(ex);
+
+ try
{
- this.flushRequestsWithException(ex);
+ this._reference.getInstance().requestHandlerFactory().removeRequestHandler(this._reference, this);
+ }
+ catch(exc)
+ {
+ // Ignore
}
-
},
initialized: function()
{
@@ -296,13 +293,6 @@ var ConnectRequestHandler = Ice.Class({
{
Debug.assert(this._connection !== null && !this._initialized);
- //
- // We set the _flushing flag to true to prevent any additional queuing. Callers
- // might block for a little while as the queued requests are being sent but this
- // shouldn't be an issue as the request sends are non-blocking.
- //
- this._flushing = true;
-
try
{
while(this._requests.length > 0)
@@ -358,27 +348,31 @@ var ConnectRequestHandler = Ice.Class({
}
}
- //
- // We've finished sending the queued requests and the request handler now send
- // the requests over the connection directly. It's time to substitute the
- // request handler of the proxy with the more efficient connection request
- // handler which does not have any synchronization. This also breaks the cyclic
- // reference count with the proxy.
- //
- // NOTE: _updateRequestHandler is immutable once _flushing = true
- //
- if(this._updateRequestHandler && this._exception === null)
+ if(this._reference.getCacheConnection() && this._exception === null)
{
- this._proxy.__setRequestHandler(this, new ConnectionRequestHandler(this._reference, this._connection,
- this._compress));
+ this._connectionRequestHandler = new ConnectionRequestHandler(this._reference,
+ this._connection,
+ this._compress);
+ for(var i in this._proxies)
+ {
+ this._proxies[i].__setRequestHandler(this, this._connectionRequestHandler);
+ }
}
Debug.assert(!this._initialized);
if(this._exception === null)
{
this._initialized = true;
- this._flushing = false;
}
+ try
+ {
+ this._reference.getInstance().requestHandlerFactory().removeRequestHandler(this._reference, this);
+ }
+ catch(exc)
+ {
+ // Ignore
+ }
+ this._proxies.length = 0;
this._proxy = null; // Break cyclic reference count.
},
flushRequestsWithException: function()
@@ -391,7 +385,7 @@ var ConnectRequestHandler = Ice.Class({
request.out.__completedEx(this._exception);
}
}
- this._requests = [];
+ this._requests.length = 0;
}
});
diff --git a/js/src/Ice/ConnectionRequestHandler.js b/js/src/Ice/ConnectionRequestHandler.js
index 914e620c040..eabfd274ec8 100644
--- a/js/src/Ice/ConnectionRequestHandler.js
+++ b/js/src/Ice/ConnectionRequestHandler.js
@@ -21,10 +21,10 @@ var ConnectionRequestHandler = Ice.Class({
this._connection = connection;
this._compress = compress;
},
- // connect : function()
- // {
- // This request handler is only created after connection binding.
- // }
+ connect : function()
+ {
+ return this;
+ },
update: function(previousHandler, newHandler)
{
try
diff --git a/js/src/Ice/Instance.js b/js/src/Ice/Instance.js
index 0ac7976d627..ab9fdbfb710 100644
--- a/js/src/Ice/Instance.js
+++ b/js/src/Ice/Instance.js
@@ -34,6 +34,7 @@ Ice.__M.require(module,
"../Ice/TcpEndpointFactory",
"../Ice/WSEndpointFactory",
"../Ice/Reference",
+ "../Ice/RequestHandlerFactory",
"../Ice/LocalException",
"../Ice/Exception",
"../Ice/ProcessLogger",
@@ -61,6 +62,7 @@ var RouterManager = Ice.RouterManager;
var Timer = Ice.Timer;
var TraceLevels = Ice.TraceLevels;
var ReferenceFactory = Ice.ReferenceFactory;
+var RequestHandlerFactory = Ice.RequestHandlerFactory;
var ACMConfig = Ice.ACMConfig;
var StateActive = 0;
@@ -84,6 +86,7 @@ var Instance = Ice.Class({
this._routerManager = null;
this._locatorManager = null;
this._referenceFactory = null;
+ this._requestHandlerFactory = null;
this._proxyFactory = null;
this._outgoingConnectionFactory = null;
this._servantFactoryManager = null;
@@ -145,6 +148,16 @@ var Instance = Ice.Class({
Debug.assert(this._referenceFactory !== null);
return this._referenceFactory;
},
+ requestHandlerFactory: function()
+ {
+ if(this._state === StateDestroyed)
+ {
+ throw new Ice.CommunicatorDestroyedException();
+ }
+
+ Debug.assert(this._requestHandlerFactory !== null);
+ return this._requestHandlerFactory;
+ },
proxyFactory: function()
{
if(this._state === StateDestroyed)
@@ -332,6 +345,8 @@ var Instance = Ice.Class({
this._referenceFactory = new ReferenceFactory(this, communicator);
+ this._requestHandlerFactory = new RequestHandlerFactory(this, communicator);
+
this._proxyFactory = new ProxyFactory(this);
this._endpointFactoryManager = new EndpointFactoryManager(this);
@@ -482,11 +497,11 @@ var Instance = Ice.Class({
self._servantFactoryManager = null;
}
- if(self._referenceFactory)
- {
- //self._referenceFactory.destroy(); // No destroy function defined.
- self._referenceFactory = null;
- }
+ //self._referenceFactory.destroy(); // No destroy function defined.
+ self._referenceFactory = null;
+
+ //self._requestHandlerFactory.destroy(); // No destroy function defined.
+ self._requestHandlerFactory = null;
// self._proxyFactory.destroy(); // No destroy function defined.
self._proxyFactory = null;
diff --git a/js/src/Ice/Makefile b/js/src/Ice/Makefile
index b9cdf2525f9..cd453b0347e 100644
--- a/js/src/Ice/Makefile
+++ b/js/src/Ice/Makefile
@@ -96,6 +96,7 @@ COMMON_SRCS = \
ProxyFactory.js \
Reference.js \
ReferenceMode.js \
+ RequestHandlerFactory.js \
RetryException.js \
RetryQueue.js \
RouterInfo.js \
diff --git a/js/src/Ice/Makefile.mak b/js/src/Ice/Makefile.mak
index 5c1138f3870..c12fa2d9e72 100644
--- a/js/src/Ice/Makefile.mak
+++ b/js/src/Ice/Makefile.mak
@@ -92,6 +92,7 @@ COMMON_SRCS = \
ProxyFactory.js \
Reference.js \
ReferenceMode.js \
+ RequestHandlerFactory.js \
RetryException.js \
RetryQueue.js \
RouterInfo.js \
diff --git a/js/src/Ice/ObjectPrx.js b/js/src/Ice/ObjectPrx.js
index 455f10bcbca..ef653e7d5a1 100644
--- a/js/src/Ice/ObjectPrx.js
+++ b/js/src/Ice/ObjectPrx.js
@@ -13,7 +13,6 @@ Ice.__M.require(module,
"../Ice/Class",
"../Ice/ArrayUtil",
"../Ice/AsyncResult",
- "../Ice/ConnectRequestHandler",
"../Ice/Debug",
"../Ice/FormatType",
"../Ice/HashMap",
@@ -29,7 +28,6 @@ Ice.__M.require(module,
var ArrayUtil = Ice.ArrayUtil;
var AsyncResultBase = Ice.AsyncResultBase;
var AsyncResult = Ice.AsyncResult;
-var ConnectRequestHandler = Ice.ConnectRequestHandler;
var Debug = Ice.Debug;
var FormatType = Ice.FormatType;
var HashMap = Ice.HashMap;
@@ -540,14 +538,14 @@ var ObjectPrx = Ice.Class({
{
return this._requestHandler;
}
- this._requestHandler = new ConnectRequestHandler(this._reference, this);
- handler = this._requestHandler;
+ handler = this._reference.getInstance().requestHandlerFactory().getRequestHandler(this._reference, this);
+ this._requestHandler = handler;
}
else
{
- handler = new ConnectRequestHandler(this._reference, this);
+ handler = this._reference.getInstance().requestHandlerFactory().getRequestHandler(this._reference, this);
}
- return handler.connect();
+ return handler.connect(this);
},
__setRequestHandler: function(previous, handler)
{
diff --git a/js/src/Ice/Operation.js b/js/src/Ice/Operation.js
index 0fc4db50335..e11f377ada1 100644
--- a/js/src/Ice/Operation.js
+++ b/js/src/Ice/Operation.js
@@ -376,7 +376,6 @@ var __dispatchImpl = function(servant, op, incomingAsync, current)
var comm = current.adapter.getCommunicator();
var msg = "servant for identity " + comm.identityToString(current.id) +
" does not define operation `" + op.servantMethod + "'";
- console.log(msg);
throw new Ice.UnknownException(msg);
}
diff --git a/js/src/Ice/Promise.js b/js/src/Ice/Promise.js
index de0a2ce2bfe..326611c0f57 100644
--- a/js/src/Ice/Promise.js
+++ b/js/src/Ice/Promise.js
@@ -142,13 +142,10 @@ var Promise = Ice.Class({
};
};
- setTimeout(
- function()
- {
- self.then(delayHandler(p, p.succeed),
- delayHandler(p, p.fail));
- });
-
+ setTimeout(function()
+ {
+ self.then(delayHandler(p, p.succeed), delayHandler(p, p.fail));
+ });
return p;
},
resolve: function()
diff --git a/js/src/Ice/RequestHandlerFactory.js b/js/src/Ice/RequestHandlerFactory.js
new file mode 100644
index 00000000000..58c63aa339b
--- /dev/null
+++ b/js/src/Ice/RequestHandlerFactory.js
@@ -0,0 +1,60 @@
+// **********************************************************************
+//
+// 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.
+//
+// **********************************************************************
+
+var Ice = require("../Ice/ModuleRegistry").Ice;
+Ice.__M.require(module,
+ [
+ "../Ice/Class",
+ "../Ice/Debug",
+ "../Ice/HashMap",
+ "../Ice/Reference",
+ "../Ice/ConnectRequestHandler"
+ ]);
+
+var Debug = Ice.Debug;
+var HashMap = Ice.HashMap;
+var ConnectRequestHandler = Ice.ConnectRequestHandler;
+
+var RequestHandlerFactory = Ice.Class({
+ __init__: function(instance)
+ {
+ this._instance = instance;
+ this._handlers = new HashMap();
+ this._handlers.keyComparator = HashMap.compareEquals;
+ },
+ getRequestHandler: function(ref, proxy)
+ {
+ if(ref.getCacheConnection())
+ {
+ var handler = this._handlers.get(ref);
+ if(handler)
+ {
+ return handler;
+ }
+ handler = new ConnectRequestHandler(ref, proxy);
+ this._handlers.set(ref, handler);
+ return handler;
+ }
+ else
+ {
+ return new ConnectRequestHandler(ref, proxy);
+ }
+ },
+ removeRequestHandler: function(ref, handler)
+ {
+ if(ref.getCacheConnection())
+ {
+ var h = this._handlers.delete(ref);
+ Debug.assert(h === handler);
+ }
+ }
+});
+
+Ice.RequestHandlerFactory = RequestHandlerFactory;
+module.exports.Ice = Ice;