GH-60: Get rid of HashCodeBuilder usage
Fixes #60 (https://github.com/spring-projects/spring-integration-kafka/issues/60) * Upgrade to Gradle 2.5 and other dependencies
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -18,8 +18,6 @@ package org.springframework.integration.kafka.support;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.apache.kafka.clients.producer.RecordMetadata;
|
||||
@@ -36,6 +34,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Ilayaperumal Gopinathan
|
||||
* @author Gary Russell
|
||||
* @author Marius Bogoevici
|
||||
* @author Artem Bilan
|
||||
* @since 0.5
|
||||
*/
|
||||
public class ProducerConfiguration<K, V> {
|
||||
@@ -53,7 +52,7 @@ public class ProducerConfiguration<K, V> {
|
||||
this.producer = producer;
|
||||
GenericConversionService genericConversionService = new GenericConversionService();
|
||||
genericConversionService.addConverter(Object.class, byte[].class, new SerializingConverter());
|
||||
conversionService = genericConversionService;
|
||||
this.conversionService = genericConversionService;
|
||||
}
|
||||
|
||||
public void setConversionService(ConversionService conversionService) {
|
||||
@@ -80,12 +79,13 @@ public class ProducerConfiguration<K, V> {
|
||||
return this.producer.send(new ProducerRecord<>(targetTopic, partition, messageKey, messagePayload));
|
||||
}
|
||||
|
||||
public Future<RecordMetadata> convertAndSend(String topic, Integer partition, Object messageKey, Object messagePayload) {
|
||||
return this.send(topic, partition, convertKeyIfNecessary(messageKey), convertPayloadIfNecessary(messagePayload));
|
||||
public Future<RecordMetadata> convertAndSend(String topic, Integer partition, Object messageKey,
|
||||
Object messagePayload) {
|
||||
return send(topic, partition, convertKeyIfNecessary(messageKey), convertPayloadIfNecessary(messagePayload));
|
||||
}
|
||||
|
||||
public Future<RecordMetadata> convertAndSend(String topic, Object messageKey, Object messagePayload) {
|
||||
return this.send(topic, convertKeyIfNecessary(messageKey), convertPayloadIfNecessary(messagePayload));
|
||||
return send(topic, convertKeyIfNecessary(messageKey), convertPayloadIfNecessary(messagePayload));
|
||||
}
|
||||
|
||||
private K convertKeyIfNecessary(Object messageKey) {
|
||||
@@ -94,8 +94,7 @@ public class ProducerConfiguration<K, V> {
|
||||
messageKey.getClass())) {
|
||||
return getProducerMetadata().getKeyClassType().cast(messageKey);
|
||||
}
|
||||
return conversionService.convert(messageKey,
|
||||
producerMetadata.getKeyClassType());
|
||||
return this.conversionService.convert(messageKey, this.producerMetadata.getKeyClassType());
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
@@ -108,31 +107,24 @@ public class ProducerConfiguration<K, V> {
|
||||
messagePayload.getClass())) {
|
||||
return getProducerMetadata().getValueClassType().cast(messagePayload);
|
||||
}
|
||||
return conversionService.convert(messagePayload,
|
||||
producerMetadata.getValueClassType());
|
||||
return this.conversionService.convert(messagePayload, this.producerMetadata.getValueClassType());
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProducerConfiguration [producerMetadata=" + this.producerMetadata + "]";
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
this.producer.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProducerConfiguration{" +
|
||||
"producer=" + this.producer +
|
||||
", producerMetadata=" + this.producerMetadata +
|
||||
", conversionService=" + this.conversionService +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -13,20 +13,21 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.kafka.support;
|
||||
|
||||
import kafka.producer.Partitioner;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.kafka.common.serialization.Serializer;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import kafka.producer.Partitioner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Soby Chacko
|
||||
* @author Rajasekar Elango
|
||||
* @author Marius Bogoevici
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 0.5
|
||||
*/
|
||||
@@ -48,7 +49,8 @@ public class ProducerMetadata<K,V> {
|
||||
|
||||
private int batchBytes = 16384;
|
||||
|
||||
public ProducerMetadata(final String topic, Class<K> keyClassType, Class<V> valueClassType, Serializer<K> keySerializer, Serializer<V> valueSerializer) {
|
||||
public ProducerMetadata(final String topic, Class<K> keyClassType, Class<V> valueClassType,
|
||||
Serializer<K> keySerializer, Serializer<V> valueSerializer) {
|
||||
Assert.notNull(topic, "Topic cannot be null");
|
||||
Assert.notNull(keyClassType, "Key class type serializer cannot be null");
|
||||
Assert.notNull(valueClassType, "Value class type cannot be null");
|
||||
@@ -107,25 +109,18 @@ public class ProducerMetadata<K,V> {
|
||||
return valueClassType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj){
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("ProducerMetadata [keyEncoder=").append(keySerializer)
|
||||
.append(", valueEncoder=").append(valueSerializer)
|
||||
.append(", topic=").append(topic)
|
||||
.append(", compressionType=").append(compressionType)
|
||||
.append("batchBytes").append(batchBytes).append("]");
|
||||
return builder.toString();
|
||||
return "ProducerMetadata{" +
|
||||
"keyClassType=" + this.keyClassType +
|
||||
", valueClassType=" + this.valueClassType +
|
||||
", keySerializer=" + this.keySerializer +
|
||||
", valueSerializer=" + this.valueSerializer +
|
||||
", topic='" + this.topic + '\'' +
|
||||
", partitioner=" + this.partitioner +
|
||||
", compressionType=" + this.compressionType +
|
||||
", batchBytes=" + this.batchBytes +
|
||||
'}';
|
||||
}
|
||||
|
||||
public enum CompressionType {
|
||||
@@ -133,4 +128,5 @@ public class ProducerMetadata<K,V> {
|
||||
gzip,
|
||||
snappy
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user