Skip to content

Commit baf2b8d

Browse files
David Turanskiartembilan
authored andcommitted
GH-3027: Rotator enhancements
* Implement `RotatingServerAdvice` enhancements * Update javadocs * Introduce a new `onRotation()` callback for possible overriding * Make a default implementation do no throw an exception when non-standard `MessageSource` impl is provided. * Adjust its JavaDocs to describe a behavior
1 parent b04a857 commit baf2b8d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

spring-integration-file/src/main/java/org/springframework/integration/file/remote/aop/RotatingServerAdvice.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ protected boolean isFair() {
171171
return this.fair;
172172
}
173173

174-
protected KeyDirectory getCurrent() {
174+
public KeyDirectory getCurrent() {
175175
return this.current;
176176
}
177177

@@ -201,18 +201,27 @@ public void afterReceive(boolean messageReceived, MessageSource<?> source) {
201201
}
202202

203203
protected void configureSource(MessageSource<?> source) {
204-
Assert.isTrue(source instanceof AbstractInboundFileSynchronizingMessageSource
205-
|| source instanceof AbstractRemoteFileStreamingMessageSource,
206-
"source must be an AbstractInboundFileSynchronizingMessageSource or a "
207-
+ "AbstractRemoteFileStreamingMessageSource");
208204
if (!this.iterator.hasNext()) {
209205
this.iterator = this.keyDirectories.iterator();
210206
}
211207
this.current = this.iterator.next();
208+
onRotation(source);
209+
}
210+
211+
/**
212+
* Update the state of the {@link MessageSource} after the server is rotated, if necessary.
213+
* The default implementation updates the remote directory for known MessageSource implementations that require it,
214+
* specifically, instances of {@link AbstractRemoteFileStreamingMessageSource}, and
215+
* {@link AbstractInboundFileSynchronizingMessageSource}, and does nothing otherwise.
216+
* Subclasses may override this method to support other MessageSource types.
217+
*
218+
* @param source the MessageSource.
219+
*/
220+
protected void onRotation(MessageSource<?> source) {
212221
if (source instanceof AbstractRemoteFileStreamingMessageSource) {
213222
((AbstractRemoteFileStreamingMessageSource<?>) source).setRemoteDirectory(this.current.getDirectory());
214223
}
215-
else {
224+
else if (source instanceof AbstractInboundFileSynchronizingMessageSource) {
216225
((AbstractInboundFileSynchronizingMessageSource<?>) source).getSynchronizer()
217226
.setRemoteDirectory(this.current.getDirectory());
218227
}

0 commit comments

Comments
 (0)