made operation objects serializable; implemented TrackRace operation

This commit is contained in:
Axel Uhl
2012-04-17 13:26:49 +02:00
parent 6ce3396cd6
commit cee0c8d37e
17 changed files with 90 additions and 10 deletions
@@ -12,6 +12,11 @@ public interface DynamicTrackedEvent extends TrackedEvent {
*/
DynamicTrackedRace getExistingTrackedRace(RaceDefinition race);
/**
* @param raceDefinitionSetToUpdate
* may be <code>null</code> which means that no update will be fired to any
* {@link DynamicRaceDefinitionSet}.
*/
DynamicTrackedRace createTrackedRace(RaceDefinition raceDefinition, WindStore windStore,
long millisecondsOverWhichToAverageWind, long millisecondsOverWhichToAverageSpeed,
DynamicRaceDefinitionSet raceDefinitionSetToUpdate);
@@ -15,6 +15,7 @@ import java.util.Map;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.base.RaceDefinition;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.EventIdentifier;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.TimePoint;
@@ -312,4 +313,7 @@ public interface RacingEventService extends TrackedEventRegistry {
RacesHandle addRace(RaceTrackingConnectivityParameters params, WindStore windStore, long timeoutInMilliseconds)
throws MalformedURLException, FileNotFoundException, URISyntaxException, Exception;
TrackedRace createTrackedRace(EventAndRaceIdentifier raceIdentifier, WindStore windStore,
long millisecondsOverWhichToAverageWind, long millisecondsOverWhichToAverageSpeed);
}
@@ -13,12 +13,13 @@ import com.sap.sailing.domain.common.HttpMessageSenderServletConstants;
import com.sap.sailing.server.RacingEventService;
public abstract class HttpMessageSenderServletRequestHandler {
private static final Logger logger = Logger.getLogger(AbstractHttpPostServlet.class.getName());
/**
* Every so many milliseconds the servlet will send a {@link #PONG} message. This shows clients that the connection
* is still alive. If after several such intervals the client hasn't received a {@link #PONG} message it seems reasonable
* to assume the connection has died.
*/
private static final Logger logger = Logger.getLogger(AbstractHttpPostServlet.class.getName());
private static final long timeoutInMilliseconds = 60000;
private long timeInMillisOfLastExpeditionMessageReceived;
private boolean stop;
@@ -34,6 +35,10 @@ public abstract class HttpMessageSenderServletRequestHandler {
protected RacingEventService getService() {
return owner.getService();
}
/**
* Obtains the writer through which the server can push data to the client.
*/
protected PrintWriter getWriter() {
return writer;
}
@@ -77,9 +82,6 @@ public abstract class HttpMessageSenderServletRequestHandler {
/**
* Sends a single message across to the receiving client. To do so, the message is Base64 encoded before being sent
* as a string. The message is terminated with a 0 byte.
* @param writer
* @param bytes
* @throws IOException
*/
protected void send(Writer writer, byte[] message) {
String bytes = Base64Utils.toBase64(message);
@@ -450,6 +450,15 @@ public class RacingEventServiceImpl implements RacingEventService, EventFetcher,
return tracker.getRacesHandle();
}
@Override
public synchronized TrackedRace createTrackedRace(EventAndRaceIdentifier raceIdentifier, WindStore windStore,
long millisecondsOverWhichToAverageWind, long millisecondsOverWhichToAverageSpeed) {
DynamicTrackedEvent trackedEvent = getTrackedEvent(getEvent(raceIdentifier));
RaceDefinition race = getRace(raceIdentifier);
return trackedEvent.createTrackedRace(race, windStore, millisecondsOverWhichToAverageWind, millisecondsOverWhichToAverageSpeed,
/* raceDefinitionSetToUpdate */ null);
}
@Override
public synchronized RacesHandle addTracTracRace(URL paramURL, URI liveURI, URI storedURI,
TimePoint startOfTracking, TimePoint endOfTracking, WindStore windStore,
@@ -3,6 +3,7 @@ package com.sap.sailing.server.operationaltransformation;
public abstract class AbstractLeaderboardColumnOperation extends AbstractLeaderboardOperation {
private static final long serialVersionUID = 8577267743945864388L;
private final String columnName;
public AbstractLeaderboardColumnOperation(String leaderboardName, String columnName) {
@@ -3,6 +3,7 @@ package com.sap.sailing.server.operationaltransformation;
public abstract class AbstractLeaderboardOperation extends AbstractRacingEventServiceOperation {
private static final long serialVersionUID = 5377910723455422127L;
private final String leaderboardName;
public AbstractLeaderboardOperation(String leaderboardName) {
@@ -0,0 +1,18 @@
package com.sap.sailing.server.operationaltransformation;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
public abstract class AbstractRaceOperation extends AbstractRacingEventServiceOperation {
private static final long serialVersionUID = -1162468486451355784L;
private EventAndRaceIdentifier raceIdentifier;
public AbstractRaceOperation(EventAndRaceIdentifier raceIdentifier) {
super();
this.raceIdentifier = raceIdentifier;
}
protected EventAndRaceIdentifier getRaceIdentifier() {
return raceIdentifier;
}
}
@@ -12,6 +12,8 @@ import com.sap.sailing.server.RacingEventService;
*
*/
public abstract class AbstractRacingEventServiceOperation implements RacingEventServiceOperation {
private static final long serialVersionUID = 3888231857034991271L;
@Override
public RacingEventServiceOperation transformRemoveLeaderboardClientOp(RemoveLeaderboard removeLeaderboard) {
return removeLeaderboard;
@@ -92,6 +94,8 @@ public abstract class AbstractRacingEventServiceOperation implements RacingEvent
public static RacingEventServiceOperation getNoOp() {
return new AbstractRacingEventServiceOperation() {
private static final long serialVersionUID = -7203280393485688834L;
@Override
public RacingEventService applyTo(RacingEventService toState) {
return toState;
@@ -10,6 +10,7 @@ import com.sap.sailing.server.RacingEventService;
*
*/
public class AddColumnToLeaderboard extends AbstractLeaderboardColumnOperation {
private static final long serialVersionUID = -7670764349119941051L;
private final boolean medalRace;
public AddColumnToLeaderboard(String columnName, String leaderboardName, boolean medalRace) {
@@ -3,6 +3,7 @@ package com.sap.sailing.server.operationaltransformation;
import com.sap.sailing.server.RacingEventService;
public class AddLeaderboard extends AbstractLeaderboardOperation {
private static final long serialVersionUID = 891352705068098580L;
private final int[] discardThresholds;
public AddLeaderboard(String leaderboardName, int[] discardThresholds) {
@@ -4,6 +4,8 @@ import com.sap.sailing.server.RacingEventService;
public class MoveLeaderboardColumnDown extends AbstractLeaderboardColumnOperation {
private static final long serialVersionUID = -1041804872669106579L;
public MoveLeaderboardColumnDown(String leaderboardName, String columnName) {
super(leaderboardName, columnName);
}
@@ -4,6 +4,8 @@ import com.sap.sailing.server.RacingEventService;
public class MoveLeaderboardColumnUp extends AbstractLeaderboardColumnOperation {
private static final long serialVersionUID = 8444485841005051004L;
public MoveLeaderboardColumnUp(String leaderboardName, String columnName) {
super(leaderboardName, columnName);
}
@@ -1,10 +1,12 @@
package com.sap.sailing.server.operationaltransformation;
import java.io.Serializable;
import com.sap.sailing.operationaltransformation.Operation;
import com.sap.sailing.operationaltransformation.Transformer;
import com.sap.sailing.server.RacingEventService;
public interface RacingEventServiceOperation extends Operation<RacingEventService> {
public interface RacingEventServiceOperation extends Operation<RacingEventService>, Serializable {
/**
* Implements the specific transformation rule for the implementing subclass for the set of possible peer operations
* along which to transform this operation, assuming this is the client operation. See
@@ -3,8 +3,8 @@ package com.sap.sailing.server.operationaltransformation;
import com.sap.sailing.server.RacingEventService;
public class RemoveColumnFromLeaderboard extends AbstractLeaderboardColumnOperation {
private static final long serialVersionUID = 5425526859417359535L;
public RemoveColumnFromLeaderboard(String columnName, String leaderboardName) {
super(leaderboardName, columnName);
}
@@ -3,6 +3,8 @@ package com.sap.sailing.server.operationaltransformation;
import com.sap.sailing.server.RacingEventService;
public class RemoveLeaderboard extends AbstractLeaderboardOperation {
private static final long serialVersionUID = -6491003416450255268L;
public RemoveLeaderboard(String leaderboardName) {
super(leaderboardName);
}
@@ -3,6 +3,7 @@ package com.sap.sailing.server.operationaltransformation;
import com.sap.sailing.server.RacingEventService;
public class RenameLeaderboardColumn extends AbstractLeaderboardColumnOperation {
private static final long serialVersionUID = -1238503068559477351L;
private final String newColumnName;
public RenameLeaderboardColumn(String leaderboardName, String oldColumnName, String newColumnName) {
@@ -1,8 +1,33 @@
package com.sap.sailing.server.operationaltransformation;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.base.RaceDefinition;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.tracking.TrackedEvent;
import com.sap.sailing.domain.tracking.TrackedRace;
import com.sap.sailing.domain.tracking.impl.EmptyWindStore;
import com.sap.sailing.server.RacingEventService;
public class TrackRace extends AbstractRacingEventServiceOperation {
/**
* Creates a tracked race for a race identifier by a {@link RaceIdentifier}. The operation assumes that the
* {@link RaceDefinition}, therefore the {@link Event} as well as the {@link TrackedEvent} into which the
* new {@link TrackedRace} will be composed already exist and that the {@link TrackedRace} does not yet
* exist.
*
* @author Axel Uhl (d043530)
*
*/
public class TrackRace extends AbstractRaceOperation {
private static final long serialVersionUID = 5084401060896514911L;
private final long millisecondsOverWhichToAverageWind;
private final long millisecondsOverWhichToAverageSpeed;
public TrackRace(EventAndRaceIdentifier raceIdentifier, long millisecondsOverWhichToAverageWind, long millisecondsOverWhichToAverageSpeed) {
super(raceIdentifier);
this.millisecondsOverWhichToAverageWind = millisecondsOverWhichToAverageWind;
this.millisecondsOverWhichToAverageSpeed = millisecondsOverWhichToAverageSpeed;
}
@Override
public RacingEventServiceOperation transformClientOp(RacingEventServiceOperation serverOp) {
@@ -18,8 +43,8 @@ public class TrackRace extends AbstractRacingEventServiceOperation {
@Override
public RacingEventService applyTo(RacingEventService toState) {
// TODO Auto-generated method stub
return null;
toState.createTrackedRace(getRaceIdentifier(), EmptyWindStore.INSTANCE, millisecondsOverWhichToAverageWind, millisecondsOverWhichToAverageSpeed);
return toState;
}
}