Skip to content

Simplify logic in RedisMessageListenerContainer and supporting classes #2663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-GH-2662-SNAPSHOT</version>

<name>Spring Data Redis</name>
<description>Spring Data module for Redis</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2017-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.listener;

import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;

/**
* Abstract base class for defining {@link Topic Topics}.
*
* @author John Blum
* @see org.springframework.data.redis.listener.Topic
* @since 3.2.0
*/
abstract class AbstractTopic implements Topic {

private final String name;

AbstractTopic(String label, String name) {
Assert.notNull(name,() -> label + " must not be null");
this.name = name;
}

@Override
public String getTopic() {
return this.name;
}

@Override
public boolean equals(@Nullable Object obj) {

if (this == obj) {
return true;
}

if (!(obj instanceof AbstractTopic that)) {
return false;
}

// Must be exact Topic type
if (this.getClass() != that.getClass()) {
return false;
}

return ObjectUtils.nullSafeEquals(this.getTopic(), that.getTopic());
}

@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(getTopic());
}

@Override
public String toString() {
return getTopic();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,71 +15,32 @@
*/
package org.springframework.data.redis.listener;

import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;

/**
* Channel topic implementation (maps to a Redis channel).
* {@link Topic Channel Topic} implementation mapping to a Redis channel.
*
* @author Costin Leau
* @author Mark Paluch
* @author John Blum
*/
public class ChannelTopic implements Topic {

private final String channelName;

/**
* Constructs a new {@link ChannelTopic} instance.
*
* @param name must not be {@literal null}.
*/
public ChannelTopic(String name) {

Assert.notNull(name, "Topic name must not be null");

this.channelName = name;
}
public class ChannelTopic extends AbstractTopic {

/**
* Create a new {@link ChannelTopic} for channel subscriptions.
*
* @param name the channel name, must not be {@literal null} or empty.
* @return the {@link ChannelTopic} for {@code channelName}.
* @param channelName {@link String name} of the Redis channel; must not be {@literal null} or {@literal empty}.
* @return the {@link ChannelTopic} for the given {@code channelName}.
* @since 2.1
*/
public static ChannelTopic of(String name) {
return new ChannelTopic(name);
public static ChannelTopic of(String channelName) {
return new ChannelTopic(channelName);
}

/**
* @return topic name.
* Constructs a new {@link ChannelTopic} instance.
*
* @param channelName must not be {@literal null}.
*/
@Override
public String getTopic() {
return channelName;
}

@Override
public String toString() {
return channelName;
}

@Override
public boolean equals(@Nullable Object o) {

if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

ChannelTopic that = (ChannelTopic) o;

return ObjectUtils.nullSafeEquals(channelName, that.channelName);
}

@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(channelName);
public ChannelTopic(String channelName) {
super("Topic name", channelName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,72 +15,32 @@
*/
package org.springframework.data.redis.listener;

import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;

/**
* Pattern topic (matching multiple channels).
* {@link Topic} {@link String pattern} matching multiple Redis channels.
*
* @author Costin Leau
* @author Mark Paluch
* @author Christoph Strobl
*/
public class PatternTopic implements Topic {

private final String channelPattern;

/**
* Constructs a new {@link PatternTopic} instance.
*
* @param pattern must not be {@literal null}.
*/
public PatternTopic(String pattern) {

Assert.notNull(pattern, "Pattern must not be null");

this.channelPattern = pattern;
}
public class PatternTopic extends AbstractTopic {

/**
* Create a new {@link PatternTopic} for channel subscriptions based on a {@code pattern}.
*
* @param pattern the channel pattern, must not be {@literal null} or empty.
* @return the {@link PatternTopic} for {@code pattern}.
* @param pattern {@link String pattern} used to match channels; must not be {@literal null} or {@literal empty}.
* @return the {@link PatternTopic} for the given {@code pattern}.
* @since 2.1
*/
public static PatternTopic of(String pattern) {
return new PatternTopic(pattern);
}

/**
* @return channel pattern.
* Constructs a new {@link PatternTopic} instance.
*
* @param channelPattern must not be {@literal null}.
*/
@Override
public String getTopic() {
return channelPattern;
}

@Override
public String toString() {
return channelPattern;
}

@Override
public boolean equals(@Nullable Object o) {

if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

PatternTopic that = (PatternTopic) o;

return ObjectUtils.nullSafeEquals(channelPattern, that.channelPattern);
}

@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(channelPattern);
public PatternTopic(String channelPattern) {
super("Pattern", channelPattern);
}
}
Loading