Skip to content
This repository was archived by the owner on Jun 7, 2021. It is now read-only.

Conversation

@tushargosavi
Copy link
Contributor

If user implements a streamcodec extending DefaultStatefulStreamCodec they need to also remember to implement newInstance method as platform use object returned by newInstance as codec. If use forget to override newInstance then platform keep on using default codec without any warning to user and
such error are caught very late mostly resulting incorrect data distribution and incorrect result at final
operator.

@vrozov
Copy link
Member

vrozov commented Sep 12, 2016

Can we change DefaultStatefulStreamCodec.newInstance() to call return getClass().newInstance() instead of return new DefaultStatefulStreamCodec<>()?

statefulSerde = ((StatefulStreamCodec<Object>)StreamContext.CODEC.defaultValue).newInstance();
} else if (codec instanceof StatefulStreamCodec) {
statefulSerde = ((StatefulStreamCodec<Object>)codec).newInstance();
if (!codec.getClass().isAssignableFrom(statefulSerde.getClass())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the check necessary if validation already checks for the correct implementation of newInstance()?

@vrozov
Copy link
Member

vrozov commented Sep 12, 2016

newInstance() may also rely on clone() and call getClass().newInstance() if clone() is not supported.

@vrozov
Copy link
Member

vrozov commented Nov 15, 2016

@tushargosavi Please fix checkstyle, add unit test and comment on BufferServerPublisher changes.

@tushargosavi
Copy link
Contributor Author

don't merge this pull request yet. I will do some tests early next week, and fix the checkstyle errors and comment on BufferServerPublisher changes

@tushargosavi
Copy link
Contributor Author

@vrozov I have updated the pull request.
Removed validation as it was not needed as suggested, instead returned correct instance from newInstance method of DefaultStatefullStreamCodec

@vrozov
Copy link
Member

vrozov commented Nov 26, 2016

@tushargosavi Please add unit test.

@tushargosavi
Copy link
Contributor Author

Added a unit test checking for type of instance returned by newInstance method.

Copy link
Member

@vrozov vrozov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good.

Object inner = outer.new InnerClass();

for (Object o: new Object[] {outer, inner}) {
for (Object o : new Object[]{outer, inner}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the change necessary? Does it impact checkstyle?

}
}

static class MyStreamCodec extends DefaultStatefulStreamCodec<String>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be private? Can the name be changed to StatefulStreamCodec to avoid My...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked, it can't be private as it will lead to instantiation error. For the name I suggest:

static class NoNewInstanceStatefulStreamCodec<T> extends DefaultStatefulStreamCodec<T>
{
}

{
MyStreamCodec codec = new MyStreamCodec();
DefaultStatefulStreamCodec newCodec = codec.newInstance();
Assert.assertEquals("The class type is correct", newCodec.getClass(), codec.getClass());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add codec != newCodec assertion and checks for DefaultStatefulStreamCodec?

@tushargosavi
Copy link
Contributor Author

@vrozov I have done the suggested changes

@vrozov
Copy link
Member

vrozov commented Nov 29, 2016

@tushargosavi commit is merged to apache master. @asfgit did not close PR due to forced push. Please close it manually.

@tushargosavi
Copy link
Contributor Author

closing the pull request, as it did not got closed because of forced push

@tushargosavi tushargosavi deleted the APEXCORE-525 branch October 24, 2019 19:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants