From 3c3f4f03d3b04102c6fbab88e713136bd444a186 Mon Sep 17 00:00:00 2001 From: Rob Shield Date: Sun, 1 Dec 2013 13:30:44 +0000 Subject: [PATCH] CAMEL-6934 enabling dns addresses to not get cached --- .../camel/component/mina2/Mina2Configuration.java | 15 ++++++++++++++- .../camel/component/mina2/Mina2Producer.java | 13 +++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Configuration.java b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Configuration.java index 245de3cdddadb..2e0b2e384b573 100644 --- a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Configuration.java +++ b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Configuration.java @@ -53,6 +53,7 @@ public class Mina2Configuration implements Cloneable { private boolean autoStartTls = true; private int maximumPoolSize = 16; // 16 is the default mina setting private boolean orderedThreadPoolExecutor = true; + private boolean cachedAddress = true; /** * Returns a copy of this configuration @@ -263,7 +264,19 @@ public boolean isOrderedThreadPoolExecutor() { public void setOrderedThreadPoolExecutor(boolean orderedThreadPoolExecutor) { this.orderedThreadPoolExecutor = orderedThreadPoolExecutor; } - + + public void setCachedAddress(boolean shouldCacheAddress){ + this.cachedAddress = shouldCacheAddress; + } + + public boolean getCachedAddress(){ + return this.cachedAddress; + } + + public boolean isCachedAddress(){ + return this.getCachedAddress(); + } + // here we just shows the option setting of host, port, protocol public String getUriString() { return "mina2:" + getProtocol() + ":" + getHost() + ":" + getPort(); diff --git a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Producer.java b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Producer.java index ba41f1870bee4..fc7c493eb0cfb 100644 --- a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Producer.java +++ b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Producer.java @@ -251,6 +251,9 @@ private void closeConnection() { } private void openConnection() { + if(this.address == null || !this.configuration.isCachedAddress()){ + setSocketAddress(this.configuration.getProtocol()); + } if (LOG.isDebugEnabled()) { LOG.debug("Creating connector to address: {} using connector: {} timeout: {} millis.", new Object[]{address, connector, timeout}); } @@ -447,6 +450,16 @@ private void appendIoFiltersToChain(List filters, DefaultIoFilterChain } } + private void setSocketAddress(String protocol){ + if(protocol.equals("tcp")){ + this.address = new InetSocketAddress(configuration.getHost(), configuration.getPort()); + }else if(configuration.isDatagramProtocol()){ + this.address = new InetSocketAddress(configuration.getHost(), configuration.getPort()); + }else if(protocol.equals("vm")){ + this.address = new VmPipeAddress(configuration.getPort()); + } + } + /** * Handles response from session writes */