You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/07/19 07:51:18 UTC
[camel] 02/02: CAMEL-12664 - Fixed CS
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 75862f30b7c982fa7e446c32f41c54ab04190655
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Jul 19 09:50:35 2018 +0200
CAMEL-12664 - Fixed CS
---
.../camel/component/nats/NatsConfiguration.java | 60 +++++++++++-----------
.../apache/camel/component/nats/NatsConsumer.java | 24 ++++-----
2 files changed, 43 insertions(+), 41 deletions(-)
diff --git a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
index 5959a76..4f1eb53 100644
--- a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
+++ b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
@@ -19,15 +19,15 @@ package org.apache.camel.component.nats;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;
+import io.nats.client.Options;
+import io.nats.client.Options.Builder;
+
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
import org.apache.camel.spi.UriPath;
import org.apache.camel.util.jsse.SSLContextParameters;
-import io.nats.client.Options;
-import io.nats.client.Options.Builder;
-
@UriParams
public class NatsConfiguration {
@@ -69,7 +69,8 @@ public class NatsConfiguration {
private SSLContextParameters sslContextParameters;
/**
- * URLs to one or more NAT servers. Use comma to separate URLs when specifying multiple servers.
+ * URLs to one or more NAT servers. Use comma to separate URLs when
+ * specifying multiple servers.
*/
public String getServers() {
return servers;
@@ -155,7 +156,6 @@ public class NatsConfiguration {
public void setPingInterval(int pingInterval) {
this.pingInterval = pingInterval;
}
-
/**
* the subject to which subscribers should send response
@@ -169,7 +169,8 @@ public class NatsConfiguration {
}
/**
- * Whether or not randomizing the order of servers for the connection attempts
+ * Whether or not randomizing the order of servers for the connection
+ * attempts
*/
public boolean getNoRandomizeServers() {
return noRandomizeServers;
@@ -191,7 +192,8 @@ public class NatsConfiguration {
}
/**
- * Stop receiving messages from a topic we are subscribing to after maxMessages
+ * Stop receiving messages from a topic we are subscribing to after
+ * maxMessages
*/
public String getMaxMessages() {
return maxMessages;
@@ -257,28 +259,28 @@ public class NatsConfiguration {
}
public Builder createOptions() throws NoSuchAlgorithmException, IllegalArgumentException {
- Builder builder = new Options.Builder();
- builder.server(splitServers());
- if (getVerbose()) {
- builder.verbose();
- }
- if (getPedantic()) {
- builder.pedantic();
- }
- if (isSecure()) {
- builder.secure();
- }
- if (!getReconnect()) {
- builder.noReconnect();
- } else {
- builder.maxReconnects(getMaxReconnectAttempts());
- builder.reconnectWait(Duration.ofMillis(getReconnectTimeWait()));
- }
- builder.pingInterval(Duration.ofMillis(getPingInterval()));
- if (getNoRandomizeServers()) {
- builder.noRandomize();
- }
- return builder;
+ Builder builder = new Options.Builder();
+ builder.server(splitServers());
+ if (getVerbose()) {
+ builder.verbose();
+ }
+ if (getPedantic()) {
+ builder.pedantic();
+ }
+ if (isSecure()) {
+ builder.secure();
+ }
+ if (!getReconnect()) {
+ builder.noReconnect();
+ } else {
+ builder.maxReconnects(getMaxReconnectAttempts());
+ builder.reconnectWait(Duration.ofMillis(getReconnectTimeWait()));
+ }
+ builder.pingInterval(Duration.ofMillis(getPingInterval()));
+ if (getNoRandomizeServers()) {
+ builder.noRandomize();
+ }
+ return builder;
}
private String splitServers() {
diff --git a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConsumer.java b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConsumer.java
index 529c6f9..9bcc8c4 100644
--- a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConsumer.java
+++ b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConsumer.java
@@ -56,7 +56,7 @@ public class NatsConsumer extends DefaultConsumer {
@Override
public NatsEndpoint getEndpoint() {
- return (NatsEndpoint) super.getEndpoint();
+ return (NatsEndpoint)super.getEndpoint();
}
@Override
@@ -79,7 +79,7 @@ public class NatsConsumer extends DefaultConsumer {
LOG.debug("Flushing Messages before stopping");
connection.flush(Duration.ofMillis(getEndpoint().getNatsConfiguration().getFlushTimeout()));
}
-
+
try {
dispatcher.unsubscribe(getEndpoint().getNatsConfiguration().getTopic());
} catch (Exception e) {
@@ -95,17 +95,17 @@ public class NatsConsumer extends DefaultConsumer {
}
}
executor = null;
-
+
LOG.debug("Closing Nats Connection");
if (!connection.getStatus().equals(Status.CLOSED)) {
- connection.close();
+ connection.close();
}
}
private Connection getConnection() throws InterruptedException, IllegalArgumentException, GeneralSecurityException, IOException {
Builder builder = getEndpoint().getNatsConfiguration().createOptions();
if (getEndpoint().getNatsConfiguration().getSslContextParameters() != null && getEndpoint().getNatsConfiguration().isSecure()) {
- SSLContext sslCtx = getEndpoint().getNatsConfiguration().getSslContextParameters().createSSLContext(getEndpoint().getCamelContext());
+ SSLContext sslCtx = getEndpoint().getNatsConfiguration().getSslContextParameters().createSSLContext(getEndpoint().getCamelContext());
builder.sslContext(sslCtx);
}
Options options = builder.build();
@@ -135,7 +135,7 @@ public class NatsConsumer extends DefaultConsumer {
public void run() {
try {
if (ObjectHelper.isNotEmpty(configuration.getQueueName())) {
- dispatcher = connection.createDispatcher(new MessageHandler() {
+ dispatcher = connection.createDispatcher(new MessageHandler() {
@Override
public void onMessage(Message msg) {
LOG.debug("Received Message: {}", msg);
@@ -149,15 +149,15 @@ public class NatsConsumer extends DefaultConsumer {
}
}
});
- dispatcher = dispatcher.subscribe(getEndpoint().getNatsConfiguration().getTopic(), getEndpoint().getNatsConfiguration().getQueueName());
+ dispatcher = dispatcher.subscribe(getEndpoint().getNatsConfiguration().getTopic(), getEndpoint().getNatsConfiguration().getQueueName());
if (ObjectHelper.isNotEmpty(getEndpoint().getNatsConfiguration().getMaxMessages())) {
dispatcher.unsubscribe(getEndpoint().getNatsConfiguration().getTopic(), Integer.parseInt(getEndpoint().getNatsConfiguration().getMaxMessages()));
}
- if (dispatcher.isActive()) {
- setActive(true);
+ if (dispatcher.isActive()) {
+ setActive(true);
}
} else {
- dispatcher = connection.createDispatcher(new MessageHandler() {
+ dispatcher = connection.createDispatcher(new MessageHandler() {
@Override
public void onMessage(Message msg) {
LOG.debug("Received Message: {}", msg);
@@ -171,12 +171,12 @@ public class NatsConsumer extends DefaultConsumer {
}
}
});
- dispatcher = dispatcher.subscribe(getEndpoint().getNatsConfiguration().getTopic());
+ dispatcher = dispatcher.subscribe(getEndpoint().getNatsConfiguration().getTopic());
if (ObjectHelper.isNotEmpty(getEndpoint().getNatsConfiguration().getMaxMessages())) {
dispatcher.unsubscribe(getEndpoint().getNatsConfiguration().getTopic(), Integer.parseInt(getEndpoint().getNatsConfiguration().getMaxMessages()));
}
if (dispatcher.isActive()) {
- setActive(true);
+ setActive(true);
}
}
} catch (Throwable e) {