4141 */
4242public class RiverState implements Streamable , ToXContent , Comparable <RiverState > {
4343
44- private final static DateTime EMPTY_DATETIME = new DateTime (0L );
45-
4644 /**
4745 * The name of the river instance
4846 */
@@ -61,12 +59,12 @@ public class RiverState implements Streamable, ToXContent, Comparable<RiverState
6159 /*
6260 * The time of the last river activity
6361 */
64- private DateTime begin ;
62+ private DateTime lastActiveBegin ;
6563
6664 /*
6765 * The time when the last river activity ended
6866 */
69- private DateTime end ;
67+ private DateTime lastActiveEnd ;
7068
7169 /**
7270 * A custom map for more information about the river
@@ -120,43 +118,23 @@ public DateTime getStarted() {
120118 * @return this state
121119 */
122120 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 ;
129123 return this ;
130124 }
131125
132126 /**
133127 * @return the begin of the last river activity
134128 */
135129 public DateTime getLastActiveBegin () {
136- return begin != null ? begin : EMPTY_DATETIME ;
130+ return lastActiveBegin ;
137131 }
138132
139133 /**
140134 * @return the end of the last river activity
141135 */
142136 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 ;
160138 }
161139
162140 public RiverState setCounter (Integer counter ) {
@@ -178,19 +156,51 @@ public Map<String, Object> getCustom() {
178156 return (Map <String , Object >) this .map .get ("custom" );
179157 }
180158
181- public boolean isAborted () {
182- return map .containsKey ("aborted" ) ? (Boolean ) map .get ("aborted" ) : false ;
183- }
184-
185159 public boolean isSuspended () {
186160 return map .containsKey ("suspended" ) ? (Boolean ) map .get ("suspended" ) : false ;
187161 }
188162
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+
189199 public RiverState fromXContent (XContentParser parser ) throws IOException {
190200 DateTimeFormatter dateTimeFormatter = ISODateTimeFormat .dateOptionalTimeParser ().withZone (DateTimeZone .UTC );
191201 Long startTimestamp = 0L ;
192- Long begin = 0L ;
193- Long end = 0L ;
202+ Long begin = null ;
203+ Long end = null ;
194204 String name = null ;
195205 String type = null ;
196206 String currentFieldName = null ;
@@ -213,11 +223,11 @@ public RiverState fromXContent(XContentParser parser) throws IOException {
213223 break ;
214224 case "last_active_begin" :
215225 begin = parser .text () != null && !"null" .equals (parser .text ()) ?
216- dateTimeFormatter .parseMillis (parser .text ()) : 0L ;
226+ dateTimeFormatter .parseMillis (parser .text ()) : null ;
217227 break ;
218228 case "last_active_end" :
219229 end = parser .text () != null && !"null" .equals (parser .text ()) ?
220- dateTimeFormatter .parseMillis (parser .text ()) : 0L ;
230+ dateTimeFormatter .parseMillis (parser .text ()) : null ;
221231 break ;
222232 }
223233 } else if (token == START_OBJECT ) {
@@ -228,7 +238,8 @@ public RiverState fromXContent(XContentParser parser) throws IOException {
228238 .setName (name )
229239 .setType (type )
230240 .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 )
232243 .setMap (map );
233244 }
234245
@@ -250,19 +261,40 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
250261 public void readFrom (StreamInput in ) throws IOException {
251262 this .name = in .readOptionalString ();
252263 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+ }
256273 map = in .readMap ();
257274 }
258275
259276 @ Override
260277 public void writeTo (StreamOutput out ) throws IOException {
261278 out .writeOptionalString (name );
262279 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+ }
266298 out .writeMap (map );
267299 }
268300
0 commit comments