-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathObservation.kerml
More file actions
161 lines (140 loc) · 4.47 KB
/
Observation.kerml
File metadata and controls
161 lines (140 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
standard library package Observation {
doc
/*
* This package models a framework for monitoring Boolean conditions and notifying
* registered observers when they change from false to true.
*/
private import ScalarValues::Boolean;
private import Occurrences::Occurrence;
private import Occurrences::Life;
private import SequenceFunctions::including;
private import SequenceFunctions::excluding;
private import ControlFunctions::select;
private import ControlPerformances::DecisionPerformance;
private import ControlPerformances::IfThenPerformance;
private import FeatureReferencingPerformances::FeatureWritePerformance;
private import FeatureReferencingPerformances::BooleanEvaluationResultToMonitorPerformance;
private import Transfers::TransferBefore;
private struct DefaultMonitorLife[1] :> ChangeMonitor, Life {
doc
/*
* DefaultMonitorLife is the classifier of the singleton Life of the defaultMonitor.
*/
}
feature defaultMonitor[1] : DefaultMonitorLife {
doc
/*
* defaultMonitor is a single ChangeMonitor that can be used as a default.
*/
}
struct ChangeSignal {
doc
/*
* A ChangeSignal is a signal to be sent when the Boolean result of its
* changeCondition Expression changes from false to true.
*/
bool signalCondition {
doc
/*
* A BooleanExpression whose result is being monitored.
*/
}
feature signalMonitor : ChangeMonitor {
doc
/*
* The ChangeMonitor responsible for monitoring the signalCondition.
*/
}
}
private behavior ObserveChange {
doc
/*
* Each Performance of ObserveChange waits for the result of the Boolean
* condition of a given ChangeSignal to change from false to true, and, when
* it does, sends the ChangeSignal to a given observer Occurrence.
*/
in feature changeObserver : Occurrence[1];
in feature changeSignal : ChangeSignal[1];
composite step wait : IfThenPerformance {
doc
/*
* If the result of the changeSignal.signalCondition is false, then wait for
* it to become true.
*/
in bool redefines ifTest {
not changeSignal.signalCondition()
}
in step redefines thenClause : BooleanEvaluationResultToMonitorPerformance {
in bool onOccurrence = changeSignal.signalCondition;
}
}
succession wait then transfer;
step transfer : TransferBefore[1]
redefines outgoingTransfersFromSelf
subsets changeObserver.incomingTransfers {
doc
/*
* Then send changeSignal to changeObserver.
*/
end feature source {
feature redefines sourceOutput = changeSignal;
}
end feature target;
}
}
struct ChangeMonitor {
doc
/*
* A ChangeMonitor is a collection of ongoing ChangeSignal observations
* for various observer Occurrences. It provides convenient operations for
* starting and canceling the observations it manages.
*/
private thisMonitor : ChangeMonitor redefines self;
private composite feature observations[0..*] : ObserveChange;
private behavior AssignObservations specializes FeatureWritePerformance {
doc
/*
* Assign a replacement set of observations as those being managed by a
* given ChangeMonitor.
*/
in feature monitor : ChangeMonitor redefines onOccurrence {
feature redefines startingAt {
feature redefines accessedFeature, observations;
}
}
inout feature redefines replacementValues[0..*] : ObserveChange;
}
step startObservation {
doc
/*
* Start an observation of a given ChangeSignal for a given Occurrence.
*/
in observer : Occurrence[1];
in signal : ChangeSignal[1];
private composite step observation : ObserveChange {
in changeObserver = observer;
in changeSignal = signal;
}
private composite step addObservation : AssignObservations[1] {
in monitor = thisMonitor;
inout replacementValues = observations->including(observation);
}
}
step cancelObservation {
doc
/*
* Cancel all observations of a given ChangeSignal for a given Occurrence.
*/
in observer : Occurrence[1];
in signal : ChangeSignal[1];
private feature observations[0..*] : ObserveChange =
observations->select{in observation : ObserveChange;
observation.changeObserver == observer and observation.changeSignal == signal
};
private composite step removeObservation : AssignObservations[1] {
in monitor = thisMonitor;
inout replacementValues = observations->excluding(observations);
}
}
}
}