You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2009/10/23 18:27:32 UTC
svn commit: r829118 - in
/incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller:
AggregateAnalysisEngineController_impl.java BaseAnalysisEngineController.java
Author: cwiklik
Date: Fri Oct 23 16:27:31 2009
New Revision: 829118
URL: http://svn.apache.org/viewvc?rev=829118&view=rev
Log:
UIMA-1630 Synchronized access to childControllerList to prevent concurrent access that may lead to IndexOutOfBounds exception
Modified:
incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AggregateAnalysisEngineController_impl.java
incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java
Modified: incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AggregateAnalysisEngineController_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AggregateAnalysisEngineController_impl.java?rev=829118&r1=829117&r2=829118&view=diff
==============================================================================
--- incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AggregateAnalysisEngineController_impl.java (original)
+++ incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AggregateAnalysisEngineController_impl.java Fri Oct 23 16:27:31 2009
@@ -121,7 +121,7 @@
protected volatile boolean initialized = false;
- protected List childControllerList = new ArrayList();
+ protected List<AnalysisEngineController> childControllerList = new ArrayList<AnalysisEngineController>();
private ConcurrentHashMap delegateStats = new ConcurrentHashMap();
@@ -190,7 +190,9 @@
"UIMAEE_register_controller__FINE",
new Object[] { getComponentName(), aChildController.getComponentName() });
}
- childControllerList.add(aChildController);
+ synchronized(childControllerList) {
+ childControllerList.add(aChildController);
+ }
}
public void saveStatsFromService(String aServiceEndpointName, Map aServiceStats) {
@@ -1291,10 +1293,14 @@
}
public void sendRequestForMetadataToRemoteDelegates() throws AsynchAEException {
- for (int i = 0; i < childControllerList.size(); i++) {
- if (childControllerList.get(i) instanceof AggregateAnalysisEngineController) {
- ((AggregateAnalysisEngineController) childControllerList.get(i))
- .sendRequestForMetadataToRemoteDelegates();
+ synchronized(childControllerList) {
+ if ( childControllerList.size() > 0 ) {
+ for( AnalysisEngineController childController : childControllerList ) {
+ if (childController instanceof AggregateAnalysisEngineController) {
+ ((AggregateAnalysisEngineController) childController)
+ .sendRequestForMetadataToRemoteDelegates();
+ }
+ }
}
}
Endpoint[] delegateEndpoints = new Endpoint[destinationMap.size()];
@@ -2729,8 +2735,11 @@
if (originMap != null) {
originMap.clear();
}
+
if (childControllerList != null) {
- childControllerList.clear();
+ synchronized( childControllerList ) {
+ childControllerList.clear();
+ }
}
if (delegateStats != null) {
delegateStats.clear();
@@ -2766,11 +2775,13 @@
*/
public void onInitialize() {
// For each collocated delegate
- for (int i = 0; i < childControllerList.size(); i++) {
- AnalysisEngineController delegateController = (AnalysisEngineController) childControllerList
- .get(i);
- // notify the delegate
- delegateController.onInitialize();
+ synchronized(childControllerList) {
+ if ( childControllerList.size() > 0 ) {
+ for( AnalysisEngineController childController : childControllerList ) {
+ // notify the delegate
+ childController.onInitialize();
+ }
+ }
}
}
Modified: incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java
URL: http://svn.apache.org/viewvc/incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java?rev=829118&r1=829117&r2=829118&view=diff
==============================================================================
--- incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java (original)
+++ incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java Fri Oct 23 16:27:31 2009
@@ -575,12 +575,12 @@
// their internal transports.
if (this instanceof AggregateAnalysisEngineController) {
// Get a list of all colocated delegate controllers.
- List childControllers = ((AggregateAnalysisEngineController_impl) this).childControllerList;
-
- for (int i = 0; i < childControllers.size(); i++) {
- AnalysisEngineController ctrl = (AnalysisEngineController) childControllers.get(i);
- // Force initialization
- ctrl.initializeVMTransport(parentControllerReplyConsumerCount);
+ List<AnalysisEngineController> childControllers = ((AggregateAnalysisEngineController_impl) this).childControllerList;
+ synchronized( childControllers ) {
+ for( AnalysisEngineController ctrl: childControllers ) {
+ // Force initialization
+ ctrl.initializeVMTransport(parentControllerReplyConsumerCount);
+ }
}
}
@@ -1732,22 +1732,20 @@
((AggregateAnalysisEngineController_impl) this).stopTimers();
// Stops ALL input channels of this service including the reply channels
stopInputChannels(InputChannel.CloseAllChannels);
-
- int childControllerListSize = ((AggregateAnalysisEngineController_impl) this)
- .getChildControllerList().size();
- // send terminate event to all collocated child controllers
- if (childControllerListSize > 0) {
- for (int i = 0; i < childControllerListSize; i++) {
- AnalysisEngineController childController = (AnalysisEngineController) ((AggregateAnalysisEngineController_impl) this)
- .getChildControllerList().get(i);
-
- if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.INFO)) {
- UIMAFramework.getLogger(CLASS_NAME).logrb(Level.INFO, getClass().getName(), "stop",
- UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE, "UIMAEE_stop_delegate__INFO",
- new Object[] { getComponentName(), childController.getComponentName() });
+
+ List<AnalysisEngineController> colocatedControllerList =
+ ((AggregateAnalysisEngineController_impl)this).getChildControllerList();
+ synchronized(colocatedControllerList) {
+ if ( colocatedControllerList.size() > 0 ) {
+ for( AnalysisEngineController childController : colocatedControllerList ) {
+ if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.INFO)) {
+ UIMAFramework.getLogger(CLASS_NAME).logrb(Level.INFO, getClass().getName(), "stop",
+ UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE, "UIMAEE_stop_delegate__INFO",
+ new Object[] { getComponentName(), childController.getComponentName() });
+ }
+ childController.stop();
+ childController.getControllerLatch().release();
}
- childController.stop();
- childController.getControllerLatch().release();
}
}
}
@@ -1970,12 +1968,15 @@
}
private AnalysisEngineController lookupDelegateController(String aName) {
- List delegateControllers = ((AggregateAnalysisEngineController) this).getChildControllerList();
- for (int i = 0; i < delegateControllers.size(); i++) {
- AnalysisEngineController delegateController = (AnalysisEngineController) ((AggregateAnalysisEngineController_impl) this)
- .getChildControllerList().get(i);
- if (delegateController.getName().equals(aName)) {
- return delegateController;
+ List<AnalysisEngineController> colocatedControllerList =
+ ((AggregateAnalysisEngineController_impl)this).getChildControllerList();
+ synchronized(colocatedControllerList) {
+ if ( colocatedControllerList.size() > 0 ) {
+ for( AnalysisEngineController childController : colocatedControllerList ) {
+ if (childController.getName().equals(aName)) {
+ return childController;
+ }
+ }
}
}
return null; // no match
@@ -2135,15 +2136,15 @@
}
public AnalysisEngineController getCasMultiplierController(String cmKey) {
- int childControllerListSize = ((AggregateAnalysisEngineController_impl) this)
- .getChildControllerList().size();
- if (childControllerListSize > 0) {
- for (int i = 0; i < childControllerListSize; i++) {
- AnalysisEngineController childController = (AnalysisEngineController) ((AggregateAnalysisEngineController_impl) this)
- .getChildControllerList().get(i);
- if (childController.isCasMultiplier()
- && ((BaseAnalysisEngineController) childController).delegateKey.equals(cmKey)) {
- return childController;
+ List<AnalysisEngineController> colocatedControllerList =
+ ((AggregateAnalysisEngineController_impl)this).getChildControllerList();
+ synchronized(colocatedControllerList) {
+ if ( colocatedControllerList.size() > 0 ) {
+ for( AnalysisEngineController childController : colocatedControllerList ) {
+ if (childController.isCasMultiplier()
+ && ((BaseAnalysisEngineController) childController).delegateKey.equals(cmKey)) {
+ return childController;
+ }
}
}
}
@@ -2465,13 +2466,12 @@
// Get a list of all colocated delegate controllers from the Aggregate
List<AnalysisEngineController> delegateControllerList = ((AggregateAnalysisEngineController_impl) this).childControllerList;
// Iterate over all colocated delegates
- for (int i = 0; i < delegateControllerList.size(); i++) {
- // Get the next delegate's controller
- AnalysisEngineController delegateController = (AnalysisEngineController) delegateControllerList
- .get(i);
- if (delegateController != null && !delegateController.isStopped()) {
- // get the CPU time for all processing threads in the current controller
- totalCpuProcessTime += delegateController.getAnalysisTime();
+ synchronized( delegateControllerList) {
+ for( AnalysisEngineController delegateController : delegateControllerList ) {
+ if (delegateController != null && !delegateController.isStopped()) {
+ // get the CPU time for all processing threads in the current controller
+ totalCpuProcessTime += delegateController.getAnalysisTime();
+ }
}
}
} else // Primitive Controller