diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/Amqp.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/Amqp.java index 014725eff0..81c7537fd7 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/Amqp.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/Amqp.java @@ -22,6 +22,7 @@ import org.springframework.amqp.rabbit.AsyncRabbitTemplate; import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer; import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; +import org.springframework.integration.amqp.channel.PollableAmqpChannel; import org.springframework.integration.amqp.inbound.AmqpMessageSource.AmqpAckCallbackFactory; import org.springframework.lang.Nullable; @@ -30,6 +31,7 @@ import org.springframework.lang.Nullable; * * @author Artem Bilan * @author Gary Russell + * @author Artem Vozhdayenko * * @since 5.0 */ @@ -269,7 +271,7 @@ public final class Amqp { * @param connectionFactory the connectionFactory. * @return the AmqpPollableMessageChannelSpec. */ - public static AmqpPollableMessageChannelSpec pollableChannel(ConnectionFactory connectionFactory) { + public static AmqpPollableMessageChannelSpec pollableChannel(ConnectionFactory connectionFactory) { return pollableChannel(null, connectionFactory); } @@ -279,11 +281,11 @@ public final class Amqp { * @param connectionFactory the connectionFactory. * @return the AmqpPollableMessageChannelSpec. */ - public static AmqpPollableMessageChannelSpec pollableChannel(@Nullable String id, + public static AmqpPollableMessageChannelSpec pollableChannel(@Nullable String id, ConnectionFactory connectionFactory) { - return new AmqpPollableMessageChannelSpec<>(connectionFactory) - .id(id); + AmqpPollableMessageChannelSpec spec = new AmqpPollableMessageChannelSpec<>(connectionFactory); + return spec.id(id); } /** @@ -291,7 +293,7 @@ public final class Amqp { * @param connectionFactory the connectionFactory. * @return the AmqpMessageChannelSpec. */ - public static AmqpMessageChannelSpec channel(ConnectionFactory connectionFactory) { + public static AmqpMessageChannelSpec channel(ConnectionFactory connectionFactory) { return channel(null, connectionFactory); } @@ -301,7 +303,7 @@ public final class Amqp { * @param connectionFactory the connectionFactory. * @return the AmqpMessageChannelSpec. */ - public static AmqpMessageChannelSpec channel(@Nullable String id, ConnectionFactory connectionFactory) { + public static AmqpMessageChannelSpec channel(@Nullable String id, ConnectionFactory connectionFactory) { return new AmqpMessageChannelSpec<>(connectionFactory) .id(id); } diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpMessageChannelSpec.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpMessageChannelSpec.java index 46ebf92616..a5d9dfe3a5 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpMessageChannelSpec.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpMessageChannelSpec.java @@ -39,10 +39,12 @@ import org.springframework.util.ErrorHandler; * * @author Artem Bilan * @author Gary Russell + * @author Artem Vozhdayenko * * @since 5.0 */ -public class AmqpMessageChannelSpec> extends AmqpPollableMessageChannelSpec { +public class AmqpMessageChannelSpec, T extends AbstractAmqpChannel> + extends AmqpPollableMessageChannelSpec { protected final List adviceChain = new LinkedList<>(); // NOSONAR @@ -215,7 +217,7 @@ public class AmqpMessageChannelSpec> extends } @Override - protected AbstractAmqpChannel doGet() { + protected T doGet() { this.amqpChannelFactoryBean.setAdviceChain(this.adviceChain.toArray(new Advice[0])); return super.doGet(); } diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpPollableMessageChannelSpec.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpPollableMessageChannelSpec.java index 510459f516..cc2aa945ba 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpPollableMessageChannelSpec.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpPollableMessageChannelSpec.java @@ -36,11 +36,12 @@ import org.springframework.util.Assert; * * @author Artem Bilan * @author Gary Russell + * @author Artem Vozhdayenko * * @since 5.0 */ -public class AmqpPollableMessageChannelSpec> - extends MessageChannelSpec { +public class AmqpPollableMessageChannelSpec, T extends AbstractAmqpChannel> + extends MessageChannelSpec { protected final AmqpChannelFactoryBean amqpChannelFactoryBean; // NOSONAR final @@ -206,10 +207,11 @@ public class AmqpPollableMessageChannelSpec { + extends AmqpMessageChannelSpec { protected AmqpPublishSubscribeMessageChannelSpec(ConnectionFactory connectionFactory) { super(connectionFactory); diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/Jms.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/Jms.java index 1d8b861937..a19c009889 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/Jms.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/Jms.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.integration.jms.dsl; import javax.jms.ConnectionFactory; import javax.jms.Destination; +import org.springframework.integration.jms.PollableJmsChannel; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.listener.AbstractMessageListenerContainer; import org.springframework.jms.listener.DefaultMessageListenerContainer; @@ -29,6 +30,7 @@ import org.springframework.lang.Nullable; * * @author Artem Bilan * @author Gary Russell + * @author Artem Vozhdayenko * * @since 5.0 */ @@ -39,7 +41,7 @@ public final class Jms { * @param connectionFactory the JMS ConnectionFactory to build on * @return the {@link JmsPollableMessageChannelSpec} instance */ - public static JmsPollableMessageChannelSpec pollableChannel(ConnectionFactory connectionFactory) { + public static JmsPollableMessageChannelSpec pollableChannel(ConnectionFactory connectionFactory) { return pollableChannel(null, connectionFactory); } @@ -49,10 +51,10 @@ public final class Jms { * @param connectionFactory the JMS ConnectionFactory to build on * @return the {@link JmsPollableMessageChannelSpec} instance */ - public static JmsPollableMessageChannelSpec pollableChannel(@Nullable String id, + public static JmsPollableMessageChannelSpec pollableChannel(@Nullable String id, ConnectionFactory connectionFactory) { - - return new JmsPollableMessageChannelSpec<>(connectionFactory).id(id); + JmsPollableMessageChannelSpec spec = new JmsPollableMessageChannelSpec<>(connectionFactory); + return spec.id(id); } /** @@ -60,7 +62,7 @@ public final class Jms { * @param connectionFactory the JMS ConnectionFactory to build on * @return the {@link JmsMessageChannelSpec} instance */ - public static JmsMessageChannelSpec channel(ConnectionFactory connectionFactory) { + public static JmsMessageChannelSpec channel(ConnectionFactory connectionFactory) { return channel(null, connectionFactory); } @@ -70,7 +72,7 @@ public final class Jms { * @param connectionFactory the JMS ConnectionFactory to build on * @return the {@link JmsMessageChannelSpec} instance */ - public static JmsMessageChannelSpec channel(@Nullable String id, ConnectionFactory connectionFactory) { + public static JmsMessageChannelSpec channel(@Nullable String id, ConnectionFactory connectionFactory) { return new JmsMessageChannelSpec<>(connectionFactory) .id(id); } @@ -180,7 +182,7 @@ public final class Jms { * @param the {@link AbstractMessageListenerContainer} inheritor type * @return the {@link JmsInboundGatewaySpec} instance */ - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) public static JmsInboundGatewaySpec.JmsInboundGatewayListenerContainerSpec inboundGateway( ConnectionFactory connectionFactory, Class containerClass) { @@ -241,7 +243,7 @@ public final class Jms { * @param the {@link AbstractMessageListenerContainer} inheritor type * @return the {@link JmsMessageDrivenChannelAdapterSpec} instance */ - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) public static JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec messageDrivenChannelAdapter(ConnectionFactory connectionFactory, Class containerClass) { diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsMessageChannelSpec.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsMessageChannelSpec.java index 6a8af37a0c..6c8ec6a3af 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsMessageChannelSpec.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsMessageChannelSpec.java @@ -20,6 +20,7 @@ import java.util.concurrent.Executor; import javax.jms.ConnectionFactory; +import org.springframework.integration.jms.AbstractJmsChannel; import org.springframework.integration.jms.config.JmsChannelFactoryBean; import org.springframework.jms.listener.AbstractMessageListenerContainer; import org.springframework.transaction.PlatformTransactionManager; @@ -33,9 +34,12 @@ import org.springframework.util.ErrorHandler; * * @author Artem Bilan * @author Gary Russell + * @author Artem Vozhdayenko + * * @since 5.0 */ -public class JmsMessageChannelSpec> extends JmsPollableMessageChannelSpec { +public class JmsMessageChannelSpec, T + extends AbstractJmsChannel> extends JmsPollableMessageChannelSpec { protected JmsMessageChannelSpec(ConnectionFactory connectionFactory) { super(new JmsChannelFactoryBean(true), connectionFactory); diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsPollableMessageChannelSpec.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsPollableMessageChannelSpec.java index 9b5fb36c81..c4e03b1dfa 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsPollableMessageChannelSpec.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsPollableMessageChannelSpec.java @@ -35,11 +35,12 @@ import org.springframework.lang.Nullable; * * @author Artem Bilan * @author Gary Russell + * @author Artem Vozhdayenko * * @since 5.0 */ -public class JmsPollableMessageChannelSpec> - extends MessageChannelSpec { +public class JmsPollableMessageChannelSpec, T extends AbstractJmsChannel> + extends MessageChannelSpec { protected final JmsChannelFactoryBean jmsChannelFactoryBean; // NOSONAR - final @@ -218,9 +219,10 @@ public class JmsPollableMessageChannelSpec { + extends JmsMessageChannelSpec { protected JmsPublishSubscribeMessageChannelSpec(ConnectionFactory connectionFactory) { super(connectionFactory); diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/dsl/JmsTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/dsl/JmsTests.java index 13f2badfeb..b588e16cf1 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/dsl/JmsTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/dsl/JmsTests.java @@ -83,6 +83,7 @@ import org.springframework.transaction.PlatformTransactionManager; * @author Artem Bilan * @author Gary Russell * @author Nasko Vasilev + * @author Artem Vozhdayenko * * @since 5.0 */ @@ -371,8 +372,7 @@ public class JmsTests extends ActiveMQMultiContextTests { @Bean public BroadcastCapableChannel jmsPublishSubscribeChannel() { - // TODO reconsider target generic type for channel implementation to return from this kind of specs - return (BroadcastCapableChannel) Jms.publishSubscribeChannel(jmsConnectionFactory()) + return Jms.publishSubscribeChannel(jmsConnectionFactory()) .destination("pubsub") .get(); }