Initial client side caching implementation

This commit is contained in:
Papick Garcia Taboada committed 2015-10-13 10:06:23 +02:00
1 parent f1e2a7404b
commit 68683b4c7a
23 files changed
+321 -29

No files matched your search

@@ -0,0 +1,143 @@
package com.sap.sailing.gwt.home.shared.dispatch;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Logger;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.Result;
import com.sap.sse.common.Duration;
/**
*
* @author pgtaboada
*
*/
public final class CachingDispatch implements DispatchAsync {
private static final Logger LOG = Logger.getLogger(CachingDispatch.class.getName());
private final DispatchAsync dispatch;
private final HashMap<String, ResultHolder> resultsCache = new HashMap<>();
private final int DEFAULT_TIME_TO_LIVE_MILLIS = (int) Duration.ONE_SECOND.asMillis() * 30;
private final InvalidationTask invalidationTask = new InvalidationTask();
public CachingDispatch(DispatchAsync service) {
this.dispatch = service;
}
@SuppressWarnings("unchecked")
@Override
public <R extends Result, A extends Action<R>> void execute(A action, AsyncCallback<R> callback) {
if (action instanceof IsClientCacheable) {
final IsClientCacheable clientCacheableAction = (IsClientCacheable) action;
final ResultHolder cachedResult = resultsCache.get(key(clientCacheableAction));
if (cachedResult != null ) {
if (cachedResult.isValid()) {
LOG.fine("Cache hit for " + action.getClass().getName());
callback.onSuccess((R) cachedResult.payload);
} else {
executeAndCache(action, callback);
}
} else {
LOG.fine("Cache miss for " + action.getClass().getName());
executeAndCache(action, callback);
}
} else {
LOG.fine("Action is not cacheable: " + action.getClass().getName());
dispatch.execute(action, callback);
}
};
/**
* Perform dispatch call with intercepting callback.
* @param action
* @param callback
*/
private <R extends Result, A extends Action<R>> void executeAndCache(final A action, final AsyncCallback<R> callback) {
dispatch.execute(action, new InterceptingCallback<>(action, callback));
}
/**
* Intercepting callback that stores the result into cache.
*
* @author pgtaboada
*
* @param <R>
* @param <A>
*/
private class InterceptingCallback<R extends Result, A extends Action<R>> implements AsyncCallback<R> {
private final A action;
private final AsyncCallback<R> callback;
public InterceptingCallback(A action, AsyncCallback<R> callback) {
this.action = action;
this.callback = callback;
}
@Override
public void onSuccess(R result) {
if (action instanceof IsClientCacheable) {
// we should cache the action
int cacheTotalTimeToLiveMillis = DEFAULT_TIME_TO_LIVE_MILLIS;
if (result instanceof HasClientCacheTotalTimeToLive) {
cacheTotalTimeToLiveMillis = ((HasClientCacheTotalTimeToLive) result).cacheTotalTimeToLiveMillis();
} else if (action instanceof HasClientCacheTotalTimeToLive) {
cacheTotalTimeToLiveMillis = ((HasClientCacheTotalTimeToLive) action).cacheTotalTimeToLiveMillis();
}
IsClientCacheable clientCacheableAction = (IsClientCacheable) action;
LOG.finest("Added " + key(clientCacheableAction) + " to cache, ttl: "
+ cacheTotalTimeToLiveMillis + "ms");
resultsCache.put(key(clientCacheableAction), new ResultHolder(System.currentTimeMillis()
+ cacheTotalTimeToLiveMillis, result));
// schedule cache cleanup
invalidationTask.schedule((int) (cacheTotalTimeToLiveMillis + Duration.ONE_SECOND.asMillis()));
}
callback.onSuccess(result);
}
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
}
private String key(IsClientCacheable action) {
StringBuilder key = new StringBuilder(action.getClass().getName()).append("_");
action.cacheInstanceKey(key);
return key.toString();
}
private static class ResultHolder {
final Result payload;
final long invalidationTimestamp;
public ResultHolder(long invalidationTimestamp, Result payload) {
this.invalidationTimestamp = invalidationTimestamp;
this.payload = payload;
}
public boolean isValid() {
return System.currentTimeMillis() < invalidationTimestamp;
}
public Result getPayload() {
return payload;
}
}
private class InvalidationTask extends Timer {
@Override
public void run() {
ArrayList<String> keys = new ArrayList<String>(resultsCache.keySet());
for (String key : keys) {
if (!resultsCache.get(key).isValid()) {
resultsCache.remove(key);
}
}
}
}
}
@@ -11,7 +11,7 @@ import com.sap.sailing.gwt.ui.shared.dispatch.ServerDispatchException;
public class DispatchSystemImpl implements DispatchSystem {
private final SimpleDispatch simpleDispatch = new SimpleDispatch(null);
private final DispatchAsync dispatch = new AutomaticBatchingDispatch(simpleDispatch);
private final DispatchAsync dispatch = new CachingDispatch(new AutomaticBatchingDispatch(simpleDispatch));
@Override
public <R extends Result, A extends Action<R>> void execute(final A action, final AsyncCallback<R> callback) {
@@ -0,0 +1,17 @@
package com.sap.sailing.gwt.home.shared.dispatch;
/**
* Interface used by actions and results to override default cache time to live.
*
* @author pgtaboada
*
*/
public interface HasClientCacheTotalTimeToLive {
/**
* How long should the result be stored in the client side cache
*
* @return
*/
int cacheTotalTimeToLiveMillis();
}
@@ -0,0 +1,17 @@
package com.sap.sailing.gwt.home.shared.dispatch;
/**
* Cache interface used by the caching dispatch to identify which command can be cached on client side.
*
* @author pgtaboada
*
*/
public interface IsClientCacheable {
/**
* The instance specific key used to identify instance specific results in the cache.
*
* @return
*/
void cacheInstanceKey(StringBuilder key);
}
@@ -26,6 +26,7 @@ public class RefreshManager {
private static final long PAUSE_ON_ERROR = Duration.ONE_SECOND.times(30).asMillis();
private List<RefreshHolder<DTO, Action<ResultWithTTL<DTO>>>> refreshables = new ArrayList<>();
private boolean scheduled;
private final Timer timer = new Timer() {
@Override
public void run() {
@@ -63,6 +64,7 @@ public class RefreshManager {
}
private void update() {
for (final RefreshHolder<DTO, Action<ResultWithTTL<DTO>>> refreshable : refreshables) {
// Everything that needs refresh within the next 5000ms will be refreshed now.
// This makes it possible to use batching resulting in less requests.
@@ -94,8 +96,6 @@ public class RefreshManager {
}
}
boolean scheduled;
private void reschedule() {
if (scheduled) {
return;
@@ -1,9 +1,10 @@
package com.sap.sailing.gwt.ui.shared.dispatch;
import com.sap.sailing.gwt.home.shared.dispatch.HasClientCacheTotalTimeToLive;
import com.sap.sse.common.Duration;
import com.sap.sse.common.impl.MillisecondsDurationImpl;
public class ResultWithTTL<T extends DTO> implements Result {
public class ResultWithTTL<T extends DTO> implements Result, HasClientCacheTotalTimeToLive {
/** Time to live*/
private Duration ttl;
@@ -33,4 +34,9 @@ public class ResultWithTTL<T extends DTO> implements Result {
public long getTtlMillis() {
return ttl.asMillis();
}
@Override
public int cacheTotalTimeToLiveMillis() {
return (int) getTtlMillis();
}
}
@@ -3,6 +3,7 @@ package com.sap.sailing.gwt.ui.shared.dispatch.event;
import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchException;
@@ -10,7 +11,8 @@ import com.sap.sailing.gwt.ui.shared.dispatch.ListResult;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
import com.sap.sse.common.Duration;
public class GetCompetitionFormatRacesAction implements Action<ResultWithTTL<ListResult<RaceCompetitionFormatSeriesDTO>>> {
public class GetCompetitionFormatRacesAction implements
Action<ResultWithTTL<ListResult<RaceCompetitionFormatSeriesDTO>>>, IsClientCacheable {
private UUID eventId;
private String regattaId;
@@ -32,4 +34,8 @@ public class GetCompetitionFormatRacesAction implements Action<ResultWithTTL<Lis
return new ResultWithTTL<>(timeToLive, new ListResult<>(competitionFormatDataCalculator.getResult()));
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(eventId).append("_").append(regattaId);
}
}
@@ -6,6 +6,7 @@ import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ListResult;
@@ -19,7 +20,7 @@ import com.sap.sailing.news.impl.InfoEventNewsItem;
import com.sap.sailing.news.impl.LeaderboardUpdateNewsItem;
import com.sap.sse.common.Duration;
public class GetEventOverviewNewsAction implements Action<ResultWithTTL<ListResult<NewsEntryDTO>>> {
public class GetEventOverviewNewsAction implements Action<ResultWithTTL<ListResult<NewsEntryDTO>>>, IsClientCacheable {
private UUID eventId;
/**
* This is number of items to deliver
@@ -68,4 +69,9 @@ public class GetEventOverviewNewsAction implements Action<ResultWithTTL<ListResu
}
return news;
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(eventId).append("_").append(limit);
}
}
@@ -9,6 +9,7 @@ import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.server.HomeServiceUtil;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
@@ -22,7 +23,7 @@ import com.sap.sse.common.impl.MillisecondsTimePoint;
import com.sap.sse.common.media.MediaTagConstants;
import com.sap.sse.common.media.VideoDescriptor;
public class GetEventOverviewStageAction implements Action<ResultWithTTL<EventOverviewStageDTO>> {
public class GetEventOverviewStageAction implements Action<ResultWithTTL<EventOverviewStageDTO>>, IsClientCacheable {
private UUID eventId;
private boolean useTeaserImage;
@@ -130,4 +131,9 @@ public class GetEventOverviewStageAction implements Action<ResultWithTTL<EventOv
//
// return new EventOverviewTickerStageDTO(null, null, stageImageUrl);
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(eventId).append("_").append(useTeaserImage);
}
}
@@ -3,11 +3,12 @@ package com.sap.sailing.gwt.ui.shared.dispatch.event;
import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
public class GetEventStatisticsAction implements Action<ResultWithTTL<EventStatisticsDTO>> {
public class GetEventStatisticsAction implements Action<ResultWithTTL<EventStatisticsDTO>>, IsClientCacheable {
private UUID eventId;
@@ -25,4 +26,9 @@ public class GetEventStatisticsAction implements Action<ResultWithTTL<EventStati
EventActionUtil.forLeaderboardsOfEvent(context, eventId, statisticsCalculator);
return statisticsCalculator.getResult();
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(eventId);
}
}
@@ -12,6 +12,7 @@ import java.util.logging.Logger;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.server.HomeServiceUtil;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
@@ -23,7 +24,7 @@ import com.sap.sailing.gwt.ui.shared.general.EventReferenceDTO;
import com.sap.sse.common.media.ImageDescriptor;
import com.sap.sse.common.media.MediaTagConstants;
public class GetEventViewAction implements Action<EventViewDTO> {
public class GetEventViewAction implements Action<EventViewDTO>, IsClientCacheable {
private static final Logger logger = Logger.getLogger(GetEventViewAction.class.getName());
private UUID eventId;
@@ -112,7 +113,11 @@ public class GetEventViewAction implements Action<EventViewDTO> {
localizedURL += "en";
dto.setSailorsInfoWebsiteURL(localizedURL);
}
return dto;
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(eventId);
}
}
@@ -3,13 +3,15 @@ package com.sap.sailing.gwt.ui.shared.dispatch.event;
import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
import com.sap.sailing.gwt.ui.shared.dispatch.SortedSetResult;
import com.sap.sse.common.Duration;
public class GetFinishedRacesAction implements Action<ResultWithTTL<SortedSetResult<RaceListRaceDTO>>> {
public class GetFinishedRacesAction implements Action<ResultWithTTL<SortedSetResult<RaceListRaceDTO>>>,
IsClientCacheable {
private UUID eventId;
private String regattaId;
@@ -32,4 +34,9 @@ public class GetFinishedRacesAction implements Action<ResultWithTTL<SortedSetRes
return new ResultWithTTL<>(EventActionUtil.getEventStateDependentTTL(context, eventId,
Duration.ONE_MINUTE.times(5)), new SortedSetResult<>(raceListDataCalculator.getResult()));
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(eventId).append("_").append(regattaId);
}
}
@@ -4,13 +4,15 @@ import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
import com.sap.sailing.gwt.ui.shared.dispatch.SortedSetResult;
import com.sap.sailing.gwt.ui.shared.dispatch.event.EventActionUtil.CalculationWithEvent;
public class GetLiveRacesForEventAction implements Action<ResultWithTTL<SortedSetResult<LiveRaceDTO>>> {
public class GetLiveRacesForEventAction implements Action<ResultWithTTL<SortedSetResult<LiveRaceDTO>>>,
IsClientCacheable {
private UUID eventId;
@SuppressWarnings("unused")
@@ -33,4 +35,9 @@ public class GetLiveRacesForEventAction implements Action<ResultWithTTL<SortedSe
}
});
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(eventId);
}
}
@@ -4,13 +4,15 @@ import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
import com.sap.sailing.gwt.ui.shared.dispatch.SortedSetResult;
import com.sap.sailing.gwt.ui.shared.dispatch.event.EventActionUtil.CalculationWithEvent;
public class GetLiveRacesForRegattaAction implements Action<ResultWithTTL<SortedSetResult<LiveRaceDTO>>> {
public class GetLiveRacesForRegattaAction implements Action<ResultWithTTL<SortedSetResult<LiveRaceDTO>>>,
IsClientCacheable {
private UUID eventId;
private String regattaName;
@@ -35,4 +37,9 @@ public class GetLiveRacesForRegattaAction implements Action<ResultWithTTL<Sorted
}
});
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(eventId);
}
}
@@ -3,11 +3,12 @@ package com.sap.sailing.gwt.ui.shared.dispatch.event;
import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
public class GetMiniLeaderbordAction implements Action<ResultWithTTL<GetMiniLeaderboardDTO>> {
public class GetMiniLeaderbordAction implements Action<ResultWithTTL<GetMiniLeaderboardDTO>>, IsClientCacheable {
private UUID eventId;
private String leaderboardName;
private int limit = 0;
@@ -31,4 +32,13 @@ public class GetMiniLeaderbordAction implements Action<ResultWithTTL<GetMiniLead
public ResultWithTTL<GetMiniLeaderboardDTO> execute(DispatchContext context) {
return EventActionUtil.getLeaderboardContext(context, eventId, leaderboardName).calculateMiniLeaderboard(context.getRacingEventService(), limit);
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(eventId);
key.append("_");
key.append(leaderboardName);
key.append("_");
key.append(limit);
}
}
@@ -3,11 +3,12 @@ package com.sap.sailing.gwt.ui.shared.dispatch.event;
import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
public class GetMiniOverallLeaderbordAction implements Action<ResultWithTTL<GetMiniLeaderboardDTO>> {
public class GetMiniOverallLeaderbordAction implements Action<ResultWithTTL<GetMiniLeaderboardDTO>>, IsClientCacheable {
private UUID seriesId;
private int limit = 0;
@@ -29,4 +30,9 @@ public class GetMiniOverallLeaderbordAction implements Action<ResultWithTTL<GetM
public ResultWithTTL<GetMiniLeaderboardDTO> execute(DispatchContext context) {
return EventActionUtil.getOverallLeaderboardContext(context, seriesId).calculateMiniLeaderboard(context.getRacingEventService(), limit);
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(seriesId).append("_").append(limit);
}
}
@@ -5,6 +5,7 @@ import java.util.List;
import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
@@ -13,7 +14,8 @@ import com.sap.sailing.gwt.ui.shared.dispatch.event.EventActionUtil.LeaderboardC
import com.sap.sailing.gwt.ui.shared.dispatch.regatta.RegattaWithProgressDTO;
import com.sap.sse.common.Duration;
public class GetRegattaListViewAction implements Action<ResultWithTTL<SortedSetResult<RegattaWithProgressDTO>>> {
public class GetRegattaListViewAction implements Action<ResultWithTTL<SortedSetResult<RegattaWithProgressDTO>>>,
IsClientCacheable {
private UUID eventId;
@SuppressWarnings("unused")
@@ -37,4 +39,9 @@ public class GetRegattaListViewAction implements Action<ResultWithTTL<SortedSetR
return new ResultWithTTL<>(EventActionUtil.getEventStateDependentTTL(context, eventId,
Duration.ONE_MINUTE.times(3)), new SortedSetResult<>(result));
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(eventId);
}
}
@@ -3,11 +3,12 @@ package com.sap.sailing.gwt.ui.shared.dispatch.event;
import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
public class GetRegattaStatisticsAction implements Action<ResultWithTTL<EventStatisticsDTO>>{
public class GetRegattaStatisticsAction implements Action<ResultWithTTL<EventStatisticsDTO>>, IsClientCacheable {
private UUID eventId;
private String regattaId;
@@ -28,4 +29,8 @@ public class GetRegattaStatisticsAction implements Action<ResultWithTTL<EventSta
return statisticsCalculator.getResult();
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(eventId).append("_").append(regattaId);
}
}
@@ -3,13 +3,14 @@ package com.sap.sailing.gwt.ui.shared.dispatch.event;
import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
import com.sap.sailing.gwt.ui.shared.dispatch.regatta.RegattaWithProgressDTO;
import com.sap.sse.common.Duration;
public class GetRegattaWithProgressAction implements Action<ResultWithTTL<RegattaWithProgressDTO>> {
public class GetRegattaWithProgressAction implements Action<ResultWithTTL<RegattaWithProgressDTO>>, IsClientCacheable {
private UUID eventId;
private String regattaId;
@@ -29,4 +30,9 @@ public class GetRegattaWithProgressAction implements Action<ResultWithTTL<Regatt
return new ResultWithTTL<>(EventActionUtil.getEventStateDependentTTL(context, eventId, Duration.ONE_MINUTE.times(5)),
EventActionUtil.getLeaderboardContext(context, eventId, regattaId).getRegattaWithProgress());
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(eventId).append("_").append(regattaId);
}
}
@@ -9,6 +9,7 @@ import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.server.HomeServiceUtil;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
@@ -19,7 +20,8 @@ import com.sap.sailing.gwt.ui.shared.eventview.RegattaMetadataDTO;
import com.sap.sailing.gwt.ui.shared.general.EventState;
import com.sap.sse.common.Duration;
public class GetRegattasAndLiveRacesForEventAction implements Action<ResultWithTTL<RegattasAndLiveRacesDTO>> {
public class GetRegattasAndLiveRacesForEventAction implements Action<ResultWithTTL<RegattasAndLiveRacesDTO>>,
IsClientCacheable {
private UUID eventId;
@SuppressWarnings("unused")
@@ -87,4 +89,9 @@ public class GetRegattasAndLiveRacesForEventAction implements Action<ResultWithT
}
return races;
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(eventId);
}
}
@@ -3,11 +3,12 @@ package com.sap.sailing.gwt.ui.shared.dispatch.event;
import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
public class GetSeriesStatisticsAction implements Action<ResultWithTTL<EventStatisticsDTO>>{
public class GetSeriesStatisticsAction implements Action<ResultWithTTL<EventStatisticsDTO>>, IsClientCacheable {
private UUID seriesId;
@@ -26,4 +27,8 @@ public class GetSeriesStatisticsAction implements Action<ResultWithTTL<EventStat
return statisticsCalculator.getResult();
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(seriesId);
}
}
@@ -8,13 +8,14 @@ import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.domain.base.EventBase;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.server.HomeServiceUtil;
import com.sap.sailing.gwt.server.HomeServiceUtil.EventVisitor;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ListResult;
public class GetRecentEventsAction implements Action<ListResult<EventQuickfinderDTO>> {
public class GetRecentEventsAction implements Action<ListResult<EventQuickfinderDTO>>, IsClientCacheable {
private int limit;
@@ -52,4 +53,9 @@ public class GetRecentEventsAction implements Action<ListResult<EventQuickfinder
}
return result;
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(limit);
}
}
@@ -3,6 +3,7 @@ package com.sap.sailing.gwt.ui.shared.dispatch.start;
import java.net.MalformedURLException;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.gwt.home.shared.dispatch.IsClientCacheable;
import com.sap.sailing.gwt.server.EventHolder;
import com.sap.sailing.gwt.server.EventStageCandidateCalculator;
import com.sap.sailing.gwt.server.HomeServiceImpl;
@@ -14,32 +15,38 @@ import com.sap.sailing.gwt.ui.shared.start.EventStageDTO;
import com.sap.sailing.gwt.ui.shared.start.StageEventType;
import com.sap.sse.common.Util.Pair;
public class GetStagedEventsAction implements Action<ListResult<EventStageDTO>> {
public class GetStagedEventsAction implements Action<ListResult<EventStageDTO>>, IsClientCacheable {
private boolean useTeaserImage;
protected GetStagedEventsAction() {
}
public GetStagedEventsAction(boolean useTeaserImage) {
this.useTeaserImage = useTeaserImage;
}
@GwtIncompatible
public ListResult<EventStageDTO> execute(final DispatchContext context) throws MalformedURLException {
EventStageCandidateCalculator stageCandidateCalculator = new EventStageCandidateCalculator();
HomeServiceUtil.forAllPublicEvents(context.getRacingEventService(), context.getRequest(), stageCandidateCalculator);
HomeServiceUtil.forAllPublicEvents(context.getRacingEventService(), context.getRequest(),
stageCandidateCalculator);
ListResult<EventStageDTO> result = new ListResult<>();
int count = 0;
for(Pair<StageEventType, EventHolder> pair : stageCandidateCalculator.getFeaturedEvents()) {
for (Pair<StageEventType, EventHolder> pair : stageCandidateCalculator.getFeaturedEvents()) {
count++;
if(count > HomeServiceImpl.MAX_STAGE_EVENTS) {
if (count > HomeServiceImpl.MAX_STAGE_EVENTS) {
break;
}
StageEventType stageType = pair.getA();
EventHolder holder = pair.getB();
result.addValue(HomeServiceUtil.convertToEventStageDTO(holder.event, holder.baseURL, holder.onRemoteServer, stageType, context.getRacingEventService(), useTeaserImage));
result.addValue(HomeServiceUtil.convertToEventStageDTO(holder.event, holder.baseURL, holder.onRemoteServer,
stageType, context.getRacingEventService(), useTeaserImage));
}
return result;
}
@Override
public void cacheInstanceKey(StringBuilder key) {
key.append(useTeaserImage);
}
}