Skip to content
Browse files

Issue #77. Pass session instance to listener and allow it to destroy …

…the session when exceptions are thrown.
  • Loading branch information...
1 parent 959866f commit a096bc8a8d2f850a412f12af9d6cd4998e40b54c @rbackhouse rbackhouse committed
Showing with 18 additions and 3 deletions.
  1. +17 −3 js/lib/coweb/listener/UnmanagedHubListener.js
  2. +1 −0 js/lib/coweb/main.js
View
20 js/lib/coweb/listener/UnmanagedHubListener.js
@@ -52,6 +52,15 @@ define([
var proto = UnmanagedHubListener.prototype;
/**
+ * Stores session instance.
+ *
+ * @param {Object} session Session Instance
+ */
+ proto.init = function(session) {
+ this._session = session;
+ };
+
+ /**
* Starts listening for cooperative events on the OpenAjax Hub to forward
* to the session.
*
@@ -221,6 +230,7 @@ define([
console.warn('UnmanagedHubListener: failed to push op into engine ' +
e.message);
// @todo: we're out of sync now probably, fail the session?
+ this._session.destroy();
return;
}
// discard null operations; they should not be sent to app
@@ -329,6 +339,7 @@ define([
// case this site is the only one in the session for now
this._shouldPurge = true;
} else if(err) {
+ this._session.destroy();
// throw error back to the caller
throw err;
}
@@ -359,7 +370,8 @@ define([
} catch(e) {
console.warn('UnmanagedHubListener: failed to thaw site ' +
event.site + ' ' + e.message);
- // @todo: op engine died, exit session?
+ this._session.destroy();
+ return;
}
} else if(type === 'unavailable') {
// leaving user
@@ -371,7 +383,8 @@ define([
} catch(x) {
console.warn('UnmanagedHubListener: failed to freeze site ' +
event.site + ' ' + x.message);
- // @todo: op engine died, exit session?
+ this._session.destroy();
+ return;
}
}
@@ -613,7 +626,7 @@ define([
} catch(e) {
console.warn('UnmanagedHubListener: failed to recv engine state ' +
e.message);
- // @todo: engine dead, should exit session
+ this._session.destroy();
throw e;
}
} else {
@@ -626,6 +639,7 @@ define([
} catch(x) {
console.warn('UnmanagedHubListener: failed to recv state ' +
x.message);
+ this._session.destroy();
throw x;
} finally {
this._mutex = false;
View
1 js/lib/coweb/main.js
@@ -62,6 +62,7 @@ define([
sessionInst = ConfigInitializer.sessionImpl ? new ConfigInitializer.sessionImpl() : new SessionImpl();
// create the listener instance
listenerInst = ConfigInitializer.listenerImpl ? new ConfigInitializer.listenerImpl() : new ListenerImpl();
+ listenerInst.init(sessionInst);
// initialize the session
sessionInst.init(cowebConfig, listenerInst);
return sessionInst;

0 comments on commit a096bc8

Please sign in to comment.
Something went wrong with that request. Please try again.