From e409124b9f3a7423fe4ab04e7ce3e446244d04e3 Mon Sep 17 00:00:00 2001
From: Alex Rudyy
Date: Fri, 21 Jun 2013 17:06:57 +0000
Subject: QPID-4943: Introduce a feature for 0-8/0-9/0-9-1 protocols to close a
connection on receiving a mandatory unroutable message in a transacted
session
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1495511 13f79535-47bb-0310-9956-ffa450edef68
---
.../java/org/apache/qpid/client/AMQConnection.java | 15 ++++-
.../handler/CloseWhenNoRouteSettingsHelper.java | 74 ++++++++++++++++++++++
.../handler/ConnectionStartMethodHandler.java | 17 ++++-
.../java/org/apache/qpid/jms/ConnectionURL.java | 13 ++++
4 files changed, 114 insertions(+), 5 deletions(-)
create mode 100644 qpid/java/client/src/main/java/org/apache/qpid/client/handler/CloseWhenNoRouteSettingsHelper.java
(limited to 'qpid/java/client/src/main')
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
index 4e885258b9..74c9878a8e 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
@@ -844,7 +844,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
}
}
- public void close() throws JMSException
+ public void close() throws JMSException
{
close(DEFAULT_TIMEOUT);
}
@@ -859,9 +859,12 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
if (!setClosed())
{
setClosing(true);
- try{
+ try
+ {
doClose(sessions, timeout);
- }finally{
+ }
+ finally
+ {
setClosing(false);
}
}
@@ -1594,4 +1597,10 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
{
return _validateQueueOnSend;
}
+
+ @Override
+ protected boolean setClosed()
+ {
+ return super.setClosed();
+ }
}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/handler/CloseWhenNoRouteSettingsHelper.java b/qpid/java/client/src/main/java/org/apache/qpid/client/handler/CloseWhenNoRouteSettingsHelper.java
new file mode 100644
index 0000000000..baae072167
--- /dev/null
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/handler/CloseWhenNoRouteSettingsHelper.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.qpid.client.handler;
+
+import org.apache.qpid.framing.FieldTable;
+import org.apache.qpid.jms.ConnectionURL;
+import org.apache.qpid.properties.ConnectionStartProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Used during connection establishment to optionally set the "close when no route" client property
+ */
+class CloseWhenNoRouteSettingsHelper
+{
+ private static final Logger _log = LoggerFactory.getLogger(CloseWhenNoRouteSettingsHelper.class);
+
+ /**
+ * @param url the client's connection URL which may contain the option
+ * {@value ConnectionStartProperties#QPID_CLOSE_WHEN_NO_ROUTE}
+ * @param serverProperties the properties received from the broker which may contain the option
+ * {@value ConnectionStartProperties#QPID_CLOSE_WHEN_NO_ROUTE}
+ * @param clientProperties the client properties to optionally set the close-when-no-route option on
+ */
+ public void setClientProperties(FieldTable clientProperties, ConnectionURL url, FieldTable serverProperties)
+ {
+ boolean brokerSupportsCloseWhenNoRoute =
+ serverProperties != null && serverProperties.containsKey(ConnectionStartProperties.QPID_CLOSE_WHEN_NO_ROUTE);
+ boolean brokerCloseWhenNoRoute = brokerSupportsCloseWhenNoRoute &&
+ Boolean.parseBoolean(serverProperties.getString(ConnectionStartProperties.QPID_CLOSE_WHEN_NO_ROUTE));
+
+ String closeWhenNoRouteOption = url.getOption(ConnectionURL.OPTIONS_CLOSE_WHEN_NO_ROUTE);
+ if(closeWhenNoRouteOption != null)
+ {
+ if(brokerSupportsCloseWhenNoRoute)
+ {
+ boolean desiredCloseWhenNoRoute = Boolean.valueOf(closeWhenNoRouteOption);
+ if(desiredCloseWhenNoRoute != brokerCloseWhenNoRoute)
+ {
+ clientProperties.setBoolean(ConnectionStartProperties.QPID_CLOSE_WHEN_NO_ROUTE, desiredCloseWhenNoRoute);
+ _log.debug(
+ "Set client property {} to {}",
+ ConnectionStartProperties.QPID_CLOSE_WHEN_NO_ROUTE, desiredCloseWhenNoRoute);
+ }
+ else
+ {
+ _log.debug(
+ "Client's desired {} value {} already matches the server's",
+ ConnectionURL.OPTIONS_CLOSE_WHEN_NO_ROUTE, desiredCloseWhenNoRoute);
+ }
+ }
+ else
+ {
+ _log.warn("The broker being connected to does not support the " + ConnectionURL.OPTIONS_CLOSE_WHEN_NO_ROUTE + " option");
+ }
+ }
+ }
+}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java b/qpid/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java
index 66c4821f60..366b5f115e 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java
@@ -37,6 +37,7 @@ import org.apache.qpid.framing.ConnectionStartOkBody;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.framing.FieldTableFactory;
import org.apache.qpid.framing.ProtocolVersion;
+import org.apache.qpid.jms.ConnectionURL;
import org.apache.qpid.properties.ConnectionStartProperties;
import javax.security.sasl.Sasl;
@@ -51,6 +52,8 @@ public class ConnectionStartMethodHandler implements StateAwareMethodListener
+ * This option is only applicable for 0-8/0-9/0-9-1 protocol connections.
+ *
+ *
+ * It tells the client to request whether the broker should close the
+ * connection when a mandatory message isn't routable, rather than return
+ * the message to the client as it normally would.
+ *
+ */
+ public static final String OPTIONS_CLOSE_WHEN_NO_ROUTE = "closeWhenNoRoute";
+
public static final String OPTIONS_DEFAULT_TOPIC_EXCHANGE = "defaultTopicExchange";
public static final String OPTIONS_DEFAULT_QUEUE_EXCHANGE = "defaultQueueExchange";
public static final String OPTIONS_TEMPORARY_TOPIC_EXCHANGE = "temporaryTopicExchange";
--
cgit v1.2.1