45d106750a6614bab98b9e9b0bc01ff459bbd1de
java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverhash/ManeuverCache.java
| ... | ... | @@ -13,4 +13,6 @@ public interface ManeuverCache { |
| 13 | 13 | void suspend(); |
| 14 | 14 | |
| 15 | 15 | void triggerUpdate(Competitor key); |
| 16 | + |
|
| 17 | + boolean canBeUpdated(); |
|
| 16 | 18 | } |
| ... | ... | \ No newline at end of file |
java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverhash/impl/ManeuverCacheDelegate.java
| ... | ... | @@ -30,7 +30,7 @@ public class ManeuverCacheDelegate implements SerializableManeuverCache { |
| 30 | 30 | super(); |
| 31 | 31 | this.race = race; |
| 32 | 32 | this.maneuverRaceFingerprintRegistry = maneuverRaceFingerprintRegistry; |
| 33 | - this.cacheToUse = new ManeuversFromSmartFutureCache((DynamicTrackedRaceImpl) race); |
|
| 33 | + this.cacheToUse = createUpdatableManeuverCache(); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { |
| ... | ... | @@ -75,6 +75,9 @@ public class ManeuverCacheDelegate implements SerializableManeuverCache { |
| 75 | 75 | } else { |
| 76 | 76 | new Thread(()->{ |
| 77 | 77 | logger.info("Maneuver fingerprints do not match for race "+race.getRaceIdentifier()+"; NOT loading from DB"); |
| 78 | + if (!cacheToUse.canBeUpdated()) { |
|
| 79 | + cacheToUse = createUpdatableManeuverCache(); |
|
| 80 | + } |
|
| 78 | 81 | cacheToUse.resume(); |
| 79 | 82 | if (maneuverRaceFingerprintRegistry != null) { |
| 80 | 83 | // wait for maneuvers to be computed by the default cache implementation (SmartFutureCache), |
| ... | ... | @@ -102,6 +105,18 @@ public class ManeuverCacheDelegate implements SerializableManeuverCache { |
| 102 | 105 | |
| 103 | 106 | @Override |
| 104 | 107 | public void triggerUpdate(Competitor competitor) { |
| 108 | + if (!cacheToUse.canBeUpdated()) { |
|
| 109 | + cacheToUse = createUpdatableManeuverCache(); |
|
| 110 | + } |
|
| 105 | 111 | cacheToUse.triggerUpdate(competitor); |
| 106 | 112 | } |
| 113 | + |
|
| 114 | + private ManeuverCache createUpdatableManeuverCache() { |
|
| 115 | + return new ManeuversFromSmartFutureCache((DynamicTrackedRaceImpl) race); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + @Override |
|
| 119 | + public boolean canBeUpdated() { |
|
| 120 | + return true; |
|
| 121 | + } |
|
| 107 | 122 | } |
| ... | ... | \ No newline at end of file |
java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverhash/impl/ManeuversFromDatabase.java
| ... | ... | @@ -6,6 +6,7 @@ import java.util.logging.Level; |
| 6 | 6 | import java.util.logging.Logger; |
| 7 | 7 | |
| 8 | 8 | import com.sap.sailing.domain.base.Competitor; |
| 9 | +import com.sap.sailing.domain.maneuverhash.ManeuverRaceFingerprintRegistry; |
|
| 9 | 10 | import com.sap.sailing.domain.maneuverhash.SerializableManeuverCache; |
| 10 | 11 | import com.sap.sailing.domain.tracking.Maneuver; |
| 11 | 12 | import com.sap.sailing.domain.tracking.TrackedRace; |
| ... | ... | @@ -28,9 +29,14 @@ public class ManeuversFromDatabase implements SerializableManeuverCache { |
| 28 | 29 | this.maneuvers = maneuvers; |
| 29 | 30 | } |
| 30 | 31 | |
| 32 | + @Override |
|
| 33 | + public boolean canBeUpdated() { |
|
| 34 | + return false; |
|
| 35 | + } |
|
| 36 | + |
|
| 31 | 37 | public void resume() { |
| 32 | 38 | logger.log(Level.WARNING, "Method should never be called"); |
| 33 | - // TODO bug5959: another case where we should revert to a SmartFutureCache? |
|
| 39 | + throw new IllegalStateException("Method should never be called"); |
|
| 34 | 40 | } |
| 35 | 41 | |
| 36 | 42 | public void suspend() { |
| ... | ... | @@ -43,7 +49,12 @@ public class ManeuversFromDatabase implements SerializableManeuverCache { |
| 43 | 49 | |
| 44 | 50 | @Override |
| 45 | 51 | public void triggerUpdate(Competitor key) { |
| 46 | - logger.log(Level.WARNING, "If Fingerprint matches, no Update should be triggered"); |
|
| 47 | - // TODO change to smartFutureCache in Delegate |
|
| 52 | + logger.log(Level.WARNING, "Method should never be called"); |
|
| 53 | + throw new IllegalStateException("If Fingerprint matches, no Update should be triggered"); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + @Override |
|
| 57 | + public void setManeuverRaceFingerprintRegistry(ManeuverRaceFingerprintRegistry maneuverRaceFingerprintRegistry) { |
|
| 58 | + // no-op; nothing to set here |
|
| 48 | 59 | } |
| 49 | 60 | } |
| ... | ... | \ No newline at end of file |
java/com.sap.sailing.domain/src/com/sap/sailing/domain/maneuverhash/impl/ManeuversFromSmartFutureCache.java
| ... | ... | @@ -46,6 +46,11 @@ public class ManeuversFromSmartFutureCache implements ManeuverCache { |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | @Override |
| 49 | + public boolean canBeUpdated() { |
|
| 50 | + return true; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + @Override |
|
| 49 | 54 | public void resume() { |
| 50 | 55 | smartFutureCache.resume(); |
| 51 | 56 | } |