GH-8586: Deprecate IntegrationComponentSpec.get() (#8594)
* GH-8586: Deprecate IntegrationComponentSpec.get() Fixes https://github.com/spring-projects/spring-integration/issues/8586 The `IntegrationComponentSpec` is not a plain wrapper around single component. Sometimes it comes with several components where all of them must be registered as beans. If `IntegrationComponentSpec.get()` is called from end-user code, we may lose other related components, for example filters in the `FileInboundChannelAdapterSpec`. * Deprecate `IntegrationComponentSpec.get()` with no-op for end-user, rather encourage to leave it as is and let the framework take care about its lifecycle and related components registration * Fix `IntegrationComponentSpec` logic to deal as a simple `FactoryBean` instead of extra overhead via `AbstractFactoryBean` * Use `IntegrationComponentSpec.getObject()` in the framework code where `get()` was called * Fix tests to expose `IntegrationComponentSpec` as beans instead of previously called `get()` * Some other clean up and typos fixes in the affected classes * Document the change * * Revert `ObjectStringMapBuilder` in the `KafkaInboundGatewaySpec.getComponentsToRegister()` * Fix language in docs Co-authored-by: Gary Russell <grussell@vmware.com> * * Remove trailing whitespace in the `ScriptMessageSourceSpec` --------- Co-authored-by: Gary Russell <grussell@vmware.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -208,7 +208,7 @@ public final class Jms {
|
||||
public static JmsMessageDrivenChannelAdapterSpec<?> messageDrivenChannelAdapter(
|
||||
JmsListenerContainerSpec<?, ? extends AbstractMessageListenerContainer> jmsListenerContainerSpec) {
|
||||
|
||||
return new JmsMessageDrivenChannelAdapterSpec<>(jmsListenerContainerSpec.get());
|
||||
return new JmsMessageDrivenChannelAdapterSpec<>(jmsListenerContainerSpec.getObject());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,7 +216,9 @@ public final class Jms {
|
||||
* @param listenerContainer the {@link AbstractMessageListenerContainer} to build on
|
||||
* @return the {@link JmsMessageDrivenChannelAdapterSpec} instance
|
||||
*/
|
||||
public static JmsMessageDrivenChannelAdapterSpec<?> messageDrivenChannelAdapter(AbstractMessageListenerContainer listenerContainer) {
|
||||
public static JmsMessageDrivenChannelAdapterSpec<?> messageDrivenChannelAdapter(
|
||||
AbstractMessageListenerContainer listenerContainer) {
|
||||
|
||||
return new JmsMessageDrivenChannelAdapterSpec<>(listenerContainer);
|
||||
}
|
||||
|
||||
@@ -227,14 +229,10 @@ public final class Jms {
|
||||
*/
|
||||
public static JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec<JmsDefaultListenerContainerSpec, DefaultMessageListenerContainer>
|
||||
messageDrivenChannelAdapter(ConnectionFactory connectionFactory) {
|
||||
try {
|
||||
return new JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec<>(
|
||||
new JmsDefaultListenerContainerSpec()
|
||||
.connectionFactory(connectionFactory));
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
return new JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec<>(
|
||||
new JmsDefaultListenerContainerSpec()
|
||||
.connectionFactory(connectionFactory));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,15 +247,11 @@ public final class Jms {
|
||||
public static <C extends AbstractMessageListenerContainer>
|
||||
JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec<?, C>
|
||||
messageDrivenChannelAdapter(ConnectionFactory connectionFactory, Class<C> containerClass) {
|
||||
try {
|
||||
JmsListenerContainerSpec<?, C> spec =
|
||||
new JmsListenerContainerSpec<>(containerClass)
|
||||
.connectionFactory(connectionFactory);
|
||||
return new JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec(spec);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
JmsListenerContainerSpec<?, C> spec =
|
||||
new JmsListenerContainerSpec<>(containerClass)
|
||||
.connectionFactory(connectionFactory);
|
||||
return new JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec(spec);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -268,14 +262,10 @@ public final class Jms {
|
||||
*/
|
||||
public static JmsDefaultListenerContainerSpec container(ConnectionFactory connectionFactory,
|
||||
Destination destination) {
|
||||
try {
|
||||
return new JmsDefaultListenerContainerSpec()
|
||||
.connectionFactory(connectionFactory)
|
||||
.destination(destination);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
return new JmsDefaultListenerContainerSpec()
|
||||
.connectionFactory(connectionFactory)
|
||||
.destination(destination);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,14 +276,10 @@ public final class Jms {
|
||||
*/
|
||||
public static JmsDefaultListenerContainerSpec container(ConnectionFactory connectionFactory,
|
||||
String destinationName) {
|
||||
try {
|
||||
return new JmsDefaultListenerContainerSpec()
|
||||
.connectionFactory(connectionFactory)
|
||||
.destination(destinationName);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
return new JmsDefaultListenerContainerSpec()
|
||||
.connectionFactory(connectionFactory)
|
||||
.destination(destinationName);
|
||||
}
|
||||
|
||||
private Jms() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2021 the original author or authors.
|
||||
* Copyright 2016-2023 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.
|
||||
@@ -49,7 +49,8 @@ public class JmsInboundChannelAdapterSpec<S extends JmsInboundChannelAdapterSpec
|
||||
}
|
||||
|
||||
private JmsInboundChannelAdapterSpec(ConnectionFactory connectionFactory) {
|
||||
this.target = new JmsDestinationPollingSource(this.jmsTemplateSpec.connectionFactory(connectionFactory).get());
|
||||
this.target =
|
||||
new JmsDestinationPollingSource(this.jmsTemplateSpec.connectionFactory(connectionFactory).getObject());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,7 +119,7 @@ public class JmsInboundChannelAdapterSpec<S extends JmsInboundChannelAdapterSpec
|
||||
|
||||
@Override
|
||||
public Map<Object, String> getComponentsToRegister() {
|
||||
return Collections.singletonMap(this.jmsTemplateSpec.get(), this.jmsTemplateSpec.getId());
|
||||
return Collections.singletonMap(this.jmsTemplateSpec.getObject(), this.jmsTemplateSpec.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -246,9 +246,9 @@ public class JmsInboundGatewaySpec<S extends JmsInboundGatewaySpec<S>>
|
||||
private final S spec;
|
||||
|
||||
protected JmsInboundGatewayListenerContainerSpec(S spec) {
|
||||
super(spec.get());
|
||||
super(spec.getObject());
|
||||
this.spec = spec;
|
||||
this.spec.get().setAutoStartup(false);
|
||||
this.spec.getObject().setAutoStartup(false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2021 the original author or authors.
|
||||
* Copyright 2016-2023 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.
|
||||
@@ -80,9 +80,9 @@ public class JmsMessageDrivenChannelAdapterSpec<S extends JmsMessageDrivenChanne
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to false to prevent listener container shutdown when the endpoint is stopped.
|
||||
* Set to 'false' to prevent listener container shutdown when the endpoint is stopped.
|
||||
* Then, if so configured, any cached consumer(s) in the container will remain.
|
||||
* Otherwise the shared connection and will be closed and the listener invokers shut
|
||||
* Otherwise, the shared connection and will be closed and the listener invokers shut
|
||||
* down; this behavior is new starting with version 5.1. Default: true.
|
||||
* @param shutdown false to not shutdown.
|
||||
* @return the spec.
|
||||
@@ -106,9 +106,9 @@ public class JmsMessageDrivenChannelAdapterSpec<S extends JmsMessageDrivenChanne
|
||||
private final S spec;
|
||||
|
||||
protected JmsMessageDrivenChannelAdapterListenerContainerSpec(S spec) {
|
||||
super(spec.get());
|
||||
super(spec.getObject());
|
||||
this.spec = spec;
|
||||
this.spec.get().setAutoStartup(false);
|
||||
this.spec.getObject().setAutoStartup(false);
|
||||
|
||||
}
|
||||
|
||||
@@ -141,6 +141,7 @@ public class JmsMessageDrivenChannelAdapterSpec<S extends JmsMessageDrivenChanne
|
||||
*/
|
||||
public JmsMessageDrivenChannelAdapterListenerContainerSpec<S, C> configureListenerContainer(
|
||||
Consumer<S> configurer) {
|
||||
|
||||
Assert.notNull(configurer, "'configurer' must not be null");
|
||||
configurer.accept(this.spec);
|
||||
return _this();
|
||||
@@ -148,7 +149,7 @@ public class JmsMessageDrivenChannelAdapterSpec<S extends JmsMessageDrivenChanne
|
||||
|
||||
@Override
|
||||
public Map<Object, String> getComponentsToRegister() {
|
||||
return Collections.singletonMap(this.spec.get(), this.spec.getId());
|
||||
return Collections.singletonMap(this.spec.getObject(), this.spec.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2021 the original author or authors.
|
||||
* Copyright 2016-2023 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.
|
||||
@@ -51,7 +51,8 @@ public class JmsOutboundChannelAdapterSpec<S extends JmsOutboundChannelAdapterSp
|
||||
}
|
||||
|
||||
private JmsOutboundChannelAdapterSpec(ConnectionFactory connectionFactory) {
|
||||
this.target = new JmsSendingMessageHandler(this.jmsTemplateSpec.connectionFactory(connectionFactory).get());
|
||||
this.target =
|
||||
new JmsSendingMessageHandler(this.jmsTemplateSpec.connectionFactory(connectionFactory).getObject());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +102,7 @@ public class JmsOutboundChannelAdapterSpec<S extends JmsOutboundChannelAdapterSp
|
||||
* which a message will be sent.
|
||||
* @param destination the destination name.
|
||||
* @return the current {@link JmsOutboundChannelAdapterSpec}.
|
||||
* @see JmsSendingMessageHandler#setDestinationExpression(Expression)
|
||||
* @see JmsSendingMessageHandler#setDestinationExpression
|
||||
*/
|
||||
public S destinationExpression(String destination) {
|
||||
this.target.setDestinationExpression(PARSER.parseExpression(destination));
|
||||
@@ -119,7 +120,7 @@ public class JmsOutboundChannelAdapterSpec<S extends JmsOutboundChannelAdapterSp
|
||||
* @param destinationFunction the destination function.
|
||||
* @param <P> the expected payload type.
|
||||
* @return the current {@link JmsOutboundChannelAdapterSpec}.
|
||||
* @see JmsSendingMessageHandler#setDestinationExpression(Expression)
|
||||
* @see JmsSendingMessageHandler#setDestinationExpression
|
||||
* @see FunctionExpression
|
||||
*/
|
||||
public <P> S destination(Function<Message<P>, ?> destinationFunction) {
|
||||
@@ -194,7 +195,7 @@ public class JmsOutboundChannelAdapterSpec<S extends JmsOutboundChannelAdapterSp
|
||||
|
||||
@Override
|
||||
public Map<Object, String> getComponentsToRegister() {
|
||||
return Collections.singletonMap(this.jmsTemplateSpec.get(), this.jmsTemplateSpec.getId());
|
||||
return Collections.singletonMap(this.jmsTemplateSpec.getObject(), this.jmsTemplateSpec.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2021 the original author or authors.
|
||||
* Copyright 2016-2023 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.
|
||||
@@ -296,7 +296,7 @@ public class JmsOutboundGatewaySpec extends MessageHandlerSpec<JmsOutboundGatewa
|
||||
Assert.notNull(configurer, "'configurer' must not be null");
|
||||
ReplyContainerSpec spec = new ReplyContainerSpec();
|
||||
configurer.accept(spec);
|
||||
this.target.setReplyContainerProperties(spec.get());
|
||||
this.target.setReplyContainerProperties(spec.getObject());
|
||||
return _this();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user