You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@excalibur.apache.org by sh...@apache.org on 2005/07/23 19:21:15 UTC
svn commit: r224483 - in /excalibur/trunk/components/monitor/src:
java/org/apache/avalon/excalibur/monitor/impl/AbstractMonitor.java
test/org/apache/avalon/excalibur/monitor/test/MonitorTestCase.java
Author: shash
Date: Sat Jul 23 10:21:11 2005
New Revision: 224483
URL: http://svn.apache.org/viewcvs?rev=224483&view=rev
Log:
Fix for EXLBR-26 - getResources() method of the AbstractMonitor should be probably synchronized on m_resources like the other methods in this class.
Modified:
excalibur/trunk/components/monitor/src/java/org/apache/avalon/excalibur/monitor/impl/AbstractMonitor.java
excalibur/trunk/components/monitor/src/test/org/apache/avalon/excalibur/monitor/test/MonitorTestCase.java
Modified: excalibur/trunk/components/monitor/src/java/org/apache/avalon/excalibur/monitor/impl/AbstractMonitor.java
URL: http://svn.apache.org/viewcvs/excalibur/trunk/components/monitor/src/java/org/apache/avalon/excalibur/monitor/impl/AbstractMonitor.java?rev=224483&r1=224482&r2=224483&view=diff
==============================================================================
--- excalibur/trunk/components/monitor/src/java/org/apache/avalon/excalibur/monitor/impl/AbstractMonitor.java (original)
+++ excalibur/trunk/components/monitor/src/java/org/apache/avalon/excalibur/monitor/impl/AbstractMonitor.java Sat Jul 23 10:21:11 2005
@@ -86,7 +86,7 @@
}
/**
- * Remove a monitored resource by key.
+ * Remove a monitored resource by key. Will throw NPE, if no resource with given key.
*/
public final void removeResource( final String key )
{
@@ -99,7 +99,7 @@
}
/**
- * Remove a monitored resource by reference.
+ * Remove a monitored resource by reference. Will throw NPE, if resource has been removed from monitor.
*/
public final void removeResource( final Resource resource )
{
@@ -113,8 +113,11 @@
*/
protected Resource[] getResources()
{
- final Collection collection = m_resources.values();
- return (Resource[])collection.toArray( new Resource[ collection.size() ] );
+ synchronized( m_resources )
+ {
+ final Collection collection = m_resources.values();
+ return (Resource[])collection.toArray( new Resource[ collection.size() ] );
+ }
}
/**
Modified: excalibur/trunk/components/monitor/src/test/org/apache/avalon/excalibur/monitor/test/MonitorTestCase.java
URL: http://svn.apache.org/viewcvs/excalibur/trunk/components/monitor/src/test/org/apache/avalon/excalibur/monitor/test/MonitorTestCase.java?rev=224483&r1=224482&r2=224483&view=diff
==============================================================================
--- excalibur/trunk/components/monitor/src/test/org/apache/avalon/excalibur/monitor/test/MonitorTestCase.java (original)
+++ excalibur/trunk/components/monitor/src/test/org/apache/avalon/excalibur/monitor/test/MonitorTestCase.java Sat Jul 23 10:21:11 2005
@@ -20,7 +20,9 @@
import java.io.OutputStreamWriter;
import java.io.Writer;
+import org.apache.avalon.excalibur.monitor.FileResource;
import org.apache.avalon.excalibur.monitor.Monitor;
+import org.apache.avalon.excalibur.monitor.Resource;
import org.apache.avalon.excalibur.testcase.CascadingAssertionFailedError;
import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
import org.apache.avalon.framework.component.Component;
@@ -103,6 +105,53 @@
selector.release( (Component)passiveMonitor );
manager.release( selector );
}
+ }
+
+ public void testActiveMonitorThreadSafety() throws CascadingAssertionFailedError
+ {
+ ComponentSelector selector = null;
+ Monitor activeMonitor = null;
+
+ try
+ {
+ selector = (ComponentSelector) manager.lookup( Monitor.ROLE + "Selector" );
+ activeMonitor = (Monitor) selector.select( "active" );
+ final Monitor monitor = activeMonitor;
+ getLogger().info( "Aquired Active monitor" );
+ for ( int i = 0; i < 500; i++ )
+ {
+ final int threadNum = i;
+ final Thread thread = new Thread() {
+ Resource resource = new FileResource( "testts-" + threadNum + ".txt" );
+
+ public void run()
+ {
+ while ( true )
+ {
+ monitor.addResource( resource );
+ monitor.removeResource( resource );
+ }
+ }
+ };
+ thread.start();
+ }
+ }
+ catch ( final Exception e )
+ {
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "There was an error in the ActiveMonitor test", e );
+ }
+
+ throw new CascadingAssertionFailedError( "There was an error in the ActiveMonitor test", e );
+ }
+ finally
+ {
+ assertTrue( "The monitor selector could not be retrieved.", null != selector );
+ selector.release( (Component)activeMonitor );
+ manager.release( selector );
+ }
+
}
private void internalTestProcedure( final Monitor testMonitor,
---------------------------------------------------------------------
To unsubscribe, e-mail: scm-unsubscribe@excalibur.apache.org
For additional commands, e-mail: scm-help@excalibur.apache.org