avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosu...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event DefaultQueue.java
Date Wed, 06 Mar 2002 08:20:30 GMT
leosutic    02/03/06 00:20:30

  Modified:    src/scratchpad/org/apache/avalon/excalibur/event
                        DefaultQueue.java
  Log:
  Bugfixes related to the aquisition and release of the mutex.
  
  Revision  Changes    Path
  1.9       +91 -67    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/DefaultQueue.java
  
  Index: DefaultQueue.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/DefaultQueue.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultQueue.java	4 Feb 2002 18:21:50 -0000	1.8
  +++ DefaultQueue.java	6 Mar 2002 08:20:30 -0000	1.9
  @@ -67,21 +67,24 @@
           try
           {
               m_mutex.acquire();
  +            try
  +            {
  +
  +                if ( maxSize() > 0 && elements.length + m_reserve + size() >
maxSize() )
  +                {
  +                    throw new SinkFullException("Not enough room to enqueue these elements.");
  +                }
   
  -            if ( maxSize() > 0 && elements.length + m_reserve + size() >
maxSize() )
  +                enqueue = new DefaultPreparedEnqueue( this, elements );
  +            }
  +            finally
               {
  -                throw new SinkFullException("Not enough room to enqueue these elements.");
  +                m_mutex.release();
               }
  -
  -            enqueue = new DefaultPreparedEnqueue( this, elements );
           }
           catch ( InterruptedException ie )
           {
           }
  -        finally
  -        {
  -            m_mutex.release();
  -        }
   
           return enqueue;
       }
  @@ -93,22 +96,25 @@
           try
           {
               m_mutex.acquire();
  +            try
  +            {
   
  -            if (  maxSize() > 0 && 1 + m_reserve + size() > maxSize() )
  +                if (  maxSize() > 0 && 1 + m_reserve + size() > maxSize()
)
  +                {
  +                    return false;
  +                }
  +
  +                m_elements.add( element );
  +                success = true;
  +            }
  +            finally
               {
  -                return false;
  +                m_mutex.release();
               }
  -
  -            m_elements.add( element );
  -            success = true;
           }
           catch ( InterruptedException ie )
           {
           }
  -        finally
  -        {
  -            m_mutex.release();
  -        }
   
           return success;
       }
  @@ -121,23 +127,26 @@
           try
           {
               m_mutex.acquire();
  -            if (  maxSize() > 0 && elements.length + m_reserve + size() >
maxSize() )
  +            try
               {
  -                throw new SinkFullException("Not enough room to enqueue these elements.");
  -            }
  +                if (  maxSize() > 0 && elements.length + m_reserve + size()
> maxSize() )
  +                {
  +                    throw new SinkFullException("Not enough room to enqueue these elements.");
  +                }
   
  -            for ( int i = 0; i < len; i++ )
  +                for ( int i = 0; i < len; i++ )
  +                {
  +                    m_elements.add( elements[i] );
  +                }
  +            }
  +            finally
               {
  -                m_elements.add( elements[i] );
  +                m_mutex.release();
               }
           }
           catch ( InterruptedException ie )
           {
           }
  -        finally
  -        {
  -            m_mutex.release();
  -        }
       }
   
       public void enqueue( final QueueElement element )
  @@ -146,20 +155,23 @@
           try
           {
               m_mutex.acquire();
  -            if (  maxSize() > 0 && 1 + m_reserve + size() > maxSize() )
  +            try
               {
  -                throw new SinkFullException("Not enough room to enqueue these elements.");
  -            }
  +                if (  maxSize() > 0 && 1 + m_reserve + size() > maxSize()
)
  +                {
  +                    throw new SinkFullException("Not enough room to enqueue these elements.");
  +                }
   
  -            m_elements.add( element );
  +                m_elements.add( element );
  +            }
  +            finally
  +            {
  +                m_mutex.release();
  +            }
           }
           catch ( InterruptedException ie )
           {
           }
  -        finally
  -        {
  -            m_mutex.release();
  -        }
       }
   
       public QueueElement[] dequeue( final int numElements )
  @@ -175,27 +187,31 @@
   
           try
           {
  -            m_mutex.attempt( m_timeout );
  -
  -            if ( size() < numElements )
  -            {
  -                arraySize = size();
  -            }
  -
  -            elements = new QueueElement[ arraySize ];
  -
  -            for ( int i = 0; i < arraySize; i++ )
  +            if (m_mutex.attempt( m_timeout )) 
               {
  -                elements[i] = (QueueElement) m_elements.remove();
  +                try
  +                {
  +                    if ( size() < numElements )
  +                    {
  +                        arraySize = size();
  +                    }
  +
  +                    elements = new QueueElement[ arraySize ];
  +
  +                    for ( int i = 0; i < arraySize; i++ )
  +                    {
  +                        elements[i] = (QueueElement) m_elements.remove();
  +                    }
  +                }
  +                finally
  +                {
  +                    m_mutex.release();
  +                }
               }
           }
           catch ( InterruptedException ie )
           {
           }
  -        finally
  -        {
  -            m_mutex.release();
  -        }
   
           return elements;
       }
  @@ -206,22 +222,26 @@
   
           try
           {
  -            m_mutex.attempt( m_timeout );
  -
  -            elements = new QueueElement[ size() ];
  -
  -            for ( int i = 0; i < elements.length; i++ )
  +            if (m_mutex.attempt( m_timeout )) 
               {
  -                elements[i] = (QueueElement) m_elements.remove();
  +                try
  +                {
  +                    elements = new QueueElement[ size() ];
  +
  +                    for ( int i = 0; i < elements.length; i++ )
  +                    {
  +                        elements[i] = (QueueElement) m_elements.remove();
  +                    }
  +                }
  +                finally
  +                {
  +                    m_mutex.release();
  +                }
               }
           }
           catch ( InterruptedException ie )
           {
           }
  -        finally
  -        {
  -            m_mutex.release();
  -        }
   
           return elements;
       }
  @@ -232,19 +252,23 @@
   
           try
           {
  -            m_mutex.attempt( m_timeout );
  -
  -            if ( size() > 0 )
  +            if (m_mutex.attempt( m_timeout )) 
               {
  -                element = (QueueElement) m_elements.remove();
  +                try
  +                {
  +                    if ( size() > 0 )
  +                    {
  +                        element = (QueueElement) m_elements.remove();
  +                    }
  +                }
  +                finally
  +                {
  +                    m_mutex.release();
  +                }
               }
           }
           catch ( InterruptedException ie )
           {
  -        }
  -        finally
  -        {
  -            m_mutex.release();
           }
   
           return element;
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message