mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-04 03:13:49 +00:00
preparations to replicate RegattaLog in RacingEventServiceImpl
This commit is contained in:
1 parent
27f325e1cd
commit
01a972093f
8 files changed
+178
-42
No files matched your search
+38
@@ -0,0 +1,38 @@
|
||||
package com.sap.sailing.domain.abstractlog.regatta.impl;
|
||||
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLogEvent;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLogEventVisitor;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.events.RegattaLogCloseOpenEndedDeviceMappingEvent;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.events.RegattaLogDeviceCompetitorMappingEvent;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.events.RegattaLogDeviceMarkMappingEvent;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.events.RegattaLogRegisterCompetitorEvent;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.events.RegattaLogRevokeEvent;
|
||||
|
||||
public abstract class RegattaLogEventListener implements RegattaLogEventVisitor {
|
||||
protected abstract void eventAdded(RegattaLogEvent event);
|
||||
|
||||
@Override
|
||||
public void visit(RegattaLogRevokeEvent event) {
|
||||
eventAdded(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(RegattaLogDeviceMarkMappingEvent event) {
|
||||
eventAdded(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(RegattaLogDeviceCompetitorMappingEvent event) {
|
||||
eventAdded(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(RegattaLogCloseOpenEndedDeviceMappingEvent event) {
|
||||
eventAdded(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(RegattaLogRegisterCompetitorEvent event) {
|
||||
eventAdded(event);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.sap.sailing.domain.base;
|
||||
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLog;
|
||||
import com.sap.sailing.domain.base.configuration.RegattaConfiguration;
|
||||
import com.sap.sailing.domain.common.RegattaAndRaceIdentifier;
|
||||
import com.sap.sailing.domain.common.RegattaIdentifier;
|
||||
import com.sap.sailing.domain.leaderboard.HasRegattaLog;
|
||||
import com.sap.sailing.domain.leaderboard.ScoringScheme;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
import com.sap.sailing.domain.tracking.TrackedRegatta;
|
||||
@@ -18,7 +18,7 @@ import com.sap.sse.common.WithID;
|
||||
* @author Axel Uhl (d043530)
|
||||
*
|
||||
*/
|
||||
public interface Regatta extends Named, WithID {
|
||||
public interface Regatta extends Named, WithID, HasRegattaLog {
|
||||
ScoringScheme getScoringScheme();
|
||||
|
||||
/**
|
||||
@@ -168,9 +168,4 @@ public interface Regatta extends Named, WithID {
|
||||
* Updates the flag deciding whether to use start time inference. See {@link #useStartTimeInference()}.
|
||||
*/
|
||||
void setUseStartTimeInference(boolean useStartTimeInference);
|
||||
|
||||
/**
|
||||
* @return The RegattaLog associated with this regatta.
|
||||
*/
|
||||
RegattaLog getRegattaLog();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.sap.sailing.domain.base;
|
||||
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLogEvent;
|
||||
import com.sap.sailing.domain.regattalike.RegattaLikeIdentifier;
|
||||
|
||||
/**
|
||||
* Listener on {@link RegattaLikeIdentifier regatta-like} objects.
|
||||
* @author Fredrik Teschke
|
||||
*
|
||||
*/
|
||||
public interface RegattaLikeListener {
|
||||
void regattaLogEventAdded(RegattaLikeIdentifier identifier, RegattaLogEvent event);
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.sap.sailing.domain.base;
|
||||
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLogEvent;
|
||||
|
||||
public interface RegattaListener {
|
||||
void raceAdded(Regatta regatta, RaceDefinition race);
|
||||
void raceRemoved(Regatta regatta, RaceDefinition race);
|
||||
void regattaLogEventAdded(final Regatta regatta, final RegattaLogEvent event);
|
||||
}
|
||||
+24
@@ -20,4 +20,28 @@ public class FlexibleLeaderboardAsRegattaLikeIdentifier implements RegattaLikeId
|
||||
resolver.resolveOnFlexibleLeaderboardIdentifier(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((leaderboardName == null) ? 0 : leaderboardName.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
FlexibleLeaderboardAsRegattaLikeIdentifier other = (FlexibleLeaderboardAsRegattaLikeIdentifier) obj;
|
||||
if (leaderboardName == null) {
|
||||
if (other.leaderboardName != null)
|
||||
return false;
|
||||
} else if (!leaderboardName.equals(other.leaderboardName))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+24
@@ -20,4 +20,28 @@ public class RegattaAsRegattaLikeIdentifier implements RegattaLikeIdentifier {
|
||||
resolver.resolveOnRegattaIdentifier(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((regattaName == null) ? 0 : regattaName.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
RegattaAsRegattaLikeIdentifier other = (RegattaAsRegattaLikeIdentifier) obj;
|
||||
if (regattaName == null) {
|
||||
if (other.regattaName != null)
|
||||
return false;
|
||||
} else if (!regattaName.equals(other.regattaName))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+49
-11
@@ -48,7 +48,9 @@ import com.sap.sailing.domain.abstractlog.race.state.RaceState;
|
||||
import com.sap.sailing.domain.abstractlog.race.state.ReadonlyRaceState;
|
||||
import com.sap.sailing.domain.abstractlog.race.state.impl.RaceStateImpl;
|
||||
import com.sap.sailing.domain.abstractlog.race.state.impl.ReadonlyRaceStateImpl;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLog;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLogEvent;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.impl.RegattaLogEventListener;
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.domain.base.CompetitorStore;
|
||||
import com.sap.sailing.domain.base.CompetitorStore.CompetitorUpdateListener;
|
||||
@@ -119,6 +121,9 @@ import com.sap.sailing.domain.racelog.RaceLogIdentifier;
|
||||
import com.sap.sailing.domain.racelog.RaceLogStore;
|
||||
import com.sap.sailing.domain.racelog.tracking.GPSFixStore;
|
||||
import com.sap.sailing.domain.racelogtracking.DeviceIdentifier;
|
||||
import com.sap.sailing.domain.regattalike.FlexibleLeaderboardAsRegattaLikeIdentifier;
|
||||
import com.sap.sailing.domain.regattalike.RegattaAsRegattaLikeIdentifier;
|
||||
import com.sap.sailing.domain.regattalike.RegattaLikeIdentifier;
|
||||
import com.sap.sailing.domain.regattalog.RegattaLogStore;
|
||||
import com.sap.sailing.domain.regattalog.impl.EmptyRegattaLogStore;
|
||||
import com.sap.sailing.domain.tracking.DynamicTrackedRace;
|
||||
@@ -200,8 +205,8 @@ import com.sap.sse.replication.ReplicationMasterDescriptor;
|
||||
import com.sap.sse.replication.impl.OperationWithResultWithIdWrapper;
|
||||
import com.sap.sse.util.ClearStateTestSupport;
|
||||
|
||||
public class RacingEventServiceImpl implements RacingEventService, ClearStateTestSupport, RegattaListener, LeaderboardRegistry,
|
||||
Replicator {
|
||||
public class RacingEventServiceImpl implements RacingEventService, ClearStateTestSupport, RegattaListener,
|
||||
LeaderboardRegistry, Replicator {
|
||||
private static final Logger logger = Logger.getLogger(RacingEventServiceImpl.class.getName());
|
||||
|
||||
/**
|
||||
@@ -312,6 +317,7 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
|
||||
|
||||
private final RaceLogReplicator raceLogReplicator;
|
||||
private final RegattaLogReplicator regattaLogReplicator;
|
||||
private final Map<RegattaLikeIdentifier, RegattaLogEventListener> regattaLogEventListeners = new ConcurrentHashMap<>();
|
||||
|
||||
private final RaceLogScoringReplicator raceLogScoringReplicator;
|
||||
|
||||
@@ -559,7 +565,7 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
|
||||
+ ") into regattasByName");
|
||||
regattasByName.put(regatta.getName(), regatta);
|
||||
regatta.addRegattaListener(this);
|
||||
regatta.addRegattaListener(regattaLogReplicator);
|
||||
registerRegattaLogReplicator(regatta);
|
||||
regatta.addRaceColumnListener(raceLogReplicator);
|
||||
regatta.addRaceColumnListener(raceLogScoringReplicator);
|
||||
}
|
||||
@@ -616,7 +622,7 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
|
||||
}
|
||||
// RaceColumns of RegattaLeaderboards are tracked via its Regatta!
|
||||
if (leaderboard instanceof FlexibleLeaderboard) {
|
||||
// FIXME: add listener for regattaLogReplicator
|
||||
registerRegattaLogReplicator((FlexibleLeaderboard) leaderboard);
|
||||
leaderboard.addRaceColumnListener(raceLogReplicator);
|
||||
leaderboard.addRaceColumnListener(raceLogScoringReplicator);
|
||||
}
|
||||
@@ -880,6 +886,9 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
|
||||
leaderboard.removeRaceColumnListener(raceLogScoringReplicator);
|
||||
mongoObjectFactory.removeLeaderboard(leaderboardName);
|
||||
syncGroupsAfterLeaderboardRemove(leaderboardName, true);
|
||||
if (leaderboard instanceof FlexibleLeaderboard) {
|
||||
unregisterRegattaLogReplicator((FlexibleLeaderboard) leaderboard);
|
||||
}
|
||||
leaderboard.destroy();
|
||||
}
|
||||
}
|
||||
@@ -1009,11 +1018,44 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
|
||||
boatClassName), /*startDate*/ null, /*endDate*/ null, this, getBaseDomainFactory().createScoringScheme(ScoringSchemeType.LOW_POINT), id,
|
||||
null);
|
||||
logger.info("Created default regatta " + result.getName() + " (" + hashCode() + ") on " + this);
|
||||
result.addRegattaListener(regattaLogReplicator);
|
||||
registerRegattaLogReplicator(result);
|
||||
cacheAndReplicateDefaultRegatta(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private <T> void registerRegattaLogReplicator(RegattaLog regattaLog, RegattaLikeIdentifier identifier) {
|
||||
RegattaLogEventListener listener = new RegattaLogEventListener() {
|
||||
@Override
|
||||
protected void eventAdded(RegattaLogEvent event) {
|
||||
regattaLogReplicator.regattaLogEventAdded(identifier, event);
|
||||
}
|
||||
};
|
||||
regattaLog.addListener(listener);
|
||||
regattaLogEventListeners.put(identifier, listener);
|
||||
}
|
||||
|
||||
private void registerRegattaLogReplicator(Regatta regatta) {
|
||||
registerRegattaLogReplicator(regatta.getRegattaLog(), new RegattaAsRegattaLikeIdentifier(regatta));
|
||||
}
|
||||
|
||||
private void registerRegattaLogReplicator(FlexibleLeaderboard leaderboard) {
|
||||
registerRegattaLogReplicator(leaderboard.getRegattaLog(),
|
||||
new FlexibleLeaderboardAsRegattaLikeIdentifier(leaderboard));
|
||||
}
|
||||
|
||||
private void unregisterRegattaLogReplicator(RegattaLog regattaLog, RegattaLikeIdentifier identifier) {
|
||||
regattaLog.removeListener(regattaLogEventListeners.remove(identifier));
|
||||
}
|
||||
|
||||
private void unregisterRegattaLogReplicator(Regatta regatta) {
|
||||
unregisterRegattaLogReplicator(regatta.getRegattaLog(), new RegattaAsRegattaLikeIdentifier(regatta));
|
||||
}
|
||||
|
||||
private void unregisterRegattaLogReplicator(FlexibleLeaderboard leaderboard) {
|
||||
unregisterRegattaLogReplicator(leaderboard.getRegattaLog(), new FlexibleLeaderboardAsRegattaLikeIdentifier(
|
||||
leaderboard));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Regatta createRegatta(String fullRegattaName, String boatClassName, TimePoint startDate, TimePoint endDate, Serializable id,
|
||||
@@ -1024,7 +1066,7 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
|
||||
useStartTimeInference);
|
||||
Regatta regatta = regattaWithCreatedFlag.getA();
|
||||
if (regattaWithCreatedFlag.getB()) {
|
||||
regatta.addRegattaListener(regattaLogReplicator);
|
||||
registerRegattaLogReplicator(regatta);
|
||||
replicateSpecificRegattaWithoutRaceColumns(regatta);
|
||||
}
|
||||
return regatta;
|
||||
@@ -1668,6 +1710,7 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
|
||||
regatta.removeRegattaListener(this);
|
||||
regatta.removeRaceColumnListener(raceLogReplicator);
|
||||
regatta.removeRaceColumnListener(raceLogScoringReplicator);
|
||||
unregisterRegattaLogReplicator(regatta);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2876,11 +2919,6 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void regattaLogEventAdded(Regatta regatta, RegattaLogEvent event) {
|
||||
// FIXME: replicate
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReplicationMasterDescriptor getMasterDescriptor() {
|
||||
return replicatingFromMaster;
|
||||
|
||||
+28
-22
@@ -1,29 +1,29 @@
|
||||
package com.sap.sailing.server.impl;
|
||||
|
||||
import com.sap.sailing.domain.abstractlog.race.RaceLogEvent;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLog;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLogEvent;
|
||||
import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.base.RaceDefinition;
|
||||
import com.sap.sailing.domain.base.Regatta;
|
||||
import com.sap.sailing.domain.base.RegattaLikeListener;
|
||||
import com.sap.sailing.domain.base.RegattaListener;
|
||||
import com.sap.sailing.domain.racelog.RaceLogIdentifier;
|
||||
import com.sap.sailing.domain.regattalike.FlexibleLeaderboardAsRegattaLikeIdentifier;
|
||||
import com.sap.sailing.domain.regattalike.RegattaAsRegattaLikeIdentifier;
|
||||
import com.sap.sailing.domain.regattalike.RegattaLikeIdentifier;
|
||||
import com.sap.sailing.domain.regattalike.RegattaLikeIdentifierResolver;
|
||||
import com.sap.sailing.server.RacingEventServiceOperation;
|
||||
import com.sap.sailing.server.Replicator;
|
||||
import com.sap.sailing.server.operationaltransformation.RecordRegattaLogEventOnFlexibleLeaderboard;
|
||||
import com.sap.sailing.server.operationaltransformation.RecordRegattaLogEventOnRegatta;
|
||||
|
||||
/**
|
||||
* Being a {@link RegattaListener}, this replicator must be added to all {@link Regatta}s managing a {@link RegattaLog}
|
||||
* so as to be notified about changes to the regatta log. This largely happens by callbacks to the
|
||||
* {@link #regattaLogEventAdded(RaceColumn, RaceLogIdentifier, RaceLogEvent)} method. This object will then use the
|
||||
* {@link Replicator} passed to this object's constructor and send a {@link RecordRegattaLogEventOnLeaderboard} or a
|
||||
* {@link RecordRegattaLogEventOnRegatta} operation to all replicas.
|
||||
* Being a {@link RegattaListener}, this replicator must be added to all {@link RegattaLikeIdentifier regatta-like}
|
||||
* objects (these manage a {@link RegattaLog}) so as to be notified about changes to the regatta log. This largely
|
||||
* happens by callbacks to the {@link #regattaLogEventAdded} method. This object will then use the {@link Replicator}
|
||||
* passed to this object's constructor and send a {@link RecordRegattaLogEventOnRegatta} or a
|
||||
* {@link RecordRegattaLogEventOnFlexibleLeaderboard} operation to all replicas.
|
||||
*
|
||||
* This class is a modified version of {@link RaceLogReplicator}
|
||||
*
|
||||
*/
|
||||
public class RegattaLogReplicator implements RegattaListener {
|
||||
|
||||
public class RegattaLogReplicator implements RegattaLikeListener {
|
||||
private final Replicator service;
|
||||
|
||||
public RegattaLogReplicator(Replicator service) {
|
||||
@@ -31,16 +31,22 @@ public class RegattaLogReplicator implements RegattaListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void regattaLogEventAdded(final Regatta regatta, final RegattaLogEvent event) {
|
||||
RacingEventServiceOperation<?> operation = new RecordRegattaLogEventOnRegatta(regatta.getName(), event);
|
||||
service.replicate(operation);
|
||||
}
|
||||
public void regattaLogEventAdded(RegattaLikeIdentifier regattaLikeIdentifier, final RegattaLogEvent event) {
|
||||
regattaLikeIdentifier.resolve(new RegattaLikeIdentifierResolver() {
|
||||
@Override
|
||||
public void resolveOnRegattaIdentifier(RegattaAsRegattaLikeIdentifier regattaLikeParent) {
|
||||
RacingEventServiceOperation<?> operation = new RecordRegattaLogEventOnRegatta(regattaLikeParent
|
||||
.getName(), event);
|
||||
service.replicate(operation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void raceAdded(Regatta regatta, RaceDefinition race) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void raceRemoved(Regatta regatta, RaceDefinition race) {
|
||||
@Override
|
||||
public void resolveOnFlexibleLeaderboardIdentifier(
|
||||
FlexibleLeaderboardAsRegattaLikeIdentifier regattaLikeParent) {
|
||||
RacingEventServiceOperation<?> operation = new RecordRegattaLogEventOnFlexibleLeaderboard(
|
||||
regattaLikeParent.getName(), event);
|
||||
service.replicate(operation);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user