@@ -50,7 +50,7 @@ public class Verb implements VerbRunner, Serializable {
50
50
51
51
private int ip = -1 ;
52
52
private String currentTarget ;
53
-
53
+
54
54
private ActionCallback cb ;
55
55
56
56
public Verb () {
@@ -75,7 +75,7 @@ public String getState() {
75
75
public void setState (String state ) {
76
76
this .state = state ;
77
77
}
78
-
78
+
79
79
public String getIcon () {
80
80
return icon ;
81
81
}
@@ -91,16 +91,16 @@ public String getTarget() {
91
91
public void setTarget (String target ) {
92
92
this .target = target ;
93
93
}
94
-
94
+
95
95
public String getHashKey () {
96
96
String key = id ;
97
-
97
+
98
98
if (target != null )
99
99
key = key + "." + target ;
100
100
101
101
if (state != null )
102
102
key = key + "." + state ;
103
-
103
+
104
104
return key ;
105
105
}
106
106
@@ -111,22 +111,22 @@ public void add(Action a) {
111
111
public ArrayList <Action > getActions () {
112
112
return actions ;
113
113
}
114
-
114
+
115
115
public String getCurrentTarget () {
116
116
return currentTarget ;
117
117
}
118
118
119
119
public void run (String currentTarget , ActionCallback cb ) {
120
120
this .currentTarget = currentTarget ;
121
121
this .cb = cb ;
122
-
122
+
123
123
if (EngineLogger .debugMode ()) {
124
124
StringBuilder sb = new StringBuilder (">>> Running verb: " ).append (id );
125
-
126
- if (currentTarget != null ) {
125
+
126
+ if (currentTarget != null ) {
127
127
sb .append (" currentTarget: " + currentTarget );
128
128
}
129
-
129
+
130
130
EngineLogger .debug (sb .toString ());
131
131
}
132
132
@@ -150,16 +150,21 @@ public void nextStep() {
150
150
else
151
151
ip ++;
152
152
} catch (Exception e ) {
153
- EngineLogger .error ("EXCEPTION EXECUTING ACTION: " + a .getClass ().getSimpleName () + " - " + e .getMessage (), e );
153
+ EngineLogger .error (
154
+ "EXCEPTION EXECUTING ACTION: " + a .getClass ().getSimpleName () + " - " + e .getMessage (), e );
154
155
ip ++;
155
156
}
156
157
}
157
158
158
159
if (ip == actions .size ()) {
159
160
EngineLogger .debug (">>> Verb FINISHED: " + id );
160
-
161
- if (cb != null )
162
- cb .resume ();
161
+
162
+ if (cb != null ) {
163
+ ActionCallback cb2 = cb ;
164
+ cb = null ;
165
+
166
+ cb2 .resume ();
167
+ }
163
168
}
164
169
}
165
170
@@ -182,34 +187,38 @@ public void setIP(int ip) {
182
187
}
183
188
184
189
public void cancel () {
190
+ ip = actions .size () + 1 ;
191
+
185
192
for (Action c : actions ) {
186
193
if (c instanceof VerbRunner )
187
194
((VerbRunner ) c ).cancel ();
188
195
}
189
196
190
- ip = actions .size () + 1 ;
191
-
197
+ if (cb != null ) {
198
+ ActionCallback cb2 = cb ;
199
+ cb = null ;
200
+
201
+ cb2 .resume ();
202
+ }
203
+
192
204
EngineLogger .debug (">>> Verb CANCELLED: " + id );
193
-
194
- if (cb != null )
195
- cb .resume ();
196
205
}
197
206
198
207
@ Override
199
208
public void write (Json json ) {
200
209
201
210
if (SerializationHelper .getInstance ().getMode () == Mode .MODEL ) {
202
211
json .writeValue ("id" , id );
203
-
204
- if (target != null )
212
+
213
+ if (target != null )
205
214
json .writeValue ("target" , target );
206
-
207
- if (state != null )
215
+
216
+ if (state != null )
208
217
json .writeValue ("state" , state );
209
-
210
- if (icon != null )
218
+
219
+ if (icon != null )
211
220
json .writeValue ("icon" , icon );
212
-
221
+
213
222
json .writeArrayStart ("actions" );
214
223
for (Action a : actions ) {
215
224
ActionUtils .writeJson (a , json );
@@ -218,8 +227,8 @@ public void write(Json json) {
218
227
} else {
219
228
json .writeValue ("ip" , ip );
220
229
json .writeValue ("cb" , ActionCallbackSerialization .find (cb ));
221
-
222
- if (currentTarget != null )
230
+
231
+ if (currentTarget != null )
223
232
json .writeValue ("currentTarget" , currentTarget );
224
233
225
234
json .writeArrayStart ("actions" );
@@ -239,27 +248,27 @@ public void read(Json json, JsonValue jsonData) {
239
248
240
249
if (SerializationHelper .getInstance ().getMode () == Mode .MODEL ) {
241
250
id = json .readValue ("id" , String .class , jsonData );
242
- target = json .readValue ("target" , String .class , (String )null , jsonData );
243
- state = json .readValue ("state" , String .class , (String )null , jsonData );
244
- icon = json .readValue ("icon" , String .class , (String )null , jsonData );
245
-
251
+ target = json .readValue ("target" , String .class , (String ) null , jsonData );
252
+ state = json .readValue ("state" , String .class , (String ) null , jsonData );
253
+ icon = json .readValue ("icon" , String .class , (String ) null , jsonData );
254
+
246
255
actions .clear ();
247
256
JsonValue actionsValue = jsonData .get ("actions" );
248
257
for (int i = 0 ; i < actionsValue .size ; i ++) {
249
258
JsonValue aValue = actionsValue .get (i );
250
259
String clazz = aValue .getString ("class" );
251
260
252
- try {
261
+ try {
253
262
Action a = ActionUtils .readJson (json , aValue );
254
263
actions .add (a );
255
- } catch (SerializationException e ) {
264
+ } catch (SerializationException e ) {
256
265
EngineLogger .error ("Error loading action: " + clazz + " " + aValue .toString ());
257
266
throw e ;
258
267
}
259
268
}
260
269
} else {
261
270
// MUTABLE
262
- currentTarget = json .readValue ("currentTarget" , String .class , (String )null , jsonData );
271
+ currentTarget = json .readValue ("currentTarget" , String .class , (String ) null , jsonData );
263
272
ip = json .readValue ("ip" , Integer .class , jsonData );
264
273
String sCb = json .readValue ("cb" , String .class , jsonData );
265
274
cb = ActionCallbackSerialization .find (sCb );
@@ -270,9 +279,9 @@ public void read(Json json, JsonValue jsonData) {
270
279
271
280
for (Action a : actions ) {
272
281
if (a instanceof Serializable && i < actionsValue .size ) {
273
- if (actionsValue .get (i ) == null )
282
+ if (actionsValue .get (i ) == null )
274
283
break ;
275
-
284
+
276
285
((Serializable ) a ).read (json , actionsValue .get (i ));
277
286
i ++;
278
287
}
0 commit comments