You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ea...@apache.org on 2017/12/07 15:21:44 UTC
[3/3] qpid-dispatch git commit: DISPATCH-896 Use promises to connect
DISPATCH-896 Use promises to connect
Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/c1684609
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/c1684609
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/c1684609
Branch: refs/heads/master
Commit: c1684609659eeb2872ef6056388c48e01c572629
Parents: fd94858
Author: Ernest Allen <ea...@redhat.com>
Authored: Thu Dec 7 10:21:21 2017 -0500
Committer: Ernest Allen <ea...@redhat.com>
Committed: Thu Dec 7 10:21:21 2017 -0500
----------------------------------------------------------------------
console/stand-alone/plugin/js/dispatchPlugin.js | 57 +++++---------------
console/stand-alone/plugin/js/qdrService.js | 55 +++++++++++++++++++
console/stand-alone/plugin/js/qdrSettings.js | 49 ++++-------------
3 files changed, 78 insertions(+), 83 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/c1684609/console/stand-alone/plugin/js/dispatchPlugin.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/dispatchPlugin.js b/console/stand-alone/plugin/js/dispatchPlugin.js
index 4a07e78..d897425 100644
--- a/console/stand-alone/plugin/js/dispatchPlugin.js
+++ b/console/stand-alone/plugin/js/dispatchPlugin.js
@@ -174,7 +174,7 @@ var QDR = (function(QDR) {
// of our module
QDR.module.run( ["$rootScope", '$route', '$timeout', "$location", "$log", "QDRService", "QDRChartService", function ($rootScope, $route, $timeout, $location, $log, QDRService, QDRChartService) {
QDR.log = new QDR.logger($log);
- QDR.log.info("*************creating Dispatch Console************");
+ QDR.log.info("************* creating Dispatch Console ************");
var curPath = $location.path()
var org = curPath.substr(1)
if (org && org.length > 0 && org !== "connect") {
@@ -188,7 +188,6 @@ var QDR = (function(QDR) {
QDRService.management.topology.delUpdatedAction("initChartService")
QDRChartService.init(); // initialize charting service after we are connected
});
- var settings = angular.fromJson(localStorage[QDR.SETTINGS_KEY]) || {autostart: false, address: 'localhost', port: 5673}
if (!QDRService.management.connection.is_connected()) {
// attempt to connect to the host:port that served this page
var protocol = $location.protocol()
@@ -200,51 +199,23 @@ var QDR = (function(QDR) {
$location.search("org", "overview")
}
var connectOptions = {address: host, port: port}
- QDRService.management.connection.testConnect(connectOptions, function (e) {
- if (e.error) {
- QDR.log.debug("failed to auto-connect to " + host + ":" + port)
- QDR.log.debug("redirecting to connect page")
- // the connect page should rneder
+ QDR.log.info("Attempting AMQP over websockets connection using address:port of browser ("+host+':'+port+")")
+ QDRService.management.connection.testConnect(connectOptions)
+ .then( function (r) {
+ QDRService.disconnect()
+ QDR.log.info("Connect succeeded. Using address:port of browser")
+ connectOptions.reconnect = true
+ // complete the connection (create the sender/receiver)
+ QDRService.connect(connectOptions) // since the testConnect succeeded, we don't need to handle the success/failure return of the promise
+ }, function (e) {
+ QDR.log.info("failed to auto-connect to " + host + ":" + port)
+ QDR.log.info("redirecting to connect page")
$timeout(function () {
$location.path('/connect')
$location.search('org', org)
+ $location.replace()
})
- } else {
- QDR.log.info("Connect succeeded. Using address:port of browser")
- // register an onConnect event handler
- QDRService.management.connection.addConnectAction( function () {
- QDRService.management.getSchema(function () {
- QDR.log.debug("got schema after connection")
- QDRService.management.topology.addUpdatedAction("initialized", function () {
- QDRService.management.topology.delUpdatedAction("initialized")
- QDR.log.debug("got initial topology")
- $timeout(function() {
- if (org === '' || org === 'connect') {
- org = localStorage[QDR.LAST_LOCATION] || "/overview"
- if (org === '/')
- org = "/overview"
- } else {
- if (org && $location.path() !== '/connect') {
- org = $location.path().substr(1)
- }
- }
- $location.path(org)
- $location.search('org', null)
- $location.replace()
- })
- })
- QDR.log.info("requesting a topology")
- QDRService.management.topology.setUpdateEntities([])
- QDRService.management.topology.get() // gets the list of routers
- })
- })
- $timeout( function () {
- // complete the connection (create the sender/receiver)
- connectOptions.reconnect = true
- QDRService.management.connection.connect(connectOptions)
- })
- }
- })
+ })
}
$rootScope.$on('$routeChangeSuccess', function(event, next, current) {
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/c1684609/console/stand-alone/plugin/js/qdrService.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/qdrService.js b/console/stand-alone/plugin/js/qdrService.js
index a2dd335..d49a4e1 100644
--- a/console/stand-alone/plugin/js/qdrService.js
+++ b/console/stand-alone/plugin/js/qdrService.js
@@ -28,7 +28,17 @@ var QDR = (function(QDR) {
management: new dm.Management($location.protocol()),
utilities: dm.Utilities,
+ onReconnect: function () {
+ self.management.connection.on('disconnected', self.onDisconnect)
+ var org = localStorage[QDR.LAST_LOCATION] || "/overview"
+ $timeout ( function () {
+ $location.path(org)
+ $location.search('org', null)
+ $location.replace()
+ })
+ },
onDisconnect: function () {
+ self.management.connection.on('connected', self.onReconnect)
$timeout( function () {
$location.path('/connect')
var curPath = $location.path()
@@ -38,9 +48,54 @@ var QDR = (function(QDR) {
} else {
$location.search('org', null)
}
+ $location.replace()
})
+ },
+
+ connect: function (connectOptions) {
+ return new Promise ( function (resolve, reject) {
+ self.management.connection.connect(connectOptions)
+ .then( function (r) {
+ // if we are ever disconnected, show the connect page and wait for a reconnect
+ self.management.connection.on('disconnected', self.onDisconnect)
+
+ self.management.getSchema()
+ .then( function (schema) {
+ QDR.log.info("got schema after connection")
+ self.management.topology.setUpdateEntities([])
+ QDR.log.info("requesting a topology")
+ self.management.topology.get() // gets the list of routers
+ .then( function () {
+ QDR.log.info("got initial topology")
+ var curPath = $location.path()
+ var org = curPath.substr(1)
+ if (org === '' || org === 'connect') {
+ org = localStorage[QDR.LAST_LOCATION] || "/overview"
+ } else {
+ if (org && $location.path() !== '/connect') {
+ org = $location.path().substr(1)
+ }
+ }
+ $timeout ( function () {
+ $location.path(org)
+ $location.search('org', null)
+ $location.replace()
+ })
+ })
+ })
+ resolve(r)
+ }, function (e) {
+ reject(e)
+ })
+ })
+ },
+ disconnect: function () {
+ self.management.connection.disconnect();
+ delete self.management
+ self.management = new dm.Management($location.protocol())
}
+
}
return self;
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/c1684609/console/stand-alone/plugin/js/qdrSettings.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/qdrSettings.js b/console/stand-alone/plugin/js/qdrSettings.js
index 746e296..3edaffc 100644
--- a/console/stand-alone/plugin/js/qdrSettings.js
+++ b/console/stand-alone/plugin/js/qdrSettings.js
@@ -61,7 +61,7 @@ var QDR = (function(QDR) {
$scope.connect = function() {
if (QDRService.management.connection.is_connected()) {
$timeout( function () {
- QDRService.management.connection.disconnect();
+ QDRService.disconnect()
})
return;
}
@@ -83,51 +83,20 @@ var QDR = (function(QDR) {
if (!$scope.formEntity.port)
$scope.formEntity.port = 5673
- var failed = function() {
- QDR.log.info("disconnect action called");
+ var failed = function(e) {
$timeout(function() {
$scope.connecting = false;
$scope.connectionErrorText = "Unable to connect to " + $scope.formEntity.address + ":" + $scope.formEntity.port
$scope.connectionError = true
})
}
- var options = {address: $scope.formEntity.address, port: $scope.formEntity.port}
- QDRService.management.connection.testConnect(options, function (e) {
- if (e.error) {
- failed()
- } else {
- QDR.log.info("test connect from connect page succeeded")
- QDRService.management.connection.addConnectAction(function() {
- QDR.log.info("real connect from connect page succeeded")
- // get notified if at any time the connection fails
- QDRService.management.connection.addDisconnectAction(QDRService.onDisconnect);
- QDRService.management.getSchema(function () {
- QDR.log.info("got schema after connection")
- QDRService.management.topology.addUpdatedAction("initialized", function () {
- QDRService.management.topology.delUpdatedAction("initialized")
- QDR.log.info("got initial topology")
- $timeout(function() {
- $scope.connecting = false;
- if ($location.path().startsWith(QDR.pluginRoot)) {
- var searchObject = $location.search();
- var goto = "overview";
- if (searchObject.org && searchObject.org !== "connect") {
- goto = searchObject.org;
- }
- $location.search('org', null)
- $location.path(QDR.pluginRoot + "/" + goto);
- }
- })
- })
- QDR.log.info("requesting a topology")
- QDRService.management.topology.setUpdateEntities([])
- QDRService.management.topology.get()
- })
- });
- options.reconnect = true
- QDRService.management.connection.connect(options)
- }
- })
+ var options = {address: $scope.formEntity.address, port: $scope.formEntity.port, reconnect: true}
+ QDRService.connect(options)
+ .then( function (r) {
+ // will have redirected to last known page or /overview
+ }, function (e) {
+ failed(e)
+ })
}
}]);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org