pass AsyncActionsExecutor also to WindPanel and WindChart and use in WindChart action call

This commit is contained in:
Axel Uhl
2012-03-19 02:11:08 +01:00
parent 9c4e5b3be9
commit 41d1bf0983
19 changed files with 69 additions and 58 deletions
@@ -9,11 +9,9 @@ public interface AsyncAction<Result> {
AsyncCallback<Result> getCallback();
void setCallback(AsyncCallback<Result> callback);
AsyncCallback<?> getWrapperCallback();
void setWrapperCallback(AsyncCallback<Result> callback);
String getName();
String getType();
}
@@ -22,11 +22,11 @@ public class AsyncActionsExecutor {
}
public <T> void execute(final AsyncAction<T> action) {
Integer numActionsOfType = actionsPerType.get(action.getName());
Integer numActionsOfType = actionsPerType.get(action.getType());
if (numPendingCalls >= maxPendingCalls || (numActionsOfType != null && numActionsOfType > maxPendingCallsPerType)) {
GWT.log("Drop action : " + action.getName());
GWT.log("Drop action : " + action.getType());
// don't put the call into the execution queue, but save it as the last one of each type
lastRequestedActions.put(action.getName(), action);
lastRequestedActions.put(action.getType(), action);
return;
}
@@ -34,12 +34,12 @@ public class AsyncActionsExecutor {
AsyncCallback<T> wrapper = new AsyncCallback<T>() {
@Override
public void onFailure(Throwable caught) {
String actionName = action.getName();
String actionName = action.getType();
GWT.log("Execution failure for action of type: " + actionName);
AsyncCallback<T> callback = action.getCallback();
callback.onFailure(caught);
Integer numActionsPerType = actionsPerType.get(actionName);
if(numActionsPerType != null && numActionsPerType > 0) {
if (numActionsPerType != null && numActionsPerType > 0) {
actionsPerType.put(actionName, numActionsPerType-1);
}
numPendingCalls--;
@@ -48,12 +48,12 @@ public class AsyncActionsExecutor {
@Override
public void onSuccess(T result) {
String actionName = action.getName();
String actionName = action.getType();
GWT.log("Execution success for action of type: " + actionName);
AsyncCallback<T> callback = action.getCallback();
callback.onSuccess(result);
Integer numActionsPerType = actionsPerType.get(actionName);
if(numActionsPerType != null && numActionsPerType > 0) {
if (numActionsPerType != null && numActionsPerType > 0) {
actionsPerType.put(actionName, numActionsPerType-1);
}
numPendingCalls--;
@@ -63,19 +63,19 @@ public class AsyncActionsExecutor {
action.setWrapperCallback(wrapper);
action.execute();
if(numActionsOfType == null) {
if (numActionsOfType == null) {
numActionsOfType = 0;
}
actionsPerType.put(action.getName(), numActionsOfType+1);
actionsPerType.put(action.getType(), numActionsOfType+1);
numPendingCalls++;
GWT.log("Execute action: " + action.getName());
GWT.log("Execute action: " + action.getType());
GWT.log("Pending actions counter: " + numPendingCalls);
}
private void checkForEmptyCallQueue(String actionName) {
if(numPendingCalls == 0 && lastRequestedActions.containsKey(actionName)) {
if (numPendingCalls == 0 && lastRequestedActions.containsKey(actionName)) {
AsyncAction<?> lastRequestedAction = lastRequestedActions.get(actionName);
GWT.log("Set back last action : " + lastRequestedAction.getName());
GWT.log("Set back last action : " + lastRequestedAction.getType());
execute(lastRequestedAction);
}
}
@@ -4,9 +4,13 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
public abstract class DefaultAsyncAction<Result> implements AsyncAction<Result> {
private AsyncCallback<Result> wrapperCallback;
private AsyncCallback<Result> callback;
private final AsyncCallback<Result> callback;
private Result result;
protected DefaultAsyncAction(AsyncCallback<Result> callback) {
this.callback = callback;
}
public AsyncCallback<Result> getWrapperCallback() {
return wrapperCallback;
}
@@ -21,12 +25,7 @@ public abstract class DefaultAsyncAction<Result> implements AsyncAction<Result>
}
@Override
public void setCallback(AsyncCallback<Result> callback) {
this.callback = callback;
}
@Override
public String getName() {
public String getType() {
return getClass().getName();
}
@@ -20,7 +20,9 @@ public class GetBoatPositionsAction extends DefaultAsyncAction<Map<CompetitorDTO
public GetBoatPositionsAction(SailingServiceAsync sailingService, RaceIdentifier raceIdentifier,
Map<CompetitorDTO, Date> from, Map<CompetitorDTO, Date> to, boolean extrapolate) {
Map<CompetitorDTO, Date> from, Map<CompetitorDTO, Date> to, boolean extrapolate,
AsyncCallback<Map<CompetitorDTO, List<GPSFixDTO>>> callback) {
super(callback);
this.sailingService = sailingService;
this.raceIdentifier = raceIdentifier;
this.from = from;
@@ -21,7 +21,8 @@ public class GetCompetitorsRaceDataAction extends DefaultAsyncAction<MultiCompet
private final DetailType detailType;
public GetCompetitorsRaceDataAction(SailingServiceAsync sailingService, RaceIdentifier race, List<Pair<Date, CompetitorDTO>> competitorsQuery,
Date toDate, long stepSize, DetailType detailType) {
Date toDate, long stepSize, DetailType detailType, AsyncCallback<MultiCompetitorRaceDataDTO> callback) {
super(callback);
this.sailingService = sailingService;
this.race = race;
this.competitorsQuery = competitorsQuery;
@@ -14,7 +14,8 @@ public class GetLeaderboardByNameAction extends DefaultAsyncAction<LeaderboardDT
private final Collection<String> namesOfRacesForWhichToLoadLegDetails;
public GetLeaderboardByNameAction(SailingServiceAsync sailingService, String leaderboardName, Date date,
final Collection<String> namesOfRacesForWhichToLoadLegDetails) {
final Collection<String> namesOfRacesForWhichToLoadLegDetails, AsyncCallback<LeaderboardDTO> callback) {
super(callback);
this.sailingService = sailingService;
this.leaderboardName = leaderboardName;
this.date = date;
@@ -13,7 +13,9 @@ public class GetMarkPositionsAction extends DefaultAsyncAction<List<MarkDTO>> {
private final RaceIdentifier raceIdentifier;
private final Date date;
public GetMarkPositionsAction(SailingServiceAsync sailingService, RaceIdentifier raceIdentifier, Date date) {
public GetMarkPositionsAction(SailingServiceAsync sailingService, RaceIdentifier raceIdentifier, Date date,
AsyncCallback<List<MarkDTO>> callback) {
super(callback);
this.sailingService = sailingService;
this.raceIdentifier = raceIdentifier;
this.date = date;
@@ -13,7 +13,9 @@ public class GetQuickRankAction extends DefaultAsyncAction<List<QuickRankDTO>> {
private final RaceIdentifier raceIdentifier;
private final Date date;
public GetQuickRankAction(SailingServiceAsync sailingService, RaceIdentifier raceIdentifier, Date date) {
public GetQuickRankAction(SailingServiceAsync sailingService, RaceIdentifier raceIdentifier, Date date,
AsyncCallback<List<QuickRankDTO>> callback) {
super(callback);
this.sailingService = sailingService;
this.raceIdentifier = raceIdentifier;
this.date = date;
@@ -18,7 +18,9 @@ public class GetRaceMapDataAction extends DefaultAsyncAction<RaceMapDataDTO> {
private final Date date;
public GetRaceMapDataAction(SailingServiceAsync sailingService, RaceIdentifier raceIdentifier, Date date,
Map<CompetitorDTO, Date> from, Map<CompetitorDTO, Date> to, boolean extrapolate) {
Map<CompetitorDTO, Date> from, Map<CompetitorDTO, Date> to, boolean extrapolate,
AsyncCallback<RaceMapDataDTO> callback) {
super(callback);
this.sailingService = sailingService;
this.raceIdentifier = raceIdentifier;
this.date = date;
@@ -24,7 +24,8 @@ public class GetWindInfoAction extends DefaultAsyncAction<WindInfoForRaceDTO> {
private final CallVariants callVariant;
public GetWindInfoAction(SailingServiceAsync sailingService, RaceIdentifier raceIdentifier, Date from, long millisecondsStepWidth,
int numberOfFixes, Collection<String> windSourceTypeNames) {
int numberOfFixes, Collection<String> windSourceTypeNames, AsyncCallback<WindInfoForRaceDTO> callback) {
super(callback);
this.sailingService = sailingService;
this.raceIdentifier = raceIdentifier;
this.from = from;
@@ -34,8 +35,10 @@ public class GetWindInfoAction extends DefaultAsyncAction<WindInfoForRaceDTO> {
callVariant = CallVariants.Variant1;
}
public GetWindInfoAction(SailingServiceAsync sailingService, RaceIdentifier raceIdentifier,
Date fromDate, Date toDate, long resolutionInMilliseconds, Collection<String> windSourceTypeNames) {
public GetWindInfoAction(SailingServiceAsync sailingService, RaceIdentifier raceIdentifier, Date fromDate,
Date toDate, long resolutionInMilliseconds, Collection<String> windSourceTypeNames,
AsyncCallback<WindInfoForRaceDTO> callback) {
super(callback);
this.sailingService = sailingService;
this.raceIdentifier = raceIdentifier;
this.fromDate = fromDate;
@@ -48,7 +48,8 @@ public class AdminConsoleEntryPoint extends AbstractEntryPoint implements EventR
CreateSwissTimingRacePanel createSwissTimingRacePanel = new CreateSwissTimingRacePanel(sailingService,this,stringMessages);
createSwissTimingRacePanel.setSize("90%", "90%");
tabPanel.add(createSwissTimingRacePanel,"Create SwissTiming race",false);
WindPanel windPanel = new WindPanel(sailingService, this, this, stringMessages);
final AsyncActionsExecutor asyncActionsExecutor = new AsyncActionsExecutor();
WindPanel windPanel = new WindPanel(sailingService, asyncActionsExecutor, this, this, stringMessages);
eventDisplayers.add(windPanel);
windPanel.setSize("90%", "90%");
tabPanel.add(windPanel, stringMessages.wind(), /* asHTML */ false);
@@ -59,7 +60,7 @@ public class AdminConsoleEntryPoint extends AbstractEntryPoint implements EventR
tabPanel.add(raceMapPanel, stringMessages.map(), /* asHTML */ false);
LeaderboardSettings defaultLeaderboardSettings = LeaderboardSettingsFactory.getInstance()
.createNewDefaultSettings(/* racesToShow */ null, /* namesOfRacesToShow */ null, /* autoExpandFirstRace */false);
final LeaderboardPanel defaultLeaderboardPanel = new LeaderboardPanel(sailingService, new AsyncActionsExecutor(),
final LeaderboardPanel defaultLeaderboardPanel = new LeaderboardPanel(sailingService, asyncActionsExecutor,
defaultLeaderboardSettings,
/* preSelectedRace */null, new CompetitorSelectionModel(/* hasMultiSelection */true),
DefaultLeaderboardName.DEFAULT_LEADERBOARD_NAME, /* leaderboard group name */null, this,
@@ -80,8 +80,8 @@ public class CombinedWindPanel extends FlowPanel implements TimeListener, RaceSe
RaceIdentifier race = selectedRaces.get(selectedRaces.size() - 1);
if (race != null) {
// draw the wind into the map, get the combined wind
GetWindInfoAction getWindInfoAction = new GetWindInfoAction(sailingService, race, date, 1000L, 1, windSourceTypeNames);
getWindInfoAction.setCallback(new AsyncCallback<WindInfoForRaceDTO>() {
GetWindInfoAction getWindInfoAction = new GetWindInfoAction(sailingService, race, date, 1000L, 1, windSourceTypeNames,
new AsyncCallback<WindInfoForRaceDTO>() {
@Override
public void onFailure(Throwable caught) {
if(timer.getPlayMode() != PlayModes.Live)
@@ -329,9 +329,7 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe
final int requestID = ++boatPositionRequestIDCounter;
GetRaceMapDataAction getRaceMapDataAction = new GetRaceMapDataAction(sailingService, race, date,
fromAndToAndOverlap.getA(), fromAndToAndOverlap.getB(), true);
getRaceMapDataAction.setCallback(new AsyncCallback<RaceMapDataDTO>() {
fromAndToAndOverlap.getA(), fromAndToAndOverlap.getB(), true, new AsyncCallback<RaceMapDataDTO>() {
@Override
public void onFailure(Throwable caught) {
if(timer.getPlayMode() != PlayModes.Live)
@@ -390,8 +388,8 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe
List<String> windSourceTypeNames = new ArrayList<String>();
windSourceTypeNames.add(WindSourceType.EXPEDITION.name());
GetWindInfoAction getWindInfoAction = new GetWindInfoAction(sailingService, race, date, 1000L, 1, windSourceTypeNames);
getWindInfoAction.setCallback(new AsyncCallback<WindInfoForRaceDTO>() {
GetWindInfoAction getWindInfoAction = new GetWindInfoAction(sailingService, race, date, 1000L, 1, windSourceTypeNames,
new AsyncCallback<WindInfoForRaceDTO>() {
@Override
public void onFailure(Throwable caught) {
if(timer.getPlayMode() != PlayModes.Live)
@@ -42,6 +42,7 @@ import com.google.gwt.user.client.ui.Widget;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.WindSource;
import com.sap.sailing.domain.common.WindSourceType;
import com.sap.sailing.gwt.ui.actions.AsyncActionsExecutor;
import com.sap.sailing.gwt.ui.actions.GetWindInfoAction;
import com.sap.sailing.gwt.ui.client.ColorMap;
import com.sap.sailing.gwt.ui.client.ErrorReporter;
@@ -74,6 +75,7 @@ public class WindChart extends SimplePanel implements Component<WindChartSetting
private final Map<WindSource, Series> windSourceSpeedSeries;
private final ErrorReporter errorReporter;
private final AsyncActionsExecutor asyncActionsExecutor;
private final SailingServiceAsync sailingService;
private final Chart chart;
private Series timeLineSeries;
@@ -93,12 +95,14 @@ public class WindChart extends SimplePanel implements Component<WindChartSetting
* if <code>null</code>, this chart won't update its contents automatically upon race selection change;
* otherwise, whenever the selection changes, the wind data of the race selected now is loaded from the
* server and displayed in this chart. If no race is selected, the chart is cleared.
* @param asyncActionsExecutor TODO
*/
public WindChart(SailingServiceAsync sailingService, RaceSelectionProvider raceSelectionProvider, Timer timer,
WindChartSettings settings, final StringMessages stringMessages, ErrorReporter errorReporter,
boolean compactChart, boolean allowTimeAdjust) {
WindChartSettings settings, final StringMessages stringMessages, AsyncActionsExecutor asyncActionsExecutor,
ErrorReporter errorReporter, boolean compactChart, boolean allowTimeAdjust) {
super();
this.sailingService = sailingService;
this.asyncActionsExecutor = asyncActionsExecutor;
this.stringMessages = stringMessages;
this.errorReporter = errorReporter;
this.allowTimeAdjust = allowTimeAdjust;
@@ -467,9 +471,7 @@ public class WindChart extends SimplePanel implements Component<WindChartSetting
// TODO Time interval should be determined by a selection in the chart but be at most 60s. See bug #121.
// Consider incremental updates for new data only.
from, to, resolutionInMilliseconds, // use race start and time of newest event as default time period
null); // retrieve data on all wind sources
getWindInfoAction.setCallback(new AsyncCallback<WindInfoForRaceDTO>() {
null, new AsyncCallback<WindInfoForRaceDTO>() {
@Override
public void onSuccess(WindInfoForRaceDTO result) {
if (result != null) {
@@ -488,6 +490,7 @@ public class WindChart extends SimplePanel implements Component<WindChartSetting
+ raceIdentifier + ": " + caught.getMessage());
}
});
asyncActionsExecutor.execute(getWindInfoAction);
}
}
@@ -39,6 +39,7 @@ import com.google.gwt.view.client.ListDataProvider;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.WindSource;
import com.sap.sailing.domain.common.WindSourceType;
import com.sap.sailing.gwt.ui.actions.AsyncActionsExecutor;
import com.sap.sailing.gwt.ui.client.ErrorReporter;
import com.sap.sailing.gwt.ui.client.EventDisplayer;
import com.sap.sailing.gwt.ui.client.EventRefresher;
@@ -84,8 +85,8 @@ public class WindPanel extends FormPanel implements EventDisplayer, WindShower,
private final WindChart windChart;
private static AdminConsoleResources resources = GWT.create(AdminConsoleResources.class);
public WindPanel(final SailingServiceAsync sailingService, ErrorReporter errorReporter,
EventRefresher eventRefresher, final StringMessages stringMessages) {
public WindPanel(final SailingServiceAsync sailingService, AsyncActionsExecutor asyncActionsExecutor,
ErrorReporter errorReporter, EventRefresher eventRefresher, final StringMessages stringMessages) {
this.sailingService = sailingService;
this.errorReporter = errorReporter;
this.stringMessages = stringMessages;
@@ -180,7 +181,7 @@ public class WindPanel extends FormPanel implements EventDisplayer, WindShower,
windSourceSelectionPanel.add(showConfigAnchor);
grid.setWidget(1, 0, windSourceSelectionPanel);
windChart = new WindChart(sailingService, raceSelectionProvider, new Timer(
PlayModes.Replay), new WindChartSettings(WindSourceType.values()), stringMessages, errorReporter, false, false);
PlayModes.Replay), new WindChartSettings(WindSourceType.values()), stringMessages, asyncActionsExecutor, errorReporter, false, false);
windChart.onResize();
grid.setWidget(2, 0, windChart.getEntryWidget());
grid.getCellFormatter().setVerticalAlignment(1, 1, HasVerticalAlignment.ALIGN_TOP);
@@ -146,7 +146,7 @@ public interface SailingServiceAsync {
* result ({@link LeaderboardEntryDTO#legDetails} will be <code>null</code> for all
* {@link LeaderboardEntryDTO} objects contained). Otherwise, the {@link LeaderboardEntryDTO#legDetails}
* list will contain one entry per leg of the race {@link Course} for those race columns whose
* {@link RaceInLeaderboard#getName() name} is contained in
* {@link RaceInLeaderboard#getType() name} is contained in
* <code>namesOfRacesForWhichToLoadLegDetails</code>. For all other columns,
* {@link LeaderboardEntryDTO#legDetails} is <code>null</code>.
*/
@@ -276,8 +276,8 @@ implements CompetitorSelectionChangeListener, RaceSelectionChangeListener, TimeL
}
GetCompetitorsRaceDataAction getCompetitorsRaceDataAction = new GetCompetitorsRaceDataAction(sailingService,
getSelectedRace(), dataQuery, toDate, getStepSize(), getDataToShow());
getCompetitorsRaceDataAction.setCallback(new AsyncCallback<MultiCompetitorRaceDataDTO>() {
getSelectedRace(), dataQuery, toDate, getStepSize(), getDataToShow(),
new AsyncCallback<MultiCompetitorRaceDataDTO>() {
@Override
public void onFailure(Throwable caught) {
@@ -301,7 +301,6 @@ implements CompetitorSelectionChangeListener, RaceSelectionChangeListener, TimeL
setWidget(chart);
}
});
asyncActionsExecutor.execute(getCompetitorsRaceDataAction);
} else {
setWidget(noCompetitorsSelectedLabel);
@@ -1127,8 +1127,7 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta
private void loadCompleteLeaderboard(Date date) {
if (needsDataLoading()) {
GetLeaderboardByNameAction getLeaderboardByNameAction = new GetLeaderboardByNameAction(sailingService, getLeaderboardName(), date,
/* namesOfRacesForWhichToLoadLegDetails */getNamesOfExpandedRaces());
getLeaderboardByNameAction.setCallback(new AsyncCallback<LeaderboardDTO>() {
/* namesOfRacesForWhichToLoadLegDetails */getNamesOfExpandedRaces(), new AsyncCallback<LeaderboardDTO>() {
@Override
public void onSuccess(LeaderboardDTO result) {
updateLeaderboard(result);
@@ -177,7 +177,7 @@ public class RaceBoardPanel extends FormPanel implements EventDisplayer, RaceSel
components.add(competitorChart);
competitorChart.setVisible(false);
windChart = createWindChart();
windChart = createWindChart(asyncActionsExecutor);
windChart.onRaceSelectionChange(raceSelectionProvider.getSelectedRaces());
windChart.setVisible(false);
components.add(windChart);
@@ -275,7 +275,7 @@ public class RaceBoardPanel extends FormPanel implements EventDisplayer, RaceSel
componentViewers.add(raceMapViewer);
}
windChart = createWindChart();
windChart = createWindChart(asyncActionsExecutor);
windChartViewer = new CollapsableComponentViewer<WindChartSettings>(
windChart, "auto", "400px", stringMessages);
windChart.onRaceSelectionChange(raceSelectionProvider.getSelectedRaces());
@@ -312,10 +312,10 @@ public class RaceBoardPanel extends FormPanel implements EventDisplayer, RaceSel
userAgentType);
}
private WindChart createWindChart() {
private WindChart createWindChart(AsyncActionsExecutor asyncActionsExecutor) {
WindChartSettings windChartSettings = new WindChartSettings(WindSourceType.values());
return new WindChart(sailingService, raceSelectionProvider, timer, windChartSettings,
stringMessages, errorReporter, viewMode == RaceBoardViewModes.ONESCREEN, true);
stringMessages, asyncActionsExecutor, errorReporter, viewMode == RaceBoardViewModes.ONESCREEN, true);
}
private void addComponentAsToogleButtonToNavigationMenu(final ComponentViewer componentViewer,