summaryrefslogtreecommitdiff
path: root/qpid/java
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2007-01-25 17:34:12 +0000
committerMartin Ritchie <ritchiem@apache.org>2007-01-25 17:34:12 +0000
commit7b43a624880b97a0f4835ff41ba6037d5183e909 (patch)
tree403f4768c229f5f916d1cdbfe83a5c4aa523d4ac /qpid/java
parent4c408e494fa38aa27c65a1cb30bd7b61eb7a9ae5 (diff)
downloadqpid-python-7b43a624880b97a0f4835ff41ba6037d5183e909.tar.gz
Correctly applied Revision: 492718 and required changes for missing patched JMSPropertyFieldTable.java
Author: rhs Date: 20:23:26, 04 January 2007 Message: QPID-248 Modified field table types to not conflict with the officially specified definitions. Also reorganized type definitions to clearly distinguish between official and extended types and reenabled the AmqPlain authentication mechanism. This change allows the python interop test suite to run. ---- Modified : /incubator/qpid/trunk/qpid/java/broker/etc/config.xml Modified : /incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQType.java Modified : /incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypeMap.java Modified : /incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/perftesting@499863 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java376
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/JMSPropertyFieldTable.java2
2 files changed, 282 insertions, 96 deletions
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
index 3c18683609..40af11e8ee 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
@@ -31,12 +31,15 @@ public class FieldTable
{
private static final Logger _logger = Logger.getLogger(FieldTable.class);
+ private ByteBuffer _encodedForm;
private LinkedHashMap<String, AMQTypedValue> _properties;
+ private long _encodedSize;
+ private static final int INITIAL_HASHMAP_CAPACITY = 16;
public FieldTable()
{
super();
- _properties = new LinkedHashMap<String, AMQTypedValue>();
+
}
@@ -52,14 +55,100 @@ public class FieldTable
public FieldTable(ByteBuffer buffer, long length) throws AMQFrameDecodingException
{
this();
- setFromBuffer(buffer, length);
+ _encodedForm = buffer.slice();
+ _encodedForm.limit((int)length);
+ _encodedSize = length;
+ buffer.skip((int)length);
+ }
+
+
+
+ private AMQTypedValue getProperty(String string)
+ {
+ synchronized(this)
+ {
+ if(_properties == null)
+ {
+ if(_encodedForm == null)
+ {
+ return null;
+ }
+ else
+ {
+ populateFromBuffer();
+ }
+ }
+ }
+
+ if(_properties == null)
+ {
+ return null;
+ }
+ else
+ {
+ return _properties.get(string);
+ }
}
+ private void populateFromBuffer()
+ {
+ try
+ {
+ setFromBuffer(_encodedForm, _encodedSize);
+ }
+ catch (AMQFrameDecodingException e)
+ {
+ _logger.error("Error decoding FieldTable in deferred decoding mode ", e);
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+
+ private AMQTypedValue setProperty(String key, AMQTypedValue val)
+ {
+ initMapIfNecessary();
+ _encodedForm = null;
+ if(val == null)
+ {
+ return removeKey(key);
+ }
+ AMQTypedValue oldVal = _properties.put(key,val);
+ if(oldVal != null)
+ {
+ _encodedSize -= oldVal.getEncodingSize();
+ }
+ else
+ {
+ _encodedSize += EncodingUtils.encodedShortStringLength(key) + 1;
+ }
+ _encodedSize += val.getEncodingSize();
+
+ return oldVal;
+ }
+
+ private void initMapIfNecessary()
+ {
+ synchronized(this)
+ {
+ if(_properties == null)
+ {
+ if(_encodedForm == null)
+ {
+ _properties = new LinkedHashMap<String,AMQTypedValue>();
+ }
+ else
+ {
+ populateFromBuffer();
+ }
+ }
+
+ }
+ }
public Boolean getBoolean(String string)
{
- AMQTypedValue value = _properties.get(string);
+ AMQTypedValue value = getProperty(string);
if (value != null && (value.getType() == AMQType.BOOLEAN))
{
return (Boolean) value.getValue();
@@ -70,9 +159,10 @@ public class FieldTable
}
}
+
public Byte getByte(String string)
{
- AMQTypedValue value = _properties.get(string);
+ AMQTypedValue value = getProperty(string);
if (value != null && (value.getType() == AMQType.BYTE))
{
return (Byte) value.getValue();
@@ -85,7 +175,7 @@ public class FieldTable
public Short getShort(String string)
{
- AMQTypedValue value = _properties.get(string);
+ AMQTypedValue value = getProperty(string);
if (value != null && (value.getType() == AMQType.SHORT))
{
return (Short) value.getValue();
@@ -98,7 +188,7 @@ public class FieldTable
public Integer getInteger(String string)
{
- AMQTypedValue value = _properties.get(string);
+ AMQTypedValue value = getProperty(string);
if (value != null && (value.getType() == AMQType.INT))
{
return (Integer) value.getValue();
@@ -111,7 +201,7 @@ public class FieldTable
public Long getLong(String string)
{
- AMQTypedValue value = _properties.get(string);
+ AMQTypedValue value = getProperty(string);
if (value != null && (value.getType() == AMQType.LONG))
{
return (Long) value.getValue();
@@ -124,7 +214,7 @@ public class FieldTable
public Float getFloat(String string)
{
- AMQTypedValue value = _properties.get(string);
+ AMQTypedValue value = getProperty(string);
if (value != null && (value.getType() == AMQType.FLOAT))
{
return (Float) value.getValue();
@@ -137,7 +227,7 @@ public class FieldTable
public Double getDouble(String string)
{
- AMQTypedValue value = _properties.get(string);
+ AMQTypedValue value = getProperty(string);
if (value != null && (value.getType() == AMQType.DOUBLE))
{
return (Double) value.getValue();
@@ -150,7 +240,7 @@ public class FieldTable
public String getString(String string)
{
- AMQTypedValue value = _properties.get(string);
+ AMQTypedValue value = getProperty(string);
if ((value != null) && ((value.getType() == AMQType.WIDE_STRING) ||
(value.getType() == AMQType.ASCII_STRING)))
{
@@ -170,7 +260,7 @@ public class FieldTable
public Character getCharacter(String string)
{
- AMQTypedValue value = _properties.get(string);
+ AMQTypedValue value = getProperty(string);
if (value != null && (value.getType() == AMQType.ASCII_CHARACTER))
{
return (Character) value.getValue();
@@ -183,7 +273,7 @@ public class FieldTable
public byte[] getBytes(String string)
{
- AMQTypedValue value = _properties.get(string);
+ AMQTypedValue value = getProperty(string);
if (value != null && (value.getType() == AMQType.BINARY))
{
return (byte[]) value.getValue();
@@ -196,7 +286,7 @@ public class FieldTable
public Object getObject(String string)
{
- AMQTypedValue value = _properties.get(string);
+ AMQTypedValue value = getProperty(string);
if(value != null)
{
return value.getValue();
@@ -213,43 +303,58 @@ public class FieldTable
public Object setBoolean(String string, boolean b)
{
checkPropertyName(string);
- return _properties.put(string, AMQType.BOOLEAN.asTypedValue(b));
+ return setProperty(string, AMQType.BOOLEAN.asTypedValue(b));
}
public Object setByte(String string, byte b)
{
checkPropertyName(string);
- return _properties.put(string, AMQType.BYTE.asTypedValue(b));
+ return setProperty(string, AMQType.BYTE.asTypedValue(b));
}
public Object setShort(String string, short i)
{
checkPropertyName(string);
- return _properties.put(string, AMQType.SHORT.asTypedValue(i));
+ return setProperty(string, AMQType.SHORT.asTypedValue(i));
}
public Object setInteger(String string, int i)
{
checkPropertyName(string);
- return _properties.put(string, AMQType.INT.asTypedValue(i));
+ return setProperty(string, AMQType.INT.asTypedValue(i));
}
public Object setLong(String string, long l)
{
checkPropertyName(string);
- return _properties.put(string, AMQType.LONG.asTypedValue(l));
+ return setProperty(string, AMQType.LONG.asTypedValue(l));
}
public Object setFloat(String string, float v)
{
checkPropertyName(string);
- return _properties.put(string, AMQType.FLOAT.asTypedValue(v));
+ return setProperty(string, AMQType.FLOAT.asTypedValue(v));
}
public Object setDouble(String string, double v)
{
checkPropertyName(string);
- return _properties.put(string, AMQType.DOUBLE.asTypedValue(v));
+ return setProperty(string, AMQType.DOUBLE.asTypedValue(v));
+ }
+
+
+ public Object setAsciiString(String string, String value)
+ {
+ checkPropertyName(string);
+ if (value == null)
+ {
+ return setProperty(string, AMQType.VOID.asTypedValue(null));
+ }
+ else
+ {
+ return setProperty(string, AMQType.ASCII_STRING.asTypedValue(value));
+
+ }
}
public Object setString(String string, String value)
@@ -257,32 +362,26 @@ public class FieldTable
checkPropertyName(string);
if (value == null)
{
- return _properties.put(string, AMQType.VOID.asTypedValue(null));
+ return setProperty(string, AMQType.VOID.asTypedValue(null));
}
else
{
- //FIXME: determine string encoding and set either WIDE or ASCII string
-// if ()
- {
- return _properties.put(string, AMQType.WIDE_STRING.asTypedValue(value));
- }
-// else
-// {
-// return _properties.put(string, AMQType.ASCII_STRING.asTypedValue(value));
-// }
+ return setProperty(string, AMQType.LONG_STRING.asTypedValue(value));
}
}
+
public Object setChar(String string, char c)
{
checkPropertyName(string);
- return _properties.put(string, AMQType.ASCII_CHARACTER.asTypedValue(c));
+ return setProperty(string, AMQType.ASCII_CHARACTER.asTypedValue(c));
}
+
public Object setBytes(String string, byte[] bytes)
{
checkPropertyName(string);
- return _properties.put(string, AMQType.BINARY.asTypedValue(bytes));
+ return setProperty(string, AMQType.BINARY.asTypedValue(bytes));
}
public Object setBytes(String string, byte[] bytes, int start, int length)
@@ -293,7 +392,6 @@ public class FieldTable
return setBytes(string, bytes);
}
-
public Object setObject(String string, Object object)
{
if (object instanceof Boolean)
@@ -343,7 +441,7 @@ public class FieldTable
public boolean isNullStringValue(String name)
{
- AMQTypedValue value = _properties.get(name);
+ AMQTypedValue value = getProperty(name);
return (value != null) && (value.getType() == AMQType.VOID);
}
@@ -351,9 +449,10 @@ public class FieldTable
public Enumeration getPropertyNames()
{
- return Collections.enumeration(_properties.keySet());
+ return Collections.enumeration(keys());
}
+
public boolean propertyExists(String propertyName)
{
return itemExists(propertyName);
@@ -361,23 +460,24 @@ public class FieldTable
public boolean itemExists(String string)
{
+ initMapIfNecessary();
return _properties.containsKey(string);
}
public String toString()
{
+ initMapIfNecessary();
return _properties.toString();
}
-
private void checkPropertyName(String propertyName)
{
if (propertyName == null)
{
throw new IllegalArgumentException("Property name must not be null");
}
- else if ("".equals(propertyName))
+ else if (propertyName.length()==0)
{
throw new IllegalArgumentException("Property name must not be the empty string");
}
@@ -415,7 +515,7 @@ public class FieldTable
}
}
-
+
// ************************* Byte Buffer Processing
public void writeToBuffer(ByteBuffer buffer)
@@ -448,20 +548,31 @@ public class FieldTable
public long getEncodedSize()
{
+ return _encodedSize;
+ }
+
+ private void recalculateEncodedSize()
+ {
+
int encodedSize = 0;
- for(Map.Entry<String,AMQTypedValue> e : _properties.entrySet())
+ if(_properties != null)
{
- encodedSize += EncodingUtils.encodedShortStringLength(e.getKey());
- encodedSize++; // the byte for the encoding Type
- encodedSize += e.getValue().getEncodingSize();
+ for(Map.Entry<String,AMQTypedValue> e : _properties.entrySet())
+ {
+ encodedSize += EncodingUtils.encodedShortStringLength(e.getKey());
+ encodedSize++; // the byte for the encoding Type
+ encodedSize += e.getValue().getEncodingSize();
+ }
}
- return encodedSize;
+ _encodedSize = encodedSize;
}
public void addAll(FieldTable fieldTable)
{
+ initMapIfNecessary();
_properties.putAll(fieldTable._properties);
+ recalculateEncodedSize();
}
@@ -473,135 +584,210 @@ public class FieldTable
public Object processOverElements(FieldTableElementProcessor processor)
{
- for(Map.Entry<String,AMQTypedValue> e : _properties.entrySet())
+ initMapIfNecessary();
+ if(_properties != null)
{
- boolean result = processor.processElement(e.getKey(), e.getValue());
- if(!result)
+ for(Map.Entry<String,AMQTypedValue> e : _properties.entrySet())
+
{
- break;
+ boolean result = processor.processElement(e.getKey(), e.getValue());
+ if(!result)
+ {
+ break;
+ }
}
}
return processor.getResult();
+
+
}
public int size()
{
+ initMapIfNecessary();
return _properties.size();
+
}
public boolean isEmpty()
{
- return _properties.isEmpty();
+ return size() ==0;
}
public boolean containsKey(String key)
{
+ initMapIfNecessary();
return _properties.containsKey(key);
}
public Set<String> keys()
{
- return _properties.keySet();
+ initMapIfNecessary();
+ Set<String> keys = new LinkedHashSet<String>();
+ for(String key : _properties.keySet())
+ {
+ keys.add(key);
+ }
+ return keys;
}
- public Object get(Object key)
+ public Object get(String key)
{
- return getObject((String)key);
+ return getObject(key);
}
- public Object put(Object key, Object value)
+ public Object put(String key, Object value)
{
- return setObject(key.toString(), value);
+ return setObject(key, value);
}
-
+
public Object remove(String key)
{
+ AMQTypedValue val = removeKey(key);
+ return val == null ? null : val.getValue();
+
+ }
+
+
+ public AMQTypedValue removeKey(String key)
+ {
+ initMapIfNecessary();
+ _encodedForm = null;
AMQTypedValue value = _properties.remove(key);
- return value == null ? null : value.getValue();
+ if(value == null)
+ {
+ return null;
+ }
+ else
+ {
+ _encodedSize -= EncodingUtils.encodedShortStringLength(key);
+ _encodedSize--;
+ _encodedSize -= value.getEncodingSize();
+ return value;
+ }
+
}
public void clear()
{
+ initMapIfNecessary();
+ _encodedForm = null;
_properties.clear();
+ _encodedSize = 0;
}
- public Set keySet()
+ public Set<String> keySet()
{
+ initMapIfNecessary();
return _properties.keySet();
}
private void putDataInBuffer(ByteBuffer buffer)
{
- final Iterator<Map.Entry<String,AMQTypedValue>> it = _properties.entrySet().iterator();
+ if(_encodedForm != null)
+ {
+ buffer.put(_encodedForm);
+ }
+ else if(_properties != null)
+ {
+ final Iterator<Map.Entry<String,AMQTypedValue>> it = _properties.entrySet().iterator();
+
+ //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())
- //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<String,AMQTypedValue> me = it.next();
- try
{
- if (_logger.isTraceEnabled())
+ final Map.Entry<String,AMQTypedValue> me = it.next();
+ try
{
- _logger.trace("Writing Property:" + me.getKey() +
- " Type:" + me.getValue().getType() +
- " Value:" + me.getValue().getValue());
- _logger.trace("Buffer Position:" + buffer.position() +
- " Remaining:" + buffer.remaining());
- }
+ 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());
+ }
- //Write the actual parameter name
- EncodingUtils.writeShortStringBytes(buffer, me.getKey());
- me.getValue().writeToBuffer(buffer);
- }
- catch (Exception e)
- {
- if (_logger.isTraceEnabled())
+ //Write the actual parameter name
+ EncodingUtils.writeShortStringBytes(buffer, me.getKey());
+ me.getValue().writeToBuffer(buffer);
+ }
+ catch (Exception e)
+
+
{
- _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());
+ 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());
+ }
+ throw new RuntimeException(e);
}
- throw new RuntimeException(e);
+
}
}
}
- public void setFromBuffer(ByteBuffer buffer, long length) throws AMQFrameDecodingException
+ private void setFromBuffer(ByteBuffer buffer, long length) throws AMQFrameDecodingException
{
+
final boolean trace = _logger.isTraceEnabled();
+ if(length > 0)
+
- int sizeRead = 0;
- while (sizeRead < length)
{
- int sizeRemaining = buffer.remaining();
- final String key = EncodingUtils.readShortString(buffer);
- AMQTypedValue value = AMQTypedValue.readFromBuffer(buffer);
- sizeRead += (sizeRemaining - buffer.remaining());
- if (trace)
+
+
+
+
+ final int expectedRemaining = buffer.remaining()-(int)length;
+
+ _properties = new LinkedHashMap<String,AMQTypedValue>(INITIAL_HASHMAP_CAPACITY);
+
+ do
{
- _logger.trace("FieldTable::PropFieldTable(buffer," + length + "): Read type '" + value.getType() + "', key '" + key + "', value '" + value.getValue() + "' (now read " + sizeRead + " of " + length + " encoded bytes)...");
+
+ final String key = EncodingUtils.readShortString(buffer);
+ AMQTypedValue value = AMQTypedValue.readFromBuffer(buffer);
+
+ if (trace)
+ {
+ _logger.trace("FieldTable::PropFieldTable(buffer," + length + "): Read type '" + value.getType() + "', key '" + key + "', value '" + value.getValue() + "'");
+ }
+
+
+
+ _properties.put(key,value);
+
+
+
}
+ while (buffer.remaining() > expectedRemaining);
+
- _properties.put(key,value);
}
+ _encodedSize = length;
if (trace)
{
@@ -609,4 +795,4 @@ public class FieldTable
}
}
-}
+} \ No newline at end of file
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/JMSPropertyFieldTable.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/JMSPropertyFieldTable.java
index d78034cf2f..97e7f6e318 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/JMSPropertyFieldTable.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/JMSPropertyFieldTable.java
@@ -426,7 +426,7 @@ public class JMSPropertyFieldTable
return _fieldtable.propertyExists(propertyName);
}
- public Object put(Object key, Object value)
+ public Object put(String key, Object value)
{
return _fieldtable.put(key, value);
}