diff options
| author | Rupert Smith <rupertlssmith@apache.org> | 2007-06-11 16:43:57 +0000 |
|---|---|---|
| committer | Rupert Smith <rupertlssmith@apache.org> | 2007-06-11 16:43:57 +0000 |
| commit | 9889573f94c99b252395262f73afe1c9055d59e7 (patch) | |
| tree | 9633f0ed0430f8c09eab9b9bfc37291f0a43d677 /java/common | |
| parent | a1b3eef439d082d62d2dc1188c14e795418c8416 (diff) | |
| download | qpid-python-9889573f94c99b252395262f73afe1c9055d59e7.tar.gz | |
Removed log4j dependency from client. Using slf4j instead, end-user to supply logging implementation as desired. Log4j used for tests.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2@546190 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common')
20 files changed, 538 insertions, 532 deletions
diff --git a/java/common/pom.xml b/java/common/pom.xml index 80e4229117..aaa9a556e8 100644 --- a/java/common/pom.xml +++ b/java/common/pom.xml @@ -98,15 +98,17 @@ <dependencies> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.4.0</version> </dependency> - <!-- This is a mina dependency but it isn't being picked up--> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.0</version> + <scope>test</scope> </dependency> <dependency> diff --git a/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java b/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java index 5a357557ca..2c783aeaa4 100644 --- a/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java +++ b/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java @@ -20,13 +20,14 @@ */ package org.apache.qpid.common; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.IOException; import java.io.InputStream; import java.util.Map; import java.util.Properties; -import org.apache.log4j.Logger; - /** * QpidProperties captures the project name, version number, and source code repository revision number from a properties * file which is generated as part of the build process. Normally, the name and version number are pulled from the module @@ -50,7 +51,7 @@ import org.apache.log4j.Logger; public class QpidProperties { /** Used for debugging purposes. */ - private static final Logger _logger = Logger.getLogger(QpidProperties.class); + private static final Logger _logger = LoggerFactory.getLogger(QpidProperties.class); /** The name of the version properties file to load from the class path. */ public static final String VERSION_RESOURCE = "qpidversion.properties"; diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java b/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java index 9f36448986..82ffc60802 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java +++ b/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.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,15 @@ */ package org.apache.qpid.framing; -import org.apache.log4j.Logger; import org.apache.mina.common.ByteBuffer; import org.apache.mina.common.IoSession; import org.apache.mina.filter.codec.ProtocolDecoderOutput; + import org.apache.qpid.protocol.AMQVersionAwareProtocolSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class AMQDataBlockDecoder { private static final String SESSION_METHOD_BODY_FACTORY = "QPID_SESSION_METHOD_BODY_FACTORY"; @@ -39,14 +42,10 @@ public class AMQDataBlockDecoder _bodiesSupported[HeartbeatBody.TYPE] = new HeartbeatBodyFactory(); } - - Logger _logger = Logger.getLogger(AMQDataBlockDecoder.class); - - + Logger _logger = LoggerFactory.getLogger(AMQDataBlockDecoder.class); public AMQDataBlockDecoder() - { - } + { } public boolean decodable(IoSession session, ByteBuffer in) throws AMQFrameDecodingException { @@ -56,26 +55,24 @@ public class AMQDataBlockDecoder { return false; } + in.skip(1 + 2); final long bodySize = in.getUnsignedInt(); - - return (remainingAfterAttributes >= bodySize); } - protected Object createAndPopulateFrame(IoSession session, ByteBuffer in) - throws AMQFrameDecodingException, AMQProtocolVersionException + throws AMQFrameDecodingException, AMQProtocolVersionException { final byte type = in.get(); BodyFactory bodyFactory; - if(type == AMQMethodBody.TYPE) + if (type == AMQMethodBody.TYPE) { bodyFactory = (BodyFactory) session.getAttribute(SESSION_METHOD_BODY_FACTORY); - if(bodyFactory == null) + if (bodyFactory == null) { AMQVersionAwareProtocolSession protocolSession = (AMQVersionAwareProtocolSession) session.getAttachment(); bodyFactory = new AMQMethodBodyFactory(protocolSession); @@ -89,10 +86,7 @@ public class AMQDataBlockDecoder bodyFactory = _bodiesSupported[type]; } - - - - if(bodyFactory == null) + if (bodyFactory == null) { throw new AMQFrameDecodingException(null, "Unsupported frame type: " + type, null); } @@ -101,25 +95,25 @@ public class AMQDataBlockDecoder final long bodySize = in.getUnsignedInt(); // bodySize can be zero - if (channel < 0 || bodySize < 0) + if ((channel < 0) || (bodySize < 0)) { - throw new AMQFrameDecodingException(null, "Undecodable frame: type = " + type + " channel = " + channel + - " bodySize = " + bodySize, null); + throw new AMQFrameDecodingException(null, "Undecodable frame: type = " + type + " channel = " + channel + + " bodySize = " + bodySize, null); } AMQFrame frame = new AMQFrame(in, channel, bodySize, bodyFactory); - byte marker = in.get(); if ((marker & 0xFF) != 0xCE) { - throw new AMQFrameDecodingException(null, "End of frame marker not found. Read " + marker + " length=" + bodySize + " type=" + type, null); + throw new AMQFrameDecodingException(null, "End of frame marker not found. Read " + marker + " length=" + bodySize + + " type=" + type, null); } + return frame; } - public void decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) - throws Exception + public void decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception { out.write(createAndPopulateFrame(session, in)); } diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockEncoder.java b/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockEncoder.java index 91814085fc..05fd2bb480 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockEncoder.java +++ b/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockEncoder.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,24 +20,25 @@ */ package org.apache.qpid.framing; -import java.util.Collections; -import java.util.Set; - -import org.apache.log4j.Logger; import org.apache.mina.common.ByteBuffer; import org.apache.mina.common.IoSession; import org.apache.mina.filter.codec.ProtocolEncoderOutput; import org.apache.mina.filter.codec.demux.MessageEncoder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Collections; +import java.util.Set; + public final class AMQDataBlockEncoder implements MessageEncoder { - private static final Logger _logger = Logger.getLogger(AMQDataBlockEncoder.class); + private static final Logger _logger = LoggerFactory.getLogger(AMQDataBlockEncoder.class); private final Set _messageTypes = Collections.singleton(EncodableAMQDataBlock.class); public AMQDataBlockEncoder() - { - } + { } public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception { diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java b/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java index 5293c00379..cf85bdab31 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java +++ b/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.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,16 +20,19 @@ */ package org.apache.qpid.framing; -import org.apache.log4j.Logger; import org.apache.mina.common.ByteBuffer; + import org.apache.qpid.protocol.AMQVersionAwareProtocolSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class AMQMethodBodyFactory implements BodyFactory { - private static final Logger _log = Logger.getLogger(AMQMethodBodyFactory.class); + private static final Logger _log = LoggerFactory.getLogger(AMQMethodBodyFactory.class); private final AMQVersionAwareProtocolSession _protocolSession; - + public AMQMethodBodyFactory(AMQVersionAwareProtocolSession protocolSession) { _protocolSession = protocolSession; @@ -37,6 +40,7 @@ public class AMQMethodBodyFactory implements BodyFactory public AMQBody createBody(ByteBuffer in, long bodySize) throws AMQFrameDecodingException { - return _protocolSession.getRegistry().get((short)in.getUnsignedShort(), (short)in.getUnsignedShort(), in, bodySize); + return _protocolSession.getRegistry().get((short) in.getUnsignedShort(), (short) in.getUnsignedShort(), in, + bodySize); } } diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java b/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java index e4e3222f01..ee7abd55c0 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java +++ b/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java @@ -1,8 +1,10 @@ package org.apache.qpid.framing;
-import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* A short string is a representation of an AMQ Short String
* Short strings differ from the Java String class by being limited to on ASCII characters (0-127)
@@ -11,7 +13,7 @@ import org.apache.mina.common.ByteBuffer; */
public final class AMQShortString implements CharSequence, Comparable<AMQShortString>
{
- private static final Logger _logger = Logger.getLogger(AMQShortString.class);
+ private static final Logger _logger = LoggerFactory.getLogger(AMQShortString.class);
private final ByteBuffer _data;
private int _hashCode;
@@ -25,22 +27,25 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt _length = data.length;
}
-
public AMQShortString(String data)
{
- this(data == null ? EMPTY_CHAR_ARRAY : data.toCharArray());
- if(data != null) _hashCode = data.hashCode();
+ this((data == null) ? EMPTY_CHAR_ARRAY : data.toCharArray());
+ if (data != null)
+ {
+ _hashCode = data.hashCode();
+ }
}
public AMQShortString(char[] data)
{
- if(data == null)
+ if (data == null)
{
throw new NullPointerException("Cannot create AMQShortString with null char[]");
}
+
final int length = data.length;
final byte[] stringBytes = new byte[length];
- for(int i = 0; i < length; i++)
+ for (int i = 0; i < length; i++)
{
stringBytes[i] = (byte) (0xFF & data[i]);
}
@@ -56,12 +61,13 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt final int length = charSequence.length();
final byte[] stringBytes = new byte[length];
int hash = 0;
- for(int i = 0 ; i < length; i++)
+ for (int i = 0; i < length; i++)
{
stringBytes[i] = ((byte) (0xFF & charSequence.charAt(i)));
hash = (31 * hash) + stringBytes[i];
}
+
_data = ByteBuffer.wrap(stringBytes);
_data.rewind();
_hashCode = hash;
@@ -73,9 +79,8 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt {
_data = data;
_length = data.limit();
-
- }
+ }
/**
* Get the length of the short string
@@ -95,17 +100,18 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt public CharSequence subSequence(int start, int end)
{
- return new CharSubSequence(start,end);
+ return new CharSubSequence(start, end);
}
public int writeToByteArray(byte[] encoding, int pos)
{
final int size = length();
encoding[pos++] = (byte) length();
- for(int i = 0; i < size; i++)
+ for (int i = 0; i < size; i++)
{
encoding[pos++] = _data.get(i);
}
+
return pos;
}
@@ -113,12 +119,12 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt {
final byte len = byteEncodedDestination[pos];
- if(len == 0)
+ if (len == 0)
{
return null;
}
- ByteBuffer data = ByteBuffer.wrap(byteEncodedDestination,pos+1,len).slice();
-
+
+ ByteBuffer data = ByteBuffer.wrap(byteEncodedDestination, pos + 1, len).slice();
return new AMQShortString(data);
}
@@ -141,11 +147,10 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt }
}
-
public byte[] getBytes()
{
- if(_data.buf().hasArray() && _data.arrayOffset() == 0)
+ if (_data.buf().hasArray() && (_data.arrayOffset() == 0))
{
return _data.array();
}
@@ -157,30 +162,27 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt buf.rewind();
buf.get(b);
-
return b;
}
-
}
public void writeToBuffer(ByteBuffer buffer)
{
-
final int size = length();
if (size != 0)
{
- buffer.put((byte)size);
- if(_data.buf().hasArray())
+ buffer.put((byte) size);
+ if (_data.buf().hasArray())
{
- buffer.put(_data.array(),_data.arrayOffset(),length());
+ buffer.put(_data.array(), _data.arrayOffset(), length());
}
else
{
- for(int i = 0; i < size; i++)
+ for (int i = 0; i < size; i++)
{
buffer.put(_data.get(i));
@@ -200,14 +202,12 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt private final int _offset;
private final int _end;
-
public CharSubSequence(final int offset, final int end)
{
_offset = offset;
_end = end;
}
-
public int length()
{
return _end - _offset;
@@ -220,29 +220,23 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt public CharSequence subSequence(int start, int end)
{
- return new CharSubSequence(start+_offset,end+_offset);
+ return new CharSubSequence(start + _offset, end + _offset);
}
}
-
-
public char[] asChars()
{
final int size = length();
final char[] chars = new char[size];
-
-
-
- for(int i = 0 ; i < size; i++)
+ for (int i = 0; i < size; i++)
{
chars[i] = (char) _data.get(i);
}
+
return chars;
}
-
-
public String asString()
{
return new String(asChars());
@@ -250,66 +244,69 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt public boolean equals(Object o)
{
- if(o == null)
+ if (o == null)
{
return false;
}
- if(o == this)
+
+ if (o == this)
{
return true;
}
- if(o instanceof AMQShortString)
+
+ if (o instanceof AMQShortString)
{
final AMQShortString otherString = (AMQShortString) o;
- if((_hashCode != 0) && (otherString._hashCode != 0) && (_hashCode != otherString._hashCode))
+ if ((_hashCode != 0) && (otherString._hashCode != 0) && (_hashCode != otherString._hashCode))
{
return false;
}
return _data.equals(otherString._data);
-
-
-
}
- return (o instanceof CharSequence) && equals((CharSequence)o);
+
+ return (o instanceof CharSequence) && equals((CharSequence) o);
}
public boolean equals(CharSequence s)
{
- if(s == null)
+ if (s == null)
{
return false;
}
- if(s.length() != length())
+
+ if (s.length() != length())
{
return false;
}
- for(int i = 0; i < length(); i++)
+
+ for (int i = 0; i < length(); i++)
{
- if(charAt(i)!= s.charAt(i))
+ if (charAt(i) != s.charAt(i))
{
return false;
}
}
+
return true;
}
public int hashCode()
{
int hash = _hashCode;
- if(hash == 0)
+ if (hash == 0)
{
final int size = length();
-
- for(int i = 0; i < size; i++)
+ for (int i = 0; i < size; i++)
{
hash = (31 * hash) + _data.get(i);
}
+
_hashCode = hash;
}
@@ -320,38 +317,42 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt {
_hashCode = 0;
}
-
+
public String toString()
{
return asString();
}
-
public int compareTo(AMQShortString name)
{
- if(name == null)
+ if (name == null)
{
return 1;
}
else
{
- if(name.length() < length())
+ if (name.length() < length())
{
- return - name.compareTo(this);
+ return -name.compareTo(this);
}
-
-
- for(int i = 0; i < length() ; i++)
+ for (int i = 0; i < length(); i++)
{
final byte d = _data.get(i);
final byte n = name._data.get(i);
- if(d < n) return -1;
- if(d > n) return 1;
+ if (d < n)
+ {
+ return -1;
+ }
+
+ if (d > n)
+ {
+ return 1;
+ }
}
- return length() == name.length() ? 0 : -1;
+ return (length() == name.length()) ? 0 : -1;
}
}
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java b/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java index 4424fc1def..61f2f891e5 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java +++ b/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.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,13 +20,14 @@ */ package org.apache.qpid.framing; -import org.apache.log4j.Logger; import org.apache.mina.common.ByteBuffer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class BasicContentHeaderProperties implements CommonContentHeaderProperties { - private static final Logger _logger = Logger.getLogger(BasicContentHeaderProperties.class); + private static final Logger _logger = LoggerFactory.getLogger(BasicContentHeaderProperties.class); private static final AMQShortString ZERO_STRING = null; @@ -96,8 +97,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti private static final int CLUSTER_ID_MASK = 1 << 2; public BasicContentHeaderProperties() - { - } + { } public int getPropertyListSize() { @@ -113,30 +113,37 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti { size += EncodingUtils.encodedShortStringLength(_contentType); } + if ((_propertyFlags & ENCONDING_MASK) > 0) { size += EncodingUtils.encodedShortStringLength(_encoding); } + if ((_propertyFlags & HEADERS_MASK) > 0) { size += EncodingUtils.encodedFieldTableLength(_headers); } + if ((_propertyFlags & DELIVERY_MODE_MASK) > 0) { size += 1; } + if ((_propertyFlags & PROPRITY_MASK) > 0) { size += 1; } + if ((_propertyFlags & CORRELATION_ID_MASK) > 0) { size += EncodingUtils.encodedShortStringLength(_correlationId); } + if ((_propertyFlags & REPLY_TO_MASK) > 0) { size += EncodingUtils.encodedShortStringLength(_replyTo); } + if ((_propertyFlags & EXPIRATION_MASK) > 0) { if (_expiration == 0L) @@ -148,40 +155,48 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti size += EncodingUtils.encodedShortStringLength(_expiration); } } + if ((_propertyFlags & MESSAGE_ID_MASK) > 0) { size += EncodingUtils.encodedShortStringLength(_messageId); } + if ((_propertyFlags & TIMESTAMP_MASK) > 0) { size += 8; } + if ((_propertyFlags & TYPE_MASK) > 0) { size += EncodingUtils.encodedShortStringLength(_type); } + if ((_propertyFlags & USER_ID_MASK) > 0) { size += EncodingUtils.encodedShortStringLength(_userId); } + if ((_propertyFlags & APPLICATION_ID_MASK) > 0) { size += EncodingUtils.encodedShortStringLength(_appId); } + if ((_propertyFlags & CLUSTER_ID_MASK) > 0) { size += EncodingUtils.encodedShortStringLength(_clusterId); } + return size; } } private void clearEncodedForm() { - if (!_decoded && _encodedForm != null) + if (!_decoded && (_encodedForm != null)) { - //decode(); + // decode(); } + _encodedForm = null; } @@ -208,30 +223,37 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti { EncodingUtils.writeShortStringBytes(buffer, _contentType); } + if ((_propertyFlags & ENCONDING_MASK) != 0) { EncodingUtils.writeShortStringBytes(buffer, _encoding); } + if ((_propertyFlags & HEADERS_MASK) != 0) { EncodingUtils.writeFieldTableBytes(buffer, _headers); } + if ((_propertyFlags & DELIVERY_MODE_MASK) != 0) { buffer.put(_deliveryMode); } + if ((_propertyFlags & PROPRITY_MASK) != 0) { buffer.put(_priority); } + if ((_propertyFlags & CORRELATION_ID_MASK) != 0) { EncodingUtils.writeShortStringBytes(buffer, _correlationId); } + if ((_propertyFlags & REPLY_TO_MASK) != 0) { EncodingUtils.writeShortStringBytes(buffer, _replyTo); } + if ((_propertyFlags & EXPIRATION_MASK) != 0) { if (_expiration == 0L) @@ -243,26 +265,32 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti EncodingUtils.writeShortStringBytes(buffer, String.valueOf(_expiration)); } } + if ((_propertyFlags & MESSAGE_ID_MASK) != 0) { EncodingUtils.writeShortStringBytes(buffer, _messageId); } + if ((_propertyFlags & TIMESTAMP_MASK) != 0) { EncodingUtils.writeTimestamp(buffer, _timestamp); } + if ((_propertyFlags & TYPE_MASK) != 0) { EncodingUtils.writeShortStringBytes(buffer, _type); } + if ((_propertyFlags & USER_ID_MASK) != 0) { EncodingUtils.writeShortStringBytes(buffer, _userId); } + if ((_propertyFlags & APPLICATION_ID_MASK) != 0) { EncodingUtils.writeShortStringBytes(buffer, _appId); } + if ((_propertyFlags & CLUSTER_ID_MASK) != 0) { EncodingUtils.writeShortStringBytes(buffer, _clusterId); @@ -270,8 +298,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti } } - public void populatePropertiesFromBuffer(ByteBuffer buffer, int propertyFlags, int size) - throws AMQFrameDecodingException + public void populatePropertiesFromBuffer(ByteBuffer buffer, int propertyFlags, int size) throws AMQFrameDecodingException { _propertyFlags = propertyFlags; @@ -279,6 +306,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti { _logger.debug("Property flags: " + _propertyFlags); } + decode(buffer); /*_encodedForm = new byte[size]; buffer.get(_encodedForm, 0, size); @@ -289,7 +317,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti private void decode(ByteBuffer buffer) { - //ByteBuffer buffer = ByteBuffer.wrap(_encodedForm); + // ByteBuffer buffer = ByteBuffer.wrap(_encodedForm); int pos = buffer.position(); try { @@ -297,54 +325,67 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti { _contentType = EncodingUtils.readAMQShortString(buffer); } + if ((_propertyFlags & ENCONDING_MASK) != 0) { _encoding = EncodingUtils.readAMQShortString(buffer); } + if ((_propertyFlags & HEADERS_MASK) != 0) { _headers = EncodingUtils.readFieldTable(buffer); } + if ((_propertyFlags & DELIVERY_MODE_MASK) != 0) { _deliveryMode = buffer.get(); } + if ((_propertyFlags & PROPRITY_MASK) != 0) { _priority = buffer.get(); } + if ((_propertyFlags & CORRELATION_ID_MASK) != 0) { _correlationId = EncodingUtils.readAMQShortString(buffer); } + if ((_propertyFlags & REPLY_TO_MASK) != 0) { _replyTo = EncodingUtils.readAMQShortString(buffer); } + if ((_propertyFlags & EXPIRATION_MASK) != 0) { _expiration = EncodingUtils.readLongAsShortString(buffer); } + if ((_propertyFlags & MESSAGE_ID_MASK) != 0) { _messageId = EncodingUtils.readAMQShortString(buffer); } + if ((_propertyFlags & TIMESTAMP_MASK) != 0) { _timestamp = EncodingUtils.readTimestamp(buffer); } + if ((_propertyFlags & TYPE_MASK) != 0) { _type = EncodingUtils.readAMQShortString(buffer); } + if ((_propertyFlags & USER_ID_MASK) != 0) { _userId = EncodingUtils.readAMQShortString(buffer); } + if ((_propertyFlags & APPLICATION_ID_MASK) != 0) { _appId = EncodingUtils.readAMQShortString(buffer); } + if ((_propertyFlags & CLUSTER_ID_MASK) != 0) { _clusterId = EncodingUtils.readAMQShortString(buffer); @@ -367,7 +408,6 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti _decoded = true; } - private void decodeUpToHeaders() { ByteBuffer buffer = ByteBuffer.wrap(_encodedForm); @@ -378,16 +418,19 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti byte length = buffer.get(); buffer.skip(length); } + if ((_propertyFlags & ENCONDING_MASK) != 0) { byte length = buffer.get(); buffer.skip(length); } + if ((_propertyFlags & HEADERS_MASK) != 0) { _headers = EncodingUtils.readFieldTable(buffer); } + _decodedHeaders = true; } catch (AMQFrameDecodingException e) @@ -412,7 +455,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti { if (!_decoded) { - //decode(); + // decode(); } } @@ -435,14 +478,15 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti public AMQShortString getContentType() { decodeContentTypeIfNecessary(); + return _contentType; } - public String getContentTypeAsString() { decodeContentTypeIfNecessary(); - return _contentType == null ? null : _contentType.toString(); + + return (_contentType == null) ? null : _contentType.toString(); } public void setContentType(AMQShortString contentType) @@ -452,21 +496,21 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti _contentType = contentType; } - public void setContentType(String contentType) { - setContentType(contentType == null ? null : new AMQShortString(contentType)); + setContentType((contentType == null) ? null : new AMQShortString(contentType)); } public String getEncodingAsString() { - return getEncoding() == null ? null : getEncoding().toString(); + return (getEncoding() == null) ? null : getEncoding().toString(); } public AMQShortString getEncoding() { decodeIfNecessary(); + return _encoding; } @@ -474,7 +518,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti { clearEncodedForm(); _propertyFlags |= ENCONDING_MASK; - _encoding = encoding == null ? null : new AMQShortString(encoding); + _encoding = (encoding == null) ? null : new AMQShortString(encoding); } public void setEncoding(AMQShortString encoding) @@ -484,7 +528,6 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti _encoding = encoding; } - public FieldTable getHeaders() { decodeHeadersIfNecessary(); @@ -504,10 +547,10 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti _headers = headers; } - public byte getDeliveryMode() { decodeIfNecessary(); + return _deliveryMode; } @@ -521,6 +564,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti public byte getPriority() { decodeIfNecessary(); + return _priority; } @@ -534,18 +578,20 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti public AMQShortString getCorrelationId() { decodeIfNecessary(); + return _correlationId; } public String getCorrelationIdAsString() { decodeIfNecessary(); - return _correlationId == null ? null : _correlationId.toString(); + + return (_correlationId == null) ? null : _correlationId.toString(); } public void setCorrelationId(String correlationId) { - setCorrelationId(correlationId == null ? null : new AMQShortString(correlationId)); + setCorrelationId((correlationId == null) ? null : new AMQShortString(correlationId)); } public void setCorrelationId(AMQShortString correlationId) @@ -558,19 +604,20 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti public String getReplyToAsString() { decodeIfNecessary(); - return _replyTo == null ? null : _replyTo.toString(); + + return (_replyTo == null) ? null : _replyTo.toString(); } public AMQShortString getReplyTo() { decodeIfNecessary(); + return _replyTo; } - public void setReplyTo(String replyTo) { - setReplyTo(replyTo == null ? null : new AMQShortString(replyTo)); + setReplyTo((replyTo == null) ? null : new AMQShortString(replyTo)); } public void setReplyTo(AMQShortString replyTo) @@ -584,6 +631,7 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti public long getExpiration() { decodeIfNecessary(); + return _expiration; } @@ -594,24 +642,25 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti _expiration = expiration; } - public AMQShortString getMessageId() { decodeIfNecessary(); + return _messageId; } public String getMessageIdAsString() { decodeIfNecessary(); - return _messageId == null ? null : _messageId.toString(); + + return (_messageId == null) ? null : _messageId.toString(); } public void setMessageId(String messageId) { clearEncodedForm(); _propertyFlags |= MESSAGE_ID_MASK; - _messageId = messageId == null ? null : new AMQShortString(messageId); + _messageId = (messageId == null) ? null : new AMQShortString(messageId); } public void setMessageId(AMQShortString messageId) @@ -621,10 +670,10 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti _messageId = messageId; } - public long getTimestamp() { decodeIfNecessary(); + return _timestamp; } @@ -638,20 +687,20 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti public String getTypeAsString() { decodeIfNecessary(); - return _type == null ? null : _type.toString(); - } + return (_type == null) ? null : _type.toString(); + } public AMQShortString getType() { decodeIfNecessary(); + return _type; } - public void setType(String type) { - setType(type == null ? null : new AMQShortString(type)); + setType((type == null) ? null : new AMQShortString(type)); } public void setType(AMQShortString type) @@ -664,18 +713,20 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti public String getUserIdAsString() { decodeIfNecessary(); - return _userId == null ? null : _userId.toString(); + + return (_userId == null) ? null : _userId.toString(); } public AMQShortString getUserId() { decodeIfNecessary(); + return _userId; } public void setUserId(String userId) { - setUserId(userId == null ? null : new AMQShortString(userId)); + setUserId((userId == null) ? null : new AMQShortString(userId)); } public void setUserId(AMQShortString userId) @@ -688,18 +739,20 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti public String getAppIdAsString() { decodeIfNecessary(); - return _appId == null ? null : _appId.toString(); + + return (_appId == null) ? null : _appId.toString(); } public AMQShortString getAppId() { decodeIfNecessary(); + return _appId; } public void setAppId(String appId) { - setAppId(appId == null ? null : new AMQShortString(appId)); + setAppId((appId == null) ? null : new AMQShortString(appId)); } public void setAppId(AMQShortString appId) @@ -712,18 +765,20 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti public String getClusterIdAsString() { decodeIfNecessary(); - return _clusterId == null ? null : _clusterId.toString(); + + return (_clusterId == null) ? null : _clusterId.toString(); } public AMQShortString getClusterId() { decodeIfNecessary(); + return _clusterId; } public void setClusterId(String clusterId) { - setClusterId(clusterId == null ? null : new AMQShortString(clusterId)); + setClusterId((clusterId == null) ? null : new AMQShortString(clusterId)); } public void setClusterId(AMQShortString clusterId) @@ -735,19 +790,10 @@ public class BasicContentHeaderProperties implements CommonContentHeaderProperti public String toString() { - return "reply-to = " + _replyTo + - ",propertyFlags = " + _propertyFlags + - ",ApplicationID = " + _appId + - ",ClusterID = " + _clusterId + - ",UserId = " + _userId + - ",JMSMessageID = " + _messageId + - ",JMSCorrelationID = " + _correlationId + - ",JMSDeliveryMode = " + _deliveryMode + - ",JMSExpiration = " + _expiration + - ",JMSPriority = " + _priority + - ",JMSTimestamp = " + _timestamp + - ",JMSType = " + _type; + return "reply-to = " + _replyTo + ",propertyFlags = " + _propertyFlags + ",ApplicationID = " + _appId + + ",ClusterID = " + _clusterId + ",UserId = " + _userId + ",JMSMessageID = " + _messageId + + ",JMSCorrelationID = " + _correlationId + ",JMSDeliveryMode = " + _deliveryMode + ",JMSExpiration = " + + _expiration + ",JMSPriority = " + _priority + ",JMSTimestamp = " + _timestamp + ",JMSType = " + _type; } - } diff --git a/java/common/src/main/java/org/apache/qpid/framing/CommonContentHeaderProperties.java b/java/common/src/main/java/org/apache/qpid/framing/CommonContentHeaderProperties.java index 1641cbf4e8..66c5e19633 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/CommonContentHeaderProperties.java +++ b/java/common/src/main/java/org/apache/qpid/framing/CommonContentHeaderProperties.java @@ -1,12 +1,7 @@ package org.apache.qpid.framing;
-import org.apache.mina.common.ByteBuffer;
-
-import org.apache.log4j.Logger;
-
public interface CommonContentHeaderProperties extends ContentHeaderProperties
{
-
AMQShortString getContentType();
void setContentType(AMQShortString contentType);
diff --git a/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java b/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java index 5636229d53..c42995d148 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java +++ b/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.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,14 @@ */ package org.apache.qpid.framing; -import org.apache.log4j.Logger; import org.apache.mina.common.ByteBuffer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class ContentBodyFactory implements BodyFactory { - private static final Logger _log = Logger.getLogger(AMQMethodBodyFactory.class); + private static final Logger _log = LoggerFactory.getLogger(AMQMethodBodyFactory.class); private static final ContentBodyFactory _instance = new ContentBodyFactory(); @@ -44,4 +46,3 @@ public class ContentBodyFactory implements BodyFactory return new ContentBody(in, bodySize); } } - diff --git a/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java b/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java index 818fc9cf0c..8d5e2f9fb4 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java +++ b/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.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,14 @@ */ package org.apache.qpid.framing; -import org.apache.log4j.Logger; import org.apache.mina.common.ByteBuffer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class ContentHeaderBodyFactory implements BodyFactory { - private static final Logger _log = Logger.getLogger(AMQMethodBodyFactory.class); + private static final Logger _log = LoggerFactory.getLogger(AMQMethodBodyFactory.class); private static final ContentHeaderBodyFactory _instance = new ContentHeaderBodyFactory(); @@ -43,8 +45,6 @@ public class ContentHeaderBodyFactory implements BodyFactory { // all content headers are the same - it is only the properties that differ. // the content header body further delegates construction of properties - return new ContentHeaderBody(in,bodySize); + return new ContentHeaderBody(in, bodySize); } - - } 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 62fefdc2fc..ccba8bd41e 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 @@ -20,15 +20,16 @@ */ package org.apache.qpid.framing; -import java.nio.charset.Charset; +import org.apache.mina.common.ByteBuffer; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import org.apache.mina.common.ByteBuffer; +import java.nio.charset.Charset; public class EncodingUtils { - private static final Logger _logger = Logger.getLogger(EncodingUtils.class); + private static final Logger _logger = LoggerFactory.getLogger(EncodingUtils.class); private static final String STRING_ENCODING = "iso8859-15"; @@ -1024,6 +1025,4 @@ public class EncodingUtils return l; } - - } diff --git a/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java b/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java index 34415777be..2fe96b722b 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java +++ b/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java @@ -20,6 +20,14 @@ */ package org.apache.qpid.framing; +import org.apache.mina.common.ByteBuffer; + +import org.apache.qpid.AMQPInvalidClassException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.math.BigDecimal; import java.util.Collections; import java.util.Enumeration; import java.util.Iterator; @@ -27,18 +35,13 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; -import java.math.BigDecimal; -import org.apache.log4j.Logger; -import org.apache.mina.common.ByteBuffer; -import org.apache.qpid.AMQPInvalidClassException; - -//extends FieldTable +// extends FieldTable public class FieldTable { - private static final Logger _logger = Logger.getLogger(FieldTable.class); + private static final Logger _logger = LoggerFactory.getLogger(FieldTable.class); private static final String STRICT_AMQP = "STRICT_AMQP"; - private final boolean _strictAMQP = Boolean.valueOf(System.getProperty(STRICT_AMQP,"false")); + private final boolean _strictAMQP = Boolean.valueOf(System.getProperty(STRICT_AMQP, "false")); private ByteBuffer _encodedForm; private LinkedHashMap<AMQShortString, AMQTypedValue> _properties; @@ -49,9 +52,9 @@ public class FieldTable public FieldTable() { super(); -// _encodedForm = ByteBuffer.allocate(INITIAL_ENCODED_FORM_SIZE); -// _encodedForm.setAutoExpand(true); -// _encodedForm.limit(0); + // _encodedForm = ByteBuffer.allocate(INITIAL_ENCODED_FORM_SIZE); + // _encodedForm.setAutoExpand(true); + // _encodedForm.limit(0); } /** @@ -71,7 +74,6 @@ public class FieldTable buffer.skip((int) length); } - private AMQTypedValue getProperty(AMQShortString string) { checkPropertyName(string); @@ -114,7 +116,6 @@ public class FieldTable } } - private AMQTypedValue setProperty(AMQShortString key, AMQTypedValue val) { checkPropertyName(key); @@ -128,7 +129,7 @@ public class FieldTable return removeKey(key); } } - else if (_encodedForm != null && val != null) + else if ((_encodedForm != null) && (val != null)) { EncodingUtils.writeShortStringBytes(_encodedForm, key); val.writeToBuffer(_encodedForm); @@ -139,7 +140,6 @@ public class FieldTable return null; } - AMQTypedValue oldVal = _properties.put(key, val); if (oldVal != null) { @@ -149,6 +149,7 @@ public class FieldTable { _encodedSize += EncodingUtils.encodedShortStringLength(key) + 1; } + _encodedSize += val.getEncodingSize(); return oldVal; @@ -160,7 +161,7 @@ public class FieldTable { if (_properties == null) { - if (_encodedForm == null || _encodedSize == 0) + if ((_encodedForm == null) || (_encodedSize == 0)) { _properties = new LinkedHashMap<AMQShortString, AMQTypedValue>(); } @@ -173,7 +174,6 @@ public class FieldTable } } - public Boolean getBoolean(String string) { return getBoolean(new AMQShortString(string)); @@ -182,7 +182,7 @@ public class FieldTable public Boolean getBoolean(AMQShortString string) { AMQTypedValue value = getProperty(string); - if (value != null && (value.getType() == AMQType.BOOLEAN)) + if ((value != null) && (value.getType() == AMQType.BOOLEAN)) { return (Boolean) value.getValue(); } @@ -192,7 +192,6 @@ public class FieldTable } } - public Byte getByte(String string) { return getByte(new AMQShortString(string)); @@ -201,7 +200,7 @@ public class FieldTable public Byte getByte(AMQShortString string) { AMQTypedValue value = getProperty(string); - if (value != null && (value.getType() == AMQType.BYTE)) + if ((value != null) && (value.getType() == AMQType.BYTE)) { return (Byte) value.getValue(); } @@ -219,7 +218,7 @@ public class FieldTable public Short getShort(AMQShortString string) { AMQTypedValue value = getProperty(string); - if (value != null && (value.getType() == AMQType.SHORT)) + if ((value != null) && (value.getType() == AMQType.SHORT)) { return (Short) value.getValue(); } @@ -237,7 +236,7 @@ public class FieldTable public Integer getInteger(AMQShortString string) { AMQTypedValue value = getProperty(string); - if (value != null && (value.getType() == AMQType.INT)) + if ((value != null) && (value.getType() == AMQType.INT)) { return (Integer) value.getValue(); } @@ -255,7 +254,7 @@ public class FieldTable public Long getLong(AMQShortString string) { AMQTypedValue value = getProperty(string); - if (value != null && (value.getType() == AMQType.LONG)) + if ((value != null) && (value.getType() == AMQType.LONG)) { return (Long) value.getValue(); } @@ -273,7 +272,7 @@ public class FieldTable public Float getFloat(AMQShortString string) { AMQTypedValue value = getProperty(string); - if (value != null && (value.getType() == AMQType.FLOAT)) + if ((value != null) && (value.getType() == AMQType.FLOAT)) { return (Float) value.getValue(); } @@ -291,7 +290,7 @@ public class FieldTable public Double getDouble(AMQShortString string) { AMQTypedValue value = getProperty(string); - if (value != null && (value.getType() == AMQType.DOUBLE)) + if ((value != null) && (value.getType() == AMQType.DOUBLE)) { return (Double) value.getValue(); } @@ -309,12 +308,10 @@ public class FieldTable public String getString(AMQShortString string) { AMQTypedValue value = getProperty(string); - if ((value != null) && ((value.getType() == AMQType.WIDE_STRING) || - (value.getType() == AMQType.ASCII_STRING))) + if ((value != null) && ((value.getType() == AMQType.WIDE_STRING) || (value.getType() == AMQType.ASCII_STRING))) { return (String) value.getValue(); } - else if ((value != null) && (value.getValue() != null) && !(value.getValue() instanceof byte[])) { return String.valueOf(value.getValue()); @@ -334,7 +331,7 @@ public class FieldTable public Character getCharacter(AMQShortString string) { AMQTypedValue value = getProperty(string); - if (value != null && (value.getType() == AMQType.ASCII_CHARACTER)) + if ((value != null) && (value.getType() == AMQType.ASCII_CHARACTER)) { return (Character) value.getValue(); } @@ -352,7 +349,7 @@ public class FieldTable public byte[] getBytes(AMQShortString string) { AMQTypedValue value = getProperty(string); - if (value != null && (value.getType() == AMQType.BINARY)) + if ((value != null) && (value.getType() == AMQType.BINARY)) { return (byte[]) value.getValue(); } @@ -384,7 +381,7 @@ public class FieldTable public Long getTimestamp(AMQShortString name) { AMQTypedValue value = getProperty(name); - if ((value != null) && ((value.getType() == AMQType.TIMESTAMP))) + if ((value != null) && (value.getType() == AMQType.TIMESTAMP)) { return (Long) value.getValue(); } @@ -397,7 +394,7 @@ public class FieldTable public BigDecimal getDecimal(AMQShortString propertyName) { AMQTypedValue value = getProperty(propertyName); - if ((value != null) && ((value.getType() == AMQType.DECIMAL))) + if ((value != null) && (value.getType() == AMQType.DECIMAL)) { return (BigDecimal) value.getValue(); } @@ -407,7 +404,6 @@ public class FieldTable } } - // ************ Setters public Object setBoolean(String string, Boolean b) { @@ -439,7 +435,6 @@ public class FieldTable return setProperty(string, AMQType.SHORT.asTypedValue(i)); } - public Object setInteger(String string, Integer i) { return setInteger(new AMQShortString(string), i); @@ -450,7 +445,6 @@ public class FieldTable return setProperty(string, AMQType.INT.asTypedValue(i)); } - public Object setLong(String string, Long l) { return setLong(new AMQShortString(string), l); @@ -539,6 +533,7 @@ public class FieldTable { byte[] newBytes = new byte[length]; System.arraycopy(bytes, start, newBytes, 0, length); + return setBytes(string, bytes); } @@ -562,7 +557,7 @@ public class FieldTable if (decimal.scale() > Byte.MAX_VALUE) { throw new UnsupportedOperationException("AMQP doesnot support decimal scales larger than " + Byte.MAX_VALUE); - } + } return setProperty(string, AMQType.DECIMAL.asTypedValue(decimal)); } @@ -621,6 +616,7 @@ public class FieldTable public boolean isNullStringValue(String name) { AMQTypedValue value = getProperty(new AMQShortString(name)); + return (value != null) && (value.getType() == AMQType.VOID); } @@ -645,6 +641,7 @@ public class FieldTable { checkPropertyName(propertyName); initMapIfNecessary(); + return _properties.containsKey(propertyName); } @@ -656,6 +653,7 @@ public class FieldTable public String toString() { initMapIfNecessary(); + return _properties.toString(); } @@ -670,7 +668,7 @@ public class FieldTable throw new IllegalArgumentException("Property name must not be the empty string"); } - if(_strictAMQP) + if (_strictAMQP) { checkIdentiferFormat(propertyName); } @@ -678,15 +676,15 @@ public class FieldTable protected static void checkIdentiferFormat(AMQShortString propertyName) { -// AMQP Spec: 4.2.5.5 Field Tables -// Guidelines for implementers: -// * Field names MUST start with a letter, '$' or '#' and may continue with -// letters, '$' or '#', digits, or underlines, to a maximum length of 128 -// characters. -// * The server SHOULD validate field names and upon receiving an invalid -// field name, it SHOULD signal a connection exception with reply code -// 503 (syntax error). Conformance test: amq_wlp_table_01. -// * A peer MUST handle duplicate fields by using only the first instance. + // AMQP Spec: 4.2.5.5 Field Tables + // Guidelines for implementers: + // * Field names MUST start with a letter, '$' or '#' and may continue with + // letters, '$' or '#', digits, or underlines, to a maximum length of 128 + // characters. + // * The server SHOULD validate field names and upon receiving an invalid + // field name, it SHOULD signal a connection exception with reply code + // 503 (syntax error). Conformance test: amq_wlp_table_01. + // * A peer MUST handle duplicate fields by using only the first instance. // AMQP length limit if (propertyName.length() > 128) @@ -695,12 +693,11 @@ public class FieldTable } // AMQ start character - if (!(Character.isLetter(propertyName.charAt(0)) - || propertyName.charAt(0) == '$' - || propertyName.charAt(0) == '#' - || propertyName.charAt(0) == '_')) // Not official AMQP added for JMS. + if (!(Character.isLetter(propertyName.charAt(0)) || (propertyName.charAt(0) == '$') + || (propertyName.charAt(0) == '#') || (propertyName.charAt(0) == '_'))) // Not official AMQP added for JMS. { - throw new IllegalArgumentException("Identifier '" + propertyName + "' does not start with a valid AMQP start character"); + throw new IllegalArgumentException("Identifier '" + propertyName + + "' does not start with a valid AMQP start character"); } } @@ -713,7 +710,7 @@ public class FieldTable if (trace) { _logger.trace("FieldTable::writeToBuffer: Writing encoded length of " + getEncodedSize() + "..."); - _logger.trace(_properties); + _logger.trace(_properties.toString()); } EncodingUtils.writeUnsignedInteger(buffer, getEncodedSize()); @@ -732,6 +729,7 @@ public class FieldTable buffer.flip(); buffer.get(result); buffer.release(); + return result; } @@ -754,6 +752,7 @@ public class FieldTable } } + _encodedSize = encodedSize; } @@ -765,7 +764,6 @@ public class FieldTable recalculateEncodedSize(); } - public static interface FieldTableElementProcessor { public boolean processElement(String propertyName, AMQTypedValue value); @@ -787,15 +785,15 @@ public class FieldTable } } } - return processor.getResult(); + return processor.getResult(); } - public int size() { initMapIfNecessary(); + return _properties.size(); } @@ -808,6 +806,7 @@ public class FieldTable public boolean containsKey(AMQShortString key) { initMapIfNecessary(); + return _properties.containsKey(key); } @@ -824,23 +823,21 @@ public class FieldTable { keys.add(key.toString()); } + return keys; } - public Object get(AMQShortString key) { return getObject(key); } - public Object put(AMQShortString key, Object value) { return setObject(key, value); } - public Object remove(String key) { @@ -851,10 +848,10 @@ public class FieldTable public Object remove(AMQShortString key) { AMQTypedValue val = removeKey(key); - return val == null ? null : val.getValue(); - } + return (val == null) ? null : val.getValue(); + } public AMQTypedValue removeKey(AMQShortString key) { @@ -870,12 +867,12 @@ public class FieldTable _encodedSize -= EncodingUtils.encodedShortStringLength(key); _encodedSize--; _encodedSize -= value.getEncodingSize(); + return value; } } - public void clear() { initMapIfNecessary(); @@ -887,6 +884,7 @@ public class FieldTable public Set<AMQShortString> keySet() { initMapIfNecessary(); + return _properties.keySet(); } @@ -900,17 +898,17 @@ public class FieldTable { _encodedForm.flip(); } -// _encodedForm.limit((int)getEncodedSize()); + // _encodedForm.limit((int)getEncodedSize()); + buffer.put(_encodedForm); } else if (_properties != null) { final Iterator<Map.Entry<AMQShortString, AMQTypedValue>> it = _properties.entrySet().iterator(); - //If there are values then write out the encoded Size... could check _encodedSize != 0 + // If there are values then write out the encoded Size... could check _encodedSize != 0 // write out the total length, which we have kept up to date as data is added - while (it.hasNext()) { final Map.Entry<AMQShortString, AMQTypedValue> me = it.next(); @@ -918,14 +916,12 @@ public class FieldTable { if (_logger.isTraceEnabled()) { - _logger.trace("Writing Property:" + me.getKey() + - " Type:" + me.getValue().getType() + - " Value:" + me.getValue().getValue()); - _logger.trace("Buffer Position:" + buffer.position() + - " Remaining:" + buffer.remaining()); + _logger.trace("Writing Property:" + me.getKey() + " Type:" + me.getValue().getType() + " Value:" + + me.getValue().getValue()); + _logger.trace("Buffer Position:" + buffer.position() + " Remaining:" + buffer.remaining()); } - //Write the actual parameter name + // Write the actual parameter name EncodingUtils.writeShortStringBytes(buffer, me.getKey()); me.getValue().writeToBuffer(buffer); } @@ -934,19 +930,17 @@ public class FieldTable if (_logger.isTraceEnabled()) { _logger.trace("Exception thrown:" + e); - _logger.trace("Writing Property:" + me.getKey() + - " Type:" + me.getValue().getType() + - " Value:" + me.getValue().getValue()); - _logger.trace("Buffer Position:" + buffer.position() + - " Remaining:" + buffer.remaining()); + _logger.trace("Writing Property:" + me.getKey() + " Type:" + me.getValue().getType() + " Value:" + + me.getValue().getValue()); + _logger.trace("Buffer Position:" + buffer.position() + " Remaining:" + buffer.remaining()); } + throw new RuntimeException(e); } } } } - private void setFromBuffer(ByteBuffer buffer, long length) throws AMQFrameDecodingException { @@ -966,17 +960,17 @@ public class FieldTable if (trace) { - _logger.trace("FieldTable::PropFieldTable(buffer," + length + "): Read type '" + value.getType() + "', key '" + key + "', value '" + value.getValue() + "'"); + _logger.trace("FieldTable::PropFieldTable(buffer," + length + "): Read type '" + value.getType() + + "', key '" + key + "', value '" + value.getValue() + "'"); } - _properties.put(key, value); - } while (buffer.remaining() > expectedRemaining); } + _encodedSize = length; if (trace) @@ -988,20 +982,22 @@ public class FieldTable public int hashCode() { initMapIfNecessary(); + return _properties.hashCode(); } - public boolean equals(Object o) { if (o == this) { return true; } + if (o == null) { return false; } + if (!(o instanceof FieldTable)) { return false; diff --git a/java/common/src/main/java/org/apache/qpid/framing/VersionSpecificRegistry.java b/java/common/src/main/java/org/apache/qpid/framing/VersionSpecificRegistry.java index 916b476185..6006e9793c 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/VersionSpecificRegistry.java +++ b/java/common/src/main/java/org/apache/qpid/framing/VersionSpecificRegistry.java @@ -20,15 +20,16 @@ */
package org.apache.qpid.framing;
-import org.apache.log4j.Logger;
-
import org.apache.mina.common.ByteBuffer;
import org.apache.qpid.framing.abstraction.ProtocolVersionMethodConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class VersionSpecificRegistry
{
- private static final Logger _log = Logger.getLogger(VersionSpecificRegistry.class);
+ private static final Logger _log = LoggerFactory.getLogger(VersionSpecificRegistry.class);
private final byte _protocolMajorVersion;
private final byte _protocolMinorVersion;
@@ -152,16 +153,17 @@ public class VersionSpecificRegistry }
catch (NullPointerException e)
{
- throw new AMQFrameDecodingException(null, "Class " + classID + " unknown in AMQP version " + _protocolMajorVersion
- + "-" + _protocolMinorVersion + " (while trying to decode class " + classID + " method " + methodID + ".", e);
+ throw new AMQFrameDecodingException(null, "Class " + classID + " unknown in AMQP version "
+ + _protocolMajorVersion + "-" + _protocolMinorVersion + " (while trying to decode class " + classID
+ + " method " + methodID + ".", e);
}
catch (IndexOutOfBoundsException e)
{
if (classID >= _registry.length)
{
- throw new AMQFrameDecodingException(null, "Class " + classID + " unknown in AMQP version " + _protocolMajorVersion
- + "-" + _protocolMinorVersion + " (while trying to decode class " + classID + " method " + methodID
- + ".", e);
+ throw new AMQFrameDecodingException(null, "Class " + classID + " unknown in AMQP version "
+ + _protocolMajorVersion + "-" + _protocolMinorVersion + " (while trying to decode class " + classID
+ + " method " + methodID + ".", e);
}
else
@@ -175,8 +177,9 @@ public class VersionSpecificRegistry if (bodyFactory == null)
{
- throw new AMQFrameDecodingException(null, "Method " + methodID + " unknown in AMQP version " + _protocolMajorVersion
- + "-" + _protocolMinorVersion + " (while trying to decode class " + classID + " method " + methodID + ".", null);
+ throw new AMQFrameDecodingException(null, "Method " + methodID + " unknown in AMQP version "
+ + _protocolMajorVersion + "-" + _protocolMinorVersion + " (while trying to decode class " + classID
+ + " method " + methodID + ".", null);
}
return bodyFactory.newInstance(_protocolMajorVersion, _protocolMinorVersion, classID, methodID, in, size);
diff --git a/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java b/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java index 7d3dfbee81..cbe08a192e 100644 --- a/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java +++ b/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java @@ -20,17 +20,18 @@ */ package org.apache.qpid.pool; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import org.apache.log4j.Logger; - import org.apache.mina.common.IdleStatus; import org.apache.mina.common.IoFilterAdapter; import org.apache.mina.common.IoSession; import org.apache.qpid.pool.Event.CloseEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + /** * PoolingFilter, is a no-op pass through filter that hands all events down the Mina filter chain by default. As it * adds no behaviour by default to the filter chain, it is abstract. @@ -81,7 +82,7 @@ import org.apache.qpid.pool.Event.CloseEvent; public abstract class PoolingFilter extends IoFilterAdapter implements Job.JobCompletionHandler { /** Used for debugging purposes. */ - private static final Logger _logger = Logger.getLogger(PoolingFilter.class); + private static final Logger _logger = LoggerFactory.getLogger(PoolingFilter.class); /** Holds a mapping from Mina sessions to batched jobs for execution. */ private final ConcurrentMap<IoSession, Job> _jobs = new ConcurrentHashMap<IoSession, Job>(); 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 353c0d39c2..1774fa1194 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 @@ -20,18 +20,19 @@ */ package org.apache.qpid.url; +import org.apache.qpid.exchange.ExchangeDefaults; +import org.apache.qpid.framing.AMQShortString; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + 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; - public class AMQBindingURL implements BindingURL { - private static final Logger _logger = Logger.getLogger(AMQBindingURL.class); + private static final Logger _logger = LoggerFactory.getLogger(AMQBindingURL.class); String _url; AMQShortString _exchangeClass; diff --git a/java/common/src/main/java/org/apache/qpid/util/ConcurrentLinkedMessageQueueAtomicSize.java b/java/common/src/main/java/org/apache/qpid/util/ConcurrentLinkedMessageQueueAtomicSize.java index 4636f44795..461cf9591d 100644 --- a/java/common/src/main/java/org/apache/qpid/util/ConcurrentLinkedMessageQueueAtomicSize.java +++ b/java/common/src/main/java/org/apache/qpid/util/ConcurrentLinkedMessageQueueAtomicSize.java @@ -14,22 +14,23 @@ * "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. + * under the License. + * * - * */ package org.apache.qpid.util; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.util.Queue; import java.util.Collection; import java.util.Iterator; +import java.util.Queue; import java.util.concurrent.atomic.AtomicInteger; public class ConcurrentLinkedMessageQueueAtomicSize<E> extends ConcurrentLinkedQueueAtomicSize<E> implements MessageQueue<E> { - private static final Logger _logger = Logger.getLogger(ConcurrentLinkedMessageQueueAtomicSize.class); + private static final Logger _logger = LoggerFactory.getLogger(ConcurrentLinkedMessageQueueAtomicSize.class); protected Queue<E> _messageHead = new ConcurrentLinkedQueueAtomicSize<E>(); @@ -62,7 +63,6 @@ public class ConcurrentLinkedMessageQueueAtomicSize<E> extends ConcurrentLinkedQ _logger.debug("Providing item(" + e + ")from message head"); } - if (e != null) { _messageHeadSize.decrementAndGet(); @@ -85,6 +85,7 @@ public class ConcurrentLinkedMessageQueueAtomicSize<E> extends ConcurrentLinkedQ if (_messageHead.remove(o)) { _messageHeadSize.decrementAndGet(); + return true; } @@ -101,26 +102,25 @@ public class ConcurrentLinkedMessageQueueAtomicSize<E> extends ConcurrentLinkedQ } else { - //fixme this is super.removeAll but iterator here doesn't work + // fixme this is super.removeAll but iterator here doesn't work // we need to be able to correctly decrement _messageHeadSize -// boolean modified = false; -// Iterator<?> e = iterator(); -// while (e.hasNext()) -// { -// if (c.contains(e.next())) -// { -// e.remove(); -// modified = true; -// _size.decrementAndGet(); -// } -// } -// return modified; + // boolean modified = false; + // Iterator<?> e = iterator(); + // while (e.hasNext()) + // { + // if (c.contains(e.next())) + // { + // e.remove(); + // modified = true; + // _size.decrementAndGet(); + // } + // } + // return modified; throw new RuntimeException("Not implemented"); } } - @Override public boolean isEmpty() { @@ -173,6 +173,7 @@ public class ConcurrentLinkedMessageQueueAtomicSize<E> extends ConcurrentLinkedQ { _logger.debug("Peeking item (" + o + ") from message head"); } + return o; } @@ -182,36 +183,40 @@ public class ConcurrentLinkedMessageQueueAtomicSize<E> extends ConcurrentLinkedQ public Iterator<E> iterator() { final Iterator<E> mainMessageIterator = super.iterator(); + return new Iterator<E>() - { - final Iterator<E> _headIterator = _messageHead.iterator(); - final Iterator<E> _mainIterator = mainMessageIterator; + { + final Iterator<E> _headIterator = _messageHead.iterator(); + final Iterator<E> _mainIterator = mainMessageIterator; - Iterator<E> last; + Iterator<E> last; - public boolean hasNext() - { - return _headIterator.hasNext() || _mainIterator.hasNext(); - } + public boolean hasNext() + { + return _headIterator.hasNext() || _mainIterator.hasNext(); + } - public E next() - { - if (_headIterator.hasNext()) + public E next() { - last = _headIterator; - return _headIterator.next(); + if (_headIterator.hasNext()) + { + last = _headIterator; + + return _headIterator.next(); + } + else + { + last = _mainIterator; + + return _mainIterator.next(); + } } - else + + public void remove() { - last = _mainIterator; - return _mainIterator.next(); + last.remove(); } - } - public void remove() - { - last.remove(); - } - }; + }; } @Override @@ -232,11 +237,14 @@ public class ConcurrentLinkedMessageQueueAtomicSize<E> extends ConcurrentLinkedQ { _logger.debug("Adding item(" + o + ") to head of queue"); } + if (_messageHead.offer(o)) { _messageHeadSize.incrementAndGet(); + return true; } + return false; } -}
\ No newline at end of file +} diff --git a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java index 3c8d3f916b..3b8ebc1666 100644 --- a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java +++ b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java @@ -22,8 +22,6 @@ package org.apache.qpid.util; import java.io.*;
-import org.apache.log4j.Logger;
-
/**
* FileUtils provides some simple helper methods for working with files. It follows the convention of wrapping all
* checked exceptions as runtimes, so code using these methods is free of try-catch blocks but does not expect to
diff --git a/java/common/src/main/java/org/apache/qpid/util/PropertiesUtils.java b/java/common/src/main/java/org/apache/qpid/util/PropertiesUtils.java index aa21841256..63cf6f252b 100644 --- a/java/common/src/main/java/org/apache/qpid/util/PropertiesUtils.java +++ b/java/common/src/main/java/org/apache/qpid/util/PropertiesUtils.java @@ -20,6 +20,9 @@ */
package org.apache.qpid.util;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -28,8 +31,6 @@ import java.net.URL; import java.util.Iterator;
import java.util.Properties;
-import org.apache.log4j.Logger;
-
/**
* PropertiesHelper defines some static methods which are useful when working with properties
* files.
@@ -46,7 +47,7 @@ import org.apache.log4j.Logger; public class PropertiesUtils
{
/** Used for logging. */
- private static final Logger log = Logger.getLogger(PropertiesUtils.class);
+ private static final Logger log = LoggerFactory.getLogger(PropertiesUtils.class);
/**
* Get properties from an input stream.
diff --git a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java index 38a2ae6256..e63b0df770 100644 --- a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java +++ b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java @@ -14,27 +14,25 @@ * "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. + * under the License. + * * - * */ package org.apache.qpid.framing; import junit.framework.Assert; import junit.framework.TestCase; -import java.util.Enumeration; -import java.util.Iterator; - import org.apache.mina.common.ByteBuffer; -import org.apache.log4j.Logger; + import org.apache.qpid.AMQPInvalidClassException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class PropertyFieldTableTest extends TestCase { - - private static final Logger _logger = Logger.getLogger(PropertyFieldTableTest.class); - + private static final Logger _logger = LoggerFactory.getLogger(PropertyFieldTableTest.class); /** * Test that setting a similar named value replaces any previous value set on that name @@ -42,9 +40,9 @@ public class PropertyFieldTableTest extends TestCase public void testReplacement() { FieldTable table1 = new FieldTable(); - //Set a boolean value + // Set a boolean value table1.setBoolean("value", true); - //Check length of table is correct (<Value length> + <type> + <Boolean length>) + // Check length of table is correct (<Value length> + <type> + <Boolean length>) int size = EncodingUtils.encodedShortStringLength("value") + 1 + EncodingUtils.encodedBooleanLength(); Assert.assertEquals(size, table1.getEncodedSize()); @@ -55,13 +53,12 @@ public class PropertyFieldTableTest extends TestCase size = EncodingUtils.encodedShortStringLength("value") + 1 + EncodingUtils.encodedIntegerLength(); Assert.assertEquals(size, table1.getEncodedSize()); - //Check boolean value is null + // Check boolean value is null Assert.assertEquals(null, table1.getBoolean("value")); // ... and integer value is good Assert.assertEquals((Integer) Integer.MAX_VALUE, table1.getInteger("value")); } - /** * Set a boolean and check that we can only get it back as a boolean and a string * Check that attempting to lookup a non existent value returns null @@ -72,10 +69,10 @@ public class PropertyFieldTableTest extends TestCase table1.setBoolean("value", true); Assert.assertTrue(table1.propertyExists("value")); - //Test Getting right value back + // Test Getting right value back Assert.assertEquals((Boolean) true, table1.getBoolean("value")); - //Check we don't get anything back for other gets + // Check we don't get anything back for other gets Assert.assertEquals(null, table1.getByte("value")); Assert.assertEquals(null, table1.getByte("value")); Assert.assertEquals(null, table1.getShort("value")); @@ -86,7 +83,7 @@ public class PropertyFieldTableTest extends TestCase Assert.assertEquals(null, table1.getLong("value")); Assert.assertEquals(null, table1.getBytes("value")); - //except value as a string + // except value as a string Assert.assertEquals("true", table1.getString("value")); table1.remove("value"); @@ -94,7 +91,7 @@ public class PropertyFieldTableTest extends TestCase // Table should now have zero length for encoding checkEmpty(table1); - //Looking up an invalid value returns null + // Looking up an invalid value returns null Assert.assertEquals(null, table1.getBoolean("Rubbish")); } @@ -108,8 +105,8 @@ public class PropertyFieldTableTest extends TestCase table1.setByte("value", Byte.MAX_VALUE); Assert.assertTrue(table1.propertyExists("value")); - //Tets lookups we shouldn't get anything back for other gets - //we should get right value back for this type .... + // Tets lookups we shouldn't get anything back for other gets + // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(Byte.MAX_VALUE, (byte) table1.getByte("value")); Assert.assertEquals(null, table1.getShort("value")); @@ -120,14 +117,14 @@ public class PropertyFieldTableTest extends TestCase Assert.assertEquals(null, table1.getLong("value")); Assert.assertEquals(null, table1.getBytes("value")); - //... and a the string value of it. + // ... and a the string value of it. Assert.assertEquals("" + Byte.MAX_VALUE, table1.getString("value")); table1.remove("value"); // Table should now have zero length for encoding checkEmpty(table1); - //Looking up an invalid value returns null + // Looking up an invalid value returns null Assert.assertEquals(null, table1.getByte("Rubbish")); } @@ -141,8 +138,8 @@ public class PropertyFieldTableTest extends TestCase table1.setShort("value", Short.MAX_VALUE); Assert.assertTrue(table1.propertyExists("value")); - //Tets lookups we shouldn't get anything back for other gets - //we should get right value back for this type .... + // Tets lookups we shouldn't get anything back for other gets + // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(null, table1.getByte("value")); Assert.assertEquals(Short.MAX_VALUE, (short) table1.getShort("value")); @@ -153,18 +150,17 @@ public class PropertyFieldTableTest extends TestCase Assert.assertEquals(null, table1.getLong("value")); Assert.assertEquals(null, table1.getBytes("value")); - //... and a the string value of it. + // ... and a the string value of it. Assert.assertEquals("" + Short.MAX_VALUE, table1.getString("value")); table1.remove("value"); // Table should now have zero length for encoding checkEmpty(table1); - //Looking up an invalid value returns null + // Looking up an invalid value returns null Assert.assertEquals(null, table1.getShort("Rubbish")); } - /** * Set a char and check that we can only get it back as a char * Check that attempting to lookup a non existent value returns null @@ -175,8 +171,8 @@ public class PropertyFieldTableTest extends TestCase table1.setChar("value", 'c'); Assert.assertTrue(table1.propertyExists("value")); - //Tets lookups we shouldn't get anything back for other gets - //we should get right value back for this type .... + // Tets lookups we shouldn't get anything back for other gets + // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(null, table1.getByte("value")); Assert.assertEquals(null, table1.getShort("value")); @@ -187,7 +183,7 @@ public class PropertyFieldTableTest extends TestCase Assert.assertEquals(null, table1.getLong("value")); Assert.assertEquals(null, table1.getBytes("value")); - //... and a the string value of it. + // ... and a the string value of it. Assert.assertEquals("c", table1.getString("value")); table1.remove("value"); @@ -195,11 +191,10 @@ public class PropertyFieldTableTest extends TestCase // Table should now have zero length for encoding checkEmpty(table1); - //Looking up an invalid value returns null + // Looking up an invalid value returns null Assert.assertEquals(null, table1.getCharacter("Rubbish")); } - /** * Set a double and check that we can only get it back as a double * Check that attempting to lookup a non existent value returns null @@ -210,8 +205,8 @@ public class PropertyFieldTableTest extends TestCase table1.setDouble("value", Double.MAX_VALUE); Assert.assertTrue(table1.propertyExists("value")); - //Tets lookups we shouldn't get anything back for other gets - //we should get right value back for this type .... + // Tets lookups we shouldn't get anything back for other gets + // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(null, table1.getByte("value")); Assert.assertEquals(null, table1.getShort("value")); @@ -222,20 +217,19 @@ public class PropertyFieldTableTest extends TestCase Assert.assertEquals(null, table1.getLong("value")); Assert.assertEquals(null, table1.getBytes("value")); - //... and a the string value of it. + // ... and a the string value of it. Assert.assertEquals("" + Double.MAX_VALUE, table1.getString("value")); table1.remove("value"); - //but after a removeKey it doesn't + // but after a removeKey it doesn't Assert.assertFalse(table1.containsKey("value")); // Table should now have zero length for encoding checkEmpty(table1); - //Looking up an invalid value returns null + // Looking up an invalid value returns null Assert.assertEquals(null, table1.getDouble("Rubbish")); } - /** * Set a float and check that we can only get it back as a float * Check that attempting to lookup a non existent value returns null @@ -246,8 +240,8 @@ public class PropertyFieldTableTest extends TestCase table1.setFloat("value", Float.MAX_VALUE); Assert.assertTrue(table1.propertyExists("value")); - //Tets lookups we shouldn't get anything back for other gets - //we should get right value back for this type .... + // Tets lookups we shouldn't get anything back for other gets + // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(null, table1.getByte("value")); Assert.assertEquals(null, table1.getShort("value")); @@ -258,22 +252,20 @@ public class PropertyFieldTableTest extends TestCase Assert.assertEquals(null, table1.getLong("value")); Assert.assertEquals(null, table1.getBytes("value")); - //... and a the string value of it. + // ... and a the string value of it. Assert.assertEquals("" + Float.MAX_VALUE, table1.getString("value")); - table1.remove("value"); - //but after a removeKey it doesn't + // but after a removeKey it doesn't Assert.assertFalse(table1.containsKey("value")); // Table should now have zero length for encoding checkEmpty(table1); - //Looking up an invalid value returns null + // Looking up an invalid value returns null Assert.assertEquals(null, table1.getFloat("Rubbish")); } - /** * Set an int and check that we can only get it back as an int * Check that attempting to lookup a non existent value returns null @@ -284,8 +276,8 @@ public class PropertyFieldTableTest extends TestCase table1.setInteger("value", Integer.MAX_VALUE); Assert.assertTrue(table1.propertyExists("value")); - //Tets lookups we shouldn't get anything back for other gets - //we should get right value back for this type .... + // Tets lookups we shouldn't get anything back for other gets + // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(null, table1.getByte("value")); Assert.assertEquals(null, table1.getShort("value")); @@ -296,22 +288,20 @@ public class PropertyFieldTableTest extends TestCase Assert.assertEquals(null, table1.getLong("value")); Assert.assertEquals(null, table1.getBytes("value")); - //... and a the string value of it. + // ... and a the string value of it. Assert.assertEquals("" + Integer.MAX_VALUE, table1.getString("value")); - table1.remove("value"); - //but after a removeKey it doesn't + // but after a removeKey it doesn't Assert.assertFalse(table1.containsKey("value")); // Table should now have zero length for encoding checkEmpty(table1); - //Looking up an invalid value returns null + // Looking up an invalid value returns null Assert.assertEquals(null, table1.getInteger("Rubbish")); } - /** * Set a long and check that we can only get it back as a long * Check that attempting to lookup a non existent value returns null @@ -322,8 +312,8 @@ public class PropertyFieldTableTest extends TestCase table1.setLong("value", Long.MAX_VALUE); Assert.assertTrue(table1.propertyExists("value")); - //Tets lookups we shouldn't get anything back for other gets - //we should get right value back for this type .... + // Tets lookups we shouldn't get anything back for other gets + // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(null, table1.getByte("value")); Assert.assertEquals(null, table1.getShort("value")); @@ -334,36 +324,34 @@ public class PropertyFieldTableTest extends TestCase Assert.assertEquals(Long.MAX_VALUE, (long) table1.getLong("value")); Assert.assertEquals(null, table1.getBytes("value")); - //... and a the string value of it. + // ... and a the string value of it. Assert.assertEquals("" + Long.MAX_VALUE, table1.getString("value")); - table1.remove("value"); - //but after a removeKey it doesn't + // but after a removeKey it doesn't Assert.assertFalse(table1.containsKey("value")); // Table should now have zero length for encoding checkEmpty(table1); - //Looking up an invalid value returns null + // Looking up an invalid value returns null Assert.assertEquals(null, table1.getLong("Rubbish")); } - /** * Set a double and check that we can only get it back as a double * Check that attempting to lookup a non existent value returns null */ public void testBytes() { - byte[] bytes = {99, 98, 97, 96, 95}; + byte[] bytes = { 99, 98, 97, 96, 95 }; FieldTable table1 = new FieldTable(); table1.setBytes("value", bytes); Assert.assertTrue(table1.propertyExists("value")); - //Tets lookups we shouldn't get anything back for other gets - //we should get right value back for this type .... + // Tets lookups we shouldn't get anything back for other gets + // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(null, table1.getByte("value")); Assert.assertEquals(null, table1.getShort("value")); @@ -374,17 +362,17 @@ public class PropertyFieldTableTest extends TestCase Assert.assertEquals(null, table1.getLong("value")); assertBytesEqual(bytes, table1.getBytes("value")); - //... and a the string value of it is null + // ... and a the string value of it is null Assert.assertEquals(null, table1.getString("value")); table1.remove("value"); - //but after a removeKey it doesn't + // but after a removeKey it doesn't Assert.assertFalse(table1.containsKey("value")); // Table should now have zero length for encoding checkEmpty(table1); - //Looking up an invalid value returns null + // Looking up an invalid value returns null Assert.assertEquals(null, table1.getBytes("Rubbish")); } @@ -405,7 +393,6 @@ public class PropertyFieldTableTest extends TestCase Assert.assertEquals(0, table.keySet().size()); } - /** * Set a String and check that we can only get it back as a String * Check that attempting to lookup a non existent value returns null @@ -416,8 +403,8 @@ public class PropertyFieldTableTest extends TestCase table1.setString("value", "Hello"); Assert.assertTrue(table1.propertyExists("value")); - //Tets lookups we shouldn't get anything back for other gets - //we should get right value back for this type .... + // Tets lookups we shouldn't get anything back for other gets + // we should get right value back for this type .... Assert.assertEquals(null, table1.getBoolean("value")); Assert.assertEquals(null, table1.getByte("value")); Assert.assertEquals(null, table1.getShort("value")); @@ -429,40 +416,35 @@ public class PropertyFieldTableTest extends TestCase Assert.assertEquals(null, table1.getBytes("value")); Assert.assertEquals("Hello", table1.getString("value")); - //Try setting a null value and read it back + // Try setting a null value and read it back table1.setString("value", null); Assert.assertEquals(null, table1.getString("value")); - //but still contains the value + // but still contains the value Assert.assertTrue(table1.containsKey("value")); table1.remove("value"); - //but after a removeKey it doesn't + // but after a removeKey it doesn't Assert.assertFalse(table1.containsKey("value")); checkEmpty(table1); - //Looking up an invalid value returns null + // Looking up an invalid value returns null Assert.assertEquals(null, table1.getString("Rubbish")); - //Additional Test that haven't been covered for string + // Additional Test that haven't been covered for string table1.setObject("value", "Hello"); - //Check that it was set correctly + // Check that it was set correctly Assert.assertEquals("Hello", table1.getString("value")); } - - - - - public void testValues() { FieldTable table = new FieldTable(); table.setBoolean("bool", true); table.setByte("byte", Byte.MAX_VALUE); - byte[] bytes = {99, 98, 97, 96, 95}; + byte[] bytes = { 99, 98, 97, 96, 95 }; table.setBytes("bytes", bytes); table.setChar("char", 'c'); table.setDouble("double", Double.MAX_VALUE); @@ -484,7 +466,6 @@ public class PropertyFieldTableTest extends TestCase table.setObject("object-short", Short.MAX_VALUE); table.setObject("object-string", "Hello"); - Assert.assertEquals((Boolean) true, table.getBoolean("bool")); Assert.assertEquals((Byte) Byte.MAX_VALUE, table.getByte("byte")); assertBytesEqual(bytes, table.getBytes("bytes")); @@ -509,10 +490,9 @@ public class PropertyFieldTableTest extends TestCase Assert.assertEquals("Hello", table.getObject("object-string")); } - public void testwriteBuffer() { - byte[] bytes = {99, 98, 97, 96, 95}; + byte[] bytes = { 99, 98, 97, 96, 95 }; FieldTable table = new FieldTable(); table.setBoolean("bool", true); @@ -569,13 +549,11 @@ public class PropertyFieldTableTest extends TestCase size += 1 + EncodingUtils.encodedShortStringLength("boolean") + EncodingUtils.encodedBooleanLength(); Assert.assertEquals(size, result.getEncodedSize()); - result.setByte("byte", (byte) Byte.MAX_VALUE); size += 1 + EncodingUtils.encodedShortStringLength("byte") + EncodingUtils.encodedByteLength(); Assert.assertEquals(size, result.getEncodedSize()); - - byte[] _bytes = {99, 98, 97, 96, 95}; + byte[] _bytes = { 99, 98, 97, 96, 95 }; result.setBytes("bytes", _bytes); size += 1 + EncodingUtils.encodedShortStringLength("bytes") + 4 + _bytes.length; @@ -597,7 +575,6 @@ public class PropertyFieldTableTest extends TestCase size += 1 + EncodingUtils.encodedShortStringLength("int") + EncodingUtils.encodedIntegerLength(); Assert.assertEquals(size, result.getEncodedSize()); - result.setLong("long", (long) Long.MAX_VALUE); size += 1 + EncodingUtils.encodedShortStringLength("long") + EncodingUtils.encodedLongLength(); Assert.assertEquals(size, result.getEncodedSize()); @@ -610,7 +587,6 @@ public class PropertyFieldTableTest extends TestCase size += 1 + EncodingUtils.encodedShortStringLength("result") + EncodingUtils.encodedLongStringLength("Hello"); Assert.assertEquals(size, result.getEncodedSize()); - result.setObject("object-bool", true); size += 1 + EncodingUtils.encodedShortStringLength("object-bool") + EncodingUtils.encodedBooleanLength(); Assert.assertEquals(size, result.getEncodedSize()); @@ -639,7 +615,6 @@ public class PropertyFieldTableTest extends TestCase size += 1 + EncodingUtils.encodedShortStringLength("object-int") + EncodingUtils.encodedIntegerLength(); Assert.assertEquals(size, result.getEncodedSize()); - result.setObject("object-long", Long.MAX_VALUE); size += 1 + EncodingUtils.encodedShortStringLength("object-long") + EncodingUtils.encodedLongLength(); Assert.assertEquals(size, result.getEncodedSize()); @@ -650,63 +625,62 @@ public class PropertyFieldTableTest extends TestCase } -// public void testEncodingSize1() -// { -// PropertyFieldTable table = new PropertyFieldTable(); -// int length = 0; -// result.put("one", 1L); -// length = EncodingUtils.encodedShortStringLength("one"); -// length += 1 + EncodingUtils.encodedLongLength(); -// assertEquals(length, result.getEncodedSize()); -// -// result.put("two", 2L); -// length += EncodingUtils.encodedShortStringLength("two"); -// length += 1 + EncodingUtils.encodedLongLength(); -// assertEquals(length, result.getEncodedSize()); -// -// result.put("three", 3L); -// length += EncodingUtils.encodedShortStringLength("three"); -// length += 1 + EncodingUtils.encodedLongLength(); -// assertEquals(length, result.getEncodedSize()); -// -// result.put("four", 4L); -// length += EncodingUtils.encodedShortStringLength("four"); -// length += 1 + EncodingUtils.encodedLongLength(); -// assertEquals(length, result.getEncodedSize()); -// -// result.put("five", 5L); -// length += EncodingUtils.encodedShortStringLength("five"); -// length += 1 + EncodingUtils.encodedLongLength(); -// assertEquals(length, result.getEncodedSize()); -// -// //fixme should perhaps be expanded to incorporate all types. -// -// final ByteBuffer buffer = ByteBuffer.allocate((int) result.getEncodedSize()); // FIXME XXX: Is cast a problem? -// -// result.writeToBuffer(buffer); -// -// buffer.flip(); -// -// long length = buffer.getUnsignedInt(); -// -// try -// { -// PropertyFieldTable table2 = new PropertyFieldTable(buffer, length); -// -// Assert.assertEquals((Long) 1L, table2.getLong("one")); -// Assert.assertEquals((Long) 2L, table2.getLong("two")); -// Assert.assertEquals((Long) 3L, table2.getLong("three")); -// Assert.assertEquals((Long) 4L, table2.getLong("four")); -// Assert.assertEquals((Long) 5L, table2.getLong("five")); -// } -// catch (AMQFrameDecodingException e) -// { -// e.printStackTrace(); -// fail("PFT should be instantiated from bytes." + e.getCause()); -// } -// -// } - + // public void testEncodingSize1() + // { + // PropertyFieldTable table = new PropertyFieldTable(); + // int length = 0; + // result.put("one", 1L); + // length = EncodingUtils.encodedShortStringLength("one"); + // length += 1 + EncodingUtils.encodedLongLength(); + // assertEquals(length, result.getEncodedSize()); + // + // result.put("two", 2L); + // length += EncodingUtils.encodedShortStringLength("two"); + // length += 1 + EncodingUtils.encodedLongLength(); + // assertEquals(length, result.getEncodedSize()); + // + // result.put("three", 3L); + // length += EncodingUtils.encodedShortStringLength("three"); + // length += 1 + EncodingUtils.encodedLongLength(); + // assertEquals(length, result.getEncodedSize()); + // + // result.put("four", 4L); + // length += EncodingUtils.encodedShortStringLength("four"); + // length += 1 + EncodingUtils.encodedLongLength(); + // assertEquals(length, result.getEncodedSize()); + // + // result.put("five", 5L); + // length += EncodingUtils.encodedShortStringLength("five"); + // length += 1 + EncodingUtils.encodedLongLength(); + // assertEquals(length, result.getEncodedSize()); + // + // //fixme should perhaps be expanded to incorporate all types. + // + // final ByteBuffer buffer = ByteBuffer.allocate((int) result.getEncodedSize()); // FIXME XXX: Is cast a problem? + // + // result.writeToBuffer(buffer); + // + // buffer.flip(); + // + // long length = buffer.getUnsignedInt(); + // + // try + // { + // PropertyFieldTable table2 = new PropertyFieldTable(buffer, length); + // + // Assert.assertEquals((Long) 1L, table2.getLong("one")); + // Assert.assertEquals((Long) 2L, table2.getLong("two")); + // Assert.assertEquals((Long) 3L, table2.getLong("three")); + // Assert.assertEquals((Long) 4L, table2.getLong("four")); + // Assert.assertEquals((Long) 5L, table2.getLong("five")); + // } + // catch (AMQFrameDecodingException e) + // { + // e.printStackTrace(); + // fail("PFT should be instantiated from bytes." + e.getCause()); + // } + // + // } /** * Additional test for setObject @@ -715,7 +689,7 @@ public class PropertyFieldTableTest extends TestCase { FieldTable table = new FieldTable(); - //Try setting a non primative object + // Try setting a non primative object try { @@ -724,7 +698,7 @@ public class PropertyFieldTableTest extends TestCase } catch (AMQPInvalidClassException iae) { - //normal path + // normal path } // so length should be zero Assert.assertEquals(0, table.getEncodedSize()); @@ -739,18 +713,17 @@ public class PropertyFieldTableTest extends TestCase try { - table.setObject((String)null, "String"); + table.setObject((String) null, "String"); fail("Null property name is not allowed"); } catch (IllegalArgumentException iae) { - //normal path + // normal path } // so length should be zero Assert.assertEquals(0, table.getEncodedSize()); } - /** * Additional test checkPropertyName doesn't accept an empty String */ @@ -765,20 +738,19 @@ public class PropertyFieldTableTest extends TestCase } catch (IllegalArgumentException iae) { - //normal path + // normal path } // so length should be zero Assert.assertEquals(0, table.getEncodedSize()); } - /** * Additional test checkPropertyName doesn't accept an empty String */ public void testCheckPropertyNamehasMaxLength() { - String oldVal =System.getProperty("STRICT_AMQP"); - System.setProperty("STRICT_AMQP","true"); + String oldVal = System.getProperty("STRICT_AMQP"); + System.setProperty("STRICT_AMQP", "true"); FieldTable table = new FieldTable(); StringBuffer longPropertyName = new StringBuffer(129); @@ -795,13 +767,13 @@ public class PropertyFieldTableTest extends TestCase } catch (IllegalArgumentException iae) { - //normal path + // normal path } // so length should be zero Assert.assertEquals(0, table.getEncodedSize()); - if(oldVal != null) + if (oldVal != null) { - System.setProperty("STRICT_AMQP",oldVal); + System.setProperty("STRICT_AMQP", oldVal); } else { @@ -809,31 +781,30 @@ public class PropertyFieldTableTest extends TestCase } } - /** * Additional test checkPropertyName starts with a letter */ public void testCheckPropertyNameStartCharacterIsLetter() { - String oldVal =System.getProperty("STRICT_AMQP"); - System.setProperty("STRICT_AMQP","true"); + String oldVal = System.getProperty("STRICT_AMQP"); + System.setProperty("STRICT_AMQP", "true"); FieldTable table = new FieldTable(); - //Try a name that starts with a number + // Try a name that starts with a number try { - table.setObject("1", "String"); + table.setObject("1", "String"); fail("property name must start with a letter"); } catch (IllegalArgumentException iae) { - //normal path + // normal path } // so length should be zero Assert.assertEquals(0, table.getEncodedSize()); - if(oldVal != null) + if (oldVal != null) { - System.setProperty("STRICT_AMQP",oldVal); + System.setProperty("STRICT_AMQP", oldVal); } else { @@ -841,17 +812,16 @@ public class PropertyFieldTableTest extends TestCase } } - /** * Additional test checkPropertyName starts with a hash or a dollar */ public void testCheckPropertyNameStartCharacterIsHashorDollar() { - String oldVal =System.getProperty("STRICT_AMQP"); - System.setProperty("STRICT_AMQP","true"); + String oldVal = System.getProperty("STRICT_AMQP"); + System.setProperty("STRICT_AMQP", "true"); FieldTable table = new FieldTable(); - //Try a name that starts with a number + // Try a name that starts with a number try { table.setObject("#", "String"); @@ -861,9 +831,10 @@ public class PropertyFieldTableTest extends TestCase { fail("property name are allowed to start with # and $s"); } - if(oldVal != null) + + if (oldVal != null) { - System.setProperty("STRICT_AMQP",oldVal); + System.setProperty("STRICT_AMQP", oldVal); } else { @@ -871,8 +842,6 @@ public class PropertyFieldTableTest extends TestCase } } - - /** * Additional test to test the contents of the table */ @@ -884,7 +853,7 @@ public class PropertyFieldTableTest extends TestCase Assert.assertEquals("String", table.getString("StringProperty")); - //Test Clear + // Test Clear table.clear(); @@ -903,18 +872,12 @@ public class PropertyFieldTableTest extends TestCase table.setObject("n2", "2"); table.setObject("n3", "3"); - Assert.assertEquals("1", table.getObject("n1")); Assert.assertEquals("2", table.getObject("n2")); Assert.assertEquals("3", table.getObject("n3")); - - - } - - private void assertBytesEqual(byte[] expected, byte[] actual) { Assert.assertEquals(expected.length, actual.length); diff --git a/java/common/src/test/java/org/apache/qpid/util/CommandLineParserTest.java b/java/common/src/test/java/org/apache/qpid/util/CommandLineParserTest.java index c480ce3944..815b61d293 100644 --- a/java/common/src/test/java/org/apache/qpid/util/CommandLineParserTest.java +++ b/java/common/src/test/java/org/apache/qpid/util/CommandLineParserTest.java @@ -1,10 +1,11 @@ package org.apache.qpid.util;
-import java.util.Properties;
-
import junit.framework.*;
-import org.apache.log4j.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Properties;
/**
* Unit tests the {@link CommandLineParser} class.
@@ -37,7 +38,7 @@ import org.apache.log4j.*; */
public class CommandLineParserTest extends TestCase
{
- private static final Logger log = Logger.getLogger(CommandLineParserTest.class);
+ private static final Logger log = LoggerFactory.getLogger(CommandLineParserTest.class);
public CommandLineParserTest(String name)
{
@@ -58,11 +59,6 @@ public class CommandLineParserTest extends TestCase return suite;
}
- public void setUp()
- {
- NDC.push(getName());
- }
-
/** Check that get errors returns an empty string on no errors. */
public void testGetErrorsReturnsEmptyStringOnNoErrors() throws Exception
{
@@ -534,9 +530,4 @@ public class CommandLineParserTest extends TestCase assertTrue("IllegalArgumentException not thrown for an unknown option when errors on unknowns mode is on.",
testPassed);
}
-
- protected void tearDown() throws Exception
- {
- NDC.pop();
- }
}
|
