Skip to content

Conversation

@artembilan
Copy link
Member

Kotlin inline reified functions cannot override as syntax sugar generic
Java methods.

  • Extract a BaseIntegrationFlowDefinition with strong typed methods,
    plus those which doesn't have a syntax sugar variants
  • Leave in the IntegrationFlowDefinition only those generic methods
    which are just a syntax sugar without any types requirements

This way we can write Kotlin inline reified functions as an extension
with the same names to make a Kotlin DSL much cleaner

@garyrussell
Copy link
Contributor

I am ok with this generally, but I think it means new builds of all downstream (extension) projects will be needed to work with this version.

@artembilan
Copy link
Member Author

I would take such a risk since the simple workaround is just to compile the project against this version.
More over it only affect those projects which use Java DSL.
And I guess you talk here only about SI-Kafka.
It's so easy to build that project and release a new version for it.
We have already Spring Kafka patch release, so that feels natural to build a new version for SIK based on this patch release for SI, too.

Otherwise we would have to deffer Kotlin DSL feature until the next year...

@garyrussell
Copy link
Contributor

garyrussell commented Oct 23, 2019

Actually, it's a lot worse than that; any user app that uses the methods in IFD has to be recompiled...

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    com.example.demo.Ktest23Application.lambda$2(Ktest23Application.java:69)

The following method did not exist:

    org.springframework.integration.dsl.IntegrationFlowDefinition.handle(Lorg/springframework/integration/dsl/MessageHandlerSpec;)Lorg/springframework/integration/dsl/IntegrationFlowDefinition;

The method's class, org.springframework.integration.dsl.IntegrationFlowDefinition, is available from the following locations:

    jar:file:/Users/grussell/.m2/repository/org/springframework/integration/spring-integration-core/5.2.1.BUILD-SNAPSHOT/spring-integration-core-5.2.1.BUILD-SNAPSHOT.jar!/org/springframework/integration/dsl/IntegrationFlowDefinition.class

It was loaded from the following location:

    file:/Users/grussell/.m2/repository/org/springframework/integration/spring-integration-core/5.2.1.BUILD-SNAPSHOT/spring-integration-core-5.2.1.BUILD-SNAPSHOT.jar

	@Bean
	public IntegrationFlow inFlow(ConsumerFactory<String, String> consumerFactory) {

		ContainerProperties props = new ContainerProperties("ktest23");
		props.setGroupId("ktest23int");
		return IntegrationFlows.from(Kafka.messageDrivenChannelAdapter(consumerFactory, props))
				.handle(msg -> System.out.println("int:" + msg.getPayload()))
				.get();

Kotlin inline reified functions cannot override as syntax sugar generic
Java methods.

* Extract a `BaseIntegrationFlowDefinition` with strong typed methods,
plus those which doesn't have a syntax sugar variants
* Leave in the `IntegrationFlowDefinition` only those generic methods
which are just a syntax sugar without any types requirements

This way we can write Kotlin inline reified functions as an extension
 with the same names to make a Kotlin DSL much cleaner
…atibility

* Extract `protected` getters and setters for `BaseIntegrationFlowDefinition`
properties to allow a proper extension
* Use those getters and setters in the code
@artembilan artembilan force-pushed the BaseIntegrationFlowDefinition branch from ff49456 to 9faaa3b Compare October 24, 2019 15:52
@artembilan
Copy link
Member Author

@garyrussell ,

Here is a solution we discussed with you yesterday. Unfortunately another one with a plain extension still doesn't work in Kotlin.

Do not merge yet this one, since I haven't finished Kotlin part to be sure that we are good.
Although you can share your feedback about bytecode compatibility.

Thanks

@artembilan artembilan changed the title Extract BaseIntegrationFlowDefinition [DO NOT MERGE YET] Extract BaseIntegrationFlowDefinition Oct 24, 2019
}


// All the methods below override super for bytecode backward compatibility.
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 we will need to mark all these with NOSONAR to avoid "useless override" smells from Sonar 😦

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, but I would like to see that message to be sure about the place for such a // NOSONAR comment

@artembilan artembilan changed the title [DO NOT MERGE YET] Extract BaseIntegrationFlowDefinition Extract BaseIntegrationFlowDefinition Oct 24, 2019
@artembilan
Copy link
Member Author

OK! Missed mavenLocal() was my mistake in Kotlin DSL project, but now all is good!
Feel free to merge or let me know where to place those // NOSONAR.

Thanks

@artembilan
Copy link
Member Author

And now you can see what happened to Kotlin DSL after this.

@garyrussell
Copy link
Contributor

It goes on the method after the { - see ContainerProperties in kafka.

@artembilan
Copy link
Member Author

Thanks. Done.
Note: I have removed protected overridden methods. I don't think they are obstacle for target projects.

@garyrussell garyrussell merged commit ca56a0e into spring-projects:master Oct 28, 2019
@artembilan artembilan deleted the BaseIntegrationFlowDefinition branch March 24, 2021 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants