Merge "Issue #1912 optimized the creation of NavigableMaps from aggregate records and delayed TreeMap creation to the tertiary loader." into omaha_13.4.1

Former-commit-id: 2719884a00 [formerly 939260496435242e06f0ebfcd91fd271c1bde4e5]
Former-commit-id: 2787b92e25
This commit is contained in:
Nate Jensen 2013-04-23 11:05:12 -05:00 committed by Gerrit Code Review
commit d9c9438b10
3 changed files with 1328 additions and 29 deletions

View file

@ -20,10 +20,10 @@
package com.raytheon.uf.common.dataplugin.ffmp; package com.raytheon.uf.common.dataplugin.ffmp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.TreeMap; import java.util.TreeMap;
import javax.persistence.Transient; import javax.persistence.Transient;
@ -31,7 +31,6 @@ import javax.persistence.Transient;
import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.ISerializableObject;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.time.util.ImmutableDate;
/** /**
* FFMP basin/aggregated value holder * FFMP basin/aggregated value holder
@ -44,6 +43,9 @@ import com.raytheon.uf.common.time.util.ImmutableDate;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* 06/22/09 2152 D. Hladky Initial release * 06/22/09 2152 D. Hladky Initial release
* 01/27/13 1478 D. Hladky Added support for writing aggregate record cache * 01/27/13 1478 D. Hladky Added support for writing aggregate record cache
* Apr 22, 2013 1912 bsteffen optimized the creation of NavigableMaps
* from aggregate records and delayed
* TreeMap creation to the tertiary loader.
* *
* </pre> * </pre>
* *
@ -65,7 +67,7 @@ public class FFMPBasin implements ISerializableObject, Cloneable {
* not serialized! * not serialized!
**/ **/
@Transient @Transient
protected TreeMap<Date, Float> values; protected NavigableMap<Date, Float> values;
/** object used for serialization **/ /** object used for serialization **/
@DynamicSerializeElement @DynamicSerializeElement
@ -316,6 +318,12 @@ public class FFMPBasin implements ISerializableObject, Cloneable {
*/ */
public void setValue(Date date, Float dvalue) { public void setValue(Date date, Float dvalue) {
synchronized (values) { synchronized (values) {
if (!(values instanceof TreeMap) && !values.containsKey(dvalue)) {
// ArrayBackedMap may have been used if this basin was
// deserialized. It is much faster to do inserts on a TreeMap so
// convert now.
values = new TreeMap<Date, Float>(values);
}
values.put(date, dvalue); values.put(date, dvalue);
} }
} }
@ -325,7 +333,7 @@ public class FFMPBasin implements ISerializableObject, Cloneable {
* *
* @return * @return
*/ */
public TreeMap<Date, Float> getValues() { public NavigableMap<Date, Float> getValues() {
return values; return values;
} }
@ -343,13 +351,7 @@ public class FFMPBasin implements ISerializableObject, Cloneable {
*/ */
public FFMPBasin() { public FFMPBasin() {
values = new TreeMap<Date, Float>(new Comparator<Date>() { values = new TreeMap<Date, Float>(Collections.reverseOrder());
@Override
public int compare(Date o1, Date o2) {
// Null checks?
return (int)(o2.getTime() - o1.getTime()) ;
}
});
} }
/** /**
@ -360,14 +362,7 @@ public class FFMPBasin implements ISerializableObject, Cloneable {
public FFMPBasin(Long pfaf, boolean aggregated) { public FFMPBasin(Long pfaf, boolean aggregated) {
setPfaf(pfaf); setPfaf(pfaf);
setAggregated(aggregated); setAggregated(aggregated);
values = new TreeMap<Date, Float>(new Comparator<Date>() { values = new TreeMap<Date, Float>(Collections.reverseOrder());
@Override
public int compare(Date o1, Date o2) {
// Null checks?
return (int)(o2.getTime() - o1.getTime()) ;
}
});
} }
/** /**
@ -375,18 +370,18 @@ public class FFMPBasin implements ISerializableObject, Cloneable {
* *
* @param times * @param times
*/ */
public void deserialize(List<Long> times) { public void deserialize(long[] times) {
// safe to avoid Array Index Exceptions / shouldn't happen but..... // safe to avoid Array Index Exceptions / shouldn't happen but.....
if (serializedValues != null && (times.size() == serializedValues.length)) { if (serializedValues != null
&& (times.length == serializedValues.length)) {
NavigableMap<Date, Float> fastMap = new ArrayBackedMap(times,
serializedValues);
values = fastMap.descendingMap();
int i = 0; // values = new TreeMap<Date, Float>(fastMap.descendingMap());
for (Long time : times) {
values.put(new Date(time), serializedValues[i]);
i++;
}
//System.out.println("populated :"+i+" pfaf : "+pfaf);
} }
serializedValues = null;
} }
/** /**

View file

@ -576,8 +576,12 @@ public class FFMPBasinData implements ISerializableObject {
* @param times * @param times
*/ */
public void populate(List<Long> times) { public void populate(List<Long> times) {
long[] timesArr = new long[times.size()];
for (int i = 0; i < timesArr.length; i += 1) {
timesArr[i] = times.get(i);
}
for (FFMPBasin basin : getBasins().values()) { for (FFMPBasin basin : getBasins().values()) {
basin.deserialize(times); basin.deserialize(timesArr);
} }
} }