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 2015/01/06 21:16:52 UTC
svn commit: r1649929 - in
/uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp:
AbstractProcessContainer.java UimaASProcessContainer.java
UimaProcessContainer.java
Author: cwiklik
Date: Tue Jan 6 20:16:52 2015
New Revision: 1649929
URL: http://svn.apache.org/r1649929
Log:
UIMA-4060 add common methods to both containers
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/AbstractProcessContainer.java (with props)
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaASProcessContainer.java
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/AbstractProcessContainer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/AbstractProcessContainer.java?rev=1649929&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/AbstractProcessContainer.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/AbstractProcessContainer.java Tue Jan 6 20:16:52 2015
@@ -0,0 +1,50 @@
+/*
+ * 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.user.jp;
+
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+
+public abstract class AbstractProcessContainer {
+
+ protected Throwable lastError = null;
+
+ public byte[] getLastSerializedError() throws Exception {
+
+ if (lastError != null) {
+
+ return serialize(lastError);
+ }
+ return null;
+
+ }
+
+ protected byte[] serialize(Throwable t) throws Exception {
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(t);
+ oos.close();
+ return baos.toByteArray();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/AbstractProcessContainer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaASProcessContainer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaASProcessContainer.java?rev=1649929&r1=1649928&r2=1649929&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaASProcessContainer.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaASProcessContainer.java Tue Jan 6 20:16:52 2015
@@ -57,7 +57,8 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
-public class UimaASProcessContainer implements IProcessContainer {
+public class UimaASProcessContainer extends AbstractProcessContainer
+implements IProcessContainer {
private String endpointName;
protected int scaleout;
private String saxonURL = null;
@@ -76,7 +77,7 @@ public class UimaASProcessContainer impl
private static Map<Long, UimaSerializer> serializerMap = new HashMap<Long, UimaSerializer>();
private String[] deploymentDescriptors = null;
private String[] ids = null;
-
+
public int initialize(String[] args) throws Exception {
// Get DDs and also extract scaleout property from DD
deploymentDescriptors = getDescriptors(args);
@@ -261,6 +262,8 @@ public class UimaASProcessContainer impl
public List<Properties> process(Object xmi) throws Exception {
CAS cas = uimaASClient.getCAS(); // fetch a new CAS from the client's Cas Pool
try {
+ // reset last error
+ lastError = null;
XmiSerializationSharedData deserSharedData = new XmiSerializationSharedData();
// Use thread dedicated UimaSerializer to de-serialize the CAS
serializerMap.get(Thread.currentThread().getId()).
@@ -282,19 +285,11 @@ public class UimaASProcessContainer impl
}
return metricsList;
} catch( Throwable e ) {
- String serializedStackTrace = serialize(e);
+ lastError = e;
Logger logger = UIMAFramework.getLogger();
logger.log(Level.WARNING, "UimaProcessContainer", e);
e.printStackTrace();
- // repackage so that the code on the other side is protected
- // against Custom Exception classes that the user code may
- // throw. Serialize the stack trace and throw a RuntimeException
- // with a causedby of AnalysisEngineProcessException. The code
- // on the other side must determine if the exception was caused
- // by processing error or something else. In case of the latter
- // it would be java only stack trace.
- throw new
- RuntimeException(serializedStackTrace, new AnalysisEngineProcessException());
+ throw new AnalysisEngineProcessException();
} finally {
if ( cas != null) {
cas.release();
@@ -302,21 +297,6 @@ public class UimaASProcessContainer impl
}
}
- private String serialize(Throwable t) throws Exception {
- try {
- //return (String)toXMLMethod.invoke(xstreamInstance, t);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream( baos );
- oos.writeObject( t );
- oos.close();
- return new String(baos.toByteArray());
-
- } catch( Exception e) {
- e.printStackTrace();
- throw e;
- }
- }
-
private void initializeUimaAsClient(String endpoint) throws Exception {
String brokerURL = System.getProperty("DefaultBrokerURL");
Map<String, Object> appCtx = new HashMap<String, Object>();
Modified: 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=1649929&r1=1649928&r2=1649929&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaProcessContainer.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/user/jp/UimaProcessContainer.java Tue Jan 6 20:16:52 2015
@@ -20,8 +20,6 @@
package org.apache.uima.ducc.user.jp;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectOutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -51,7 +49,8 @@ import org.apache.uima.util.Level;
import org.apache.uima.util.Logger;
-public class UimaProcessContainer implements IProcessContainer {
+public class UimaProcessContainer extends AbstractProcessContainer
+implements IProcessContainer {
public static final String IMPORT_BY_NAME_PREFIX = "*importByName:";
private DuccUimaSerializer uimaSerializer = new DuccUimaSerializer();
// private Object xstreamInstance=null;
@@ -63,8 +62,7 @@ public class UimaProcessContainer implem
// Some AEs depend on ThreadLocal storage.
UimaAnalysisEngineInstancePoolWithThreadAffinity instanceMap = new UimaAnalysisEngineInstancePoolWithThreadAffinity();
AnalysisEngineMetaData analysisEngineMetadata;
- private Throwable lastError = null;
-
+
private static CasPool casPool = null;
/** Class and Method handles for reflection */
// private static Class<?> mbeanServerClass;
@@ -172,31 +170,7 @@ public class UimaProcessContainer implem
}
*/
- public byte[] getLastSerializedError() throws Exception {
-
- if ( lastError != null ) {
-
- return serialize(lastError);
- }
- return null;
-
- }
- private byte[] serialize(Throwable t) throws Exception {
- try {
- //return (String)toXMLMethod.invoke(xstreamInstance, t);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream( baos );
- oos.writeObject( t );
- oos.close();
-
- return baos.toByteArray();
-// return new String(baos.toByteArray());
-
- } catch( Exception e) {
- e.printStackTrace();
- throw e;
- }
- }
+
public int initialize(String[] args ) throws Exception {
analysisEngineDescriptor = ArgsParser.getArg("-aed", args);
scaleout = Integer.valueOf(ArgsParser.getArg("-t", args));
@@ -271,6 +245,8 @@ public class UimaProcessContainer implem
CAS cas = casPool.getCas();
int num = counter.incrementAndGet();
try {
+ // reset last error
+ lastError = null;
XmiSerializationSharedData deserSharedData = new XmiSerializationSharedData();
// deserialize the CAS
uimaSerializer.deserializeCasFromXmi((String) xmi, cas,
@@ -308,20 +284,10 @@ public class UimaProcessContainer implem
// System.out.println("Thread:"+Thread.currentThread().getId()+" Processed "+num+" CASes");
return metricsList;
} catch( Throwable e ) {
- lastError = e;
-// String serializedStackTrace = serialize(e);
+ super.lastError = e;
Logger logger = UIMAFramework.getLogger();
logger.log(Level.WARNING, "UimaProcessContainer", e);
e.printStackTrace();
- // repackage so that the code on the other side is protected
- // against Custom Exception classes that the user code may
- // throw. Serialize the stack trace and throw a RuntimeException
- // with a causedby of AnalysisEngineProcessException. The code
- // on the other side must determine if the exception was caused
- // by processing error or something else. In case of the latter
- // it would be java only stack trace.
-// throw new
-// RuntimeException(serializedStackTrace, new AnalysisEngineProcessException());
throw new AnalysisEngineProcessException();
}
// catch( Throwable t) {