-
Notifications
You must be signed in to change notification settings - Fork 160
Reworked a bit the Extension interface #158
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
Reworked a bit the Extension interface #158
Conversation
Signed-off-by: Francesco Guardiani <[email protected]>
@bsideup mind giving a look? |
/** | ||
* Materialized CloudEvent Extension interface to read/write the extension attributes key/values. | ||
*/ | ||
public interface Extension extends CloudEventExtensions { |
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 sounds wrong. Extension extends CloudEventExtensions
smells.
Especially given that it will look like:
Extension ext = ...;
ext.getExtension("OMG WTF!");
ext.getExtensionNames(); // whaaaat?
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.
how about:
public interface Extension {
void readFrom(CloudEventExtensions extensions);
Object getValue(String key);
Set<String> getKeys();
}
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.
Much better :)
WDYT about Iterable<String> getKeys();
? Since extension may define a dynamic set of keys, Set
here can be a bit restrictive, and it does not look like we need to have Set
's characteristics in this case
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.
To me it doesn't sound explicative Iterable<String>
, because Iterable
can contain duplicates. Because we're returning a key set, to me it makes sense using the Set<String>
type, exactly like i expect a Map to return the keys as a set
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.
On the other hand, I don't think it would be a bad idea to let this interface extend Iterable<Map.Entry<String, Object>>
or have a method like iter()
that returns such Iterable
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.
And btw such Iterable
can be default implemented
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.
Iterable<Map.Entry<String, Object>>
would require allocations.
Okay, let's keep Set
then.
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.
Iterable<Map.Entry<String, Object>> would require allocations.
Sure, it's like "use it at your own risk" 😄
Signed-off-by: Francesco Guardiani <[email protected]>
Signed-off-by: Francesco Guardiani <[email protected]>
core/src/main/java/io/cloudevents/core/extensions/DistributedTracingExtension.java
Outdated
Show resolved
Hide resolved
…terialized extension Signed-off-by: Francesco Guardiani <[email protected]>
Signed-off-by: Francesco Guardiani <[email protected]>
Look at #122
This change:
readFromEvent
to acceptCloudEventExtensions
asMap()
and letExtension
extendCloudEventExtensions
. Because the number of attributes for a materialized extension is always the same, allocating a map to provide an unstructrured view (needed to write the materialized extension to the cloud event builder) is useless. This solution makes more efficient the implementation of such materialized extensionsSigned-off-by: Francesco Guardiani [email protected]