-
Notifications
You must be signed in to change notification settings - Fork 263
Add unified way of initializing classes via string and configuring them. #943
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
Conversation
Signed-off-by: Felix Engl <felix.engl@hotmail.com>
|
||
/** Replace with URLBufferUtil.createInstance */ | ||
@Deprecated | ||
public static URLBuffer getInstance(Map<String, Object> stormConf) { |
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.
InlineMeSuggester: This deprecated API looks inlineable. If you'd like the body of the API to be inlined to its callers, please annotate it with @InlineMe. (details)
(at-me in a reply with help
or ignore
)
*/ | ||
@SuppressWarnings("rawtypes") | ||
/** @deprecated Replace with ConfigurableUtil.configure */ | ||
@Deprecated | ||
public static <T extends Configurable> List<T> configure( |
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.
InlineMeSuggester: This deprecated API looks inlineable. If you'd like the body of the API to be inlined to its callers, please annotate it with @InlineMe. (details)
(at-me in a reply with help
or ignore
)
|
||
/** @see ConfigurableUtil for more information */ |
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.
MissingSummary: A summary fragment is required; consider using the value of the @see block as a summary fragment instead. (details)
(at-me in a reply with help
or ignore
)
hi @FelixEngl did you see my comments in #937? Some of the changes you are proposing here would meet the same objections e.g. use of org.jetbrains annotations. |
No, where are these comments? I didn't see them in that PR-Conversation and I didn't get any kind of notification. Or are there any other tabs that I have to check for notifications like that? |
They were pending, you should be able to see them now |
Signed-off-by: Felix Engl <felix.engl@hotmail.com>
Signed-off-by: Felix Engl <felix.engl@hotmail.com>
No rest for the wicked ;-) Could you please explain what you are trying to achieve in the description of this PR and why you think it is necessary? |
Yes, the next one will be a little bit better with the description. I didn't know it better until recently. Basically: This PR proposes a unified toolkit for initializing classes from qualified names. The core of this PR is the Proposing a universal way has multiple advantages:
|
@@ -156,19 +144,27 @@ boolean isMatch(final Metadata metadata) { | |||
private final LinkedList<FilteredProtocol> protocols = new LinkedList<>(); |
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.
JdkObsolete: It is very rare for LinkedList to out-perform ArrayList or ArrayDeque. Avoid it unless you're willing to invest a lot of time into benchmarking. Caveat: LinkedList supports null elements, but ArrayDeque does not. (details)
(at-me in a reply with help
or ignore
)
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.
@FelixEngl could we replace the LinkedList with an ArrayList or ArrayDeque as suggested by Lift?
@jnioche Ah, I forgot something: |
* | ||
* @throws IOException | ||
*/ | ||
/** loads the filters from a JSON configuration file */ |
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.
This might break end user code (removal of a checked exception), so we need to be clear in the changelog.
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.
Why should this break end user code?
It still throws that IOException
but i removed the empty comment.
} catch (Exception e) { | ||
throw new RuntimeException("Can't instanciate " + className); | ||
throw new RuntimeException("Can't instanciate " + className, e); |
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 catch!
@@ -85,29 +89,4 @@ default void acked(String url) { | |||
} | |||
|
|||
default void configure(Map<String, Object> stormConf) {} | |||
|
|||
/** Returns a URLBuffer instance based on the configuration * */ | |||
public static URLBuffer getInstance(Map stormConf) { |
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.
This might break end user code (removal of a public method), so we need to be clear in the changelog.
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 deprecated it at line 42.
I just moved it up. Strange that git doesn't recognize this. :/
@@ -0,0 +1,128 @@ | |||
package com.digitalpebble.stormcrawler.util; |
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.
Misses a license header
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.
yes every new class needs a license header
@@ -0,0 +1,7 @@ | |||
package com.digitalpebble.stormcrawler.util.exceptions.initialisation; |
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.
License? wdyt @jnioche
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.
yes every new class needs a license header
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.
@jnioche What about Tests?
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.
yes, test classes as well please.
@@ -0,0 +1,3 @@ | |||
package com.digitalpebble.stormcrawler.helper.initialisation; |
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.
License? wdyt @jnioche
@@ -0,0 +1,21 @@ | |||
package com.digitalpebble.stormcrawler.helper.initialisation.base; |
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.
License? wdyt @jnioche
@@ -0,0 +1,3 @@ | |||
package com.digitalpebble.stormcrawler.helper.initialisation.base; |
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.
License? wdyt @jnioche
@@ -0,0 +1,4 @@ | |||
package com.digitalpebble.stormcrawler.helper.initialisation.base; |
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.
License? wdyt @jnioche
@@ -0,0 +1,168 @@ | |||
package com.digitalpebble.stormcrawler.util; |
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.
License? wdyt @jnioche
Guys, apologies in advance if I come across as being a bit blunt. |
Don't worry about being blunt, I prefer it when someone speaks his/her mind directly instead of dancing around the problem or finding some straw arguments. :D I could remove the exception classes and only throw runtime exceptions. That would reduce the number of classes. |
I think, that it looks like a lot of classes. Basically, I see 2 (new) utility classes + a lot of test-related classes + (runtime) exception sugar. Guess, that the new runtime exceptions can be dropped. |
Then I'll drop them. |
Signed-off-by: Felix Engl <felix.engl@hotmail.com>
@jnioche I removed the Exceptions. We could also remove the But we need the other new classes for testing the initialisation feature, so we can't remove the new classes created in the test source. |
Signed-off-by: Felix Engl <felix.engl@hotmail.com>
Signed-off-by: Felix Engl <felix.engl@hotmail.com>
# Conflicts: # core/src/main/java/com/digitalpebble/stormcrawler/persistence/urlbuffer/URLBuffer.java
Removed the |
Signed-off-by: Felix Engl <felix.engl@hotmail.com>
|
||
/** Replace with {@link URLBuffer#createInstance(Map)} */ | ||
@Deprecated | ||
static URLBuffer getInstance(Map<String, Object> stormConf) { |
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.
InlineMeSuggester: This deprecated API looks inlineable. If you'd like the body of the API to be inlined to its callers, please annotate it with @InlineMe. (details)
(at-me in a reply with help
or ignore
)
return filterLists; | ||
/** @deprecated Replace with ConfigurableUtil.configure */ | ||
@Deprecated | ||
static <T extends Configurable> List<T> configure( |
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.
InlineMeSuggester: This deprecated API looks inlineable. If you'd like the body of the API to be inlined to its callers, please annotate it with @InlineMe. (details)
(at-me in a reply with help
or ignore
)
Great! That's way better InitialisationUtil has no equivalent in the current code, so we definitely need it. ConfigurableUtil is a bit different. I see that you removed the utility code from the interface and kept the latter as a strict interface. I can understand why but to be honest I quite liked having the utility code within the interface class - all in one place. Probably not orthodox, I agree but I thought it was quite elegant in a way. How open would you be to keeping it that way? This is just an extra class, I can also be swayed. And @rzo1 is right, we need license headers on every new file. Thanks for your open-mindedness BTW. |
|
||
public static ProtocolFactory getInstance(Config conf) { | ||
|
||
if (single_instance != null) return single_instance; | ||
// https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java |
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.
such a great bugfix! thanks for that
I didn't have a problem with the static function (tbh I like putting creation calls for interfaces there too) but i had a problem with the static What about hiding the ConfigUtil in package scope and keeping the original creation method in the interface? |
…tionUtil to ParserBolt. Use ArrayList in DelegatorProtocol. Signed-off-by: Felix Engl <felix.engl@hotmail.com>
@jnioche I implemented the hidden-util-class approach, I think this should make both of us happy. |
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.
Looks good, just one minor point about returning an immutable List
@@ -366,7 +363,7 @@ public void declareOutputFields(OutputFieldsDeclarer declarer) { | |||
// components check whether the URL is valid | |||
LOG.error("MalformedURLException on {}", parentURL); | |||
eventCounter.scope("error_invalid_source_url").incrBy(1); | |||
return new LinkedList<Outlink>(); | |||
return Collections.emptyList(); |
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.
the list can get things added to it later. it must not be immutable
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.
Signed-off-by: Felix Engl <felix.engl@hotmail.com>
Hello @jnioche,
I extracted the code for initializing classes from string and configuring them from my fork https://github.com/FelixEngl/storm-crawler/tree/local_version. (This branch contains all fixes/changes that i made. I'll try to extract PR after PR until both are on a same level.)
I don't know how far you got with #937, but I this one has a more reasonable size with the trade-off that it introduces some new warnings due to missing
@Contract
,@NotNull
and@Nullable
annotations in various sub-classes and sub-interfaces. These warnings will be fixed by either #937 or a PR in the future.Best Regards
Felix
Signed-off-by: Felix Engl felix.engl@hotmail.com
Developer Certificate of Origin