I all I have a few accumulated changes that I've made to the js client that I wanted to share with the community:
1) First is, when I was debugging some memory leaks in ie6 I found it really helpful to set the http_max_spare parameter to zero. This linearize the calls and look at one xmlrpc object at a time. Here's the line I changed to do this:
JSONRpcClient.http_max_spare = 0; // changing the pool size to 0.
2) Session timeouts were a problem we struggled with. We decided to handle them this way in json-rpc-java
JSONRpcClient.toplevel_ex_handler = function (ex) {
if(ex instanceof JSONRpcClient.Exception)
{
// assuming this is because of a session timeout. navigate to current location,
// and the auth filter should let them log in and get back to whatever page we're on.
if(ex.code == 550) //550 happens when the session has timed out
{
setTimeout(function () {navigate(document.location)}, 300);
return;
}
}
if(ex)
throw ex.message.substring(ex.name.length + 2); //ideally this would throw a complex exception object
else
throw "Error making rpc request to server";
};
3) In our templated pages its possible that we need an instance of the js rpc client in many unrelated templates. We didn't want to have to instantiate separate
JSONRpcClient objects and make a separate getMethods call back to the server for each template so we used the js singleton patter to solve it this way:
var RpcClient = function()
{
var instance = null;
return function()
{
if(instance == null)
instance = new JSONRpcClient(CONTEXT_PATH + "/RPC", null, null, null);
return instance;
};
}(); //<---- The outer function gets evaluated here, so all new's refer to the same var instance.
Now we can just make new RpcClients where ever we like and they will always return the same instance:
var a = new RpcClient();
var b = new RpcClient();
if(a !== b) throw "Oh noes! Not same instance"
This code will run without a problem. Also, this has the nice side benefit of encapsulating our remote RPC URL inside the RpcClient constructor so it can be changed easily in one location.
I hope some or all of these are helpful.
All the best,
Evan Leonard