Add distibuted action

- New module spring-statemachine-cluster which is
  based on spring-cloud-cluster to provide leader
  election.
- Ensemble now has a concept of a leader if implementation
  supports it.
- New DistributedLeaderAction can use leader info to execute
  action only on a leader.
- Tweak web sample with these new concepts.
- Fixes #176
This commit is contained in:
Janne Valkealahti
2016-03-28 10:44:48 +01:00
parent 89d183f91c
commit 6cce27e30b
23 changed files with 951 additions and 123 deletions

View File

@@ -1,44 +1,44 @@
+----------------------------------------------------------------------------------------------+
| S0 |
+----------------------------------------------------------------------------------------------+
| entry/ |
| exit/ |
| H/[foo.equals(0)]; |
| |
| +-------------------------+ +--------------------------------------------+ |
| *-->| S1 | | S2 | |
| +-------------------------+ +--------------------------------------------+ |
| | entry/ | C | entry/ | |
| D | exit/ |----->| exit/ | |
|<-----------| H/ | | H/[foo.equals(1)]; | |
| | | | | |
| | +---------------+ | K | +------------------------------+ | |
| | *-->| S11 | |<-----| *-->| S21 | | |
| | +---------------+ | | +------------------------------+ | |
| | | entry/ | | F | | entry/ | | |
| | | exit/ |<---------| | exit/ | | |
| | | | | | | +--------------+ | | |
| | B | | | | | *-->| s211 | | | |
| |---->| J | | | F | +--------------+ G | | |
| | | +-------+ | |-------------------->| entry/ |----------------->|
| | +--| | | | | | G | | exit/ | | | |
| | | | | v |------------------------>| | | E | |
| | | +---------------+ | | | B | |<-----------------|
| | | | | |------>| | | | |
| | | +---------------+ | | | | | D | | |
| | I| | S12 | | | | +--| |------>| | |
| | | +---------------+ | | | | +--------------+ | | |
| | | | entry/ | | | | | | | |
| | | | exit/ | | | | I| +--------------+ | | |
| | | | | | | | | | s212 | | | |
| | +->| | | | | | +--------------+ | | |
| +--| | | | | | +->| entry/ | | | |
| | | | | | I | | | exit/ | | | |
| | | | |------------------------>| | | | |
| A| | | | | | | +--------------+ | | |
| | | | | | | | | | |
| | | +---------------+ | | +------------------------------+ | |
| +->| | | | |
| +-------------------------+ +--------------------------------------------+ |
| A[foo.equals(1)]; |
+----------------------------------------------------------------------------------------------+
+-----------------------------------------------------------------------------------------------+
| S0 |
+-----------------------------------------------------------------------------------------------+
| entry/ |
| exit/ |
| H/[foo.equals(0)]; |
| |
| +--------------------------+ +--------------------------------------------+ |
| *-->| S1 | | S2 | |
| +--------------------------+ +--------------------------------------------+ |
| | entry/ | C | entry/ | |
| D | exit/ |----->| exit/ | |
|<-----------| H/ | | H/[foo.equals(1)]; | |
| | | | | |
| | +----------------+ | K | +------------------------------+ | |
| | *-->| S11 | |<-----| *-->| S21 | | |
| | +----------------+ | | +------------------------------+ | |
| | | entry/ | | F | | entry/ | | |
| | | exit/ |<---------| | exit/ | | |
| | | | | | | +--------------+ | | |
| | B | | | | | *-->| s211 | | | |
| |---->| J | | | F | +--------------+ G | | |
| | | +-------+ | |-------------------->| entry/ |----------------->|
| | +--| | | | | | G | | exit/ | | | |
| | | | | v |------------------------>| | | E | |
| | | +----------------+ | | | B | |<-----------------|
| | | | | |------>| | | | |
| | | +----------------+ | | | | | D | | |
| | I| | S12 | | | | +--| |------>| | |
| | | +----------------+ | | | | +--------------+ | | |
| | | | entry/ | | | | | | | |
| | | | distAction() | | | | I| +--------------+ | | |
| | | | exit/ | | | | | | s212 | | | |
| | +->| | | | | | +--------------+ | | |
| +--| | | | | | +->| entry/ | | | |
| | | | | | I | | | exit/ | | | |
| | | | |------------------------>| | | | |
| A| | | | | | | +--------------+ | | |
| | | | | | | | | | |
| | | +----------------+ | | +------------------------------+ | |
| +->| | | | |
| +--------------------------+ +--------------------------------------------+ |
| A[foo.equals(1)]; |
+-----------------------------------------------------------------------------------------------+

View File

@@ -1,15 +1,15 @@
<!DOCTYPE html>
<html lang="en" ng-app="springChat">
<head>
<meta charset="utf-8" />
<title>Spring Statemachine Zookeeper Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8" />
<title>Spring Statemachine Zookeeper Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="lib/flat-ui/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
<link href="lib/flat-ui/dist/css/flat-ui.css" rel="stylesheet">
<link href="lib/angularjs-toaster/toaster.css" rel="stylesheet">
<link href="lib/flat-ui/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
<link href="lib/flat-ui/dist/css/flat-ui.css" rel="stylesheet">
<link href="lib/angularjs-toaster/toaster.css" rel="stylesheet">
<link href="css/chat.css" rel="stylesheet">
<link href="css/chat.css" rel="stylesheet">
</head>
<body>
@@ -23,18 +23,18 @@
</nav>
</div>
<div class="row">
<div>
<button ng-click="sendEvent('A')">event A</button>
<button ng-click="sendEvent('B')">event B</button>
<button ng-click="sendEvent('C')">event C</button>
<button ng-click="sendEvent('D')">event D</button>
<button ng-click="sendEvent('E')">event E</button>
<button ng-click="sendEvent('F')">event F</button>
<button ng-click="sendEvent('G')">event G</button>
<button ng-click="sendEvent('H')">event H</button>
<button ng-click="sendEvent('I')">event I</button>
<button ng-click="sendEvent('K')">event K</button>
</div>
<div>
<button ng-click="sendEvent('A')">event A</button>
<button ng-click="sendEvent('B')">event B</button>
<button ng-click="sendEvent('C')">event C</button>
<button ng-click="sendEvent('D')">event D</button>
<button ng-click="sendEvent('E')">event E</button>
<button ng-click="sendEvent('F')">event F</button>
<button ng-click="sendEvent('G')">event G</button>
<button ng-click="sendEvent('H')">event H</button>
<button ng-click="sendEvent('I')">event I</button>
<button ng-click="sendEvent('K')">event K</button>
</div>
</div>
<div class="row">
<div>
@@ -42,44 +42,53 @@
<input id="newTestVariable" type="text" ng-model="testVariable" placeholder="New testVariable value..." />
</div>
</div>
<div class="row">
<div class="col-xs-3">
<h4>States</h4>
<div class="share">
<ul ng-repeat="participant in participants">
<li>
<div>{{participant.message}}</div>
</li>
</ul>
</div>
</div>
<div class="col-xs-3">
<h4>Variables</h4>
<div class="share">
<ul ng-repeat="variable in variables">
<li>
<div>{{variable}}</div>
</li>
</ul>
</div>
</div>
<div class="col-xs-8 chat-box">
<h4>Messages</h4>
<div ng-repeat="message in messages">
<small print-message></small>
</div>
</div>
</div>
</div>
<!-- /.container -->
<div class="row">
<div>
<button ng-click="joinEnsemble()">Join</button>
<button ng-click="leaveEnsemble()">Leave</button>
</div>
</div>
<div class="row">
<div ng-if="uuid">UUID: {{uuid}}</div>
</div>
<div class="row">
<div class="col-xs-3">
<h4>States</h4>
<div class="share">
<ul ng-repeat="participant in participants">
<li>
<div>{{participant.message}}</div>
</li>
</ul>
</div>
</div>
<div class="col-xs-3">
<h4>Variables</h4>
<div class="share">
<ul ng-repeat="variable in variables">
<li>
<div>{{variable}}</div>
</li>
</ul>
</div>
</div>
<div class="col-xs-8 chat-box">
<h4>Messages</h4>
<div ng-repeat="message in messages">
<small print-message></small>
</div>
</div>
</div>
</div>
<!-- /.container -->
<!-- 3rd party -->
<script src="lib/angular/angular.min.js"></script>
<script src="lib/angular-animate/angular-animate.min.js"></script>
<script src="lib/angularjs-toaster/toaster.js"></script>
<script src="lib/angularjs-scroll-glue/src/scrollglue.js"></script>
<script src="lib/sockjs/sockjs.min.js"></script>
<script src="lib/stomp/lib/stomp.min.js"></script>
<script src="lib/angular-animate/angular-animate.min.js"></script>
<script src="lib/angularjs-toaster/toaster.js"></script>
<script src="lib/angularjs-scroll-glue/src/scrollglue.js"></script>
<script src="lib/sockjs/sockjs.min.js"></script>
<script src="lib/stomp/lib/stomp.min.js"></script>
<!-- App -->
<script src="js/app.js"></script>

View File

@@ -7,10 +7,11 @@ angular.module('springChat.controllers', ['toaster'])
var typing = undefined;
$scope.uuid = '';
$scope.participants = [];
$scope.variables = [];
$scope.messages = [];
$scope.newMessage = '';
$scope.messages = [];
$scope.newMessage = '';
$scope.sendEvent = function(event) {
$http.post('/event', null, {params:{"id": event}}).
@@ -24,11 +25,27 @@ angular.module('springChat.controllers', ['toaster'])
});
};
$scope.joinEnsemble = function(event) {
$http.post('/join', null, {}).
success(function(data) {
});
};
$scope.leaveEnsemble = function(event) {
$http.post('/leave', null, {}).
success(function(data) {
});
};
var initStompClient = function() {
chatSocket.init('/ws');
chatSocket.connect(function(frame) {
chatSocket.subscribe("/app/sm.uuid", function(message) {
$scope.uuid = message.body;
});
chatSocket.subscribe("/app/sm.states", function(message) {
$scope.participants = JSON.parse(message.body);
});
@@ -55,16 +72,16 @@ angular.module('springChat.controllers', ['toaster'])
chatSocket.subscribe("/topic/sm.message", function(message) {
$scope.messages.unshift(JSON.parse(message.body));
});
});
chatSocket.subscribe("/user/queue/errors", function(message) {
toaster.pop('error', "Error", message.body);
});
});
}, function(error) {
toaster.pop('error', 'Error', 'Connection error ' + error);
});
});
};
initStompClient();