Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1915 - development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: niclas AT netcompartner.com
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1915 - development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl
  • Date: Tue, 01 Mar 2005 05:54:11 +0100

Author: niclas
Date: Tue Mar 1 05:54:11 2005
New Revision: 1915

Modified:

development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl/BitMappedFlags.java

development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl/EnumeratedString.java
Log:
More thread-safety introduced, just in case...

Modified:
development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl/BitMappedFlags.java
==============================================================================
---
development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl/BitMappedFlags.java
(original)
+++
development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl/BitMappedFlags.java
Tue Mar 1 05:54:11 2005
@@ -79,11 +79,14 @@
public void addFlag( String name, int value )
throws IllegalArgumentException
{
- if( value < 0 || value > 31 )
- throw new IllegalArgumentException( "Data out of range: " + name
+ " = " + value );
- Integer data = new Integer( value );
- m_names.put( name, data );
- m_values.put( data, name );
+ synchronized( this )
+ {
+ if( value < 0 || value > 31 )
+ throw new IllegalArgumentException( "Data out of range: " +
name + " = " + value );
+ Integer data = new Integer( value );
+ m_names.put( name, data );
+ m_values.put( data, name );
+ }
}

/** Removes an enumeration of a string from this field type.
@@ -92,9 +95,12 @@
*/
public int removeFlag( String name )
{
- Integer value = (Integer) m_names.remove( name );
- m_values.remove( value );
- return value.intValue();
+ synchronized( this )
+ {
+ Integer value = (Integer) m_names.remove( name );
+ m_values.remove( value );
+ return value.intValue();
+ }
}

/** Returns the FieldType name.
@@ -172,11 +178,7 @@
while( st.hasMoreTokens() )
{
String token = st.nextToken();
- Object obj = m_names.get( content );
- if( obj == null )
- throw new IllegalPacketFormatException( "Flag name not
registered: " + token, this );
- Integer data = (Integer) obj;
- int value = data.intValue();
+ int value = lookupValue( token );
value = 1 << value;
result = result | value;
}
@@ -236,12 +238,38 @@
{
result.append( ", " );
}
- Integer lookup = new Integer( i );
- String name = (String) m_values.get( lookup );
+ String name = lookupName( i );
result.append( name );
}
}
return result.toString();
}
+
+ private int lookupValue( String name )
+ throws IllegalPacketFormatException
+ {
+ synchronized( this )
+ {
+ Object obj = m_names.get( name );
+ if( obj == null )
+ throw new IllegalPacketFormatException( "Flag name not
registered: " + name, this );
+ int value = ((Integer) obj).intValue();
+ return value;
+ }
+ }
+
+ private String lookupName( int value )
+ throws IllegalPacketFormatException
+ {
+ synchronized( this )
+ {
+ Integer lookup = new Integer( value );
+ Object obj = m_values.get( lookup );
+ if( obj == null )
+ throw new IllegalPacketFormatException( "No flag with this
value has been registered: " + value, this );
+ String name = (String) obj;
+ return name;
+ }
+ }
}


Modified:
development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl/EnumeratedString.java
==============================================================================
---
development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl/EnumeratedString.java
(original)
+++
development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl/EnumeratedString.java
Tue Mar 1 05:54:11 2005
@@ -150,12 +150,8 @@
public byte[] serialize( String content )
throws IllegalPacketFormatException
{
- Object obj = m_names.get( content );
- if( obj == null )
- throw new IllegalPacketFormatException( "The enumerated string
has not been registered: " + content, this );
- Integer value = (Integer) obj;
- byte data = value.byteValue();
- return new byte[] { data };
+ int value = lookupValue( content );
+ return new byte[] { (byte) value };
}

/** Deserializes the content from the input stream.
@@ -169,7 +165,34 @@
{
throw new IllegalPacketFormatException( "Field contains the
wrong length: " + input.length, this );
}
- Integer data = new Integer( input[ 0 ] );
- return (String) m_values.get( data );
+ String name = lookupName( input[ 0 ] );
+ return name;
+ }
+
+ private int lookupValue( String name )
+ throws IllegalPacketFormatException
+ {
+ synchronized( this )
+ {
+ Object obj = m_names.get( name );
+ if( obj == null )
+ throw new IllegalPacketFormatException( "The string name has
not been registered: " + name, this );
+ int value = ((Integer) obj).intValue();
+ return value;
+ }
+ }
+
+ private String lookupName( int value )
+ throws IllegalPacketFormatException
+ {
+ synchronized( this )
+ {
+ Integer lookup = new Integer( value );
+ Object obj = m_values.get( lookup );
+ if( obj == null )
+ throw new IllegalPacketFormatException( "Enumerated string
with this value has not been registered: " + value, this );
+ String name = (String) obj;
+ return name;
+ }
}
}



  • svn commit: r1915 - development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl, niclas, 02/28/2005

Archive powered by MHonArc 2.6.24.

Top of Page