-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement RotatingServerAdvice enhancements #3028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
dturanski
wants to merge
2
commits into
spring-projects:5.1.x
from
dturanski:rotator-enhancements-5.1.x
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
.../java/org/springframework/integration/file/remote/aop/AbstractStandardRotationPolicy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /* | ||
| * Copyright 2019 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.springframework.integration.file.remote.aop; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
|
|
||
| import org.apache.commons.logging.Log; | ||
| import org.apache.commons.logging.LogFactory; | ||
|
|
||
| import org.springframework.integration.core.MessageSource; | ||
| import org.springframework.integration.file.remote.session.DelegatingSessionFactory; | ||
| import org.springframework.util.Assert; | ||
|
|
||
| /** | ||
| * Standard rotation policy; iterates over key/directory pairs; when the end | ||
| * is reached, starts again at the beginning. If the fair option is true | ||
| * the rotation occurs on every poll, regardless of result. Otherwise rotation | ||
| * occurs when the current pair returns no message. | ||
| * | ||
| * Subclasses implement {@code onRotation(MessageSource<?> source)} to configure the {@link MessageSource} on each rotation. | ||
| * | ||
| * @author Gary Russell | ||
| * @author Michael Forstner | ||
| * @author Artem Bilan | ||
| * @author David Turanski | ||
| * | ||
| * @since 5.2.0 | ||
| */ | ||
| public abstract class AbstractStandardRotationPolicy implements RotationPolicy { | ||
| protected final Log logger = LogFactory.getLog(getClass()); // NOSONAR final | ||
|
|
||
| private final DelegatingSessionFactory<?> factory; // NOSONAR final | ||
|
|
||
| private final List<KeyDirectory> keyDirectories = new ArrayList<>(); | ||
|
|
||
| private final boolean fair; | ||
|
|
||
| private volatile Iterator<KeyDirectory> iterator; | ||
|
|
||
| private volatile KeyDirectory current; | ||
|
|
||
| private volatile boolean initialized; | ||
|
|
||
| protected AbstractStandardRotationPolicy(DelegatingSessionFactory<?> factory, List<KeyDirectory> keyDirectories, boolean fair) { | ||
|
|
||
| Assert.notNull(factory, "factory cannot be null"); | ||
| Assert.notNull(keyDirectories, "keyDirectories cannot be null"); | ||
| Assert.isTrue(keyDirectories.size() > 0, "At least one KeyDirectory is required"); | ||
| this.factory = factory; | ||
| this.keyDirectories.addAll(keyDirectories); | ||
| this.fair = fair; | ||
| this.iterator = this.keyDirectories.iterator(); | ||
| } | ||
|
|
||
| @Override | ||
| public void beforeReceive(MessageSource<?> source) { | ||
| if (this.fair || !this.initialized) { | ||
| configureSource(source); | ||
| this.initialized = true; | ||
| } | ||
| if (this.logger.isTraceEnabled()) { | ||
| this.logger.trace("Next poll is for " + this.current); | ||
| } | ||
| this.factory.setThreadKey(this.current.getKey()); | ||
| } | ||
|
|
||
| @Override | ||
| public void afterReceive(boolean messageReceived, MessageSource<?> source) { | ||
| if (this.logger.isTraceEnabled()) { | ||
| this.logger.trace("Poll produced " | ||
| + (messageReceived ? "a" : "no") | ||
| + " message"); | ||
| } | ||
| this.factory.clearThreadKey(); | ||
| if (!this.fair && !messageReceived) { | ||
| configureSource(source); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public KeyDirectory getCurrent() { | ||
| return this.current; | ||
| } | ||
|
|
||
|
|
||
| protected DelegatingSessionFactory<?> getFactory() { | ||
| return this.factory; | ||
| } | ||
|
|
||
| protected List<KeyDirectory> getKeyDirectories() { | ||
| return this.keyDirectories; | ||
| } | ||
|
|
||
| protected boolean isFair() { | ||
| return this.fair; | ||
| } | ||
|
|
||
| protected Iterator<KeyDirectory> getIterator() { | ||
| return this.iterator; | ||
| } | ||
|
|
||
| protected boolean isInitialized() { | ||
| return this.initialized; | ||
| } | ||
|
|
||
| protected void configureSource(MessageSource<?> source) { | ||
|
|
||
| if (!this.iterator.hasNext()) { | ||
| this.iterator = this.keyDirectories.iterator(); | ||
| } | ||
| this.current = this.iterator.next(); | ||
|
|
||
| onRotation(source); | ||
| } | ||
|
|
||
| protected abstract void onRotation(MessageSource<?> source); | ||
| } |
51 changes: 51 additions & 0 deletions
51
...tion-file/src/main/java/org/springframework/integration/file/remote/aop/KeyDirectory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Copyright 2019 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.springframework.integration.file.remote.aop; | ||
|
|
||
| import org.springframework.integration.file.remote.session.DelegatingSessionFactory; | ||
| import org.springframework.util.Assert; | ||
|
|
||
| /** | ||
| * A {@link DelegatingSessionFactory} key/directory pair. | ||
| */ | ||
| public class KeyDirectory { | ||
|
|
||
| private final Object key; | ||
|
|
||
| private final String directory; | ||
|
|
||
| public KeyDirectory(Object key, String directory) { | ||
| Assert.notNull(key, "key cannot be null"); | ||
| Assert.notNull(directory, "directory cannot be null"); | ||
| this.key = key; | ||
| this.directory = directory; | ||
| } | ||
|
|
||
| public Object getKey() { | ||
| return this.key; | ||
| } | ||
|
|
||
| public String getDirectory() { | ||
| return this.directory; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "KeyDirectory [key=" + this.key.toString() + ", directory=" + this.directory + "]"; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to revert this change. It is fully blown breaking change in the point version.
I'm OK with a decoupling in the current
5.2(preparing some polishing PR), but I'm against any breaking changes for public API in the point release.Does it make sense, @garyrussell , @dturanski ?
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically you're right. But I think it would be ok if we default it. Then it won't break anything. I'd be surprised if anyone else has actually implemented this interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just can't guess from here. This interface is
publicin this place, therefore moving it somewhere else is a breaking change.The first rule: don't break any public API in the point release!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, because I moved it from the inner class. Yes that is a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good. So, @garyrussell , your turn now and then we will make a final decision!