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 2018/03/15 22:27:47 UTC

svn commit: r1826882 - in /uima/uima-as/trunk: uimaj-as-activemq/src/test/java/org/apache/uima/ee/test/ uimaj-as-activemq/src/test/resources/deployment/ uimaj-as-core/src/main/java/org/apache/uima/aae/controller/

Author: cwiklik
Date: Thu Mar 15 22:27:47 2018
New Revision: 1826882

URL: http://svn.apache.org/viewvc?rev=1826882&view=rev
Log:
UIMA-5750 Fixed ClassCastException when async aggregate initializes delegate with JMS Service Descriptor

Added:
    uima/uima-as/trunk/uimaj-as-activemq/src/test/resources/deployment/Deploy_AsyncAggregateWithJmsService.xml
Modified:
    uima/uima-as/trunk/uimaj-as-activemq/src/test/java/org/apache/uima/ee/test/TestUimaASExtended.java
    uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java

Modified: uima/uima-as/trunk/uimaj-as-activemq/src/test/java/org/apache/uima/ee/test/TestUimaASExtended.java
URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/uimaj-as-activemq/src/test/java/org/apache/uima/ee/test/TestUimaASExtended.java?rev=1826882&r1=1826881&r2=1826882&view=diff
==============================================================================
--- uima/uima-as/trunk/uimaj-as-activemq/src/test/java/org/apache/uima/ee/test/TestUimaASExtended.java (original)
+++ uima/uima-as/trunk/uimaj-as-activemq/src/test/java/org/apache/uima/ee/test/TestUimaASExtended.java Thu Mar 15 22:27:47 2018
@@ -893,12 +893,33 @@ public class TestUimaASExtended extends
         deployService(eeUimaEngine, relativePath + "/Deploy_NoOpAnnotator.xml");
         deployService(eeUimaEngine, relativePath + "/Deploy_SyncAggregateWithJmsService.xml");
         runTest(null, eeUimaEngine, String.valueOf(getMasterConnectorURI(broker)), "TopLevelTaeQueue",
-                0, PROCESS_LATCH);
+                1, PROCESS_LATCH);
        
     } catch( Exception e ) {
     	throw e;
     }
   }
+    /**
+     * Test use of a JMS Service Adapter. Invoke from a synchronous aggregate to emulate usage from
+     * RunAE or RunCPE.
+     * 
+     * @throws Exception
+     */
+      @Test
+      public void testJmsServiceAdapterInAsyncAggregate() throws Exception {
+  	  Logger.getLogger(this.getClass()).info("-------------- testJmsServiceAdapter -------------");
+  	  //setUp();
+  	  BaseUIMAAsynchronousEngine_impl eeUimaEngine = new BaseUIMAAsynchronousEngine_impl();
+      try {
+          deployService(eeUimaEngine, relativePath + "/Deploy_NoOpAnnotator.xml");
+          deployService(eeUimaEngine, relativePath + "/Deploy_AsyncAggregateWithJmsService.xml");
+          runTest(null, eeUimaEngine, String.valueOf(getMasterConnectorURI(broker)), "TopLevelTaeQueue",
+                  1, PROCESS_LATCH);
+         
+      } catch( Exception e ) {
+      	throw e;
+      }
+    }
   /*
    * Tests Uima AS client placeholder handling and substitution. The Uima Aggregate instantiates
    * UIMA AS client proxy using Jms Client Descriptor that contains a placeholder

Added: uima/uima-as/trunk/uimaj-as-activemq/src/test/resources/deployment/Deploy_AsyncAggregateWithJmsService.xml
URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/uimaj-as-activemq/src/test/resources/deployment/Deploy_AsyncAggregateWithJmsService.xml?rev=1826882&view=auto
==============================================================================
--- uima/uima-as/trunk/uimaj-as-activemq/src/test/resources/deployment/Deploy_AsyncAggregateWithJmsService.xml (added)
+++ uima/uima-as/trunk/uimaj-as-activemq/src/test/resources/deployment/Deploy_AsyncAggregateWithJmsService.xml Thu Mar 15 22:27:47 2018
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+  <!--
+   ***************************************************************
+   * Licensed to the Apache Software Foundation (ASF) under one
+   * or more contributor license agreements.  See the NOTICE file
+   * distributed with this work for additional information
+   * regarding copyright ownership.  The ASF licenses this file
+   * to you under the Apache License, Version 2.0 (the
+   * "License"); you may not use this file except in compliance
+   * with the License.  You may obtain a copy of the License at
+         *
+   *   http://www.apache.org/licenses/LICENSE-2.0
+   * 
+   * Unless required by applicable law or agreed to in writing,
+   * software distributed under the License is distributed on an
+   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   * KIND, either express or implied.  See the License for the
+   * specific language governing permissions and limitations
+   * under the License.
+   ***************************************************************
+   -->
+
+<analysisEngineDeploymentDescription xmlns="http://uima.apache.org/resourceSpecifier">
+  
+  <name>Top Level TAE</name>
+  <description></description>
+  
+  <deployment protocol="jms" provider="activemq">
+    <casPool numberOfCASes="5" initialFsHeapSize="500"/>
+    <service>
+      <inputQueue endpoint="TopLevelTaeQueue" brokerURL="${DefaultBrokerURL}" prefetch="1"/>
+      <topDescriptor>
+        <import location="../descriptors/analysis_engine/SimpleTestAggregateWithJmsService.xml"/>
+      </topDescriptor>
+      <analysisEngine async="true">
+      <!-- Run the CM & Jms Service Adapter asynchronously, just as RunAE and CPE do -->
+      </analysisEngine>
+    </service>
+  </deployment>
+  
+</analysisEngineDeploymentDescription>

Modified: uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java
URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java?rev=1826882&r1=1826881&r2=1826882&view=diff
==============================================================================
--- uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java (original)
+++ uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java Thu Mar 15 22:27:47 2018
@@ -94,6 +94,7 @@ import org.apache.uima.analysis_engine.m
 import org.apache.uima.analysis_engine.metadata.SofaMapping;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.collection.CollectionReaderDescription;
+import org.apache.uima.resource.CustomResourceSpecifier;
 import org.apache.uima.resource.PearSpecifier;
 import org.apache.uima.resource.Resource;
 import org.apache.uima.resource.ResourceCreationSpecifier;
@@ -963,46 +964,68 @@ public abstract class BaseAnalysisEngine
   public boolean isTopLevelComponent() {
     return (parentController == null);
   }
+
+  private String getDelegateServiceName() {
+	  String svcName = null;
+		try {
+			UimaContext childContext = parentController.getChildUimaContext(endpointName);
+			svcName = ((UimaContextAdmin) childContext).getQualifiedContextName();
+			if (svcName != null) {
+				if (svcName.startsWith("/")) {
+					svcName = svcName.substring(1);
+					svcName = svcName.replaceAll("/", "_"); // normalize
+					if (svcName.endsWith("_")) {
+						svcName = svcName.substring(0, serviceName.length() - 1);
+					}
+				}
+			}
+		} catch (Exception e) {
+			svcName = delegateKey;
+		}
+		return svcName;
+  }
+  private String getTopLevelServiceName() {
+	  String svcName = null;
+		if (isPrimitive()) {
+			String implementationName = "";
+			if (resourceSpecifier instanceof ResourceCreationSpecifier) {
+				implementationName = ((ResourceCreationSpecifier) resourceSpecifier).getImplementationName();
+			} else if (resourceSpecifier instanceof CustomResourceSpecifier) {
+				implementationName = ((CustomResourceSpecifier) resourceSpecifier).getResourceClassName();
+			}
+
+			if (implementationName.indexOf(".") > 0) {
+				implementationName = implementationName.substring(implementationName.lastIndexOf(".") + 1);
+			}
+			svcName = implementationName;
+		} else {
+			svcName = "Top Level Aggregate Service";
+		}
+		return svcName;
+  }
   private String setupName() {
-    //return ((ResourceCreationSpecifier) resourceSpecifier).getMetaData().getName();
-    String serviceName = ((ResourceCreationSpecifier) resourceSpecifier).getMetaData().getName();
-    if ( serviceName == null || serviceName.trim().length() == 0 ) {
-      
-      if ( isTopLevelComponent() ) {
-        if ( isPrimitive() ) {
-          String implementationName = ((ResourceCreationSpecifier) resourceSpecifier).getImplementationName();
-          if ( implementationName.indexOf(".") > 0) {
-            implementationName = implementationName.substring(implementationName.lastIndexOf(".")+1);
-          }
-          serviceName = implementationName;
-        } else {
-          serviceName = "Top Level Aggregate Service";
-        }
-      } else {
-        try {
-          UimaContext childContext = parentController.getChildUimaContext(endpointName);
-          serviceName = ((UimaContextAdmin)childContext).getQualifiedContextName();
-          if ( serviceName != null ) {
-            if ( serviceName.startsWith("/")) {
-              serviceName = serviceName.substring(1);
-              serviceName = serviceName.replaceAll("/", "_"); // normalize
-              if ( serviceName.endsWith("_")) {
-                serviceName = serviceName.substring(0, serviceName.length()-1);
-              }
-            }
-          }
-        } catch( Exception e){
-          serviceName = delegateKey;
-        }
-      }
-      if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.INFO)) {
-        UIMAFramework.getLogger(CLASS_NAME).logrb(Level.INFO, CLASS_NAME.getName(),
-                "setupName", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
-                "UIMAEE_using_generated_name_INFO", new Object[] { serviceName });
-      }
-    
-    } 
-    return serviceName;
+		String svcName = null;
+
+		if (!(resourceSpecifier instanceof CustomResourceSpecifier)) {
+			svcName = ((ResourceCreationSpecifier) resourceSpecifier).getMetaData().getName();
+		}
+
+		if (svcName == null || svcName.trim().length() == 0) {
+
+			if (isTopLevelComponent()) {
+				svcName = getTopLevelServiceName();
+			} else {
+				svcName = getDelegateServiceName();
+			}
+
+		}
+
+		if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.INFO)) {
+			UIMAFramework.getLogger(CLASS_NAME).logrb(Level.INFO, CLASS_NAME.getName(), "setupName",
+					UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE, "UIMAEE_using_generated_name_INFO",
+					new Object[] { svcName });
+		}
+		return svcName;
   }
   /**
    * Returns the name of the component. The name comes from the analysis engine descriptor