You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by jo...@apache.org on 2009/06/15 16:27:04 UTC
svn commit: r784792 - in
/incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/uima/ src/main/java/org/apache/uima/camel/
src/main/resources/ src/mai...
Author: joern
Date: Mon Jun 15 14:27:03 2009
New Revision: 784792
URL: http://svn.apache.org/viewvc?rev=784792&view=rev
Log:
UIMA-1354 Initial check in
Added:
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/pom.xml (with props)
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsComponent.java (with props)
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsEndpoint.java (with props)
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsProducer.java (with props)
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/resources/
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/resources/META-INF/
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/resources/META-INF/services/
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/resources/META-INF/services/org/
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/resources/META-INF/services/org/apache/
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/resources/META-INF/services/org/apache/camel/
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/resources/META-INF/services/org/apache/camel/component/
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/resources/META-INF/services/org/apache/camel/component/uimadriver
Modified:
incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/ (props changed)
Propchange: incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jun 15 14:27:03 2009
@@ -0,0 +1,7 @@
+.project
+
+target
+
+.settings
+
+.classpath
Added: incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/pom.xml
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/pom.xml?rev=784792&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/pom.xml (added)
+++ incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/pom.xml Mon Jun 15 14:27:03 2009
@@ -0,0 +1,86 @@
+<?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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-as-camel</artifactId>
+ <packaging>bundle</packaging>
+ <version>${uimaj-as-release-version}</version>
+ <name>Apache UIMA Async Scaleout Camel Driver</name>
+ <url>http://incubator.apache.org/uima</url>
+ <parent>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-as</artifactId>
+ <version>2.3.0-incubating-SNAPSHOT</version> <!-- this comment is a flag for changeVersion -->
+ <relativePath>../uimaj-as</relativePath>
+ </parent>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <version>1.6.1</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-core</artifactId>
+ <version>2.3.0-incubating-SNAPSHOT</version> <!-- this comment is a flag for changeVersion -->
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-as-core</artifactId>
+ <version>${uimaj-as-release-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-as-activemq</artifactId>
+ <version>${uimaj-as-release-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.0.0</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Private-Package>dk.infopaq.messaging.camel.uima</Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsComponent.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsComponent.java?rev=784792&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsComponent.java (added)
+++ incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsComponent.java Mon Jun 15 14:27:03 2009
@@ -0,0 +1,63 @@
+/*
+ * 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.camel;
+
+import java.net.URI;
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.impl.DefaultComponent;
+
+/**
+ * Defines the UIMA-AS camel driver component.
+ */
+public class UimaAsComponent extends DefaultComponent<Exchange> {
+
+ @Override
+ protected Endpoint<Exchange> createEndpoint(String uri, String remaining,
+ Map parameters) throws Exception {
+
+ URI hbaseURI = URI.create(uri);
+
+ String scheme = hbaseURI.getScheme();
+
+ if (!"uimadriver".equals(scheme)) {
+ throw new RuntimeCamelException("Unsupported scheme: " + scheme);
+ }
+
+ // get string between first : and first ?
+ int indexBeginBrokerUrl = uri.indexOf(':');
+ int indexEndBrokerUrl = uri.indexOf('?');
+
+ if (indexBeginBrokerUrl == -1 || indexEndBrokerUrl == -1 ||
+ indexBeginBrokerUrl + 1 == uri.length()) {
+ throw new RuntimeCamelException("Invalid broker Url!");
+ }
+
+ indexBeginBrokerUrl += 1;
+
+ String brokerAddress = uri.substring(indexBeginBrokerUrl,
+ indexEndBrokerUrl);
+
+ return new UimaAsEndpoint(uri, brokerAddress, this);
+ }
+}
Propchange: incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsComponent.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsEndpoint.java?rev=784792&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsEndpoint.java (added)
+++ incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsEndpoint.java Mon Jun 15 14:27:03 2009
@@ -0,0 +1,62 @@
+/*
+ * 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.camel;
+
+import java.util.Map;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+
+/**
+ * Represent the UIMA-AS camel driver endpoint.
+ */
+public class UimaAsEndpoint extends DefaultEndpoint<Exchange>{
+
+ private String brokerAddress;
+ private String queue;
+
+ public UimaAsEndpoint(String uri, String brokerAddress,
+ UimaAsComponent component) {
+ super(uri, component);
+
+ this.brokerAddress = brokerAddress;
+ }
+
+ @Override
+ public void configureProperties(Map options) {
+ super.configureProperties(options);
+ queue = (String) options.remove("queue");
+ }
+
+ public Consumer<Exchange> createConsumer(Processor arg0) throws Exception {
+ return null;
+ }
+
+ public Producer<Exchange> createProducer() throws Exception {
+ return new UimaAsProducer(brokerAddress, queue, this);
+ }
+
+ public boolean isSingleton() {
+ return false;
+ }
+}
Propchange: incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsEndpoint.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsProducer.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsProducer.java?rev=784792&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsProducer.java (added)
+++ incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsProducer.java Mon Jun 15 14:27:03 2009
@@ -0,0 +1,155 @@
+/*
+ * 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.camel;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.AsyncProcessor;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.uima.aae.client.UimaASProcessStatusImpl;
+import org.apache.uima.aae.client.UimaAsBaseCallbackListener;
+import org.apache.uima.aae.client.UimaAsynchronousEngine;
+import org.apache.uima.adapter.jms.client.BaseUIMAAsynchronousEngine_impl;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.collection.EntityProcessStatus;
+import org.apache.uima.resource.ResourceInitializationException;
+
+/**
+ * The <code>UimaAsProducer</code> sends the body of a message to a UIMA AS processing
+ * pipeline.
+ *
+ * Configuration URI:
+ * uimadriver:authority?queue="nameofqueue"
+ *
+ * For example:
+ * uimadriver:tcp://localhost:61616?queue=TextAnalysisQueue
+ */
+public class UimaAsProducer extends DefaultProducer<Exchange> implements AsyncProcessor {
+
+ private static class ExchangeAsyncCallbackPair {
+ Exchange exchange;
+
+ AsyncCallback callback;
+ }
+
+ // TODO: ups need thread safety here
+ class UimaStatusCallbackListener extends UimaAsBaseCallbackListener {
+
+ public void initializationComplete(EntityProcessStatus aStatus) {
+ // TODO:
+ // Log error status
+ }
+
+ public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) {
+ UimaASProcessStatusImpl statusImpl = (UimaASProcessStatusImpl) aStatus;
+
+ String referenceId = statusImpl.getCasReferenceId();
+
+ ExchangeAsyncCallbackPair exchangeCallbackPair = intermediateMap.remove(referenceId);
+
+ if (exchangeCallbackPair != null) {
+ if (aStatus.isException()) {
+
+ // TODO: Retrieve exceptions from status object
+
+ exchangeCallbackPair.exchange.setException(new Exception(aStatus.getStatusMessage()));
+ }
+
+ exchangeCallbackPair.callback.done(false);
+ } else {
+ // TODO: log error
+ }
+ }
+
+ public void collectionProcessComplete(EntityProcessStatus aStatus) {
+ // TODO: log error status
+ }
+ }
+
+ private UimaAsynchronousEngine uimaAsEngine;
+
+ /**
+ * The intermediate map keeps all {@link Exchange}s and their callbacks until asynchronous
+ * processing is finished.
+ */
+ private Map<String, ExchangeAsyncCallbackPair> intermediateMap;
+
+ public UimaAsProducer(String brokerAddress, String queue, Endpoint<Exchange> endpoint)
+ throws Exception {
+ super(endpoint);
+
+ intermediateMap = new HashMap<String, ExchangeAsyncCallbackPair>();
+
+ uimaAsEngine = new BaseUIMAAsynchronousEngine_impl();
+
+ uimaAsEngine.addStatusCallbackListener(new UimaStatusCallbackListener());
+
+ Map<String, Object> appCtx = new HashMap<String, Object>();
+ appCtx.put(UimaAsynchronousEngine.ServerUri, brokerAddress);
+ appCtx.put(UimaAsynchronousEngine.Endpoint, queue);
+ appCtx.put(UimaAsynchronousEngine.CasPoolSize, 15);
+
+ try {
+ uimaAsEngine.initialize(appCtx);
+ } catch (ResourceInitializationException e) {
+ throw e;
+ }
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ }
+
+ public boolean process(Exchange exchange, AsyncCallback callback) {
+
+ String rowId = exchange.getIn().getBody(String.class);
+
+ String refernceId;
+
+ try {
+ CAS cas = uimaAsEngine.getCAS();
+
+ cas.setDocumentText(rowId);
+
+ refernceId = uimaAsEngine.sendCAS(cas);
+
+ } catch (Exception e) {
+ // Processing of the exchange failed
+
+ // The error message is set on the exchange
+ exchange.setException(e);
+
+ // and the method returns synchronously with true
+ callback.done(true);
+ return true;
+ }
+
+ ExchangeAsyncCallbackPair exchangeCallback = new ExchangeAsyncCallbackPair();
+ exchangeCallback.exchange = exchange;
+ exchangeCallback.callback = callback;
+
+ intermediateMap.put(refernceId, exchangeCallback);
+
+ return false;
+ }
+}
Propchange: incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/java/org/apache/uima/camel/UimaAsProducer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/resources/META-INF/services/org/apache/camel/component/uimadriver
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/resources/META-INF/services/org/apache/camel/component/uimadriver?rev=784792&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/resources/META-INF/services/org/apache/camel/component/uimadriver (added)
+++ incubator/uima/sandbox/trunk/uima-as/uimaj-as-camel/src/main/resources/META-INF/services/org/apache/camel/component/uimadriver Mon Jun 15 14:27:03 2009
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.uima.camel.UimaAsComponent
\ No newline at end of file