You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by an...@apache.org on 2016/06/22 12:35:04 UTC
[2/3] camel git commit: CAMEL-10024: Renamed latch and null-safety
CAMEL-10024: Renamed latch and null-safety
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4d14c575
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4d14c575
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4d14c575
Branch: refs/heads/master
Commit: 4d14c575057f5f4610605f2cda0254c5e8c71885
Parents: fe41b1b
Author: Arno Noordover <an...@users.noreply.github.com>
Authored: Sat Jun 18 17:11:31 2016 +0200
Committer: Arno Noordover <an...@users.noreply.github.com>
Committed: Sat Jun 18 17:11:31 2016 +0200
----------------------------------------------------------------------
.../camel/component/mina2/Mina2Producer.java | 42 ++++++++------------
.../component/mina2/Mina2TextLineDelimiter.java | 18 ++++++++-
2 files changed, 34 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4d14c575/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Producer.java
----------------------------------------------------------------------
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 4337075..2ac6e92 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
@@ -67,7 +67,8 @@ public class Mina2Producer extends DefaultProducer implements ServicePoolAware {
private static final Logger LOG = LoggerFactory.getLogger(Mina2Producer.class);
private final ResponseHandler handler;
private IoSession session;
- private CountDownLatch latch;
+ private CountDownLatch responseLatch;
+ private CountDownLatch closeLatch;
private boolean lazySessionCreation;
private long timeout;
private SocketAddress address;
@@ -77,7 +78,6 @@ public class Mina2Producer extends DefaultProducer implements ServicePoolAware {
private Mina2Configuration configuration;
private IoSessionConfig connectorConfig;
private ExecutorService workerPool;
- private CountDownLatch closeLatch;
public Mina2Producer(Mina2Endpoint endpoint) throws Exception {
super(endpoint);
@@ -147,8 +147,8 @@ public class Mina2Producer extends DefaultProducer implements ServicePoolAware {
// if sync is true then we should also wait for a response (synchronous mode)
if (sync) {
- // only initialize latch if we should get a response
- latch = new CountDownLatch(1);
+ // only initialize responseLatch if we should get a response
+ responseLatch = new CountDownLatch(1);
// reset handler if we expect a response
handler.reset();
}
@@ -168,7 +168,7 @@ public class Mina2Producer extends DefaultProducer implements ServicePoolAware {
if (sync) {
// wait for response, consider timeout
LOG.debug("Waiting for response using timeout {} millis.", timeout);
- boolean done = latch.await(timeout, TimeUnit.MILLISECONDS);
+ boolean done = responseLatch.await(timeout, TimeUnit.MILLISECONDS);
if (!done) {
throw new ExchangeTimedOutException(exchange, timeout);
}
@@ -421,21 +421,7 @@ public class Mina2Producer extends DefaultProducer implements ServicePoolAware {
if (delimiter == null) {
return LineDelimiter.DEFAULT;
}
-
- switch (delimiter) {
- case DEFAULT:
- return LineDelimiter.DEFAULT;
- case AUTO:
- return LineDelimiter.AUTO;
- case UNIX:
- return LineDelimiter.UNIX;
- case WINDOWS:
- return LineDelimiter.WINDOWS;
- case MAC:
- return LineDelimiter.MAC;
- default:
- throw new IllegalArgumentException("Unknown textline delimiter: " + delimiter);
- }
+ return delimiter.getLineDelimiter();
}
private Charset getEncodingParameter(String type, Mina2Configuration configuration) {
@@ -492,11 +478,11 @@ public class Mina2Producer extends DefaultProducer implements ServicePoolAware {
this.message = message;
messageReceived = true;
cause = null;
- countDown();
+ notifyResultAvailable();
}
- protected void countDown() {
- CountDownLatch downLatch = latch;
+ protected void notifyResultAvailable() {
+ CountDownLatch downLatch = responseLatch;
if (downLatch != null) {
downLatch.countDown();
}
@@ -509,9 +495,15 @@ public class Mina2Producer extends DefaultProducer implements ServicePoolAware {
LOG.debug("Session closed but no message received from address: {}", address);
// session was closed but no message received. This could be because the remote server had an internal error
// and could not return a response. We should count down to stop waiting for a response
- countDown();
+ notifyResultAvailable();
+ }
+ notifySessionClosed();
+ }
+
+ private void notifySessionClosed() {
+ if (closeLatch != null) {
+ closeLatch.countDown();
}
- closeLatch.countDown();
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/4d14c575/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2TextLineDelimiter.java
----------------------------------------------------------------------
diff --git a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2TextLineDelimiter.java b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2TextLineDelimiter.java
index 8bf87c7..bc83a7e 100644
--- a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2TextLineDelimiter.java
+++ b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2TextLineDelimiter.java
@@ -16,10 +16,26 @@
*/
package org.apache.camel.component.mina2;
+import org.apache.mina.filter.codec.textline.LineDelimiter;
+
/**
* Possible text line delimiters to be used with the textline codec.
*/
public enum Mina2TextLineDelimiter {
- DEFAULT, AUTO, UNIX, WINDOWS, MAC
+ DEFAULT(LineDelimiter.DEFAULT),
+ AUTO(LineDelimiter.AUTO),
+ UNIX(LineDelimiter.UNIX),
+ WINDOWS(LineDelimiter.WINDOWS),
+ MAC(LineDelimiter.MAC);
+
+ private final LineDelimiter lineDelimiter;
+
+ Mina2TextLineDelimiter(LineDelimiter lineDelimiter) {
+ this.lineDelimiter = lineDelimiter;
+ }
+
+ public LineDelimiter getLineDelimiter() {
+ return lineDelimiter;
+ }
}