Author: cwiklik
Date: Thu Oct 30 14:00:57 2014
New Revision: 1635501
URL: http://svn.apache.org/r1635501
Log:
UIMA-4066 created jd and jp configuration packages in transport project.
Initial implementation of JP component. Reorg of poms to support jd and jp
development
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/jp/
uima/sandbox/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/jp/JobProcess.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jd/
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jd/JobDriverConfiguration.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/JobProcessConfiguration.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/listener/
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/listener/jd/
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/listener/jd/JobDriverEventListener.java
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/listener/jp/
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/listener/jp/JobProcessEventListener.java
uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/
uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/DuccUimaLoader.java
uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaProcessContainer.java
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-container/pom.xml
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/pom.xml
uima/sandbox/uima-ducc/trunk/uima-ducc-user/pom.xml
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-container/pom.xml
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-container/pom.xml?rev=1635501&r1=1635500&r2=1635501&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-container/pom.xml (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-container/pom.xml Thu Oct 30
14:00:57 2014
@@ -47,6 +47,15 @@
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-container
</url>
</scm>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uima-ducc-user</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
<dependencies>
<!-- Dependencies on other DUCC projects -->
@@ -55,11 +64,11 @@
<artifactId>uima-ducc-common</artifactId>
</dependency>
+
<dependency>
<groupId>org.apache.uima</groupId>
- <artifactId>uima-ducc-transport</artifactId>
+ <artifactId>uima-ducc-user</artifactId>
</dependency>
-
</dependencies>
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/jp/JobProcess.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/jp/JobProcess.java?rev=1635501&view=auto
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/jp/JobProcess.java
(added)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-container/src/main/java/org/apache/uima/ducc/container/jp/JobProcess.java
Thu Oct 30 14:00:57 2014
@@ -0,0 +1,10 @@
+package org.apache.uima.ducc.container.jp;
+
+public class JobProcess {
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-transport/pom.xml
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/pom.xml?rev=1635501&r1=1635500&r2=1635501&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-transport/pom.xml (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-transport/pom.xml Thu Oct 30
14:00:57 2014
@@ -48,7 +48,15 @@
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport
</url>
</scm>
-
+<dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uima-ducc-container</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.uima</groupId>
@@ -56,6 +64,16 @@
<scope>compile</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uima-ducc-container</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
+
+
+
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jd/JobDriverConfiguration.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jd/JobDriverConfiguration.java?rev=1635501&view=auto
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jd/JobDriverConfiguration.java
(added)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jd/JobDriverConfiguration.java
Thu Oct 30 14:00:57 2014
@@ -0,0 +1,5 @@
+package org.apache.uima.ducc.transport.configuration.jd;
+
+public class JobDriverConfiguration {
+
+}
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/JobProcessConfiguration.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/JobProcessConfiguration.java?rev=1635501&view=auto
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/JobProcessConfiguration.java
(added)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/configuration/jp/JobProcessConfiguration.java
Thu Oct 30 14:00:57 2014
@@ -0,0 +1,5 @@
+package org.apache.uima.ducc.transport.configuration.jp;
+
+public class JobProcessConfiguration {
+
+}
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/listener/jd/JobDriverEventListener.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/listener/jd/JobDriverEventListener.java?rev=1635501&view=auto
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/listener/jd/JobDriverEventListener.java
(added)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/listener/jd/JobDriverEventListener.java
Thu Oct 30 14:00:57 2014
@@ -0,0 +1,5 @@
+package org.apache.uima.ducc.transport.listener.jd;
+
+public class JobDriverEventListener {
+
+}
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/listener/jp/JobProcessEventListener.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/listener/jp/JobProcessEventListener.java?rev=1635501&view=auto
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/listener/jp/JobProcessEventListener.java
(added)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/listener/jp/JobProcessEventListener.java
Thu Oct 30 14:00:57 2014
@@ -0,0 +1,36 @@
+/*
+ * 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.
+*/
+package org.apache.uima.ducc.transport.listener.jp;
+
+//import org.apache.uima.ducc.agent.deploy.ManagedService;
+import org.apache.uima.ducc.transport.dispatcher.DuccEventDispatcher;
+import org.apache.uima.ducc.transport.event.delegate.DuccEventDelegateListener;
+
+
+public class JobProcessEventListener implements DuccEventDelegateListener{
+
+ @Override
+ public void setDuccEventDispatcher(DuccEventDispatcher eventDispatcher)
{
+ // TODO Auto-generated method stub
+
+ }
+
+
+
+}
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-user/pom.xml
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-user/pom.xml?rev=1635501&r1=1635500&r2=1635501&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-user/pom.xml (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-user/pom.xml Thu Oct 30 14:00:57 2014
@@ -50,17 +50,40 @@
<dependencies>
<!-- Dependencies on other DUCC projects -->
- <dependency>
+
+ <dependency>
<groupId>org.apache.uima</groupId>
- <artifactId>uima-ducc-common</artifactId>
+ <artifactId>uimaj-as-activemq</artifactId>
+ <exclusions>
+ <exclusion>
+ <artifactId>jetty-webapp</artifactId>
+ <groupId>org.eclipse.jetty</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>josql</artifactId>
+ <groupId>net.sf.josql</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>gentlyweb-utils</artifactId>
+ <groupId>net.sf.josql</groupId>
+ </exclusion>
+ </exclusions>
</dependency>
- <dependency>
- <groupId>org.apache.uima</groupId>
- <artifactId>uima-ducc-transport</artifactId>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-camel</artifactId>
</dependency>
- </dependencies>
-
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-xstream</artifactId>
+ </dependency>
+ </dependencies>
+
</project>
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/DuccUimaLoader.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/DuccUimaLoader.java?rev=1635501&view=auto
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/DuccUimaLoader.java
(added)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/DuccUimaLoader.java
Thu Oct 30 14:00:57 2014
@@ -0,0 +1,142 @@
+package org.apache.uima.ducc.user.jp;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DuccUimaLoader {
+ private static boolean suppressClassPathDisplay;
+ Object uimaContainerInstance = null;
+ Method processMethod = null;
+ Method stopMethod = null;
+
+ //
+ public static void main(String[] args) {
+ try {
+ DuccUimaLoader loader = new DuccUimaLoader();
+ loader.deploy(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ public int deploy(String[] args) throws Exception {
+ URL[] urls = getUrls();
+
+ addUrlsToSystemLoader(urls);
+
+ Class<?> classToLaunch = null;
+ try {
+ classToLaunch =
ClassLoader.getSystemClassLoader().loadClass(
+ "UimaProcessContainer");
+ } catch (ClassNotFoundException e) {
+ System.err.println("Cannot find class to launch");
+ System.exit(1);
+ }
+ Method deployMethod = classToLaunch.getMethod("deploy",
String[].class);
+ processMethod = classToLaunch.getMethod("process",
String.class);
+ stopMethod = classToLaunch.getMethod("stop");
+ int args2length = args.length - 1;
+ if (args2length < 0) {
+ args2length = 0;
+ }
+ // String [] args2 = new String[args2length];
+ // if ( args2.length > 0 ) {
+ // System.arraycopy(args, 0, args2, 0, args2length);
+ // }
+ uimaContainerInstance = classToLaunch.newInstance();
+ Object scaleout = deployMethod.invoke(uimaContainerInstance,
+ (Object) args);
+ return (Integer) scaleout;
+ // return 1;
+ }
+
+ public void stop() throws Exception {
+ stopMethod.invoke(uimaContainerInstance);
+
+ }
+
+ public void process(String xmi) throws Exception {
+ processMethod.invoke(uimaContainerInstance, xmi);
+ }
+
+ private static void addUrlsToSystemLoader(URL[] urls) throws
IOException {
+ URLClassLoader systemClassLoader = (URLClassLoader) ClassLoader
+ .getSystemClassLoader();
+ try {
+ Method method =
URLClassLoader.class.getDeclaredMethod("addURL",
+ new Class[] { URL.class });
+ method.setAccessible(true); // is normally "protected"
+ for (URL url : urls) {
+ method.invoke(systemClassLoader, new Object[] {
url });
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ throw new IOException(
+ "Error, could not add URL to system
classloader");
+ }
+ }
+
+ private URL[] getUrls() throws MalformedURLException, IOException,
+ URISyntaxException {
+ String jps =
System.getProperty("org.apache.uima.ducc.userjarpath");
+ if (null == jps) {
+ System.err
+ .println("Missing the
-Dorg.apache.uima.jarpath=XXXX property");
+ System.exit(1);
+ }
+ if (!suppressClassPathDisplay) {
+ System.out.println("UimaBootstrap ClassPath:");
+ }
+ List<URL> urls = new ArrayList<URL>();
+ String[] jpaths = jps.split(File.pathSeparator);
+ for (String p : jpaths) {
+ addUrlsFromPath(p, urls);
+ }
+ return urls.toArray(new URL[urls.size()]);
+ }
+
+ private static FilenameFilter jarFilter = new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ name = name.toLowerCase();
+ return (name.endsWith(".jar"));
+ }
+ };
+
+ private static void addUrlsFromPath(String p, List<URL> urls)
+ throws MalformedURLException, IOException,
URISyntaxException {
+ File pf = new File(p);
+ if (pf.isDirectory()) {
+ File[] jars = pf.listFiles(jarFilter);
+ if (jars.length == 0) {
+ // this is the case where the user wants to
include
+ // a directory containing non-jar'd .class files
+ add(urls, pf);
+ } else {
+ for (File f : jars) {
+ add(urls, f);
+ }
+ }
+ } else if (p.toLowerCase().endsWith(".jar")) {
+ add(urls, pf);
+ }
+ }
+
+ private static void add(List<URL> urls, File cp)
+ throws MalformedURLException {
+ URL url = cp.toURI().toURL();
+ if (!suppressClassPathDisplay) {
+ System.out.format(" %s%n", url.toString());
+ }
+ urls.add(url);
+ }
+
+}
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaProcessContainer.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaProcessContainer.java?rev=1635501&view=auto
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaProcessContainer.java
(added)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaProcessContainer.java
Thu Oct 30 14:00:57 2014
@@ -0,0 +1,396 @@
+package org.apache.uima.ducc.user.jp;
+import java.io.File;
+import java.io.IOException;
+import java.net.BindException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.aae.UimaASApplicationEvent.EventTrigger;
+import org.apache.uima.aae.UimaAsVersion;
+import org.apache.uima.aae.UimaSerializer;
+import org.apache.uima.aae.client.UimaASProcessStatus;
+import org.apache.uima.aae.client.UimaAsBaseCallbackListener;
+import org.apache.uima.aae.client.UimaAsynchronousEngine;
+import org.apache.uima.aae.monitor.statistics.AnalysisEnginePerformanceMetrics;
+import org.apache.uima.adapter.jms.client.BaseUIMAAsynchronousEngine_impl;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.impl.XmiSerializationSharedData;
+import org.apache.uima.collection.EntityProcessStatus;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.util.Level;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class UimaProcessContainer {
+ String endpointName;
+ protected int scaleout;
+ String saxonURL = null;
+ String xslTransform = null;
+ String uimaAsDebug = null;
+ static final BaseUIMAAsynchronousEngine_impl uimaASClient = new
BaseUIMAAsynchronousEngine_impl();
+ protected Object initializeMonitor = new Object();
+ public volatile boolean initialized = false;
+ private static final Class CLASS_NAME = UimaProcessContainer.class;
+ private static final char FS =
System.getProperty("file.separator").charAt(
+ 0);
+ public static BrokerService broker = null;// new BrokerService();
+ private UimaSerializer uimaSerializer = new UimaSerializer();
+
+ public int deploy(String[] args) throws Exception {
+
+ broker = new BrokerService();
+ broker.setDedicatedTaskRunner(false);
+ broker.setPersistent(false);
+ int port = 61626;
+ String brokerURL = "tcp://localhost:";
+ while (true) {
+ try {
+ broker.addConnector(brokerURL + port);
+ broker.start();
+ broker.waitUntilStarted();
+ System.setProperty("DefaultBrokerURL",
brokerURL + port);
+ break;
+ } catch (IOException e) {
+ if (e.getCause() instanceof BindException) {
+ port++;
+ } else {
+ e.printStackTrace();
+ break;
+ }
+
+ }
+
+ }
+ String[] deploymentDescriptors = initialize(args);
+ // deploy colocated UIMA-AS services from provided deployment
+ // descriptors
+ String[] ids = new String[deploymentDescriptors.length];
+ int i = 0;
+ for (String dd : deploymentDescriptors) {
+ // keep the container id so that we can un-deploy it
when shutting
+ // down
+ ids[i] = deployService(dd);
+ }
+ // initialize and start UIMA-AS client. This sends GetMeta
request to
+ // deployed top level service and waits for reply
+ initializeUimaAsClient(endpointName);
+
+ return scaleout;
+ }
+
+ public void stop() throws Exception {
+ System.out.println("Stopping UIMA_AS Client");
+ try {
+ uimaASClient.stop();
+
+ } catch( Exception e) {
+ e.printStackTrace();
+ }
+ System.out.println("Stopping Broker");
+ broker.stop();
+ broker.waitUntilStopped();
+ }
+ public void initializeUimaAsClient(String endpoint) throws Exception {
+
+ String brokerURL = System.getProperty("DefaultBrokerURL");//
"vm://localhost?broker.persistent=false";
+
+ Map<String, Object> appCtx = new HashMap<String, Object>();
+ appCtx.put(UimaAsynchronousEngine.ServerUri, brokerURL);
+ appCtx.put(UimaAsynchronousEngine.ENDPOINT, endpoint);
+ appCtx.put(UimaAsynchronousEngine.CasPoolSize, scaleout);
+ appCtx.put(UimaAsynchronousEngine.Timeout, 0);
+ appCtx.put(UimaAsynchronousEngine.GetMetaTimeout, 0);
+ appCtx.put(UimaAsynchronousEngine.CpcTimeout, 1100);
+ UimaAsTestCallbackListener listener = new
UimaAsTestCallbackListener();
+
+ uimaASClient.addStatusCallbackListener(listener);
+ uimaASClient.initialize(appCtx);
+
+ waitUntilInitialized();
+
+ }
+
+ protected void waitUntilInitialized() throws Exception {
+ synchronized (initializeMonitor) {
+ while (!initialized) {
+ initializeMonitor.wait();
+ }
+ }
+ }
+
+ protected String deployService(String aDeploymentDescriptorPath)
+ throws Exception {
+
+ Map<String, Object> appCtx = new HashMap<String, Object>();
+ appCtx.put(UimaAsynchronousEngine.DD2SpringXsltFilePath,
+ xslTransform.replace('/', FS));
+ appCtx.put(UimaAsynchronousEngine.SaxonClasspath,
+ saxonURL.replace('/', FS));
+ String containerId = null;
+ try {
+ containerId = uimaASClient
+ .deploy(aDeploymentDescriptorPath,
appCtx);
+
+ } catch (ResourceInitializationException e) {
+
+ System.out.println(">>>>>>>>>>> Exception ---:"
+ + e.getClass().getName());
+ } catch (Exception e) {
+ System.out.println(">>>>>>>>>>> runTest: Exception:"
+ + e.getClass().getName());
+ throw e;
+ }
+ return containerId;
+ }
+
+ public void process(String xmi) throws Exception {
+ CAS cas = uimaASClient.getCAS();
+ XmiSerializationSharedData deserSharedData = new
XmiSerializationSharedData();
+
+ uimaSerializer.deserializeCasFromXmi(xmi, cas, deserSharedData,
true,-1);
+ // System.out.println("Sending CAS to JD");
+ uimaASClient.sendAndReceiveCAS(cas);
+ cas.release();
+ }
+
+ public String[] initialize(String[] args) throws Exception {
+ UIMAFramework.getLogger(CLASS_NAME).log(Level.INFO,
+ "UIMA-AS version " +
UimaAsVersion.getFullVersionString());
+
+ int nbrOfArgs = args.length;
+ String[] deploymentDescriptors = getMultipleArg("-d", args);
+ if (deploymentDescriptors.length == 0) {
+ // allow multiple args for one key
+ deploymentDescriptors = getMultipleArg2("-dd", args);
+ }
+ saxonURL = getArg("-saxonURL", args);
+ xslTransform = getArg("-xslt", args);
+ uimaAsDebug = getArg("-uimaEeDebug", args);
+ endpointName = getArg("-q", args);
+
+ if (nbrOfArgs < 1
+ || (deploymentDescriptors.length == 0
+// || (args[0].startsWith("-") &&
(deploymentDescriptors.length == 0
+ || saxonURL.equals("") ||
xslTransform.equals(""))) {
+ printUsageMessage();
+ return null; // Done here
+ }
+ parseDD(deploymentDescriptors[0]);
+ return deploymentDescriptors;
+ }
+
+ public void parseDD(String ddPath) throws Exception {
+ SAXParserFactory parserFactor = SAXParserFactory.newInstance();
+ SAXParser parser = parserFactor.newSAXParser();
+ SAXHandler handler = new SAXHandler();
+ parser.parse(new File(ddPath), handler);
+
+ }
+
+ class SAXHandler extends DefaultHandler {
+
+ String content = null;
+
+ @Override
+ // Triggered when the start of tag is found.
+ public void startElement(String uri, String localName, String
qName,
+ Attributes attributes) throws SAXException {
+ if (qName.equals("inputQueue")) {
+ endpointName = attributes.getValue("endpoint");
+ } else if (qName.equals("scaleout")) {
+ scaleout = Integer.parseInt(attributes
+ .getValue("numberOfInstances"));
+ }
+
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String
qName)
+ throws SAXException {
+
+ }
+
+ }
+
+ /**
+ * scan args for a particular arg, return the following token or the
empty
+ * string if not found
+ *
+ * @param id
+ * the arg to search for
+ * @param args
+ * the array of strings
+ * @return the following token, or a 0 length string if not found
+ */
+ private static String getArg(String id, String[] args) {
+ for (int i = 0; i < args.length; i++) {
+ if (id.equals(args[i]))
+ return (i + 1 < args.length) ? args[i + 1] : "";
+ }
+ return "";
+ }
+
+ /**
+ * scan args for a particular arg, return the following token(s) or the
+ * empty string if not found
+ *
+ * @param id
+ * the arg to search for
+ * @param args
+ * the array of strings
+ * @return the following token, or a 0 length string array if not found
+ */
+ private static String[] getMultipleArg(String id, String[] args) {
+ String[] retr = {};
+ for (int i = 0; i < args.length; i++) {
+ if (id.equals(args[i])) {
+ String[] temp = new String[retr.length + 1];
+ for (int s = 0; s < retr.length; s++) {
+ temp[s] = retr[s];
+ }
+ retr = temp;
+ retr[retr.length - 1] = (i + 1 < args.length) ?
args[i + 1]
+ : null;
+ }
+ }
+ return retr;
+ }
+
+ /**
+ * scan args for a particular arg, return the following token(s) or the
+ * empty string if not found
+ *
+ * @param id
+ * the arg to search for
+ * @param args
+ * the array of strings
+ * @return the following token, or a 0 length string array if not found
+ */
+ private static String[] getMultipleArg2(String id, String[] args) {
+ String[] retr = {};
+ for (int i = 0; i < args.length; i++) {
+ if (id.equals(args[i])) {
+ int j = 0;
+ while ((i + 1 + j < args.length)
+ && !args[i + 1 +
j].startsWith("-")) {
+ String[] temp = new String[retr.length
+ 1];
+ for (int s = 0; s < retr.length; s++) {
+ temp[s] = retr[s];
+ }
+ retr = temp;
+ retr[retr.length - 1] = args[i + 1 +
j++];
+ }
+ return retr;
+ }
+ }
+ return retr;
+ }
+
+ protected void finalize() {
+ System.err.println(this + " finalized");
+ }
+
+ private static void printUsageMessage() {
+ System.out
+ .println(" Arguments to the program are as
follows : \n"
+ + "-d
path-to-UIMA-Deployment-Descriptor [-d path-to-UIMA-Deployment-Descriptor ...]
\n"
+ + "-saxon path-to-saxon.jar \n"
+ + "-q top level service queue
name \n"
+ + "-xslt
path-to-dd2spring-xslt\n"
+ + " or\n"
+ + "path to Spring XML
Configuration File which is the output of running dd2spring\n");
+ }
+
+ protected class UimaAsTestCallbackListener extends
+ UimaAsBaseCallbackListener {
+
+ public void onBeforeProcessCAS(UimaASProcessStatus status,
+ String nodeIP, String pid) {
+// System.out
+// .println("runTest: onBeforeProcessCAS()
Notification - CAS:"
+// +
status.getCasReferenceId()
+// + " is being processed
on machine:"
+// + nodeIP
+// + " by process (PID):"
+ pid);
+ }
+
+ public synchronized void
onBeforeMessageSend(UimaASProcessStatus status) {
+ // casSent = status.getCasReferenceId();
+// System.out
+// .println("runTest: Received
onBeforeMessageSend() Notification With CAS:"
+// +
status.getCasReferenceId());
+ }
+
+ public void onUimaAsServiceExit(EventTrigger cause) {
+ System.out
+ .println("runTest: Received
onUimaAsServiceExit() Notification With Cause:"
+ + cause.name());
+ }
+
+ public synchronized void entityProcessComplete(CAS aCAS,
+ EntityProcessStatus aProcessStatus,
+ List<AnalysisEnginePerformanceMetrics>
componentMetricsList) {
+ String casReferenceId = ((UimaASProcessStatus)
aProcessStatus)
+ .getCasReferenceId();
+
+// if (aProcessStatus instanceof UimaASProcessStatus) {
+// if (aProcessStatus.isException()) {
+// System.out
+// .println("--------- Got
Exception While Processing CAS"
+// +
casReferenceId);
+// } else {
+// System.out.println("Client Received
Reply - CAS:"
+// + casReferenceId);
+// }
+// }
+ }
+
+ /**
+ * Callback method which is called by Uima EE client when a
reply to
+ * process CAS is received. The reply contains either the CAS
or an
+ * exception that occurred while processing the CAS.
+ */
+ public synchronized void entityProcessComplete(CAS aCAS,
+ EntityProcessStatus aProcessStatus) {
+ String casReferenceId = ((UimaASProcessStatus)
aProcessStatus)
+ .getCasReferenceId();
+
+// if (aProcessStatus instanceof UimaASProcessStatus) {
+// if (aProcessStatus.isException()) {
+// System.out
+// .println("--------- Got
Exception While Processing CAS"
+// +
casReferenceId);
+// } else {
+// System.out.println("Client Received
Reply - CAS:"
+// + casReferenceId);
+// }
+// }
+
+ }
+
+ /**
+ * Callback method which is called by Uima EE client when the
+ * initialization of the client is completed successfully.
+ */
+ public void initializationComplete(EntityProcessStatus aStatus)
{
+ synchronized (initializeMonitor) {
+ initialized = true;
+ initializeMonitor.notifyAll();
+ }
+ }
+
+ /**
+ * Callback method which is called by Uima EE client when a CPC
reply is
+ * received OR exception occured while processing CPC request.
+ */
+ public void collectionProcessComplete(EntityProcessStatus
aStatus) {
+ }
+ }
+}