Rework KotlinIntFlowDefinition for delegation

According Kotlin best practice it is better to not
extend from Java classes, but instead provide a
clean Kotlin API and delegate to Java one internally

* Implement all the `IntegrationFlowDefinition` methods
in the `KotlinIntegrationFlowDefinition` Kotlin way and
delegate to the provided `IntegrationFlowDefinition` instance
* Remove `@UseExperimental` and `@BuilderInference` since
we now have all the API in Kotlin
* Rework `KotlinDslTests` for support now Kotlin code style
* Remove `-Xuse-experimental` from Gradle config since we
don't use experimental API any more
This commit is contained in:
Artem Bilan
2019-12-16 15:35:10 -05:00
parent 609f88c876
commit 69157dea82
4 changed files with 946 additions and 116 deletions

View File

@@ -66,7 +66,7 @@ dependencyManagement {
compileKotlin {
kotlinOptions {
jvmTarget = '1.8'
freeCompilerArgs = ['-Xjsr305=strict', '-Xuse-experimental=kotlin.Experimental']
freeCompilerArgs = ['-Xjsr305=strict']
allWarningsAsErrors = true
}
}

View File

@@ -14,8 +14,6 @@
* limitations under the License.
*/
@file:UseExperimental(kotlin.experimental.ExperimentalTypeInference::class)
package org.springframework.integration.dsl
import org.reactivestreams.Publisher
@@ -38,7 +36,7 @@ private fun buildIntegrationFlow(flowBuilder: IntegrationFlowBuilder,
*
* @author Artem Bilan
*/
fun integrationFlow(@BuilderInference flow: KotlinIntegrationFlowDefinition.() -> Unit) =
fun integrationFlow(flow: KotlinIntegrationFlowDefinition.() -> Unit) =
IntegrationFlow {
flow(KotlinIntegrationFlowDefinition(it))
}
@@ -51,7 +49,7 @@ fun integrationFlow(@BuilderInference flow: KotlinIntegrationFlowDefinition.() -
*/
inline fun <reified T> integrationFlow(
crossinline gateway: (GatewayProxySpec) -> Unit = {},
@BuilderInference flow: KotlinIntegrationFlowDefinition.() -> Unit): IntegrationFlow {
flow: KotlinIntegrationFlowDefinition.() -> Unit): IntegrationFlow {
val flowBuilder = IntegrationFlows.from(T::class.java) { gateway(it) }
flow(KotlinIntegrationFlowDefinition(flowBuilder))
@@ -65,7 +63,7 @@ inline fun <reified T> integrationFlow(
* @author Artem Bilan
*/
fun integrationFlow(channelName: String, fixedSubscriber: Boolean = false,
@BuilderInference flow: KotlinIntegrationFlowDefinition.() -> Unit) =
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(channelName, fixedSubscriber), flow)
/**
@@ -74,7 +72,7 @@ fun integrationFlow(channelName: String, fixedSubscriber: Boolean = false,
*
* @author Artem Bilan
*/
fun integrationFlow(channel: MessageChannel, @BuilderInference flow: KotlinIntegrationFlowDefinition.() -> Unit) =
fun integrationFlow(channel: MessageChannel, flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(channel), flow)
/**
@@ -85,7 +83,7 @@ fun integrationFlow(channel: MessageChannel, @BuilderInference flow: KotlinInteg
*/
fun integrationFlow(messageSource: MessageSource<*>,
options: (SourcePollingChannelAdapterSpec) -> Unit = {},
@BuilderInference flow: KotlinIntegrationFlowDefinition.() -> Unit) =
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(messageSource, Consumer { options(it) }), flow)
/**
@@ -96,7 +94,7 @@ fun integrationFlow(messageSource: MessageSource<*>,
*/
fun integrationFlow(messageSource: MessageSourceSpec<*, out MessageSource<*>>,
options: (SourcePollingChannelAdapterSpec) -> Unit = {},
@BuilderInference flow: KotlinIntegrationFlowDefinition.() -> Unit) =
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(messageSource, options), flow)
/**
@@ -107,7 +105,7 @@ fun integrationFlow(messageSource: MessageSourceSpec<*, out MessageSource<*>>,
*/
fun integrationFlow(source: () -> Any,
options: (SourcePollingChannelAdapterSpec) -> Unit = {},
@BuilderInference flow: KotlinIntegrationFlowDefinition.() -> Unit) =
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(source, options), flow)
/**
@@ -117,7 +115,7 @@ fun integrationFlow(source: () -> Any,
* @author Artem Bilan
*/
fun integrationFlow(publisher: Publisher<out Message<*>>,
@BuilderInference flow: KotlinIntegrationFlowDefinition.() -> Unit) =
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(publisher), flow)
/**
@@ -127,7 +125,7 @@ fun integrationFlow(publisher: Publisher<out Message<*>>,
* @author Artem Bilan
*/
fun integrationFlow(gateway: MessagingGatewaySupport,
@BuilderInference flow: KotlinIntegrationFlowDefinition.() -> Unit) =
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(gateway), flow)
/**
@@ -137,7 +135,7 @@ fun integrationFlow(gateway: MessagingGatewaySupport,
* @author Artem Bilan
*/
fun integrationFlow(gatewaySpec: MessagingGatewaySpec<*, *>,
@BuilderInference flow: KotlinIntegrationFlowDefinition.() -> Unit) =
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(gatewaySpec), flow)
/**
@@ -147,7 +145,7 @@ fun integrationFlow(gatewaySpec: MessagingGatewaySpec<*, *>,
* @author Artem Bilan
*/
fun integrationFlow(producer: MessageProducerSupport,
@BuilderInference flow: KotlinIntegrationFlowDefinition.() -> Unit) =
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(producer), flow)
/**
@@ -157,5 +155,5 @@ fun integrationFlow(producer: MessageProducerSupport,
* @author Artem Bilan
*/
fun integrationFlow(producerSpec: MessageProducerSpec<*, *>,
@BuilderInference flow: KotlinIntegrationFlowDefinition.() -> Unit) =
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(producerSpec), flow)

View File

@@ -207,8 +207,10 @@ class KotlinDslTests {
fun functionFlow() =
integrationFlow<Function<String, String>>({ it.beanName("functionGateway") }) {
transform<String, String> { it.toUpperCase() }
split<String> { p -> p }
split<String>({ p -> p }) { it.id("splitterEndpoint") }
split<Message<*>> { it.payload }
split<String>({ it }) { it.id("splitterEndpoint") }
resequence()
aggregate { it.id("aggregator").outputProcessor { it.one } }
}
@Bean
@@ -223,43 +225,44 @@ class KotlinDslTests {
fun messageSourceFlow() =
integrationFlow(MessageProcessorMessageSource { "testSource" },
{ it.poller { it.trigger(OnlyOnceTrigger()) } }) {
channel { c -> c.queue("fromSupplierQueue") }
channel { it.queue("fromSupplierQueue") }
}
@Bean
fun messageSourceFlow2() =
integrationFlow(MessageProcessorMessageSource { "testSource2" }) {
channel { c -> c.queue("fromSupplierQueue2") }
channel { it.queue("fromSupplierQueue2") }
}
@Bean
fun fixedSubscriberFlow() =
integrationFlow("fixedSubscriberInput", true) {
logAndReply(LoggingHandler.Level.WARN)
log<Any>(LoggingHandler.Level.WARN) { it.payload }
transform("payload") { it.id("spelTransformer") }
}
@Bean
fun flowFromSupplier() =
integrationFlow({ "testSupplier" }) {
channel { c -> c.queue("testSupplierResult") }
channel { it.queue("testSupplierResult") }
}
@Bean
fun flowFromSupplier2() =
integrationFlow({ "testSupplier2" },
{ it.poller { it.trigger(OnlyOnceTrigger()) } }) {
filter<Message<Any>> { m -> m.payload is String }
channel { c -> c.queue("testSupplierResult2") }
filter<Message<*>> { m -> m.payload is String }
channel { it.queue("testSupplierResult2") }
}
@Bean
fun flowLambda() =
integrationFlow {
filter<String>({ it === "test" }) { it.id("filterEndpoint") }
wireTap(
integrationFlow {
channel { c -> c.queue("wireTapChannel") }
})
wireTap {
channel { it.queue("wireTapChannel") }
}
delay("delayGroup") { it.defaultDelay(100) }
transform<String, String> { it.toUpperCase() }
}