You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/04/28 08:07:44 UTC
[4/5] camel git commit: Component docs
Component docs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/aff019f0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/aff019f0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/aff019f0
Branch: refs/heads/master
Commit: aff019f0a7c8d708ecf856035f741b279257153e
Parents: 7f28a1e
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 28 07:58:26 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 28 07:59:38 2015 +0200
----------------------------------------------------------------------
.../apache/camel/component/redis/Command.java | 2 +-
.../component/redis/CommandDispatcher.java | 12 +++---
.../component/redis/RedisConfiguration.java | 41 ++++++++++++++++----
.../camel/component/redis/RedisConsumer.java | 15 +++----
.../camel/component/redis/RedisEndpoint.java | 4 +-
5 files changed, 50 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/aff019f0/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/Command.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/Command.java b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/Command.java
index 71e4a53..5aa6d25 100755
--- a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/Command.java
+++ b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/Command.java
@@ -31,5 +31,5 @@ public enum Command {
ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE,
BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN,
SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT,
- GETBIT, SETRANGE, GETRANGE, PEXPIRE, PEXPIREAT;
+ GETBIT, SETRANGE, GETRANGE, PEXPIRE, PEXPIREAT
}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff019f0/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/CommandDispatcher.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/CommandDispatcher.java b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/CommandDispatcher.java
index ee3a22d..79daceb 100755
--- a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/CommandDispatcher.java
+++ b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/CommandDispatcher.java
@@ -34,10 +34,10 @@ public class CommandDispatcher {
this.exchange = exchange;
}
- // TODO: This method is longer than maximally allowed 200 lines
// CHECKSTYLE:OFF
public void execute(final RedisClient redisClient) {
- switch (determineCommand()) {
+ final Command command = determineCommand();
+ switch (command) {
case PING:
setResult(redisClient.ping());
@@ -337,20 +337,20 @@ public class CommandDispatcher {
setResult(redisClient.getrange(getKey(), getStart(), getEnd()));
break;
default:
- throw new RuntimeExchangeException("Unsupported command", exchange);
+ throw new RuntimeExchangeException("Unsupported command: " + command, exchange);
}
}
// CHECKSTYLE:ON
private Command determineCommand() {
- String command = exchange.getIn().getHeader(RedisConstants.COMMAND, String.class);
+ Command command = exchange.getIn().getHeader(RedisConstants.COMMAND, Command.class);
if (command == null) {
command = configuration.getCommand();
}
if (command == null) {
- return Command.SET;
+ command = Command.SET;
}
- return Command.valueOf(command);
+ return command;
}
private static <T> T getInHeaderValue(Exchange exchange, String key, Class<T> aClass) {
http://git-wip-us.apache.org/repos/asf/camel/blob/aff019f0/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisConfiguration.java b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisConfiguration.java
index 0c48845..9369e33 100755
--- a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisConfiguration.java
+++ b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisConfiguration.java
@@ -29,12 +29,15 @@ import org.springframework.data.redis.serializer.RedisSerializer;
@UriParams
public class RedisConfiguration {
+ private boolean managedListenerContainer;
+ private boolean managedConnectionFactory;
+
@UriPath @Metadata(required = "true")
private String host;
@UriPath @Metadata(required = "true")
private Integer port;
- @UriParam
- private String command;
+ @UriParam(defaultValue = "SET")
+ private Command command = Command.SET;
@UriParam
private String channels;
@UriParam
@@ -45,16 +48,17 @@ public class RedisConfiguration {
private RedisConnectionFactory connectionFactory;
@UriParam
private RedisSerializer serializer;
- @UriParam
- private boolean managedListenerContainer;
- @UriParam
- private boolean managedConnectionFactory;
- public String getCommand() {
+ public Command getCommand() {
return command;
}
- public void setCommand(String command) {
+ /**
+ * Default command, which can be overridden by message header.
+ * <p/>
+ * Notice the consumer only supports the following commands: PSUBSCRIBE and SUBSCRIBE
+ */
+ public void setCommand(Command command) {
this.command = command;
}
@@ -62,6 +66,9 @@ public class RedisConfiguration {
return port;
}
+ /**
+ * Redis server port number
+ */
public void setPort(Integer port) {
this.port = port;
}
@@ -70,6 +77,9 @@ public class RedisConfiguration {
return host;
}
+ /**
+ * The host where Redis server is running.
+ */
public void setHost(String host) {
this.host = host;
}
@@ -78,6 +88,9 @@ public class RedisConfiguration {
return redisTemplate != null ? redisTemplate : createDefaultTemplate();
}
+ /**
+ * Reference to a pre-configured RedisTemplate instance to use.
+ */
public void setRedisTemplate(RedisTemplate redisTemplate) {
this.redisTemplate = redisTemplate;
}
@@ -86,6 +99,9 @@ public class RedisConfiguration {
return listenerContainer != null ? listenerContainer : createDefaultListenerContainer();
}
+ /**
+ * Reference to a pre-configured RedisMessageListenerContainer instance to use.
+ */
public void setListenerContainer(RedisMessageListenerContainer listenerContainer) {
this.listenerContainer = listenerContainer;
}
@@ -94,10 +110,16 @@ public class RedisConfiguration {
return channels;
}
+ /**
+ * List of topic names or name patterns to subscribe to. Multiple names can be separated by comma.
+ */
public void setChannels(String channels) {
this.channels = channels;
}
+ /**
+ * Reference to a pre-configured RedisConnectionFactory instance to use.
+ */
public void setConnectionFactory(RedisConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}
@@ -110,6 +132,9 @@ public class RedisConfiguration {
return serializer != null ? serializer : createDefaultSerializer();
}
+ /**
+ * Reference to a pre-configured RedisSerializer instance to use.
+ */
public void setSerializer(RedisSerializer serializer) {
this.serializer = serializer;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff019f0/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisConsumer.java b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisConsumer.java
index 4afdc5a..84d2338 100755
--- a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisConsumer.java
+++ b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisConsumer.java
@@ -23,14 +23,14 @@ import java.util.List;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
-import org.apache.camel.component.direct.DirectConsumer;
+import org.apache.camel.impl.DefaultConsumer;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.Topic;
-public class RedisConsumer extends DirectConsumer implements MessageListener {
+public class RedisConsumer extends DefaultConsumer implements MessageListener {
private final RedisConfiguration redisConfiguration;
public RedisConsumer(RedisEndpoint redisEndpoint, Processor processor,
@@ -50,12 +50,13 @@ public class RedisConsumer extends DirectConsumer implements MessageListener {
String[] channelsArrays = channels.split(",");
List<Topic> topics = new ArrayList<Topic>();
for (String channel : channelsArrays) {
- if (Command.PSUBSCRIBE.toString().equals(redisConfiguration.getCommand())) {
- topics.add(new PatternTopic(channel));
- } else if (Command.SUBSCRIBE.toString().equals(redisConfiguration.getCommand())) {
- topics.add(new ChannelTopic(channel));
+ String name = channel.trim();
+ if (Command.PSUBSCRIBE.equals(redisConfiguration.getCommand())) {
+ topics.add(new PatternTopic(name));
+ } else if (Command.SUBSCRIBE.equals(redisConfiguration.getCommand())) {
+ topics.add(new ChannelTopic(name));
} else {
- throw new RuntimeException("Unsupported Command");
+ throw new IllegalArgumentException("Unsupported Command " + redisConfiguration.getCommand());
}
}
return topics;
http://git-wip-us.apache.org/repos/asf/camel/blob/aff019f0/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisEndpoint.java b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisEndpoint.java
index d790f7e..2952dd6 100755
--- a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisEndpoint.java
+++ b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisEndpoint.java
@@ -19,7 +19,7 @@ package org.apache.camel.component.redis;
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
-import org.apache.camel.component.direct.DirectEndpoint;
+import org.apache.camel.impl.DefaultEndpoint;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
@@ -27,7 +27,7 @@ import org.apache.camel.spi.UriParam;
* Represents a Redis endpoint.
*/
@UriEndpoint(scheme = "spring-redis", title = "Spring Redis", syntax = "spring-redist:host:port", consumerClass = RedisConsumer.class, label = "spring,nosql")
-public class RedisEndpoint extends DirectEndpoint {
+public class RedisEndpoint extends DefaultEndpoint {
@UriParam
private RedisConfiguration configuration;