|
1 | 1 | /*
|
2 |
| - * Copyright 2018-2019 the original author or authors. |
| 2 | + * Copyright 2018-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
24 | 24 | import org.apache.commons.logging.Log;
|
25 | 25 | import org.apache.commons.logging.LogFactory;
|
26 | 26 |
|
| 27 | +import org.springframework.core.log.LogMessage; |
27 | 28 | import org.springframework.integration.core.MessageSource;
|
| 29 | +import org.springframework.integration.endpoint.AbstractFetchLimitingMessageSource; |
28 | 30 | import org.springframework.integration.file.remote.AbstractRemoteFileStreamingMessageSource;
|
29 | 31 | import org.springframework.integration.file.remote.session.DelegatingSessionFactory;
|
30 | 32 | import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource;
|
|
33 | 35 | /**
|
34 | 36 | * Standard rotation policy; iterates over key/directory pairs; when the end is reached,
|
35 | 37 | * starts again at the beginning. If the fair option is true the rotation occurs on every
|
36 |
| - * poll, regardless of result. Otherwise rotation occurs when the current pair returns no |
| 38 | + * poll, regardless of result. Otherwise, rotation occurs when the current pair returns no |
37 | 39 | * message.
|
38 |
| - * |
| 40 | + * <p> |
39 | 41 | * Subclasses implement {@code onRotation(MessageSource<?> source)} to configure the
|
40 | 42 | * {@link MessageSource} on each rotation.
|
41 | 43 | *
|
@@ -78,6 +80,12 @@ public StandardRotationPolicy(DelegatingSessionFactory<?> factory, List<KeyDirec
|
78 | 80 | public void beforeReceive(MessageSource<?> source) {
|
79 | 81 | if (this.fair || !this.initialized) {
|
80 | 82 | configureSource(source);
|
| 83 | + if (this.fair && !this.initialized |
| 84 | + && source instanceof AbstractFetchLimitingMessageSource<?> fetchLimitingMessageSource) { |
| 85 | + |
| 86 | + this.logger.info(LogMessage.format("Enforce 'maxFetchSize = 1' for '%s' in the 'fair' mode", source)); |
| 87 | + fetchLimitingMessageSource.setMaxFetchSize(1); |
| 88 | + } |
81 | 89 | this.initialized = true;
|
82 | 90 | }
|
83 | 91 | if (this.logger.isTraceEnabled()) {
|
@@ -142,11 +150,11 @@ protected void configureSource(MessageSource<?> source) {
|
142 | 150 | * @param source the MessageSource.
|
143 | 151 | */
|
144 | 152 | protected void onRotation(MessageSource<?> source) {
|
145 |
| - if (source instanceof AbstractRemoteFileStreamingMessageSource) { |
146 |
| - ((AbstractRemoteFileStreamingMessageSource<?>) source).setRemoteDirectory(this.current.getDirectory()); |
| 153 | + if (source instanceof AbstractRemoteFileStreamingMessageSource<?> streamingMessageSource) { |
| 154 | + streamingMessageSource.setRemoteDirectory(this.current.getDirectory()); |
147 | 155 | }
|
148 |
| - else if (source instanceof AbstractInboundFileSynchronizingMessageSource) { |
149 |
| - ((AbstractInboundFileSynchronizingMessageSource<?>) source).getSynchronizer() |
| 156 | + else if (source instanceof AbstractInboundFileSynchronizingMessageSource<?> synchronizingMessageSource) { |
| 157 | + synchronizingMessageSource.getSynchronizer() |
150 | 158 | .setRemoteDirectory(this.current.getDirectory());
|
151 | 159 | }
|
152 | 160 | }
|
|
0 commit comments