summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java95
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java128
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java60
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java261
-rw-r--r--java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java53
-rw-r--r--java/common/src/main/java/org/apache/qpid/url/URLHelper.java44
6 files changed, 305 insertions, 336 deletions
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java
index b112979a9a..e76cd55024 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java
@@ -1,5 +1,25 @@
/*
*
+ * 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.
+ *
+ */
+/*
+ *
* Copyright (c) 2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,15 +37,15 @@
*/
package org.apache.qpid.server.protocol;
+import java.security.Principal;
import java.util.Date;
import java.util.List;
-import java.security.Principal;
import javax.management.JMException;
import javax.management.MBeanException;
import javax.management.MBeanNotificationInfo;
-import javax.management.Notification;
import javax.management.NotCompliantMBeanException;
+import javax.management.Notification;
import javax.management.monitor.MonitorNotification;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
@@ -57,15 +77,17 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed
{
private AMQMinaProtocolSession _session = null;
private String _name = null;
-
- //openmbean data types for representing the channel attributes
- private final static String[] _channelAtttibuteNames = {"Channel Id", "Transactional", "Default Queue", "Unacknowledged Message Count"};
- private final static String[] _indexNames = {_channelAtttibuteNames[0]};
- private final static OpenType[] _channelAttributeTypes = {SimpleType.INTEGER, SimpleType.BOOLEAN, SimpleType.STRING, SimpleType.INTEGER};
- private static CompositeType _channelType = null; // represents the data type for channel data
- private static TabularType _channelsType = null; // Data type for list of channels type
+
+ // openmbean data types for representing the channel attributes
+ private static final String[] _channelAtttibuteNames =
+ { "Channel Id", "Transactional", "Default Queue", "Unacknowledged Message Count" };
+ private static final String[] _indexNames = { _channelAtttibuteNames[0] };
+ private static final OpenType[] _channelAttributeTypes =
+ { SimpleType.INTEGER, SimpleType.BOOLEAN, SimpleType.STRING, SimpleType.INTEGER };
+ private static CompositeType _channelType = null; // represents the data type for channel data
+ private static TabularType _channelsType = null; // Data type for list of channels type
private static final AMQShortString BROKER_MANAGEMENT_CONSOLE_HAS_CLOSED_THE_CONNECTION =
- new AMQShortString("Broker Management Console has closed the connection.");
+ new AMQShortString("Broker Management Console has closed the connection.");
@MBeanConstructor("Creates an MBean exposing an AMQ Broker Connection")
public AMQProtocolSessionMBean(AMQMinaProtocolSession session) throws NotCompliantMBeanException, OpenDataException
@@ -73,22 +95,21 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed
super(ManagedConnection.class, ManagedConnection.TYPE);
_session = session;
String remote = getRemoteAddress();
- remote = "anonymous".equals(remote) ? remote + hashCode() : remote;
+ remote = "anonymous".equals(remote) ? (remote + hashCode()) : remote;
_name = jmxEncode(new StringBuffer(remote), 0).toString();
init();
}
-
static
{
try
{
init();
}
- catch(JMException ex)
+ catch (JMException ex)
{
- // It should never occur
- System.out.println(ex.getMessage());
+ // This is not expected to ever occur.
+ throw new RuntimeException("Got JMException in static initializer.", ex);
}
}
@@ -97,14 +118,15 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed
*/
private static void init() throws OpenDataException
{
- _channelType = new CompositeType("Channel", "Channel Details", _channelAtttibuteNames,
- _channelAtttibuteNames, _channelAttributeTypes);
+ _channelType =
+ new CompositeType("Channel", "Channel Details", _channelAtttibuteNames, _channelAtttibuteNames,
+ _channelAttributeTypes);
_channelsType = new TabularType("Channels", "Channels", _channelType, _indexNames);
}
public String getClientId()
{
- return _session.getContextKey() == null ? null : _session.getContextKey().toString();
+ return (_session.getContextKey() == null) ? null : _session.getContextKey().toString();
}
public Principal getAuthorizedId()
@@ -114,9 +136,9 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed
public String getVersion()
{
- return _session.getClientVersion() == null ? null : _session.getClientVersion().toString();
+ return (_session.getClientVersion() == null) ? null : _session.getClientVersion().toString();
}
-
+
public Date getLastIoTime()
{
return new Date(_session.getIOSession().getLastIoTime());
@@ -172,6 +194,7 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed
{
throw new JMException("The channel (channel Id = " + channelId + ") does not exist");
}
+
_session.commitTransactions(channel);
}
catch (AMQException ex)
@@ -195,6 +218,7 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed
{
throw new JMException("The channel (channel Id = " + channelId + ") does not exist");
}
+
_session.rollbackTransactions(channel);
}
catch (AMQException ex)
@@ -216,9 +240,12 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed
for (AMQChannel channel : list)
{
- Object[] itemValues = {channel.getChannelId(), channel.isTransactional(),
+ Object[] itemValues =
+ {
+ channel.getChannelId(), channel.isTransactional(),
(channel.getDefaultQueue() != null) ? channel.getDefaultQueue().getName().asString() : null,
- channel.getUnacknowledgedMessageMap().size()};
+ channel.getUnacknowledgedMessageMap().size()
+ };
CompositeData channelData = new CompositeDataSupport(_channelType, _channelAtttibuteNames, itemValues);
channelsList.put(channelData);
@@ -233,17 +260,16 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed
* @throws JMException
*/
public void closeConnection() throws JMException
- {
+ {
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
// Be aware of possible changes to parameter order as versions change.
- final AMQFrame response = ConnectionCloseBody.createAMQFrame(0,
- _session.getProtocolMajorVersion(),
- _session.getProtocolMinorVersion(), // AMQP version (major, minor)
- 0, // classId
- 0, // methodId
- AMQConstant.REPLY_SUCCESS.getCode(), // replyCode
- BROKER_MANAGEMENT_CONSOLE_HAS_CLOSED_THE_CONNECTION // replyText
+ final AMQFrame response =
+ ConnectionCloseBody.createAMQFrame(0, _session.getProtocolMajorVersion(), _session.getProtocolMinorVersion(), // AMQP version (major, minor)
+ 0, // classId
+ 0, // methodId
+ AMQConstant.REPLY_SUCCESS.getCode(), // replyCode
+ BROKER_MANAGEMENT_CONSOLE_HAS_CLOSED_THE_CONNECTION // replyText
);
_session.writeFrame(response);
@@ -260,18 +286,19 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed
@Override
public MBeanNotificationInfo[] getNotificationInfo()
{
- String[] notificationTypes = new String[]{MonitorNotification.THRESHOLD_VALUE_EXCEEDED};
+ String[] notificationTypes = new String[] { MonitorNotification.THRESHOLD_VALUE_EXCEEDED };
String name = MonitorNotification.class.getName();
String description = "Channel count has reached threshold value";
MBeanNotificationInfo info1 = new MBeanNotificationInfo(notificationTypes, name, description);
- return new MBeanNotificationInfo[]{info1};
+ return new MBeanNotificationInfo[] { info1 };
}
public void notifyClients(String notificationMsg)
{
- Notification n = new Notification(MonitorNotification.THRESHOLD_VALUE_EXCEEDED, this,
- ++_notificationSequenceNumber, System.currentTimeMillis(), notificationMsg);
+ Notification n =
+ new Notification(MonitorNotification.THRESHOLD_VALUE_EXCEEDED, this, ++_notificationSequenceNumber,
+ System.currentTimeMillis(), notificationMsg);
_broadcaster.sendNotification(n);
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java
index e7e7f5c22f..bbaa7379f6 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueMBean.java
@@ -1,5 +1,25 @@
/*
*
+ * 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.
+ *
+ */
+/*
+ *
* Copyright (c) 2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,11 +37,11 @@
*/
package org.apache.qpid.server.queue;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
-import java.util.Date;
-import java.text.SimpleDateFormat;
import javax.management.JMException;
import javax.management.MBeanException;
@@ -41,12 +61,14 @@ import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType;
import org.apache.log4j.Logger;
+
import org.apache.mina.common.ByteBuffer;
+
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.CommonContentHeaderProperties;
-import org.apache.qpid.framing.ContentHeaderBody;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.BasicContentHeaderProperties;
+import org.apache.qpid.framing.CommonContentHeaderProperties;
+import org.apache.qpid.framing.ContentHeaderBody;
import org.apache.qpid.framing.abstraction.ContentChunk;
import org.apache.qpid.server.management.AMQManagedObject;
import org.apache.qpid.server.management.MBeanConstructor;
@@ -73,15 +95,15 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
private AMQQueue _queue = null;
private String _queueName = null;
// OpenMBean data types for viewMessages method
- private final static String[] _msgAttributeNames = {"AMQ MessageId", "Header", "Size(bytes)", "Redelivered"};
- private static String[] _msgAttributeIndex = {_msgAttributeNames[0]};
+ private static final String[] _msgAttributeNames = { "AMQ MessageId", "Header", "Size(bytes)", "Redelivered" };
+ private static String[] _msgAttributeIndex = { _msgAttributeNames[0] };
private static OpenType[] _msgAttributeTypes = new OpenType[4]; // AMQ message attribute types.
- private static CompositeType _messageDataType = null; // Composite type for representing AMQ Message data.
- private static TabularType _messagelistDataType = null; // Datatype for representing AMQ messages list.
+ private static CompositeType _messageDataType = null; // Composite type for representing AMQ Message data.
+ private static TabularType _messagelistDataType = null; // Datatype for representing AMQ messages list.
// OpenMBean data types for viewMessageContent method
private static CompositeType _msgContentType = null;
- private final static String[] _msgContentAttributes = {"AMQ MessageId", "MimeType", "Encoding", "Content"};
+ private static final String[] _msgContentAttributes = { "AMQ MessageId", "MimeType", "Encoding", "Content" };
private static OpenType[] _msgContentAttributeTypes = new OpenType[4];
private final long[] _lastNotificationTimes = new long[NotificationCheck.values().length];
@@ -95,7 +117,6 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
_queueName = jmxEncode(new StringBuffer(queue.getName()), 0).toString();
}
-
public ManagedObject getParentObject()
{
return _queue.getVirtualHost().getManagedObject();
@@ -107,10 +128,10 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
{
init();
}
- catch(JMException ex)
+ catch (JMException ex)
{
- // It should never occur
- System.out.println(ex.getMessage());
+ // This is not expected to ever occur.
+ throw new RuntimeException("Got JMException in static initializer.", ex);
}
}
@@ -119,19 +140,21 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
*/
private static void init() throws OpenDataException
{
- _msgContentAttributeTypes[0] = SimpleType.LONG; // For message id
- _msgContentAttributeTypes[1] = SimpleType.STRING; // For MimeType
- _msgContentAttributeTypes[2] = SimpleType.STRING; // For Encoding
- _msgContentAttributeTypes[3] = new ArrayType(1, SimpleType.BYTE); // For message content
- _msgContentType = new CompositeType("Message Content", "AMQ Message Content", _msgContentAttributes,
- _msgContentAttributes, _msgContentAttributeTypes);
-
- _msgAttributeTypes[0] = SimpleType.LONG; // For message id
- _msgAttributeTypes[1] = new ArrayType(1, SimpleType.STRING); // For header attributes
- _msgAttributeTypes[2] = SimpleType.LONG; // For size
- _msgAttributeTypes[3] = SimpleType.BOOLEAN; // For redelivered
-
- _messageDataType = new CompositeType("Message", "AMQ Message", _msgAttributeNames, _msgAttributeNames, _msgAttributeTypes);
+ _msgContentAttributeTypes[0] = SimpleType.LONG; // For message id
+ _msgContentAttributeTypes[1] = SimpleType.STRING; // For MimeType
+ _msgContentAttributeTypes[2] = SimpleType.STRING; // For Encoding
+ _msgContentAttributeTypes[3] = new ArrayType(1, SimpleType.BYTE); // For message content
+ _msgContentType =
+ new CompositeType("Message Content", "AMQ Message Content", _msgContentAttributes, _msgContentAttributes,
+ _msgContentAttributeTypes);
+
+ _msgAttributeTypes[0] = SimpleType.LONG; // For message id
+ _msgAttributeTypes[1] = new ArrayType(1, SimpleType.STRING); // For header attributes
+ _msgAttributeTypes[2] = SimpleType.LONG; // For size
+ _msgAttributeTypes[3] = SimpleType.BOOLEAN; // For redelivered
+
+ _messageDataType =
+ new CompositeType("Message", "AMQ Message", _msgAttributeNames, _msgAttributeNames, _msgAttributeTypes);
_messagelistDataType = new TabularType("Messages", "List of messages", _messageDataType, _msgAttributeIndex);
}
@@ -213,7 +236,8 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
public Long getMaximumQueueDepth()
{
long queueDepthInBytes = _queue.getMaximumQueueDepth();
- return queueDepthInBytes >> 10 ;
+
+ return queueDepthInBytes >> 10;
}
public void setMaximumQueueDepth(Long value)
@@ -227,7 +251,8 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
public Long getQueueDepth() throws JMException
{
long queueBytesSize = _queue.getQueueDepth();
- return queueBytesSize >> 10 ;
+
+ return queueBytesSize >> 10;
}
/**
@@ -237,13 +262,13 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
{
final long currentTime = System.currentTimeMillis();
- final long thresholdTime = currentTime - _queue.getMinimumAlertRepeatGap();
+ final long thresholdTime = currentTime - _queue.getMinimumAlertRepeatGap();
- for(NotificationCheck check : NotificationCheck.values())
+ for (NotificationCheck check : NotificationCheck.values())
{
- if(check.isMessageSpecific() || _lastNotificationTimes[check.ordinal()]<thresholdTime)
+ if (check.isMessageSpecific() || (_lastNotificationTimes[check.ordinal()] < thresholdTime))
{
- if(check.notifyIfNecessary(msg, _queue, this))
+ if (check.notifyIfNecessary(msg, _queue, this))
{
_lastNotificationTimes[check.ordinal()] = currentTime;
}
@@ -260,9 +285,10 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
// important : add log to the log file - monitoring tools may be looking for this
_logger.info(notification.name() + " On Queue " + queue.getName() + " - " + notificationMsg);
notificationMsg = notification.name() + " " + notificationMsg;
-
- _lastNotification = new Notification(MonitorNotification.THRESHOLD_VALUE_EXCEEDED, this,
- ++_notificationSequenceNumber, System.currentTimeMillis(), notificationMsg);
+
+ _lastNotification =
+ new Notification(MonitorNotification.THRESHOLD_VALUE_EXCEEDED, this, ++_notificationSequenceNumber,
+ System.currentTimeMillis(), notificationMsg);
_broadcaster.sendNotification(_lastNotification);
}
@@ -334,15 +360,18 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
try
{
// Create header attributes list
- CommonContentHeaderProperties headerProperties = (CommonContentHeaderProperties) msg.getContentHeaderBody().properties;
+ CommonContentHeaderProperties headerProperties =
+ (CommonContentHeaderProperties) msg.getContentHeaderBody().properties;
String mimeType = null, encoding = null;
if (headerProperties != null)
{
AMQShortString mimeTypeShortSting = headerProperties.getContentType();
- mimeType = mimeTypeShortSting == null ? null : mimeTypeShortSting.toString();
- encoding = headerProperties.getEncoding() == null ? "" : headerProperties.getEncoding().toString();
+ mimeType = (mimeTypeShortSting == null) ? null : mimeTypeShortSting.toString();
+ encoding = (headerProperties.getEncoding() == null) ? "" : headerProperties.getEncoding().toString();
}
- Object[] itemValues = {msgId, mimeType, encoding, msgContent.toArray(new Byte[0])};
+
+ Object[] itemValues = { msgId, mimeType, encoding, msgContent.toArray(new Byte[0]) };
+
return new CompositeDataSupport(_msgContentType, _msgContentAttributes, itemValues);
}
catch (AMQException e)
@@ -360,8 +389,8 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
{
if ((beginIndex > endIndex) || (beginIndex < 1))
{
- throw new OperationsException("From Index = " + beginIndex + ", To Index = " + endIndex +
- "\n\"From Index\" should be greater than 0 and less than \"To Index\"");
+ throw new OperationsException("From Index = " + beginIndex + ", To Index = " + endIndex
+ + "\n\"From Index\" should be greater than 0 and less than \"To Index\"");
}
List<AMQMessage> list = _queue.getMessagesOnTheQueue();
@@ -370,13 +399,13 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
try
{
// Create the tabular list of message header contents
- for (int i = beginIndex; i <= endIndex && i <= list.size(); i++)
+ for (int i = beginIndex; (i <= endIndex) && (i <= list.size()); i++)
{
AMQMessage msg = list.get(i - 1);
ContentHeaderBody headerBody = msg.getContentHeaderBody();
// Create header attributes list
String[] headerAttributes = getMessageHeaderProperties(headerBody);
- Object[] itemValues = {msg.getMessageId(), headerAttributes, headerBody.bodySize, msg.isRedelivered()};
+ Object[] itemValues = { msg.getMessageId(), headerAttributes, headerBody.bodySize, msg.isRedelivered() };
CompositeData messageData = new CompositeDataSupport(_messageDataType, _msgAttributeNames, itemValues);
_messageList.put(messageData);
}
@@ -404,11 +433,11 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
list.add("JMSCorrelationID = " + headerProperties.getCorrelationIdAsString());
int delMode = headerProperties.getDeliveryMode();
- list.add("JMSDeliveryMode = " + (delMode == 1 ? "Persistent" : "Non_Persistent"));
+ list.add("JMSDeliveryMode = " + ((delMode == 1) ? "Persistent" : "Non_Persistent"));
list.add("JMSPriority = " + headerProperties.getPriority());
list.add("JMSType = " + headerProperties.getType());
-
+
long longDate = headerProperties.getExpiration();
String strDate = (longDate != 0) ? _dateFormat.format(new Date(longDate)) : null;
list.add("JMSExpiration = " + strDate);
@@ -429,27 +458,26 @@ public class AMQQueueMBean extends AMQManagedObject implements ManagedQueue, Que
*/
public void moveMessages(long fromMessageId, long toMessageId, String toQueueName) throws JMException
{
- if (fromMessageId > toMessageId || (fromMessageId < 1))
+ if ((fromMessageId > toMessageId) || (fromMessageId < 1))
{
- throw new OperationsException("\"From MessageId\" should be greater then 0 and less then \"To MessageId\"");
+ throw new OperationsException("\"From MessageId\" should be greater then 0 and less then \"To MessageId\"");
}
_queue.moveMessagesToAnotherQueue(fromMessageId, toMessageId, toQueueName, _storeContext);
}
-
/**
* returns Notifications sent by this MBean.
*/
@Override
public MBeanNotificationInfo[] getNotificationInfo()
{
- String[] notificationTypes = new String[]{MonitorNotification.THRESHOLD_VALUE_EXCEEDED};
+ String[] notificationTypes = new String[] { MonitorNotification.THRESHOLD_VALUE_EXCEEDED };
String name = MonitorNotification.class.getName();
String description = "Either Message count or Queue depth or Message size has reached threshold high value";
MBeanNotificationInfo info1 = new MBeanNotificationInfo(notificationTypes, name, description);
- return new MBeanNotificationInfo[]{info1};
+ return new MBeanNotificationInfo[] { info1 };
}
} // End of AMQQueueMBean class
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java
index 0dcc544ea8..b3fbd1f510 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionURL.java
@@ -7,9 +7,9 @@
* 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
@@ -20,12 +20,6 @@
*/
package org.apache.qpid.client;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.jms.BrokerDetails;
-import org.apache.qpid.jms.ConnectionURL;
-import org.apache.qpid.url.URLHelper;
-import org.apache.qpid.url.URLSyntaxException;
-
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
@@ -33,6 +27,12 @@ import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.jms.BrokerDetails;
+import org.apache.qpid.jms.ConnectionURL;
+import org.apache.qpid.url.URLHelper;
+import org.apache.qpid.url.URLSyntaxException;
+
public class AMQConnectionURL implements ConnectionURL
{
private String _url;
@@ -49,7 +49,6 @@ public class AMQConnectionURL implements ConnectionURL
private AMQShortString _temporaryTopicExchangeName;
private AMQShortString _temporaryQueueExchangeName;
-
public AMQConnectionURL(String fullURL) throws URLSyntaxException
{
_url = fullURL;
@@ -58,18 +57,18 @@ public class AMQConnectionURL implements ConnectionURL
_failoverOptions = new HashMap<String, String>();
// Connection URL format
- //amqp://[user:pass@][clientid]/virtualhost?brokerlist='tcp://host:port?option=\'value\',option=\'value\';vm://:3/virtualpath?option=\'value\'',failover='method?option=\'value\',option='value''"
+ // amqp://[user:pass@][clientid]/virtualhost?brokerlist='tcp://host:port?option=\'value\',option=\'value\';vm://:3/virtualpath?option=\'value\'',failover='method?option=\'value\',option='value''"
// Options are of course optional except for requiring a single broker in the broker list.
try
{
URI connection = new URI(fullURL);
- if (connection.getScheme() == null || !(connection.getScheme().equalsIgnoreCase(AMQ_PROTOCOL)))
+ if ((connection.getScheme() == null) || !(connection.getScheme().equalsIgnoreCase(AMQ_PROTOCOL)))
{
throw new URISyntaxException(fullURL, "Not an AMQP URL");
}
- if (connection.getHost() == null || connection.getHost().equals(""))
+ if ((connection.getHost() == null) || connection.getHost().equals(""))
{
String uid = AMQConnectionFactory.getUniqueClientID();
if (uid == null)
@@ -91,7 +90,7 @@ public class AMQConnectionURL implements ConnectionURL
if (userInfo == null)
{
- //Fix for Java 1.5 which doesn't parse UserInfo for non http URIs
+ // Fix for Java 1.5 which doesn't parse UserInfo for non http URIs
userInfo = connection.getAuthority();
if (userInfo != null)
@@ -112,16 +111,16 @@ public class AMQConnectionURL implements ConnectionURL
if (userInfo == null)
{
- throw URLHelper.parseError(AMQ_PROTOCOL.length() + 3,
- "User information not found on url", fullURL);
+ throw URLHelper.parseError(AMQ_PROTOCOL.length() + 3, "User information not found on url", fullURL);
}
else
{
parseUserInfo(userInfo);
}
+
String virtualHost = connection.getPath();
- if (virtualHost != null && (!virtualHost.equals("")))
+ if ((virtualHost != null) && (!virtualHost.equals("")))
{
setVirtualHost(virtualHost);
}
@@ -130,7 +129,7 @@ public class AMQConnectionURL implements ConnectionURL
int authLength = connection.getAuthority().length();
int start = AMQ_PROTOCOL.length() + 3;
int testIndex = start + authLength;
- if (testIndex < fullURL.length() && fullURL.charAt(testIndex) == '?')
+ if ((testIndex < fullURL.length()) && (fullURL.charAt(testIndex) == '?'))
{
throw URLHelper.parseError(start, testIndex - start, "Virtual host found", fullURL);
}
@@ -141,14 +140,9 @@ public class AMQConnectionURL implements ConnectionURL
}
-
URLHelper.parseOptions(_options, connection.getQuery());
processOptions();
-
- //Fragment is #string (not used)
- //System.out.println(connection.getFragment());
-
}
catch (URISyntaxException uris)
{
@@ -165,11 +159,10 @@ public class AMQConnectionURL implements ConnectionURL
}
else
{
- if (slash != 0 && fullURL.charAt(slash - 1) == ':')
+ if ((slash != 0) && (fullURL.charAt(slash - 1) == ':'))
{
throw URLHelper.parseError(slash - 2, fullURL.indexOf('?') - slash + 2,
- "Virtual host looks like a windows path, forward slash not allowed in URL",
- fullURL);
+ "Virtual host looks like a windows path, forward slash not allowed in URL", fullURL);
}
else
{
@@ -182,14 +175,14 @@ public class AMQConnectionURL implements ConnectionURL
private void parseUserInfo(String userinfo) throws URLSyntaxException
{
- //user info = user:pass
+ // user info = user:pass
int colonIndex = userinfo.indexOf(':');
if (colonIndex == -1)
{
throw URLHelper.parseError(AMQ_PROTOCOL.length() + 3, userinfo.length(),
- "Null password in user information not allowed.", _url);
+ "Null password in user information not allowed.", _url);
}
else
{
@@ -205,7 +198,7 @@ public class AMQConnectionURL implements ConnectionURL
{
String brokerlist = _options.get(OPTIONS_BROKERLIST);
- //brokerlist tcp://host:port?option='value',option='value';vm://:3/virtualpath?option='value'
+ // brokerlist tcp://host:port?option='value',option='value';vm://:3/virtualpath?option='value'
StringTokenizer st = new StringTokenizer(brokerlist, "" + URLHelper.BROKER_SEPARATOR);
while (st.hasMoreTokens())
@@ -244,19 +237,16 @@ public class AMQConnectionURL implements ConnectionURL
_defaultTopicExchangeName = new AMQShortString(_options.get(OPTIONS_DEFAULT_TOPIC_EXCHANGE));
}
-
if (_options.containsKey(OPTIONS_DEFAULT_QUEUE_EXCHANGE))
{
_defaultQueueExchangeName = new AMQShortString(_options.get(OPTIONS_DEFAULT_QUEUE_EXCHANGE));
}
-
if (_options.containsKey(OPTIONS_TEMPORARY_QUEUE_EXCHANGE))
{
_temporaryQueueExchangeName = new AMQShortString(_options.get(OPTIONS_TEMPORARY_QUEUE_EXCHANGE));
}
-
if (_options.containsKey(OPTIONS_TEMPORARY_TOPIC_EXCHANGE))
{
_temporaryTopicExchangeName = new AMQShortString(_options.get(OPTIONS_TEMPORARY_TOPIC_EXCHANGE));
@@ -439,12 +429,11 @@ public class AMQConnectionURL implements ConnectionURL
return sb.toString();
}
-
public static void main(String[] args) throws URLSyntaxException
{
-
- String url2 = "amqp://ritchiem:bob@temp?brokerlist='tcp://localhost:5672;jcp://fancyserver:3000/',failover='roundrobin'";
- //"amqp://user:pass@clientid/virtualhost?brokerlist='tcp://host:1?option1=\'value\',option2=\'value\';vm://:3?option1=\'value\'',failover='method?option1=\'value\',option2='value''";
+ String url2 =
+ "amqp://ritchiem:bob@temp?brokerlist='tcp://localhost:5672;jcp://fancyserver:3000/',failover='roundrobin'";
+ // "amqp://user:pass@clientid/virtualhost?brokerlist='tcp://host:1?option1=\'value\',option2=\'value\';vm://:3?option1=\'value\'',failover='method?option1=\'value\',option2='value''";
ConnectionURL connectionurl2 = new AMQConnectionURL(url2);
@@ -452,5 +441,4 @@ public class AMQConnectionURL implements ConnectionURL
System.out.println(connectionurl2);
}
-
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java b/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java
index f94cd4934c..f0cdda487c 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java
@@ -7,9 +7,9 @@
* 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
@@ -23,6 +23,7 @@ package org.apache.qpid.framing;
import java.nio.charset.Charset;
import org.apache.log4j.Logger;
+
import org.apache.mina.common.ByteBuffer;
public class EncodingUtils
@@ -49,96 +50,95 @@ public class EncodingUtils
}
}
-
public static int encodedShortStringLength(short s)
{
- if( s == 0 )
+ if (s == 0)
{
return 1 + 1;
}
int len = 0;
- if(s < 0)
+ if (s < 0)
{
- len=1;
+ len = 1;
// sloppy - doesn't work of Integer.MIN_VALUE
- s=(short)-s;
+ s = (short) -s;
}
- if(s>9999)
+ if (s > 9999)
{
- return 1+5;
+ return 1 + 5;
}
- else if(s>999)
+ else if (s > 999)
{
- return 1+4;
+ return 1 + 4;
}
- else if(s>99)
+ else if (s > 99)
{
- return 1+3;
+ return 1 + 3;
}
- else if(s>9)
+ else if (s > 9)
{
- return 1+2;
+ return 1 + 2;
}
else
{
- return 1+1;
+ return 1 + 1;
}
}
-
public static int encodedShortStringLength(int i)
{
- if( i == 0 )
+ if (i == 0)
{
return 1 + 1;
}
int len = 0;
- if(i < 0)
+ if (i < 0)
{
- len=1;
+ len = 1;
// sloppy - doesn't work of Integer.MIN_VALUE
- i=-i;
+ i = -i;
}
// range is now 1 - 2147483647
- if(i < Short.MAX_VALUE)
+ if (i < Short.MAX_VALUE)
{
- return len + encodedShortStringLength((short)i);
+ return len + encodedShortStringLength((short) i);
}
else if (i > 999999)
{
- return len + 6 + encodedShortStringLength((short)(i/1000000));
+ return len + 6 + encodedShortStringLength((short) (i / 1000000));
}
else // if (i > 99999)
{
- return len + 5 + encodedShortStringLength((short)(i/100000));
+ return len + 5 + encodedShortStringLength((short) (i / 100000));
}
}
public static int encodedShortStringLength(long l)
{
- if(l == 0)
+ if (l == 0)
{
return 1 + 1;
}
int len = 0;
- if(l < 0)
+ if (l < 0)
{
- len=1;
+ len = 1;
// sloppy - doesn't work of Long.MIN_VALUE
- l=-l;
+ l = -l;
}
- if(l < Integer.MAX_VALUE)
+
+ if (l < Integer.MAX_VALUE)
{
return len + encodedShortStringLength((int) l);
}
- else if(l > 9999999999L)
+ else if (l > 9999999999L)
{
return len + 10 + encodedShortStringLength((int) (l / 10000000000L));
}
@@ -149,7 +149,6 @@ public class EncodingUtils
}
-
public static int encodedShortStringLength(AMQShortString s)
{
if (s == null)
@@ -162,7 +161,6 @@ public class EncodingUtils
}
}
-
public static int encodedLongStringLength(String s)
{
if (s == null)
@@ -219,7 +217,6 @@ public class EncodingUtils
return 0;
}
-
public static void writeShortStringBytes(ByteBuffer buffer, String s)
{
if (s != null)
@@ -230,6 +227,7 @@ public class EncodingUtils
{
encodedString[i] = (byte) cha[i];
}
+
writeBytes(buffer, encodedString);
}
else
@@ -239,7 +237,6 @@ public class EncodingUtils
}
}
-
public static void writeShortStringBytes(ByteBuffer buffer, AMQShortString s)
{
if (s != null)
@@ -256,7 +253,7 @@ public class EncodingUtils
public static void writeLongStringBytes(ByteBuffer buffer, String s)
{
- assert s == null || s.length() <= 0xFFFE;
+ assert (s == null) || (s.length() <= 0xFFFE);
if (s != null)
{
int len = s.length();
@@ -267,6 +264,7 @@ public class EncodingUtils
{
encodedString[i] = (byte) cha[i];
}
+
buffer.put(encodedString);
}
else
@@ -277,7 +275,7 @@ public class EncodingUtils
public static void writeLongStringBytes(ByteBuffer buffer, char[] s)
{
- assert s == null || s.length <= 0xFFFE;
+ assert (s == null) || (s.length <= 0xFFFE);
if (s != null)
{
int len = s.length;
@@ -287,6 +285,7 @@ public class EncodingUtils
{
encodedString[i] = (byte) s[i];
}
+
buffer.put(encodedString);
}
else
@@ -297,7 +296,7 @@ public class EncodingUtils
public static void writeLongStringBytes(ByteBuffer buffer, byte[] bytes)
{
- assert bytes == null || bytes.length <= 0xFFFE;
+ assert (bytes == null) || (bytes.length <= 0xFFFE);
if (bytes != null)
{
writeUnsignedInteger(buffer, bytes.length);
@@ -330,7 +329,6 @@ public class EncodingUtils
}
}
-
public static int unsignedIntegerLength()
{
return 4;
@@ -356,7 +354,6 @@ public class EncodingUtils
}
}
-
public static void writeFieldTableBytes(ByteBuffer buffer, FieldTable table)
{
if (table != null)
@@ -400,10 +397,9 @@ public class EncodingUtils
if (value1)
{
- packedValue = (byte) (packedValue | (byte)(1 << 1));
+ packedValue = (byte) (packedValue | (byte) (1 << 1));
}
-
buffer.put(packedValue);
}
@@ -413,213 +409,181 @@ public class EncodingUtils
if (value1)
{
- packedValue = (byte) (packedValue | (byte)(1 << 1));
+ packedValue = (byte) (packedValue | (byte) (1 << 1));
}
if (value2)
{
- packedValue = (byte) (packedValue | (byte)(1 << 2));
+ packedValue = (byte) (packedValue | (byte) (1 << 2));
}
-
buffer.put(packedValue);
}
-
-
- public static void writeBooleans(ByteBuffer buffer,
- boolean value0,
- boolean value1,
- boolean value2,
- boolean value3)
+ public static void writeBooleans(ByteBuffer buffer, boolean value0, boolean value1, boolean value2, boolean value3)
{
byte packedValue = value0 ? (byte) 1 : (byte) 0;
if (value1)
{
- packedValue = (byte) (packedValue | (byte)(1 << 1));
+ packedValue = (byte) (packedValue | (byte) (1 << 1));
}
if (value2)
{
- packedValue = (byte) (packedValue | (byte)(1 << 2));
+ packedValue = (byte) (packedValue | (byte) (1 << 2));
}
if (value3)
{
- packedValue = (byte) (packedValue | (byte)(1 << 3));
+ packedValue = (byte) (packedValue | (byte) (1 << 3));
}
buffer.put(packedValue);
}
- public static void writeBooleans(ByteBuffer buffer,
- boolean value0,
- boolean value1,
- boolean value2,
- boolean value3,
- boolean value4)
+ public static void writeBooleans(ByteBuffer buffer, boolean value0, boolean value1, boolean value2, boolean value3,
+ boolean value4)
{
byte packedValue = value0 ? (byte) 1 : (byte) 0;
if (value1)
{
- packedValue = (byte) (packedValue | (byte)(1 << 1));
+ packedValue = (byte) (packedValue | (byte) (1 << 1));
}
if (value2)
{
- packedValue = (byte) (packedValue | (byte)(1 << 2));
+ packedValue = (byte) (packedValue | (byte) (1 << 2));
}
if (value3)
{
- packedValue = (byte) (packedValue | (byte)(1 << 3));
+ packedValue = (byte) (packedValue | (byte) (1 << 3));
}
if (value4)
{
- packedValue = (byte) (packedValue | (byte)(1 << 4));
+ packedValue = (byte) (packedValue | (byte) (1 << 4));
}
buffer.put(packedValue);
}
- public static void writeBooleans(ByteBuffer buffer,
- boolean value0,
- boolean value1,
- boolean value2,
- boolean value3,
- boolean value4,
- boolean value5)
+ public static void writeBooleans(ByteBuffer buffer, boolean value0, boolean value1, boolean value2, boolean value3,
+ boolean value4, boolean value5)
{
byte packedValue = value0 ? (byte) 1 : (byte) 0;
if (value1)
{
- packedValue = (byte) (packedValue | (byte)(1 << 1));
+ packedValue = (byte) (packedValue | (byte) (1 << 1));
}
if (value2)
{
- packedValue = (byte) (packedValue | (byte)(1 << 2));
+ packedValue = (byte) (packedValue | (byte) (1 << 2));
}
if (value3)
{
- packedValue = (byte) (packedValue | (byte)(1 << 3));
+ packedValue = (byte) (packedValue | (byte) (1 << 3));
}
if (value4)
{
- packedValue = (byte) (packedValue | (byte)(1 << 4));
+ packedValue = (byte) (packedValue | (byte) (1 << 4));
}
if (value5)
{
- packedValue = (byte) (packedValue | (byte)(1 << 5));
+ packedValue = (byte) (packedValue | (byte) (1 << 5));
}
buffer.put(packedValue);
}
- public static void writeBooleans(ByteBuffer buffer,
- boolean value0,
- boolean value1,
- boolean value2,
- boolean value3,
- boolean value4,
- boolean value5,
- boolean value6)
+ public static void writeBooleans(ByteBuffer buffer, boolean value0, boolean value1, boolean value2, boolean value3,
+ boolean value4, boolean value5, boolean value6)
{
byte packedValue = value0 ? (byte) 1 : (byte) 0;
if (value1)
{
- packedValue = (byte) (packedValue | (byte)(1 << 1));
+ packedValue = (byte) (packedValue | (byte) (1 << 1));
}
if (value2)
{
- packedValue = (byte) (packedValue | (byte)(1 << 2));
+ packedValue = (byte) (packedValue | (byte) (1 << 2));
}
if (value3)
{
- packedValue = (byte) (packedValue | (byte)(1 << 3));
+ packedValue = (byte) (packedValue | (byte) (1 << 3));
}
if (value4)
{
- packedValue = (byte) (packedValue | (byte)(1 << 4));
+ packedValue = (byte) (packedValue | (byte) (1 << 4));
}
if (value5)
{
- packedValue = (byte) (packedValue | (byte)(1 << 5));
+ packedValue = (byte) (packedValue | (byte) (1 << 5));
}
if (value6)
{
- packedValue = (byte) (packedValue | (byte)(1 << 6));
+ packedValue = (byte) (packedValue | (byte) (1 << 6));
}
buffer.put(packedValue);
}
- public static void writeBooleans(ByteBuffer buffer,
- boolean value0,
- boolean value1,
- boolean value2,
- boolean value3,
- boolean value4,
- boolean value5,
- boolean value6,
- boolean value7)
+ public static void writeBooleans(ByteBuffer buffer, boolean value0, boolean value1, boolean value2, boolean value3,
+ boolean value4, boolean value5, boolean value6, boolean value7)
{
byte packedValue = value0 ? (byte) 1 : (byte) 0;
if (value1)
{
- packedValue = (byte) (packedValue | (byte)(1 << 1));
+ packedValue = (byte) (packedValue | (byte) (1 << 1));
}
if (value2)
{
- packedValue = (byte) (packedValue | (byte)(1 << 2));
+ packedValue = (byte) (packedValue | (byte) (1 << 2));
}
if (value3)
{
- packedValue = (byte) (packedValue | (byte)(1 << 3));
+ packedValue = (byte) (packedValue | (byte) (1 << 3));
}
if (value4)
{
- packedValue = (byte) (packedValue | (byte)(1 << 4));
+ packedValue = (byte) (packedValue | (byte) (1 << 4));
}
if (value5)
{
- packedValue = (byte) (packedValue | (byte)(1 << 5));
+ packedValue = (byte) (packedValue | (byte) (1 << 5));
}
if (value6)
{
- packedValue = (byte) (packedValue | (byte)(1 << 6));
+ packedValue = (byte) (packedValue | (byte) (1 << 6));
}
if (value7)
{
- packedValue = (byte) (packedValue | (byte)(1 << 7));
+ packedValue = (byte) (packedValue | (byte) (1 << 7));
}
buffer.put(packedValue);
}
-
-
-
/**
* This is used for writing longstrs.
*
@@ -647,26 +611,27 @@ public class EncodingUtils
public static boolean[] readBooleans(ByteBuffer buffer)
{
final byte packedValue = buffer.get();
- if(packedValue == 0)
+ if (packedValue == 0)
{
return ALL_FALSE_ARRAY;
}
+
final boolean[] result = new boolean[8];
result[0] = ((packedValue & 1) != 0);
result[1] = ((packedValue & (1 << 1)) != 0);
result[2] = ((packedValue & (1 << 2)) != 0);
result[3] = ((packedValue & (1 << 3)) != 0);
- if((packedValue & 0xF0) == 0)
+ if ((packedValue & 0xF0) == 0)
{
result[0] = ((packedValue & 1) != 0);
}
+
result[4] = ((packedValue & (1 << 4)) != 0);
result[5] = ((packedValue & (1 << 5)) != 0);
result[6] = ((packedValue & (1 << 6)) != 0);
result[7] = ((packedValue & (1 << 7)) != 0);
-
return result;
}
@@ -742,6 +707,7 @@ public class EncodingUtils
{
stringChars[i] = (char) stringBytes[i];
}
+
return new String(stringChars);
}
}
@@ -757,6 +723,7 @@ public class EncodingUtils
{
byte[] result = new byte[(int) length];
buffer.get(result);
+
return result;
}
}
@@ -764,15 +731,14 @@ public class EncodingUtils
public static long readTimestamp(ByteBuffer buffer)
{
// Discard msb from AMQ timestamp
- //buffer.getUnsignedInt();
+ // buffer.getUnsignedInt();
return buffer.getLong();
}
-
static byte[] hexToByteArray(String id)
{
// Should check param for null, long enough for this check, upper-case and trailing char
- String s = (id.charAt(1) == 'x') ? id.substring(2) : id; // strip 0x
+ String s = (id.charAt(1) == 'x') ? id.substring(2) : id; // strip 0x
int len = s.length();
int byte_len = len / 2;
@@ -786,7 +752,7 @@ public class EncodingUtils
byte b1 = Byte.parseByte(s.substring(ch, ch + 1), 16);
byte b2 = Byte.parseByte(s.substring(ch + 1, ch + 2), 16);
- b[i] = (byte) (b1 * 16 + b2);
+ b[i] = (byte) ((b1 * 16) + b2);
}
return (b);
@@ -795,7 +761,7 @@ public class EncodingUtils
public static char[] convertToHexCharArray(byte[] from)
{
int length = from.length;
- char[] result_buff = new char[length * 2 + 2];
+ char[] result_buff = new char[(length * 2) + 2];
result_buff[0] = '0';
result_buff[1] = 'x';
@@ -831,7 +797,7 @@ public class EncodingUtils
byte[] from = new byte[size];
// Is this not the same.
- //bb.get(from, 0, length);
+ // bb.get(from, 0, length);
for (int i = 0; i < size; i++)
{
from[i] = bb.get(i);
@@ -840,9 +806,9 @@ public class EncodingUtils
return (new String(convertToHexCharArray(from)));
}
- private static char hex_chars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+ private static char[] hex_chars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
- //**** new methods
+ // **** new methods
// AMQP_BOOLEAN_PROPERTY_PREFIX
@@ -854,6 +820,7 @@ public class EncodingUtils
public static boolean readBoolean(ByteBuffer buffer)
{
byte packedValue = buffer.get();
+
return (packedValue == 1);
}
@@ -878,7 +845,6 @@ public class EncodingUtils
return 1;
}
-
// AMQP_SHORT_PROPERTY_PREFIX
public static void writeShort(ByteBuffer buffer, Short aShort)
{
@@ -943,7 +909,6 @@ public class EncodingUtils
return 4;
}
-
// Double_PROPERTY_PREFIX
public static void writeDouble(ByteBuffer buffer, Double aDouble)
{
@@ -960,7 +925,6 @@ public class EncodingUtils
return 8;
}
-
public static byte[] readBytes(ByteBuffer buffer)
{
short length = buffer.getUnsigned();
@@ -981,7 +945,7 @@ public class EncodingUtils
{
if (data != null)
{
- // TODO: check length fits in an unsigned byte
+ // TODO: check length fits in an unsigned byte
writeUnsignedByte(buffer, (short) data.length);
buffer.put(data);
}
@@ -992,7 +956,7 @@ public class EncodingUtils
}
}
- //CHAR_PROPERTY
+ // CHAR_PROPERTY
public static int encodedCharLength()
{
return encodedByteLength();
@@ -1000,31 +964,29 @@ public class EncodingUtils
public static char readChar(ByteBuffer buffer)
{
- //This is valid as we know that the Character is ASCII 0..127
+ // This is valid as we know that the Character is ASCII 0..127
return (char) buffer.get();
}
public static void writeChar(ByteBuffer buffer, char character)
{
- //This is valid as we know that the Character is ASCII 0..127
+ // This is valid as we know that the Character is ASCII 0..127
writeByte(buffer, (byte) character);
}
-
-
-
public static long readLongAsShortString(ByteBuffer buffer)
{
short length = buffer.getUnsigned();
short pos = 0;
- if(length == 0)
+ if (length == 0)
{
return 0L;
}
+
byte digit = buffer.get();
boolean isNegative;
long result = 0;
- if(digit == (byte)'-')
+ if (digit == (byte) '-')
{
isNegative = true;
pos++;
@@ -1034,15 +996,16 @@ public class EncodingUtils
{
isNegative = false;
}
- result = digit - (byte)'0';
+
+ result = digit - (byte) '0';
pos++;
- while(pos < length)
+ while (pos < length)
{
pos++;
digit = buffer.get();
result = (result << 3) + (result << 1);
- result += digit - (byte)'0';
+ result += digit - (byte) '0';
}
return result;
@@ -1051,33 +1014,13 @@ public class EncodingUtils
public static long readUnsignedInteger(ByteBuffer buffer)
{
long l = 0xFF & buffer.get();
- l <<=8;
+ l <<= 8;
l = l | (0xFF & buffer.get());
- l <<=8;
+ l <<= 8;
l = l | (0xFF & buffer.get());
- l <<=8;
+ l <<= 8;
l = l | (0xFF & buffer.get());
return l;
}
-
-
- public static void main(String[] args)
- {
- ByteBuffer buf = ByteBuffer.allocate(8);
- buf.setAutoExpand(true);
-
- long l = (long) Integer.MAX_VALUE;
- l += 1024L;
-
- writeUnsignedInteger(buf, l);
-
- buf.flip();
-
- long l2 = readUnsignedInteger(buf);
-
- System.out.println("before: " + l);
- System.out.println("after: " + l2);
- }
-
}
diff --git a/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java b/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java
index f558523864..353c0d39c2 100644
--- a/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java
+++ b/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java
@@ -7,9 +7,9 @@
* 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
@@ -24,9 +24,10 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
+import org.apache.log4j.Logger;
+
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
-import org.apache.log4j.Logger;
public class AMQBindingURL implements BindingURL
{
@@ -39,10 +40,9 @@ public class AMQBindingURL implements BindingURL
AMQShortString _queueName;
private HashMap<String, String> _options;
-
public AMQBindingURL(String url) throws URLSyntaxException
{
- //format:
+ // format:
// <exch_class>://<exch_name>/[<destination>]/[<queue>]?<option>='<value>'[,<option>='<value>']*
_logger.debug("Parsing URL: " + url);
_url = url;
@@ -61,10 +61,10 @@ public class AMQBindingURL implements BindingURL
if (exchangeClass == null)
{
- _url = ExchangeDefaults.DIRECT_EXCHANGE_CLASS + "://" +
- "" + "//" + _url;
- //URLHelper.parseError(-1, "Exchange Class not specified.", _url);
+ _url = ExchangeDefaults.DIRECT_EXCHANGE_CLASS + "://" + "" + "//" + _url;
+ // URLHelper.parseError(-1, "Exchange Class not specified.", _url);
parseBindingURL();
+
return;
}
else
@@ -76,7 +76,7 @@ public class AMQBindingURL implements BindingURL
if (exchangeName == null)
{
- if(getExchangeClass().equals(ExchangeDefaults.DIRECT_EXCHANGE_CLASS))
+ if (getExchangeClass().equals(ExchangeDefaults.DIRECT_EXCHANGE_CLASS))
{
setExchangeName("");
}
@@ -92,11 +92,10 @@ public class AMQBindingURL implements BindingURL
String queueName;
- if (connection.getPath() == null ||
- connection.getPath().equals(""))
+ if ((connection.getPath() == null) || connection.getPath().equals(""))
{
throw URLHelper.parseError(_url.indexOf(_exchangeName.toString()) + _exchangeName.length(),
- "Destination or Queue requried", _url);
+ "Destination or Queue requried", _url);
}
else
{
@@ -104,7 +103,7 @@ public class AMQBindingURL implements BindingURL
if (slash == -1)
{
throw URLHelper.parseError(_url.indexOf(_exchangeName.toString()) + _exchangeName.length(),
- "Destination requried", _url);
+ "Destination requried", _url);
}
else
{
@@ -127,9 +126,8 @@ public class AMQBindingURL implements BindingURL
setQueueName(queueName);
- //Fragment is #string (not used)
- //System.out.println(connection.getFragment());
- _logger.debug("URL Parsed: " + this);
+ // Fragment is #string (not used)
+ _logger.debug("URL Parsed: " + this);
}
catch (URISyntaxException uris)
@@ -162,7 +160,7 @@ public class AMQBindingURL implements BindingURL
private void processOptions()
{
- //this is where we would parse any options that needed more than just storage.
+ // this is where we would parse any options that needed more than just storage.
}
public String getURL()
@@ -219,11 +217,13 @@ public class AMQBindingURL implements BindingURL
{
if (containsOption(BindingURL.OPTION_CLIENTID) && containsOption(BindingURL.OPTION_SUBSCRIPTION))
{
- _queueName = new AMQShortString(getOption(BindingURL.OPTION_CLIENTID + ":" + BindingURL.OPTION_SUBSCRIPTION));
+ _queueName =
+ new AMQShortString(getOption(BindingURL.OPTION_CLIENTID + ":" + BindingURL.OPTION_SUBSCRIPTION));
}
else
{
- throw URLHelper.parseError(-1, "Durable subscription must have values for " + BindingURL.OPTION_CLIENTID + " and " + BindingURL.OPTION_SUBSCRIPTION + ".", _url);
+ throw URLHelper.parseError(-1, "Durable subscription must have values for " + BindingURL.OPTION_CLIENTID
+ + " and " + BindingURL.OPTION_SUBSCRIPTION + ".", _url);
}
}
@@ -237,7 +237,6 @@ public class AMQBindingURL implements BindingURL
_queueName = name;
}
-
}
public String getOption(String key)
@@ -275,7 +274,6 @@ public class AMQBindingURL implements BindingURL
setOption(OPTION_ROUTING_KEY, key.toString());
}
-
public String toString()
{
StringBuffer sb = new StringBuffer();
@@ -289,18 +287,7 @@ public class AMQBindingURL implements BindingURL
sb.append(_queueName);
sb.append(URLHelper.printOptions(_options));
- return sb.toString();
- }
-
- public static void main(String args[]) throws URLSyntaxException
- {
- String url = "exchangeClass://exchangeName/Destination/Queue?option='value',option2='value2'";
-
- AMQBindingURL dest = new AMQBindingURL(url);
-
- System.out.println(url);
- System.out.println(dest);
+ return sb.toString();
}
-
}
diff --git a/java/common/src/main/java/org/apache/qpid/url/URLHelper.java b/java/common/src/main/java/org/apache/qpid/url/URLHelper.java
index 806f879818..c08b443acf 100644
--- a/java/common/src/main/java/org/apache/qpid/url/URLHelper.java
+++ b/java/common/src/main/java/org/apache/qpid/url/URLHelper.java
@@ -7,9 +7,9 @@
* 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
@@ -30,10 +30,10 @@ public class URLHelper
public static void parseOptions(HashMap<String, String> optionMap, String options) throws URLSyntaxException
{
- //options looks like this
- //brokerlist='tcp://host:port?option='value',option='value';vm://:3/virtualpath?option='value'',failover='method?option='value',option='value''
+ // options looks like this
+ // brokerlist='tcp://host:port?option='value',option='value';vm://:3/virtualpath?option='value'',failover='method?option='value',option='value''
- if (options == null || options.indexOf('=') == -1)
+ if ((options == null) || (options.indexOf('=') == -1))
{
return;
}
@@ -49,8 +49,8 @@ public class URLHelper
// to store index of final "'"
int valueIndex = optionIndex;
- //Walk remainder of url.
- while (nestedQuotes > 0 || valueIndex < length)
+ // Walk remainder of url.
+ while ((nestedQuotes > 0) || (valueIndex < length))
{
valueIndex++;
@@ -61,27 +61,24 @@ public class URLHelper
if (options.charAt(valueIndex) == '\'')
{
- if (valueIndex + 1 < options.length())
+ if ((valueIndex + 1) < options.length())
{
- if (options.charAt(valueIndex + 1) == DEFAULT_OPTION_SEPERATOR ||
- options.charAt(valueIndex + 1) == ALTERNATIVE_OPTION_SEPARATOR ||
- options.charAt(valueIndex + 1) == BROKER_SEPARATOR ||
- options.charAt(valueIndex + 1) == '\'')
+ if ((options.charAt(valueIndex + 1) == DEFAULT_OPTION_SEPERATOR)
+ || (options.charAt(valueIndex + 1) == ALTERNATIVE_OPTION_SEPARATOR)
+ || (options.charAt(valueIndex + 1) == BROKER_SEPARATOR)
+ || (options.charAt(valueIndex + 1) == '\''))
{
nestedQuotes--;
-// System.out.println(
-// options + "\n" + "-" + nestedQuotes + ":" + getPositionString(valueIndex - 2, 1));
+
if (nestedQuotes == 0)
{
- //We've found the value of an option
+ // We've found the value of an option
break;
}
}
else
{
nestedQuotes++;
-// System.out.println(
-// options + "\n" + "+" + nestedQuotes + ":" + getPositionString(valueIndex - 2, 1));
}
}
else
@@ -98,11 +95,11 @@ public class URLHelper
}
}
- if (nestedQuotes != 0 || valueIndex < (optionIndex + 2))
+ if ((nestedQuotes != 0) || (valueIndex < (optionIndex + 2)))
{
int sepIndex = 0;
- //Try and identify illegal separator character
+ // Try and identify illegal separator character
if (nestedQuotes > 1)
{
for (int i = 0; i < nestedQuotes; i++)
@@ -112,14 +109,14 @@ public class URLHelper
}
}
- if (sepIndex >= options.length() || sepIndex == 0)
+ if ((sepIndex >= options.length()) || (sepIndex == 0))
{
throw parseError(valueIndex, "Unterminated option", options);
}
else
{
- throw parseError(sepIndex, "Unterminated option. Possible illegal option separator:'" +
- options.charAt(sepIndex) + "'", options);
+ throw parseError(sepIndex, "Unterminated option. Possible illegal option separator:'"
+ + options.charAt(sepIndex) + "'", options);
}
}
@@ -130,12 +127,11 @@ public class URLHelper
if (valueIndex < (options.length() - 1))
{
- //Recurse to get remaining options
+ // Recurse to get remaining options
parseOptions(optionMap, options.substring(valueIndex + 2));
}
}
-
public static URLSyntaxException parseError(int index, String error, String url)
{
return parseError(index, 1, error, url);