41
41
*/
42
42
public class RiverState implements Streamable , ToXContent , Comparable <RiverState > {
43
43
44
- private final static DateTime EMPTY_DATETIME = new DateTime (0L );
45
-
46
44
/**
47
45
* The name of the river instance
48
46
*/
@@ -61,12 +59,12 @@ public class RiverState implements Streamable, ToXContent, Comparable<RiverState
61
59
/*
62
60
* The time of the last river activity
63
61
*/
64
- private DateTime begin ;
62
+ private DateTime lastActiveBegin ;
65
63
66
64
/*
67
65
* The time when the last river activity ended
68
66
*/
69
- private DateTime end ;
67
+ private DateTime lastActiveEnd ;
70
68
71
69
/**
72
70
* A custom map for more information about the river
@@ -120,43 +118,23 @@ public DateTime getStarted() {
120
118
* @return this state
121
119
*/
122
120
public RiverState setLastActive (DateTime begin , DateTime end ) {
123
- if (begin != null ) {
124
- this .begin = begin ;
125
- }
126
- if (end != null ) {
127
- this .end = end ;
128
- }
121
+ this .lastActiveBegin = begin ;
122
+ this .lastActiveEnd = end ;
129
123
return this ;
130
124
}
131
125
132
126
/**
133
127
* @return the begin of the last river activity
134
128
*/
135
129
public DateTime getLastActiveBegin () {
136
- return begin != null ? begin : EMPTY_DATETIME ;
130
+ return lastActiveBegin ;
137
131
}
138
132
139
133
/**
140
134
* @return the end of the last river activity
141
135
*/
142
136
public DateTime getLastActiveEnd () {
143
- return end != null ? end : EMPTY_DATETIME ;
144
- }
145
-
146
- /**
147
- * Was the river active at a certain time? Only the last activity can be checked.
148
- *
149
- * @param instant the time to check
150
- * @return true if river was active, false if not
151
- */
152
- public boolean wasActiveAt (DateTime instant ) {
153
- return instant != null
154
- && begin != null && begin .getMillis () != 0L && begin .isBefore (instant )
155
- && (end == null || end .getMillis () == 0L || end .isAfter (instant ));
156
- }
157
-
158
- public boolean wasInactiveAt (DateTime instant ) {
159
- return !wasActiveAt (instant );
137
+ return lastActiveEnd ;
160
138
}
161
139
162
140
public RiverState setCounter (Integer counter ) {
@@ -178,19 +156,51 @@ public Map<String, Object> getCustom() {
178
156
return (Map <String , Object >) this .map .get ("custom" );
179
157
}
180
158
181
- public boolean isAborted () {
182
- return map .containsKey ("aborted" ) ? (Boolean ) map .get ("aborted" ) : false ;
183
- }
184
-
185
159
public boolean isSuspended () {
186
160
return map .containsKey ("suspended" ) ? (Boolean ) map .get ("suspended" ) : false ;
187
161
}
188
162
163
+ public RiverState setLastStartDate (long lastStartDate ) {
164
+ this .map .put ("lastStartDate" , lastStartDate );
165
+ return this ;
166
+ }
167
+
168
+ public long getLastStartDate () {
169
+ return (long )this .map .get ("lastStartDate" );
170
+ }
171
+
172
+ public RiverState setLastEndDate (long lastEndDate ) {
173
+ this .map .put ("lastEndDate" , lastEndDate );
174
+ return this ;
175
+ }
176
+
177
+ public long getLastEndDate () {
178
+ return (long )this .map .get ("lastEndDate" );
179
+ }
180
+
181
+ public RiverState setLastExecutionStartDate (long lastExecutionStartDate ) {
182
+ this .map .put ("lastExecutionStartDate" , lastExecutionStartDate );
183
+ return this ;
184
+ }
185
+
186
+ public long getLastExecutionStartDate () {
187
+ return (long )this .map .get ("lastExecutionStartDate" );
188
+ }
189
+
190
+ public RiverState setLastExecutionEndDate (long lastExecutionEndDate ) {
191
+ this .map .put ("lastExecutionEndDate" , lastExecutionEndDate );
192
+ return this ;
193
+ }
194
+
195
+ public long getLastExecutionEndDate () {
196
+ return (long )this .map .get ("lastExecutionEndDate" );
197
+ }
198
+
189
199
public RiverState fromXContent (XContentParser parser ) throws IOException {
190
200
DateTimeFormatter dateTimeFormatter = ISODateTimeFormat .dateOptionalTimeParser ().withZone (DateTimeZone .UTC );
191
201
Long startTimestamp = 0L ;
192
- Long begin = 0L ;
193
- Long end = 0L ;
202
+ Long begin = null ;
203
+ Long end = null ;
194
204
String name = null ;
195
205
String type = null ;
196
206
String currentFieldName = null ;
@@ -213,11 +223,11 @@ public RiverState fromXContent(XContentParser parser) throws IOException {
213
223
break ;
214
224
case "last_active_begin" :
215
225
begin = parser .text () != null && !"null" .equals (parser .text ()) ?
216
- dateTimeFormatter .parseMillis (parser .text ()) : 0L ;
226
+ dateTimeFormatter .parseMillis (parser .text ()) : null ;
217
227
break ;
218
228
case "last_active_end" :
219
229
end = parser .text () != null && !"null" .equals (parser .text ()) ?
220
- dateTimeFormatter .parseMillis (parser .text ()) : 0L ;
230
+ dateTimeFormatter .parseMillis (parser .text ()) : null ;
221
231
break ;
222
232
}
223
233
} else if (token == START_OBJECT ) {
@@ -228,7 +238,8 @@ public RiverState fromXContent(XContentParser parser) throws IOException {
228
238
.setName (name )
229
239
.setType (type )
230
240
.setStarted (new DateTime (startTimestamp ))
231
- .setLastActive (new DateTime (begin ), new DateTime (end ))
241
+ .setLastActive (begin != null ? new DateTime (begin ) : null ,
242
+ end != null ? new DateTime (end ) : null )
232
243
.setMap (map );
233
244
}
234
245
@@ -250,19 +261,40 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
250
261
public void readFrom (StreamInput in ) throws IOException {
251
262
this .name = in .readOptionalString ();
252
263
this .type = in .readOptionalString ();
253
- this .started = new DateTime (in .readLong ());
254
- this .begin = new DateTime (in .readLong ());
255
- this .end = new DateTime (in .readLong ());
264
+ if (in .readBoolean ()) {
265
+ this .started = new DateTime (in .readLong ());
266
+ }
267
+ if (in .readBoolean ()) {
268
+ this .lastActiveBegin = new DateTime (in .readLong ());
269
+ }
270
+ if (in .readBoolean ()) {
271
+ this .lastActiveEnd = new DateTime (in .readLong ());
272
+ }
256
273
map = in .readMap ();
257
274
}
258
275
259
276
@ Override
260
277
public void writeTo (StreamOutput out ) throws IOException {
261
278
out .writeOptionalString (name );
262
279
out .writeOptionalString (type );
263
- out .writeLong (started != null ? started .getMillis () : 0L );
264
- out .writeLong (begin != null ? begin .getMillis () : 0L );
265
- out .writeLong (end != null ? end .getMillis () : 0L );
280
+ if (started != null ) {
281
+ out .writeBoolean (true );
282
+ out .writeLong (started .getMillis ());
283
+ } else {
284
+ out .writeBoolean (false );
285
+ }
286
+ if (lastActiveBegin != null ) {
287
+ out .writeBoolean (true );
288
+ out .writeLong (lastActiveBegin .getMillis ());
289
+ } else {
290
+ out .writeBoolean (false );
291
+ }
292
+ if (lastActiveEnd != null ) {
293
+ out .writeBoolean (true );
294
+ out .writeLong (lastActiveEnd .getMillis ());
295
+ } else {
296
+ out .writeBoolean (false );
297
+ }
266
298
out .writeMap (map );
267
299
}
268
300
0 commit comments