|
From: Richard G C. <pim...@us...> - 2004-09-10 16:56:25
|
Update of /cvsroot/openorb/OpenORB/src/main/org/openorb/orb/pi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17963/OpenORB/src/main/org/openorb/orb/pi Modified Files: CurrentImpl.java Log Message: fixed possible thread safety issue in CurrentImpl & cleaned up code Index: CurrentImpl.java =================================================================== RCS file: /cvsroot/openorb/OpenORB/src/main/org/openorb/orb/pi/CurrentImpl.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- CurrentImpl.java 13 May 2004 23:54:13 -0000 1.4 +++ CurrentImpl.java 10 Sep 2004 16:56:08 -0000 1.5 @@ -10,9 +10,14 @@ import java.util.Map; import java.util.WeakHashMap; -import java.util.Collections; +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_INV_ORDER; +import org.omg.CORBA.LocalObject; +import org.omg.CORBA.ORB; +import org.omg.PortableInterceptor.Current; import org.omg.PortableInterceptor.CurrentOperations; +import org.omg.PortableInterceptor.InvalidSlot; /** * Implementation of PICurrent. @@ -20,20 +25,19 @@ * @author Chris Wood * @version $Revision$ $Date$ */ -public class CurrentImpl - extends org.omg.CORBA.LocalObject - implements org.omg.PortableInterceptor.Current +public class CurrentImpl extends LocalObject implements Current { + private final ORB m_orb; + private ThreadLocal m_curr = new ThreadLocal(); private Map m_stored_ctxts; - private int m_slots = 0; - private boolean m_slots_set = false; - private org.omg.CORBA.ORB m_orb; + private int m_slots; + private boolean m_slots_set; /** * Creates new CurrentImpl. */ - CurrentImpl( org.omg.CORBA.ORB orb ) + CurrentImpl( final ORB orb ) { m_orb = orb; } @@ -41,11 +45,11 @@ /** * Called at the end of the post init phase. Sets the slot count. */ - void set_slots( int slots ) + void set_slots( final int slots ) { if ( m_slots_set ) { - throw new org.omg.CORBA.BAD_INV_ORDER(); + throw new BAD_INV_ORDER(); } // create a new current stack. The old one's slot tables will be the // wrong size. @@ -67,7 +71,7 @@ /** * Copy a slot table. */ - public CurrentOperations copy( CurrentOperations from ) + public CurrentOperations copy( final CurrentOperations from ) { if ( from == null ) { @@ -75,9 +79,9 @@ } if ( !( from instanceof CurrentEntry ) ) { - throw new java.lang.IllegalArgumentException(); + throw new IllegalArgumentException(); } - CurrentEntry fr = ( CurrentEntry ) from; + final CurrentEntry fr = ( CurrentEntry ) from; if ( fr.get_table() == null ) { @@ -89,11 +93,11 @@ /** * Set a previously created or retrieved table. */ - public void set( CurrentOperations value ) + public void set( final CurrentOperations value ) { if ( value != null && !( value instanceof CurrentEntry ) ) { - throw new java.lang.IllegalArgumentException(); + throw new IllegalArgumentException(); } m_curr.set( value ); } @@ -103,7 +107,7 @@ */ public CurrentOperations remove() { - CurrentEntry ret = ( CurrentEntry ) m_curr.get(); + final CurrentEntry ret = ( CurrentEntry ) m_curr.get(); if ( ret != null ) { @@ -120,21 +124,19 @@ return ( CurrentOperations ) m_curr.get(); } - public void set_slot( int id, org.omg.CORBA.Any data ) - throws org.omg.PortableInterceptor.InvalidSlot + public void set_slot( final int id, final Any data ) throws InvalidSlot { get_p().set_slot( id, data ); } - public org.omg.CORBA.Any get_slot( int id ) - throws org.omg.PortableInterceptor.InvalidSlot + public Any get_slot( final int id ) throws InvalidSlot { return get_p().get_slot( id ); } public Object get_invocation_ctx() { - CurrentEntry ret = ( CurrentEntry ) m_curr.get(); + final CurrentEntry ret = ( CurrentEntry ) m_curr.get(); if ( ret == null ) { @@ -143,39 +145,42 @@ return ret.get_invocation_ctx(); } - public void set_invocation_ctx( Object invocation_ctx ) + public void set_invocation_ctx( final Object invocation_ctx ) { get_p().set_invocation_ctx( invocation_ctx ); } - public void store_invocation_ctx( Object handle ) + public void store_invocation_ctx( final Object handle ) { synchronized ( this ) { if ( m_stored_ctxts == null ) { - m_stored_ctxts = Collections.synchronizedMap( - new WeakHashMap() ); + m_stored_ctxts = new WeakHashMap(); } - } - CurrentEntry curr = get_p(); - m_stored_ctxts.put( handle, curr.get_invocation_ctx() ); + final CurrentEntry curr = get_p(); + + m_stored_ctxts.put( handle, curr.get_invocation_ctx() ); + } } - public Object retrieve_invocation_ctx( Object handle, boolean delete ) + public Object retrieve_invocation_ctx( final Object handle, final boolean delete ) { - if ( m_stored_ctxts == null ) - { - return null; - } - if ( delete ) - { - return m_stored_ctxts.remove( handle ); - } - else + synchronized ( this ) { - return m_stored_ctxts.get( handle ); + if ( m_stored_ctxts == null ) + { + return null; + } + if ( delete ) + { + return m_stored_ctxts.remove( handle ); + } + else + { + return m_stored_ctxts.get( handle ); + } } } @@ -196,7 +201,7 @@ * Replace LocalObject _orb() method for get orb in server/client * manager. */ - public org.omg.CORBA.ORB _orb() + public ORB _orb() { return m_orb; } |