diff --git a/java/com.sap.sailing.gwt.ui/WEB-INF/web.xml b/java/com.sap.sailing.gwt.ui/WEB-INF/web.xml index 8538c7b0804..7f9c9641021 100755 --- a/java/com.sap.sailing.gwt.ui/WEB-INF/web.xml +++ b/java/com.sap.sailing.gwt.ui/WEB-INF/web.xml @@ -70,6 +70,7 @@ SailingService /service/sailing + /service/sailing/* @@ -90,6 +91,7 @@ sailingDispatch /service/dispatch + /service/dispatch/* diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/communication/event/GetLiveRacesForRegattaAction.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/communication/event/GetLiveRacesForRegattaAction.java index ebee5ed0bf5..77c42356b79 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/communication/event/GetLiveRacesForRegattaAction.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/home/communication/event/GetLiveRacesForRegattaAction.java @@ -8,7 +8,9 @@ import com.sap.sailing.gwt.home.communication.SailingAction; import com.sap.sailing.gwt.home.communication.SailingDispatchContext; import com.sap.sailing.gwt.home.server.EventActionUtil; import com.sap.sailing.gwt.home.server.EventActionUtil.CalculationWithEvent; +import com.sap.sailing.gwt.home.shared.utils.SailingTransportRoutingUtils; import com.sap.sailing.gwt.home.server.LiveRaceCalculator; +import com.sap.sse.gwt.dispatch.client.system.routing.ProvidesDispatchRoutingKey; import com.sap.sse.gwt.dispatch.shared.caching.IsClientCacheable; import com.sap.sse.gwt.dispatch.shared.commands.ResultWithTTL; import com.sap.sse.gwt.dispatch.shared.commands.SortedSetResult; @@ -30,7 +32,7 @@ import com.sap.sse.gwt.dispatch.shared.commands.SortedSetResult; *

*/ public class GetLiveRacesForRegattaAction implements SailingAction>>, - IsClientCacheable { + IsClientCacheable, ProvidesDispatchRoutingKey { private UUID eventId; private String regattaName; @@ -66,4 +68,9 @@ public class GetLiveRacesForRegattaAction implements SailingAction */ -public class GetMiniLeaderbordAction implements SailingAction>, IsClientCacheable { +public class GetMiniLeaderbordAction implements SailingAction>, IsClientCacheable, ProvidesDispatchRoutingKey { private UUID eventId; private String leaderboardName; private int limit = 0; @@ -74,4 +77,9 @@ public class GetMiniLeaderbordAction implements SailingAction */ -public class GetMiniOverallLeaderbordAction implements SailingAction>, IsClientCacheable { +public class GetMiniOverallLeaderbordAction implements SailingAction>, IsClientCacheable,ProvidesDispatchRoutingKey { private UUID seriesId; private int limit = 0; @@ -63,4 +65,9 @@ public class GetMiniOverallLeaderbordAction implements SailingAction imp ProvidesServerTime { private final Logger LOG = Logger.getLogger(DispatchSystemDefaultImpl.class.getName()); private final DefaultTransport simpleDispatch; - private final DispatchSystemAsync dispatch; - + private final DispatchSystemAsync defaultDispatch; + private final Map> routingRegistry = new HashMap<>(); + private final boolean processResultsScheduled; + private final String dispatchRPCPath; + public DispatchSystemDefaultImpl(String dispatchRPCPath) { this(dispatchRPCPath, false); } @@ -43,10 +49,25 @@ public abstract class DispatchSystemDefaultImpl imp * use a {@link Scheduler} to process the results */ public DispatchSystemDefaultImpl(String dispatchRPCPath, boolean processResultsScheduled) { + this.dispatchRPCPath = dispatchRPCPath; + this.processResultsScheduled = processResultsScheduled; simpleDispatch = new DefaultTransport(dispatchRPCPath); - dispatch = new CachingDispatch(new AutomaticBatchingDispatch( - simpleDispatch, processResultsScheduled)); - LOG.finest("Started dispatch system for " + dispatchRPCPath); + defaultDispatch = new CachingDispatch(new AutomaticBatchingDispatch(simpleDispatch, processResultsScheduled)); + LOG.finest("Started default dispatch system for " + dispatchRPCPath); + } + + private DispatchSystemAsync createDispatchFor(String routing) { + final StringBuilder destinationUrlBuilder = new StringBuilder(dispatchRPCPath); + if (routing != null && routing.isEmpty()) { + if (!dispatchRPCPath.endsWith("/")) { + destinationUrlBuilder.append("/"); + } + destinationUrlBuilder.append(routing); + } + DefaultTransport transport = new DefaultTransport(destinationUrlBuilder.toString()); + DispatchSystemAsync dispatch = new CachingDispatch(new AutomaticBatchingDispatch( + transport, processResultsScheduled)); + return dispatch; } @Override @@ -66,7 +87,19 @@ public abstract class DispatchSystemDefaultImpl imp callback.onSuccess(result); } }; - dispatch.execute(action, wrappedCallback); + final DispatchSystemAsync dispatchToUse; + if (action instanceof ProvidesDispatchRoutingKey) { + ProvidesDispatchRoutingKey providesDispatchRoutingKey = (ProvidesDispatchRoutingKey) action; + String routingPath = providesDispatchRoutingKey.routingPath(); + + dispatchToUse = routingRegistry.computeIfAbsent(routingPath, this::createDispatchFor); + + LOG.fine("Using routed dispatch for path "+ routingPath); + } else { + LOG.fine("Using default dispatch for "+ action.getClass().getName()); + dispatchToUse = defaultDispatch; + } + dispatchToUse.execute(action, wrappedCallback); } @Override diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/dispatch/client/system/routing/ProvidesDispatchRoutingKey.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/dispatch/client/system/routing/ProvidesDispatchRoutingKey.java new file mode 100644 index 00000000000..5b5f558c6cd --- /dev/null +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/dispatch/client/system/routing/ProvidesDispatchRoutingKey.java @@ -0,0 +1,6 @@ +package com.sap.sse.gwt.dispatch.client.system.routing; + +public interface ProvidesDispatchRoutingKey { + + String routingPath(); +}