From 8ae2c89490164fd0a831eae597372c3bc2150f52 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 1 May 2012 15:39:06 -0400 Subject: [PATCH] Better reconnect logic. --- web/about.html | 15 +++++-- web/bootstrap/template.xsl | 5 ++- web/bootstrap/templates/about.xml | 6 +++ web/index.html | 10 +++-- web/index.js | 72 ++++++++++++++++++------------- web/nodes.html | 10 +++-- web/nodes.js | 1 - web/ocamlmsg.js | 27 +++++++++--- 8 files changed, 96 insertions(+), 50 deletions(-) diff --git a/web/about.html b/web/about.html index 09f3770..7141d6c 100644 --- a/web/about.html +++ b/web/about.html @@ -17,13 +17,15 @@ @@ -65,6 +65,7 @@ + diff --git a/web/bootstrap/templates/about.xml b/web/bootstrap/templates/about.xml index fbe9007..4999291 100644 --- a/web/bootstrap/templates/about.xml +++ b/web/bootstrap/templates/about.xml @@ -7,6 +7,12 @@ Ocamlmsg is a prototype of a sensible recursive message broker.

+

Homepage

+

+ The project is currently hosted on github at http://github.com/tonyg/ocamlmsg/. +

+

Copyright & Licence

Ocamlmsg is Copyright (C) 2012 Tony Garnock-Jones. diff --git a/web/index.html b/web/index.html index dd296a8..7f3b82a 100644 --- a/web/index.html +++ b/web/index.html @@ -17,13 +17,15 @@

- + diff --git a/web/nodes.js b/web/nodes.js index 4136c3f..47e578f 100644 --- a/web/nodes.js +++ b/web/nodes.js @@ -27,5 +27,4 @@ function refresh_node_list() { function nodes_main() { Ocamlmsg.$open_hooks.push(refresh_node_list); - Ocamlmsg.install_tap({}); } diff --git a/web/ocamlmsg.js b/web/ocamlmsg.js index ab2dbe0..5fadf7b 100644 --- a/web/ocamlmsg.js +++ b/web/ocamlmsg.js @@ -3,12 +3,17 @@ var Ocamlmsg = { $args: null, $open_hooks: [], + $message_hooks: [], $close_hooks: [], run_open_hooks: function (event, stream) { $.each(Ocamlmsg.$open_hooks, function (i, f) { f(event, stream); }); }, + run_message_hooks: function (event, stream) { + $.each(Ocamlmsg.$message_hooks, function (i, f) { f(event, stream); }); + }, + run_close_hooks: function (event, stream) { $.each(Ocamlmsg.$close_hooks, function (i, f) { f(event, stream); }); }, @@ -67,21 +72,33 @@ var Ocamlmsg = { Ocamlmsg._send(Ocamlmsg._create(classname, arg, reply_name, factory)); }, - install_tap: function (args) { - Ocamlmsg.$args = args; + _install_tap: function () { Ocamlmsg.$tap = $.stream("/_/tap", { type: "http", dataType: "json", enableXDR: true, open: Ocamlmsg.run_open_hooks, - message: args.message, + message: Ocamlmsg.run_message_hooks, error: Ocamlmsg.run_close_hooks, close: Ocamlmsg.run_close_hooks }); }, - force_reinstall: function () { - Ocamlmsg.install_tap(Ocamlmsg.$args); + install_tap: function (args) { + Ocamlmsg.$args = args; + Ocamlmsg._install_tap(); + setInterval(Ocamlmsg.check_connectivity, 5000); + }, + + check_connectivity: function () { + switch (Ocamlmsg.$tap.readyState) { + case 0: // connecting + case 1: // open + case 2: // closing + break; + case 3: // closed + Ocamlmsg._install_tap(); + } } }