|
| 1 | +# Prioritized transfer services |
| 2 | + |
| 3 | +## Decision |
| 4 | + |
| 5 | +We will add a priority to `TransferServices` within the `TransferServiceRegistry`. `TransferServices` can then either |
| 6 | +be registered with a specific priority or, when registered without specifying one, be assigned the default priority. |
| 7 | +When a `TransferService` is selected, it will be chosen by priority. |
| 8 | + |
| 9 | +## Rationale |
| 10 | + |
| 11 | +For a given transfer, there may be multiple `TransferServices` which can handle the transfer and, for a given use case, |
| 12 | +a specific `TransferService` may be preferred over others. Right now, there is no way to ensure that a specific |
| 13 | +`TransferService` is chosen. Instead, the first applicable one is selected. By assigning a priority to the |
| 14 | +`TransferServices`, it can be ensured that more specialized services are chosen over less specialized ones, if both are |
| 15 | +applicable. |
| 16 | + |
| 17 | +## Approach |
| 18 | + |
| 19 | +The implementation will be similar to the registration and selection of `DataFlowControllers` in the |
| 20 | +`DataFlowManagerImpl`, as these are also based on a prioritization. |
| 21 | + |
| 22 | +### Registration |
| 23 | + |
| 24 | +A new method will be added to the `TransferServiceRegistry` for registering a `TransferService` with a priority: |
| 25 | + |
| 26 | +```java |
| 27 | +void registerTransferService(int priority, TransferService transferService); |
| 28 | +``` |
| 29 | + |
| 30 | +The existing method for registering a `TransferService` without assigning a priority will default to using priority 0. |
| 31 | +This also ensures that existing registrations continue working in the same way. |
| 32 | + |
| 33 | +Within the `TransferServiceRegistryImpl`, a record will be created which links a `TransferService` to its priority. |
| 34 | +Internally, the `TransferServiceRegistryImpl` will then work with this new record. |
| 35 | + |
| 36 | +```java |
| 37 | +record PrioritizedTransferService(int priority, TransferService service) { } |
| 38 | +``` |
| 39 | + |
| 40 | +### Selection |
| 41 | + |
| 42 | +At the moment, a `TransferServiceSelectionStrategy` is used to select a `TransferService`. This will be deprecated |
| 43 | +in favor of the prioritization. Selection will then be handled by filtering for all applicable services and choosing |
| 44 | +the one with the highest priority: |
| 45 | + |
| 46 | +```java |
| 47 | +@Override |
| 48 | +@Nullable |
| 49 | +public TransferService resolveTransferService(DataFlowStartMessage request) { |
| 50 | + return transferServices.stream() |
| 51 | + .filter(pts -> pts.service.canHandle(request)) |
| 52 | + .sorted(Comparator.comparingInt(pts -> -pts.priority)) |
| 53 | + .map(PrioritizedTransferService::service) |
| 54 | + .findFirst().orElse(null); |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +As by our deprecation policy the `TransferServiceSelectionStrategy` needs to remain functional until removed, both |
| 59 | +solutions will be applied in parallel until its removal. Therefore, the `TransferServiceSelectionStrategy` will |
| 60 | +for now be applied as a fallback in case no `TransferService` with a priority greater than 0 is present. |
0 commit comments