Code Cleanup - StringBuilder, Redundant Iteration, Record
This commit is contained in:
@@ -69,6 +69,7 @@ import org.springframework.util.CollectionUtils;
|
|||||||
* @author Soby Chacko
|
* @author Soby Chacko
|
||||||
* @author Byungjun You
|
* @author Byungjun You
|
||||||
* @author Georg Friedrich
|
* @author Georg Friedrich
|
||||||
|
* @author Omer Celik
|
||||||
* @since 2.2.0
|
* @since 2.2.0
|
||||||
*/
|
*/
|
||||||
public class KafkaStreamsFunctionProcessor extends AbstractKafkaStreamsBinderProcessor implements BeanFactoryAware {
|
public class KafkaStreamsFunctionProcessor extends AbstractKafkaStreamsBinderProcessor implements BeanFactoryAware {
|
||||||
@@ -475,7 +476,7 @@ public class KafkaStreamsFunctionProcessor extends AbstractKafkaStreamsBinderPro
|
|||||||
String next = iterator.next();
|
String next = iterator.next();
|
||||||
kafkaStreamsBindableProxyFactory.addOutputBinding(next, KStream.class);
|
kafkaStreamsBindableProxyFactory.addOutputBinding(next, KStream.class);
|
||||||
RootBeanDefinition rootBeanDefinition1 = new RootBeanDefinition();
|
RootBeanDefinition rootBeanDefinition1 = new RootBeanDefinition();
|
||||||
rootBeanDefinition1.setInstanceSupplier(() -> kafkaStreamsBindableProxyFactory.getOutputHolders().get(next).getBoundTarget());
|
rootBeanDefinition1.setInstanceSupplier(() -> kafkaStreamsBindableProxyFactory.getOutputHolders().get(next).boundTarget());
|
||||||
registry.registerBeanDefinition(next, rootBeanDefinition1);
|
registry.registerBeanDefinition(next, rootBeanDefinition1);
|
||||||
|
|
||||||
Object targetBean = this.applicationContext.getBean(next);
|
Object targetBean = this.applicationContext.getBean(next);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2023 the original author or authors.
|
* Copyright 2019-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -65,6 +65,7 @@ import org.springframework.util.CollectionUtils;
|
|||||||
* the actual size in the returned array. That has to wait until the function is invoked and we get a result.
|
* the actual size in the returned array. That has to wait until the function is invoked and we get a result.
|
||||||
*
|
*
|
||||||
* @author Soby Chacko
|
* @author Soby Chacko
|
||||||
|
* @author Omer Celik
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public class KafkaStreamsBindableProxyFactory extends AbstractBindableProxyFactory implements InitializingBean, BeanFactoryAware {
|
public class KafkaStreamsBindableProxyFactory extends AbstractBindableProxyFactory implements InitializingBean, BeanFactoryAware {
|
||||||
@@ -173,7 +174,7 @@ public class KafkaStreamsBindableProxyFactory extends AbstractBindableProxyFacto
|
|||||||
.createOutput(outputBinding), true));
|
.createOutput(outputBinding), true));
|
||||||
String outputBinding1 = outputBinding;
|
String outputBinding1 = outputBinding;
|
||||||
RootBeanDefinition rootBeanDefinition1 = new RootBeanDefinition();
|
RootBeanDefinition rootBeanDefinition1 = new RootBeanDefinition();
|
||||||
rootBeanDefinition1.setInstanceSupplier(() -> outputHolders.get(outputBinding1).getBoundTarget());
|
rootBeanDefinition1.setInstanceSupplier(() -> outputHolders.get(outputBinding1).boundTarget());
|
||||||
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
|
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
|
||||||
registry.registerBeanDefinition(outputBinding1, rootBeanDefinition1);
|
registry.registerBeanDefinition(outputBinding1, rootBeanDefinition1);
|
||||||
}
|
}
|
||||||
@@ -248,7 +249,7 @@ public class KafkaStreamsBindableProxyFactory extends AbstractBindableProxyFacto
|
|||||||
}
|
}
|
||||||
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
|
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
|
||||||
RootBeanDefinition rootBeanDefinition = new RootBeanDefinition();
|
RootBeanDefinition rootBeanDefinition = new RootBeanDefinition();
|
||||||
rootBeanDefinition.setInstanceSupplier(() -> inputHolders.get(inputName).getBoundTarget());
|
rootBeanDefinition.setInstanceSupplier(() -> inputHolders.get(inputName).boundTarget());
|
||||||
registry.registerBeanDefinition(inputName, rootBeanDefinition);
|
registry.registerBeanDefinition(inputName, rootBeanDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019-2022 the original author or authors.
|
* Copyright 2019-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -35,6 +35,7 @@ import org.springframework.util.StringUtils;
|
|||||||
*
|
*
|
||||||
* Original authors in {@link BindableProxyFactory}
|
* Original authors in {@link BindableProxyFactory}
|
||||||
* @author Soby Chacko
|
* @author Soby Chacko
|
||||||
|
* @author Omer Celik
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public class AbstractBindableProxyFactory implements Bindable {
|
public class AbstractBindableProxyFactory implements Bindable {
|
||||||
@@ -94,9 +95,9 @@ public class AbstractBindableProxyFactory implements Bindable {
|
|||||||
.entrySet()) {
|
.entrySet()) {
|
||||||
String inputTargetName = boundTargetHolderEntry.getKey();
|
String inputTargetName = boundTargetHolderEntry.getKey();
|
||||||
BoundTargetHolder boundTargetHolder = boundTargetHolderEntry.getValue();
|
BoundTargetHolder boundTargetHolder = boundTargetHolderEntry.getValue();
|
||||||
if (boundTargetHolder.isBindable()) {
|
if (boundTargetHolder.bindable()) {
|
||||||
bindings.addAll(bindingService.bindConsumer(
|
bindings.addAll(bindingService.bindConsumer(
|
||||||
boundTargetHolder.getBoundTarget(), inputTargetName));
|
boundTargetHolder.boundTarget(), inputTargetName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bindings;
|
return bindings;
|
||||||
@@ -111,9 +112,9 @@ public class AbstractBindableProxyFactory implements Bindable {
|
|||||||
.entrySet()) {
|
.entrySet()) {
|
||||||
BoundTargetHolder boundTargetHolder = boundTargetHolderEntry.getValue();
|
BoundTargetHolder boundTargetHolder = boundTargetHolderEntry.getValue();
|
||||||
String outputTargetName = boundTargetHolderEntry.getKey();
|
String outputTargetName = boundTargetHolderEntry.getKey();
|
||||||
if (boundTargetHolderEntry.getValue().isBindable()) {
|
if (boundTargetHolderEntry.getValue().bindable()) {
|
||||||
bindings.add(bindingService.bindProducer(
|
bindings.add(bindingService.bindProducer(
|
||||||
boundTargetHolder.getBoundTarget(), outputTargetName));
|
boundTargetHolder.boundTarget(), outputTargetName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bindings;
|
return bindings;
|
||||||
@@ -123,7 +124,7 @@ public class AbstractBindableProxyFactory implements Bindable {
|
|||||||
public void unbindInputs(BindingService bindingService) {
|
public void unbindInputs(BindingService bindingService) {
|
||||||
for (Map.Entry<String, BoundTargetHolder> boundTargetHolderEntry : this.inputHolders
|
for (Map.Entry<String, BoundTargetHolder> boundTargetHolderEntry : this.inputHolders
|
||||||
.entrySet()) {
|
.entrySet()) {
|
||||||
if (boundTargetHolderEntry.getValue().isBindable()) {
|
if (boundTargetHolderEntry.getValue().bindable()) {
|
||||||
bindingService.unbindConsumers(boundTargetHolderEntry.getKey());
|
bindingService.unbindConsumers(boundTargetHolderEntry.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,7 +134,7 @@ public class AbstractBindableProxyFactory implements Bindable {
|
|||||||
public void unbindOutputs(BindingService bindingService) {
|
public void unbindOutputs(BindingService bindingService) {
|
||||||
for (Map.Entry<String, BoundTargetHolder> boundTargetHolderEntry : this.outputHolders
|
for (Map.Entry<String, BoundTargetHolder> boundTargetHolderEntry : this.outputHolders
|
||||||
.entrySet()) {
|
.entrySet()) {
|
||||||
if (boundTargetHolderEntry.getValue().isBindable()) {
|
if (boundTargetHolderEntry.getValue().bindable()) {
|
||||||
bindingService.unbindProducers(boundTargetHolderEntry.getKey());
|
bindingService.unbindProducers(boundTargetHolderEntry.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015-2019 the original author or authors.
|
* Copyright 2015-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -24,25 +24,8 @@ package org.springframework.cloud.stream.binding;
|
|||||||
*
|
*
|
||||||
* @author Original authors in {@link BindableProxyFactory}
|
* @author Original authors in {@link BindableProxyFactory}
|
||||||
* @author Soby Chacko
|
* @author Soby Chacko
|
||||||
|
* @author Omer Celik
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public final class BoundTargetHolder {
|
public record BoundTargetHolder(Object boundTarget, boolean bindable) {
|
||||||
|
|
||||||
private Object boundTarget;
|
|
||||||
|
|
||||||
private boolean bindable;
|
|
||||||
|
|
||||||
public BoundTargetHolder(Object boundTarget, boolean bindable) {
|
|
||||||
this.boundTarget = boundTarget;
|
|
||||||
this.bindable = bindable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getBoundTarget() {
|
|
||||||
return this.boundTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isBindable() {
|
|
||||||
return this.bindable;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015-2018 the original author or authors.
|
* Copyright 2015-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -148,16 +148,16 @@ public class BindingProperties {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("destination=" + this.destination);
|
sb.append("destination=").append(this.destination);
|
||||||
sb.append(COMMA);
|
sb.append(COMMA);
|
||||||
sb.append("group=" + this.group);
|
sb.append("group=").append(this.group);
|
||||||
sb.append(COMMA);
|
sb.append(COMMA);
|
||||||
if (this.contentType != null) {
|
if (this.contentType != null) {
|
||||||
sb.append("contentType=" + this.contentType);
|
sb.append("contentType=").append(this.contentType);
|
||||||
sb.append(COMMA);
|
sb.append(COMMA);
|
||||||
}
|
}
|
||||||
if (this.binder != null) {
|
if (this.binder != null) {
|
||||||
sb.append("binder=" + this.binder);
|
sb.append("binder=").append(this.binder);
|
||||||
sb.append(COMMA);
|
sb.append(COMMA);
|
||||||
}
|
}
|
||||||
sb.deleteCharAt(sb.lastIndexOf(COMMA));
|
sb.deleteCharAt(sb.lastIndexOf(COMMA));
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ import org.springframework.util.ObjectUtils;
|
|||||||
* @author Oleg Zhurakousky
|
* @author Oleg Zhurakousky
|
||||||
* @author Soby Chacko
|
* @author Soby Chacko
|
||||||
* @author Chris Bono
|
* @author Chris Bono
|
||||||
|
* @author Omer Celik
|
||||||
*/
|
*/
|
||||||
@AutoConfiguration
|
@AutoConfiguration
|
||||||
@EnableConfigurationProperties({ BindingServiceProperties.class,
|
@EnableConfigurationProperties({ BindingServiceProperties.class,
|
||||||
@@ -132,6 +133,7 @@ public class BindingServiceConfiguration {
|
|||||||
.entrySet()) {
|
.entrySet()) {
|
||||||
if (configurationEntry.getValue().isDefaultCandidate()) {
|
if (configurationEntry.getValue().isDefaultCandidate()) {
|
||||||
defaultCandidatesExist = true;
|
defaultCandidatesExist = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!defaultCandidatesExist) {
|
if (!defaultCandidatesExist) {
|
||||||
|
|||||||
Reference in New Issue
Block a user