This repository has been archived by the owner on Jul 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
Jiayang/gdpr #289
Merged
Merged
Jiayang/gdpr #289
Changes from 1 commit
Commits
Show all changes
4 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
updated implementation based on Ted's comments
- Loading branch information
commit 097bca908883de4cd082607723fa7fe361d6a564
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -22,9 +22,8 @@ | |
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Supplier; | ||
import java.util.regex.Pattern; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledThreadPoolExecutor; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
import com.addthis.ahocorasick.AhoCorasick; | ||
import com.addthis.ahocorasick.SearchResult; | ||
|
@@ -107,7 +106,7 @@ abstract class AbstractMatchStringFilter extends AbstractValueFilterContextual i | |
/** | ||
* Set an interval to fetch the required URL and update the bundle filter setting by calling the postDecodeHelper. | ||
*/ | ||
final private int refreshInterval; | ||
final private int refreshMinutes; | ||
|
||
final private int urlMinBackoff; | ||
|
||
|
@@ -132,7 +131,7 @@ abstract class AbstractMatchStringFilter extends AbstractValueFilterContextual i | |
boolean toLower, | ||
int urlTimeout, | ||
int urlRetries, | ||
int refreshInterval, | ||
int refreshMinutes, | ||
int urlMinBackoff, | ||
int urlMaxBackoff, | ||
boolean not) { | ||
|
@@ -148,7 +147,7 @@ abstract class AbstractMatchStringFilter extends AbstractValueFilterContextual i | |
this.toLower = toLower; | ||
this.urlTimeout = urlTimeout; | ||
this.urlRetries = urlRetries; | ||
this.refreshInterval = refreshInterval; | ||
this.refreshMinutes = refreshMinutes; | ||
this.urlMinBackoff = urlMinBackoff; | ||
this.urlMaxBackoff = urlMaxBackoff; | ||
this.not = not; | ||
|
@@ -270,20 +269,15 @@ public void postDecodeHelper() { | |
} | ||
|
||
@Override public void postDecode() { | ||
if (refreshInterval == 0) { | ||
if (refreshMinutes == 0) { | ||
postDecodeHelper(); | ||
} else { | ||
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(5); | ||
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1); | ||
// upon JVM termination, wait for the tasks for up to 100ms before exiting the executor service | ||
ExecutorService executorService = MoreExecutors.getExitingExecutorService(executor, 100, TimeUnit.MILLISECONDS); | ||
|
||
executorService.submit(() -> { | ||
while (true) { | ||
postDecodeHelper(); | ||
// sleep for refreshInterval minutes before decoding again | ||
Thread.sleep(refreshInterval * 60 * 1000 ); | ||
} | ||
}); | ||
ScheduledExecutorService executorService = MoreExecutors.getExitingScheduledExecutorService(executor, 100, TimeUnit.MILLISECONDS); | ||
executorService.scheduleWithFixedDelay(() -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My intellij inspections recommend using a method reference instead of a lambda here: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
postDecodeHelper(); | ||
}, 0, refreshMinutes, TimeUnit.MINUTES); | ||
} | ||
} | ||
|
||
|
@@ -302,7 +296,7 @@ public ValidationOnly(@AutoParam @JsonProperty("value") TypedField<Set<String>> | |
@JsonProperty("toLower") boolean toLower, | ||
@Time(TimeUnit.MILLISECONDS) @JsonProperty("urlTimeout") int urlTimeout, | ||
@JsonProperty("urlRetries") int urlRetries, | ||
@Time(TimeUnit.MINUTES) @JsonProperty("refreshInterval") int refreshInterval, | ||
@Time(TimeUnit.MINUTES) @JsonProperty("refreshMinutes") int refreshMinutes, | ||
@Time(TimeUnit.MILLISECONDS) @JsonProperty("urlMinBackoff") int urlMinBackoff, | ||
@Time(TimeUnit.MILLISECONDS) @JsonProperty("urlMaxBackoff") int urlMaxBackoff) { | ||
super(value, | ||
|
@@ -317,7 +311,7 @@ public ValidationOnly(@AutoParam @JsonProperty("value") TypedField<Set<String>> | |
toLower, | ||
urlTimeout, | ||
urlRetries, | ||
refreshInterval, | ||
refreshMinutes, | ||
urlMinBackoff, | ||
urlMaxBackoff, | ||
false); | ||
|
This file contains 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
This file contains 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
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.
I noticed a pretty serious issue here - in the case where refresh is enabled, we only call postDecodeHelper in the scheduled executor service. While it's true that we call it immediately, it's called asynchronously without blocking. We need to block here so that this value filter can't be used until the post decode step has occured at least once. Therefore, we should always call postDecodeHelper in this method, and change the scheduled executor to not refresh immediately.
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.
Done