Skip to content
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

Migrate some logic from generated code into the runtime library #475

Merged
merged 6 commits into from
Mar 3, 2020

Conversation

carterkozak
Copy link
Contributor

This approach tends to be easier to support, and safer to fix with
library upgrades.
Code reuse should be preferred over excessive generation because
it produces more readable code which the JVM is able to optimize
more efficiently.

After this PR

==COMMIT_MSG==
Migrate some logic from generated code into the runtime library
==COMMIT_MSG==

This approach tends to be easier to support, and safer to fix with
library upgrades.
Code reuse should be preferred over excessive generation because
it produces more readable code which the JVM is able to optimize
more efficiently.
@changelog-app
Copy link

changelog-app bot commented Mar 3, 2020

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Migrate some logic from generated code into the runtime library

Check the box to generate changelog(s)

  • Generate changelog entry

@@ -52,6 +53,11 @@ public PlainSerDe plainSerDe() {
return ConjurePlainSerDe.INSTANCE;
}

@Override
public Clients clients() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thoughts on naming?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like it!

@Override
public <T> T blocking(Channel channel, Endpoint endpoint, Request request, Deserializer<T> deserializer) {
ListenableFuture<T> call = call(channel, endpoint, request, deserializer);
return RemoteExceptions.getUnchecked(call);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The RemoteExceptions utility can be moved out of the compilation target (break for older generated code).

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure lets do it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll plan to move this after we've cut a release where generated code uses the new methods, that way we have a window for libraries to safely upgrade.

@ferozco
Copy link
Contributor

ferozco commented Mar 3, 2020

I'll follow up and update the codegen accordingly

@carterkozak
Copy link
Contributor Author

Great, I'll update this with docs + revapi :-)

* limitations under the License.
*/

package com.palantir.conjure.java.dialogue.serde;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the serde package+module don't make a great deal of sense for the entire runtime object, but I'm not going to couple changing that with this PR.

@carterkozak carterkozak marked this pull request as ready for review March 3, 2020 20:28
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

does this project not use junit-jupiter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct

* This approach is used instead of using a separate method to block on a single future to simplify
* otherwise redundant generated code.
*/
<T> T blocking(Channel channel, Endpoint endpoint, Request request, Deserializer<T> deserializer);
Copy link
Contributor

Choose a reason for hiding this comment

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

this interface doesn't quite work with the existing codegen. It would force us to duplicate the code for building the request in the blocking/async impls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah doh, our sample services are no longer representative

Copy link
Contributor Author

@carterkozak carterkozak Mar 3, 2020

Choose a reason for hiding this comment

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

I could go either way naming <T> T blocking(ListenableFuture<T>). Preference on return clients().block(future) vs return clients().blocking(future);

Copy link
Contributor

Choose a reason for hiding this comment

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

I think i prefer block so that both methods are verbs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 thanks!

@carterkozak
Copy link
Contributor Author

I need to step away for a half hour, will update this when I get back

@bulldozer-bot bulldozer-bot bot merged commit 1fad96e into develop Mar 3, 2020
@bulldozer-bot bulldozer-bot bot deleted the ckozak/reduce_generated_logic branch March 3, 2020 21:39
@svc-autorelease
Copy link
Collaborator

Released 0.12.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants