mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-10 14:20:55 +00:00
Created wrapper for trackedRaces map in AbstractRaceColumn
see bug 1847
This commit is contained in:
1 parent
c369e8e25f
commit
14b5ee8ae1
2 files changed
+101
-43
No files matched your search
+6
-43
@@ -2,7 +2,6 @@ package com.sap.sailing.domain.base.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -25,7 +24,7 @@ import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
public abstract class AbstractRaceColumn extends SimpleAbstractRaceColumn implements RaceColumn {
|
||||
private static final long serialVersionUID = -7801617988982540470L;
|
||||
|
||||
private Map<Fleet, TrackedRace> trackedRaces;
|
||||
private TrackedRaces trackedRaces;
|
||||
private Map<Fleet, RaceIdentifier> raceIdentifiers;
|
||||
|
||||
private Map<Fleet, RaceLog> raceLogs;
|
||||
@@ -38,25 +37,11 @@ public abstract class AbstractRaceColumn extends SimpleAbstractRaceColumn implem
|
||||
private transient RaceLogInformation raceLogInformation;
|
||||
private RaceLogIdentifierTemplate raceLogIdentifierTemplate;
|
||||
|
||||
/**
|
||||
* we don't want the TrackedRaces to be serialized during a master data export. Thus, we need this thread flag which
|
||||
* is true only during master data export
|
||||
*/
|
||||
private transient ThreadLocal<Boolean> ongoingMasterDataExport;
|
||||
|
||||
public AbstractRaceColumn() {
|
||||
this.trackedRaces = new HashMap<Fleet, TrackedRace>();
|
||||
this.trackedRaces = new TrackedRaces();
|
||||
this.raceIdentifiers = new HashMap<Fleet, RaceIdentifier>();
|
||||
this.raceLogs = new HashMap<Fleet, RaceLog>();
|
||||
this.ongoingMasterDataExport = createOngoingMasterDataExportThreadLocal();
|
||||
}
|
||||
|
||||
private ThreadLocal<Boolean> createOngoingMasterDataExportThreadLocal() {
|
||||
return new ThreadLocal<Boolean>() {
|
||||
protected Boolean initialValue() {
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -205,19 +190,8 @@ public abstract class AbstractRaceColumn extends SimpleAbstractRaceColumn implem
|
||||
/**
|
||||
* When deserializing, replication listeners are registered on all race logs.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
|
||||
this.ongoingMasterDataExport = createOngoingMasterDataExportThreadLocal();
|
||||
// Check if master data export is ongoing
|
||||
boolean masterDataImportOngoing = ois.readBoolean();
|
||||
if (masterDataImportOngoing) {
|
||||
this.trackedRaces = new HashMap<Fleet, TrackedRace>();
|
||||
this.raceIdentifiers = (Map<Fleet, RaceIdentifier>) ois.readObject();
|
||||
this.raceLogs = (Map<Fleet, RaceLog>) ois.readObject();
|
||||
this.raceLogIdentifierTemplate = (RaceLogIdentifierTemplate) ois.readObject();
|
||||
} else {
|
||||
ois.defaultReadObject();
|
||||
}
|
||||
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
|
||||
ois.defaultReadObject();
|
||||
for (Entry<Fleet, RaceLog> entry : raceLogs.entrySet()) {
|
||||
Fleet fleet = entry.getKey();
|
||||
RaceLog raceLog = entry.getValue();
|
||||
@@ -227,18 +201,7 @@ public abstract class AbstractRaceColumn extends SimpleAbstractRaceColumn implem
|
||||
|
||||
@Override
|
||||
public void setMasterDataExportOngoingThreadFlag(boolean flagValue) {
|
||||
ongoingMasterDataExport.set(flagValue);
|
||||
trackedRaces.setMasterDataExportOngoingThreadFlag(flagValue);
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream stream) throws IOException {
|
||||
if (ongoingMasterDataExport.get()) {
|
||||
stream.writeBoolean(true);
|
||||
stream.writeObject(raceIdentifiers);
|
||||
stream.writeObject(raceLogs);
|
||||
stream.writeObject(raceLogIdentifierTemplate);
|
||||
} else {
|
||||
stream.writeBoolean(false);
|
||||
stream.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.sap.sailing.domain.base.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sap.sailing.domain.base.Fleet;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
|
||||
/**
|
||||
* Wraps the trackedRaces map in the {@link AbstractRaceColumn} allowing to serialize an empty map when a master data
|
||||
* import is running by using the {@link ThreadLocal} flag {@link #ongoingMasterDataExport}. If the flag is
|
||||
* <code>false</code> the map is serialized as is.
|
||||
*
|
||||
*
|
||||
* @author Frederik Petersen (D054528)
|
||||
*
|
||||
*/
|
||||
public class TrackedRaces implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5521115213267651333L;
|
||||
|
||||
/**
|
||||
* we don't want the TrackedRaces to be serialized during a master data export. Thus, we need this thread flag which
|
||||
* is true only during master data export
|
||||
*/
|
||||
private transient ThreadLocal<Boolean> ongoingMasterDataExport;
|
||||
|
||||
private final Map<Fleet, TrackedRace> trackedRaces;
|
||||
|
||||
public TrackedRaces(Map<Fleet, TrackedRace> trackedRaces) {
|
||||
this.trackedRaces = trackedRaces;
|
||||
this.ongoingMasterDataExport = createOngoingMasterDataExportThreadLocal();
|
||||
}
|
||||
|
||||
public TrackedRaces() {
|
||||
this(new HashMap<Fleet, TrackedRace>());
|
||||
}
|
||||
|
||||
public TrackedRace get(Fleet fleet) {
|
||||
return trackedRaces.get(fleet);
|
||||
}
|
||||
|
||||
public void put(Fleet fleet, TrackedRace trackedRace) {
|
||||
trackedRaces.put(fleet, trackedRace);
|
||||
}
|
||||
|
||||
public void remove(Fleet fleet) {
|
||||
trackedRaces.remove(fleet);
|
||||
}
|
||||
|
||||
public Set<Entry<Fleet, TrackedRace>> entrySet() {
|
||||
return trackedRaces.entrySet();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return trackedRaces.isEmpty();
|
||||
}
|
||||
|
||||
public Collection<TrackedRace> values() {
|
||||
return trackedRaces.values();
|
||||
}
|
||||
|
||||
private ThreadLocal<Boolean> createOngoingMasterDataExportThreadLocal() {
|
||||
return new ThreadLocal<Boolean>() {
|
||||
protected Boolean initialValue() {
|
||||
return false;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
public void setMasterDataExportOngoingThreadFlag(boolean flagValue) {
|
||||
ongoingMasterDataExport.set(flagValue);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
|
||||
ois.defaultReadObject();
|
||||
this.ongoingMasterDataExport = createOngoingMasterDataExportThreadLocal();
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream oos) throws IOException {
|
||||
if (ongoingMasterDataExport.get()) {
|
||||
oos.writeObject(new HashMap<Fleet, TrackedRace>());
|
||||
} else {
|
||||
oos.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user