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 2019/08/02 17:30:47 UTC
svn commit: r1864248 [6/7] - in
/uima/uima-ducc/trunk/uima-ducc-pullservice/src:
main/java/org/apache/uima/ducc/ps/
main/java/org/apache/uima/ducc/ps/net/iface/
main/java/org/apache/uima/ducc/ps/net/impl/
main/java/org/apache/uima/ducc/ps/sd/ main/java...
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/HttpTargetURI.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/HttpTargetURI.java?rev=1864248&r1=1864247&r2=1864248&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/HttpTargetURI.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/HttpTargetURI.java Fri Aug 2 17:30:46 2019
@@ -22,53 +22,57 @@ import org.apache.uima.ducc.ps.service.t
public class HttpTargetURI implements ITargetURI {
- String target;
- String targetContext;
- String targetPort;
- String protocol;
- String targetDescription="";
-
- public HttpTargetURI(String target) {
- this.target = target;
-
- int pos = target.indexOf("//");
- protocol = target.substring(0, pos-1);
- int ipEndPos = target.indexOf(":", pos);
- String jdIP = target.substring(pos+2,ipEndPos);
- int portEndPos = target.indexOf("/", ipEndPos);
- targetContext = target.substring(portEndPos+1);
- targetPort = target.substring(ipEndPos+1, portEndPos);
-
-
- }
-
- @Override
- public String getProtocol() {
- return protocol;
- }
-
- @Override
- public String getNodename() {
- return null;
- }
-
- @Override
- public String getPort() {
- return targetPort;
- }
-
- @Override
- public String getContext() {
- return targetContext;
- }
-
- @Override
- public String asString() {
- return target;
- }
- @Override
- public String getDescription() {
- return targetDescription;
- }
+ String target;
+
+ String targetContext;
+
+ String targetPort;
+
+ String protocol;
+
+ String targetDescription = "";
+
+ public HttpTargetURI(String target) {
+ this.target = target;
+
+ int pos = target.indexOf("//");
+ protocol = target.substring(0, pos - 1);
+ int ipEndPos = target.indexOf(":", pos);
+ String jdIP = target.substring(pos + 2, ipEndPos);
+ int portEndPos = target.indexOf("/", ipEndPos);
+ targetContext = target.substring(portEndPos + 1);
+ targetPort = target.substring(ipEndPos + 1, portEndPos);
+
+ }
+
+ @Override
+ public String getProtocol() {
+ return protocol;
+ }
+
+ @Override
+ public String getNodename() {
+ return null;
+ }
+
+ @Override
+ public String getPort() {
+ return targetPort;
+ }
+
+ @Override
+ public String getContext() {
+ return targetContext;
+ }
+
+ @Override
+ public String asString() {
+ return target;
+ }
+
+ @Override
+ public String getDescription() {
+ return targetDescription;
+ }
}
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/NoOpTargetURI.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/NoOpTargetURI.java?rev=1864248&r1=1864247&r2=1864248&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/NoOpTargetURI.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/NoOpTargetURI.java Fri Aug 2 17:30:46 2019
@@ -22,34 +22,34 @@ import org.apache.uima.ducc.ps.service.t
public class NoOpTargetURI implements ITargetURI {
- @Override
- public String asString() {
- return "";
- }
-
- @Override
- public String getProtocol() {
- return "";
- }
-
- @Override
- public String getNodename() {
- return "";
- }
-
- @Override
- public String getPort() {
- return "";
- }
-
- @Override
- public String getContext() {
- return "";
- }
-
- @Override
- public String getDescription() {
- return "";
- }
+ @Override
+ public String asString() {
+ return "";
+ }
+
+ @Override
+ public String getProtocol() {
+ return "";
+ }
+
+ @Override
+ public String getNodename() {
+ return "";
+ }
+
+ @Override
+ public String getPort() {
+ return "";
+ }
+
+ @Override
+ public String getContext() {
+ return "";
+ }
+
+ @Override
+ public String getDescription() {
+ return "";
+ }
}
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/SocketTargetURI.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/SocketTargetURI.java?rev=1864248&r1=1864247&r2=1864248&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/SocketTargetURI.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/SocketTargetURI.java Fri Aug 2 17:30:46 2019
@@ -21,46 +21,46 @@ package org.apache.uima.ducc.ps.service.
import org.apache.uima.ducc.ps.service.transport.ITargetURI;
public class SocketTargetURI implements ITargetURI {
- String target;
-
- public SocketTargetURI(String target) {
- this.target = target;
- }
-
- @Override
- public String getProtocol() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getNodename() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getPort() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getContext() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String asString() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getDescription() {
- // TODO Auto-generated method stub
- return null;
- }
+ String target;
+
+ public SocketTargetURI(String target) {
+ this.target = target;
+ }
+
+ @Override
+ public String getProtocol() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getNodename() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getPort() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getContext() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String asString() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getDescription() {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/TargetURIFactory.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/TargetURIFactory.java?rev=1864248&r1=1864247&r2=1864248&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/TargetURIFactory.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/target/TargetURIFactory.java Fri Aug 2 17:30:46 2019
@@ -22,15 +22,18 @@ import org.apache.uima.ducc.ps.service.e
import org.apache.uima.ducc.ps.service.transport.ITargetURI;
public class TargetURIFactory {
- private TargetURIFactory() {}
-
- public static ITargetURI newTarget(String targetAsString) throws ServiceException {
- if ( targetAsString.toLowerCase().startsWith("http:")) {
- return new HttpTargetURI(targetAsString);
- } else if ( targetAsString.toLowerCase().startsWith("tcp:")) {
- return new SocketTargetURI(targetAsString);
- } else {
- throw new ServiceException("Registry provider unsupported URL protocol - Expected either tcp or http - Instead got "+targetAsString);
- }
- }
+ private TargetURIFactory() {
+ }
+
+ public static ITargetURI newTarget(String targetAsString) throws ServiceException {
+ if (targetAsString.toLowerCase().startsWith("http:")) {
+ return new HttpTargetURI(targetAsString);
+ } else if (targetAsString.toLowerCase().startsWith("tcp:")) {
+ return new SocketTargetURI(targetAsString);
+ } else {
+ throw new ServiceException(
+ "Registry provider unsupported URL protocol - Expected either tcp or http - Instead got "
+ + targetAsString);
+ }
+ }
}
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/utils/UimaSerializer.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/utils/UimaSerializer.java?rev=1864248&r1=1864247&r2=1864248&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/utils/UimaSerializer.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/utils/UimaSerializer.java Fri Aug 2 17:30:46 2019
@@ -42,16 +42,17 @@ import org.xml.sax.SAXNotSupportedExcept
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
-
public class UimaSerializer {
- private static final String LOAD_EXTERNAL_DTD = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
- private static final String EXTERNAL_GENERAL_ENTITIES = "http://xml.org/sax/features/external-general-entities";
- private static final String EXTERNAL_PARAMETER_ENTITIES = "http://xml.org/sax/features/external-parameter-entities";
+ private static final String LOAD_EXTERNAL_DTD = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
+
+ private static final String EXTERNAL_GENERAL_ENTITIES = "http://xml.org/sax/features/external-general-entities";
+
+ private static final String EXTERNAL_PARAMETER_ENTITIES = "http://xml.org/sax/features/external-parameter-entities";
+
/**
* Utility method for serializing a CAS to an XMI String
*/
- public String serializeCasToXmi(CAS aCAS)
- throws Exception {
+ public String serializeCasToXmi(CAS aCAS) throws Exception {
Writer writer = new StringWriter();
try {
XMLSerializer xmlSer = new XMLSerializer(writer, false);
@@ -64,53 +65,54 @@ public class UimaSerializer {
writer.close();
}
}
+
private void secureXmlReader(XMLReader xmlReader) {
- try {
- xmlReader.setFeature(EXTERNAL_GENERAL_ENTITIES, false);
- } catch (SAXNotRecognizedException e) {
- UIMAFramework.getLogger().log(Level.WARNING,
- "XMLReader didn't recognize feature " + EXTERNAL_GENERAL_ENTITIES);
- } catch (SAXNotSupportedException e) {
- UIMAFramework.getLogger().log(Level.WARNING,
- "XMLReader doesn't support feature " + EXTERNAL_GENERAL_ENTITIES);
- }
-
- try {
- xmlReader.setFeature(EXTERNAL_PARAMETER_ENTITIES, false);
- } catch (SAXNotRecognizedException e) {
- UIMAFramework.getLogger().log(Level.WARNING,
- "XMLReader didn't recognize feature " + EXTERNAL_PARAMETER_ENTITIES);
- } catch (SAXNotSupportedException e) {
- UIMAFramework.getLogger().log(Level.WARNING,
- "XMLReader doesn't support feature " + EXTERNAL_PARAMETER_ENTITIES);
- }
-
- try {
- xmlReader.setFeature(LOAD_EXTERNAL_DTD,false);
- } catch (SAXNotRecognizedException e) {
- UIMAFramework.getLogger().log(Level.WARNING,
- "XMLReader didn't recognized feature " + LOAD_EXTERNAL_DTD);
- } catch (SAXNotSupportedException e) {
- UIMAFramework.getLogger().log(Level.WARNING,
- "XMLReader doesn't support feature " + LOAD_EXTERNAL_DTD);
- }
+ try {
+ xmlReader.setFeature(EXTERNAL_GENERAL_ENTITIES, false);
+ } catch (SAXNotRecognizedException e) {
+ UIMAFramework.getLogger().log(Level.WARNING,
+ "XMLReader didn't recognize feature " + EXTERNAL_GENERAL_ENTITIES);
+ } catch (SAXNotSupportedException e) {
+ UIMAFramework.getLogger().log(Level.WARNING,
+ "XMLReader doesn't support feature " + EXTERNAL_GENERAL_ENTITIES);
+ }
+
+ try {
+ xmlReader.setFeature(EXTERNAL_PARAMETER_ENTITIES, false);
+ } catch (SAXNotRecognizedException e) {
+ UIMAFramework.getLogger().log(Level.WARNING,
+ "XMLReader didn't recognize feature " + EXTERNAL_PARAMETER_ENTITIES);
+ } catch (SAXNotSupportedException e) {
+ UIMAFramework.getLogger().log(Level.WARNING,
+ "XMLReader doesn't support feature " + EXTERNAL_PARAMETER_ENTITIES);
+ }
+
+ try {
+ xmlReader.setFeature(LOAD_EXTERNAL_DTD, false);
+ } catch (SAXNotRecognizedException e) {
+ UIMAFramework.getLogger().log(Level.WARNING,
+ "XMLReader didn't recognized feature " + LOAD_EXTERNAL_DTD);
+ } catch (SAXNotSupportedException e) {
+ UIMAFramework.getLogger().log(Level.WARNING,
+ "XMLReader doesn't support feature " + LOAD_EXTERNAL_DTD);
+ }
}
- /**
- * Utility method for deserializing a CAS from an XMI String
- * Does both processing of requests arriving to this service
- * and responses returning to this service, or to a client.
+
+ /**
+ * Utility method for deserializing a CAS from an XMI String Does both processing of requests
+ * arriving to this service and responses returning to this service, or to a client.
*/
- public void deserializeCasFromXmi(String anXmlStr, CAS aCAS)
- throws FactoryConfigurationError, ParserConfigurationException, SAXException, IOException {
+ public void deserializeCasFromXmi(String anXmlStr, CAS aCAS) throws FactoryConfigurationError,
+ ParserConfigurationException, SAXException, IOException {
- XMLReader xmlReader = XMLReaderFactory.createXMLReader();
- secureXmlReader(xmlReader);
+ XMLReader xmlReader = XMLReaderFactory.createXMLReader();
+ secureXmlReader(xmlReader);
Reader reader = new StringReader(anXmlStr);
XmiCasDeserializer deser = new XmiCasDeserializer(aCAS.getTypeSystem());
ContentHandler handler = deser.getXmiCasHandler(aCAS);
xmlReader.setContentHandler(handler);
xmlReader.parse(new InputSource(reader));
}
-
+
}
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/utils/UimaUtils.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/utils/UimaUtils.java?rev=1864248&r1=1864247&r2=1864248&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/utils/UimaUtils.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/utils/UimaUtils.java Fri Aug 2 17:30:46 2019
@@ -49,370 +49,347 @@ import org.apache.uima.util.InvalidXMLEx
import org.apache.uima.util.XMLInputSource;
public class UimaUtils {
-
- public static final String FlowControllerKey="FixedFlowController";
- public static RelativePathResolver resolver = new RelativePathResolver_impl();
-
- public static URL getRelativePathWithProtocol(String aRelativePath)
- throws MalformedURLException {
- URL relativeUrl;
- try {
- relativeUrl = new URL(aRelativePath);
- } catch (MalformedURLException e) {
- relativeUrl = new URL("file", "", aRelativePath);
- }
- return relativeUrl;
- }
-
- public static ResourceSpecifier getResourceSpecifier(String resourceFile)
- throws Exception {
- return UIMAFramework.getXMLParser().parseResourceSpecifier(
- getXMLInputSource(resourceFile));
- }
-
- /**
- * Use the UIMA routine to load an xml descriptor from the filesystem or the current classpath
- * @param resourceName - resource to load by location or name
- * @return
- * @throws InvalidXMLException
- */
- public static XMLInputSource getXMLInputSource(String resourceFile)
- throws InvalidXMLException {
- return getXMLInputSource(resourceFile, Thread.currentThread().getContextClassLoader());
- }
-
- /**
- * Use the UIMA routine to load an xml descriptor from the filesystem or the specified classloader
- * @param resourceFile - resource to load by location or name
- * @param classloader - class loader to use
- * @return - input source stream
- * @throws InvalidXMLException
- */
- public static XMLInputSource getXMLInputSource(String resourceFile, ClassLoader classloader)
- throws InvalidXMLException {
-
- // If the resourceFile ends in .xml then we look in the filesystem.
- // If not, then we turn it into a path by replacing . with / and
- // appending .xml, and look in the classpath or datapath.
- // TODO - should this be synchronized since resolver is statis?
-
- String resource = null;
- try {
- resourceFile = Utils.resolvePlaceholderIfExists(resourceFile, System.getProperties());
- XMLInputSource in = null;
- if (resourceFile.endsWith(".xml")) {
- resource = resourceFile;
- in = new XMLInputSource(resourceFile);
- } else {
- resource = resourceFile.replace('.', '/') + ".xml";
- resolver.setPathResolverClassLoader(classloader);
- URL relativeURL = resolver.resolveRelativePath(new URL("file", "", resource));
- if (relativeURL == null) {
- throw new InvalidXMLException(InvalidXMLException.IMPORT_BY_NAME_TARGET_NOT_FOUND,
- new String[] { resource, resourceFile });
- }
- in = new XMLInputSource(relativeURL);
- }
- return in;
- } catch (IOException e) {
- throw new InvalidXMLException(
- InvalidXMLException.IMPORT_FAILED_COULD_NOT_READ_FROM_URL,
- new String[] { resource, resourceFile });
- }
- }
-
- public static ConfigurationParameter findConfigurationParameter(
- ConfigurationParameterDeclarations configurationParameterDeclarations,
- String name) {
- ConfigurationParameter retVal = null;
- for (ConfigurationParameter parameter : configurationParameterDeclarations
- .getConfigurationParameters()) {
- if (name.equals(parameter.getName())) {
- retVal = parameter;
- break;
- }
- }
- return retVal;
- }
-
- public static Object getOverrideValueObject(
- ConfigurationParameter configurationParameter, String value)
- throws ResourceConfigurationException {
- Object retVal = value;
- try {
- if (configurationParameter.getType().equals("Integer")) {
- retVal = Integer.parseInt(value);
- } else if (configurationParameter.getType().equals("Boolean")) {
- retVal = Boolean.parseBoolean(value);
- } else if (configurationParameter.getType().equals("Float")) {
- retVal = Float.parseFloat(value);
- }
- } catch (Throwable t) {
- throw new ResourceConfigurationException(t);
- }
- return retVal;
- }
- /**
- * Creates UIMA aggregate AE description from provided parts. Takes as input
- * vararg of AE descriptor paths for CM, AE, and CC. It creates an aggregate
- * description with each component identified by its implementation class.
- * The generated aggregate uses fixed flow.
- *
- * @param overrides
- * - a list containing overrides. Each component override is a
- * separate list containing strings with format <name>=<value>
- *
- * @param descriptorPaths
- * - paths to uima component descriptors
- *
- * @return - instantiated aggregate {@link AnalysisEngineDescription}
- *
- * @throws Exception
- */
- public static AnalysisEngineDescription createAggregateDescription(
- String flowController, boolean multipleDeploymentAllowed, List<List<String>> overrides, String... descriptorPaths)
- throws Exception {
-
- // create the descriptor and set configuration parameters
- AnalysisEngineDescription desc = new AnalysisEngineDescription_impl();
- resolver.setPathResolverClassLoader(desc.getClass().getClassLoader());
- desc.setFrameworkImplementation(Constants.JAVA_FRAMEWORK_NAME);
- desc.setPrimitive(false);
- ResourceSpecifier[] specifiers = new ResourceSpecifier[descriptorPaths.length];
-
- // Allow scale up
- desc.getAnalysisEngineMetaData().getOperationalProperties()
- .setMultipleDeploymentAllowed(multipleDeploymentAllowed);
- // Stores component names derived from implementation class
- List<String> flowNames = new ArrayList<String>();
- int inx = 0;
- // First produce ResourceSpecifiers from provided descriptors
- for (String aeDescription : descriptorPaths) {
- /*
- aeDescription = Utils.resolvePlaceholderIfExists(aeDescription,
- System.getProperties());
- XMLInputSource in = null;
- if (!aeDescription.endsWith(".xml")) {
- aeDescription = aeDescription.replace('.', '/') + ".xml";
- URL relativeURL = resolver.resolveRelativePath(getRelativePathWithProtocol(aeDescription));
-// URL relativeURL = resolveRelativePath(aeDescription);
- in = new XMLInputSource(relativeURL);
- } else {
- in = new XMLInputSource(aeDescription);
- }
- // XMLInputSource in = new XMLInputSource(aeDescription);
- ResourceSpecifier specifier = UIMAFramework.getXMLParser()
- .parseResourceSpecifier(in);
- specifiers[inx++] = specifier;
- */
- specifiers[inx++] = getResourceSpecifier(aeDescription);
- // UimaClassFactory.produceResourceSpecifier(aeDescription);
- }
-
- for (String aeDescription : descriptorPaths) {
- Import descriptorImport = new Import_impl();
- // If user provides a descriptor with .xml at the end, assume he
- // wants import by location
- if (aeDescription.endsWith(".xml")) {
- aeDescription = Utils.resolvePlaceholderIfExists(aeDescription,
- System.getProperties());
- if (!aeDescription.startsWith("file:")) {
- aeDescription = "file:" + aeDescription;
- }
- descriptorImport.setLocation(aeDescription);
- } else {
- // uima import by name expects dot separated path as in
- // a.b.descriptor and no .xml at the end
- descriptorImport.setName(aeDescription);
- }
- String key = new String(aeDescription);
- if (key.startsWith("file:")) {
- key = key.substring(5); // skip "file:"
- }
- if (key.endsWith(".xml")) {
- key = key.substring(0, key.indexOf(".xml")); // strip ".xml"
- }
- // preprocess the ae descriptor name to replace "/" and
- // "\" with ".". We will use the ae
- // descriptor name as AE key in the aggregate
- if (key.indexOf("/") != -1) {
- key = key.replaceAll("/", ".");
- }
- if (key.indexOf("\\") != -1) {
- key = key.replaceAll("\\\\", ".");
- }
- key = key.substring(key.lastIndexOf(".") + 1);
- desc.getDelegateAnalysisEngineSpecifiersWithImports().put(key,
- descriptorImport);
- flowNames.add(key);
-
- }
- if ( flowController != null ) {
- FlowControllerDeclaration fcd = new FlowControllerDeclaration_impl();
- desc.setFlowControllerDeclaration(fcd);
- fcd.setImport(new Import_impl());
- fcd.setKey(FlowControllerKey);
- fcd.getImport().setName(flowController);
- }
-
- FixedFlow fixedFlow = new FixedFlow_impl();
- fixedFlow.setFixedFlow(flowNames.toArray(new String[flowNames.size()]));
- desc.getAnalysisEngineMetaData().setFlowConstraints(fixedFlow);
- addOverrides(overrides, desc, specifiers, flowNames);
-
- return desc;
- }
-
- private static void addOverrides(List<List<String>> overrides,
- AnalysisEngineDescription desc, ResourceSpecifier[] specifiers,
- List<String> flowNames) throws Exception {
-
- ConfigurationParameterDeclarations aggregateDeclarations = desc
- .getAnalysisEngineMetaData()
- .getConfigurationParameterDeclarations();
- ConfigurationParameterSettings aggregateSetttings = desc
- .getAnalysisEngineMetaData()
- .getConfigurationParameterSettings();
- int indx = 0;
- for (List<String> componentOverrides : overrides) {
- if ( specifiers[indx] instanceof ResourceCreationSpecifier ) {
- addComponentOverrides(flowNames.get(indx), componentOverrides,
- (ResourceCreationSpecifier) specifiers[indx],
- aggregateDeclarations, aggregateSetttings);
- }
- indx++;
- }
-
- }
-
- /**
- * Modifies aggregate descriptor by adding component specific overrides.
- *
- * @param key
- * - component key
- * @param componentOverrides
- * - List of override params where element is expressed as String
- * with format <name>=<value>
- * @param specifier
- * - component resource specifier
- * @param aggregateDeclarations
- * - aggregate ConfigurationParameterDeclarations
- * @param aggregateSetttings
- * - aggregate ConfigurationParameterSettings
- */
- private static void addComponentOverrides(String key,
- List<String> componentOverrides,
-// AnalysisEngineDescription specifier,
- ResourceCreationSpecifier specifier,
- ConfigurationParameterDeclarations aggregateDeclarations,
- ConfigurationParameterSettings aggregateSetttings) throws Exception {
-
- if (componentOverrides == null || componentOverrides.isEmpty()) { // no
- // overrides
- return; // nothing to do
- }
- processOverrides(key, componentOverrides,
- specifier, aggregateDeclarations,
- // (ResourceCreationSpecifier) specifier, aggregateDeclarations,
- aggregateSetttings);
-
- }
-
- private static void processOverrides(String key,
- List<String> componentOverrides,
- ResourceCreationSpecifier specifier,
- ConfigurationParameterDeclarations aggregateDeclarations,
- ConfigurationParameterSettings aggregateSetttings) throws Exception {
- // Process overrides
- for (String cmOverride : componentOverrides) {
- System.out.println(".... Processing Override:"+cmOverride);
- // each override is expressed as <name>=<value> pair, so split on
- // the first '=' found ... in case the value contains an '='
- String[] nvp = cmOverride.split("=", 2);
- // Fetch component parameter declarations to get the primitive type
- // of the parameter
- ConfigurationParameterDeclarations componentParameterDeclarations = specifier
- .getMetaData().getConfigurationParameterDeclarations();
- // Iterate over component parameter declarations looking to find one
- // with the same name
- // as provided in the override. On match, add an override to the
- // aggregate and preserve
- // the type defined for the parameter in the component descriptor.
- // If no match, throw
- // an exception
- boolean found = false;
- for (ConfigurationParameter parameter : componentParameterDeclarations
- .getConfigurationParameters()) {
- if (nvp[0].equals(parameter.getName())) {
- addParam(key, nvp, parameter, aggregateDeclarations);
- addParamValue(nvp, parameter, aggregateSetttings);
- found = true;
- break;
- }
- }
- if (!found) {
- throw new UIMARuntimeException(
- new InvalidOverrideParameterException(
- "Override Parameter:"
- + nvp[0]
- + " is not defined for the component with key: "
- + key));
- }
- }
-
- }
-
- /**
- * Adds parameter to aggregate ConfigurationParameterDeclarations.
- *
- * @param key
- * - component key
- * @param nvp
- * - override name value pair
- * @param parameter
- * - matching ConfigurationParameter instance from component
- * descriptor or null
- * @param aggregateDeclarations
- * - aggregate ConfigurationParameterDeclarations instance
- */
- private static void addParam(String key, String[] nvp,
- ConfigurationParameter parameter,
- ConfigurationParameterDeclarations aggregateDeclarations) {
- ConfigurationParameter cfgParam = new ConfigurationParameter_impl();
- cfgParam.setName(nvp[0]);
- if (parameter == null) { // component descriptor doesnt contain a
- // parameter provided in the override list.
- // Default to String
- cfgParam.setType("String"); // create String param as default
- } else {
- cfgParam.setType(parameter.getType());
- }
-// if ( key.equals(FlowControllerKey)) {
-// cfgParam.addOverride(key + "/ActionAfterCasMultiplier");
-// } else {
-// cfgParam.addOverride(key + "/" + nvp[0]);
-// }
- cfgParam.addOverride(key + "/" + nvp[0]);
- aggregateDeclarations.addConfigurationParameter(cfgParam);
-
- }
-
- private static void addParamValue(String[] nvp,
- ConfigurationParameter parameter,
- ConfigurationParameterSettings aggregateSettings) {
-
- Object value = nvp[1]; // default is String value
- if (parameter != null) {
- if (parameter.getType().equals("Integer")) {
- value = Integer.parseInt(nvp[1]);
- } else if (parameter.getType().equals("Boolean")) {
- value = Boolean.parseBoolean(nvp[1]);
- } else if (parameter.getType().equals("Float")) {
- value = Float.parseFloat(nvp[1]);
- }
- aggregateSettings.setParameterValue(nvp[0], value);
- } else {
- aggregateSettings.setParameterValue(nvp[0], value);
- }
- }
+
+ public static final String FlowControllerKey = "FixedFlowController";
+
+ public static RelativePathResolver resolver = new RelativePathResolver_impl();
+
+ public static URL getRelativePathWithProtocol(String aRelativePath) throws MalformedURLException {
+ URL relativeUrl;
+ try {
+ relativeUrl = new URL(aRelativePath);
+ } catch (MalformedURLException e) {
+ relativeUrl = new URL("file", "", aRelativePath);
+ }
+ return relativeUrl;
+ }
+
+ public static ResourceSpecifier getResourceSpecifier(String resourceFile) throws Exception {
+ return UIMAFramework.getXMLParser().parseResourceSpecifier(getXMLInputSource(resourceFile));
+ }
+
+ /**
+ * Use the UIMA routine to load an xml descriptor from the filesystem or the current classpath
+ *
+ * @param resourceName
+ * - resource to load by location or name
+ * @return
+ * @throws InvalidXMLException
+ */
+ public static XMLInputSource getXMLInputSource(String resourceFile) throws InvalidXMLException {
+ return getXMLInputSource(resourceFile, Thread.currentThread().getContextClassLoader());
+ }
+
+ /**
+ * Use the UIMA routine to load an xml descriptor from the filesystem or the specified classloader
+ *
+ * @param resourceFile
+ * - resource to load by location or name
+ * @param classloader
+ * - class loader to use
+ * @return - input source stream
+ * @throws InvalidXMLException
+ */
+ public static XMLInputSource getXMLInputSource(String resourceFile, ClassLoader classloader)
+ throws InvalidXMLException {
+
+ // If the resourceFile ends in .xml then we look in the filesystem.
+ // If not, then we turn it into a path by replacing . with / and
+ // appending .xml, and look in the classpath or datapath.
+ // TODO - should this be synchronized since resolver is statis?
+
+ String resource = null;
+ try {
+ resourceFile = Utils.resolvePlaceholderIfExists(resourceFile, System.getProperties());
+ XMLInputSource in = null;
+ if (resourceFile.endsWith(".xml")) {
+ resource = resourceFile;
+ in = new XMLInputSource(resourceFile);
+ } else {
+ resource = resourceFile.replace('.', '/') + ".xml";
+ resolver.setPathResolverClassLoader(classloader);
+ URL relativeURL = resolver.resolveRelativePath(new URL("file", "", resource));
+ if (relativeURL == null) {
+ throw new InvalidXMLException(InvalidXMLException.IMPORT_BY_NAME_TARGET_NOT_FOUND,
+ new String[] { resource, resourceFile });
+ }
+ in = new XMLInputSource(relativeURL);
+ }
+ return in;
+ } catch (IOException e) {
+ throw new InvalidXMLException(InvalidXMLException.IMPORT_FAILED_COULD_NOT_READ_FROM_URL,
+ new String[] { resource, resourceFile });
+ }
+ }
+
+ public static ConfigurationParameter findConfigurationParameter(
+ ConfigurationParameterDeclarations configurationParameterDeclarations, String name) {
+ ConfigurationParameter retVal = null;
+ for (ConfigurationParameter parameter : configurationParameterDeclarations
+ .getConfigurationParameters()) {
+ if (name.equals(parameter.getName())) {
+ retVal = parameter;
+ break;
+ }
+ }
+ return retVal;
+ }
+
+ public static Object getOverrideValueObject(ConfigurationParameter configurationParameter,
+ String value) throws ResourceConfigurationException {
+ Object retVal = value;
+ try {
+ if (configurationParameter.getType().equals("Integer")) {
+ retVal = Integer.parseInt(value);
+ } else if (configurationParameter.getType().equals("Boolean")) {
+ retVal = Boolean.parseBoolean(value);
+ } else if (configurationParameter.getType().equals("Float")) {
+ retVal = Float.parseFloat(value);
+ }
+ } catch (Throwable t) {
+ throw new ResourceConfigurationException(t);
+ }
+ return retVal;
+ }
+
+ /**
+ * Creates UIMA aggregate AE description from provided parts. Takes as input vararg of AE
+ * descriptor paths for CM, AE, and CC. It creates an aggregate description with each component
+ * identified by its implementation class. The generated aggregate uses fixed flow.
+ *
+ * @param overrides
+ * - a list containing overrides. Each component override is a separate list containing
+ * strings with format <name>=<value>
+ *
+ * @param descriptorPaths
+ * - paths to uima component descriptors
+ *
+ * @return - instantiated aggregate {@link AnalysisEngineDescription}
+ *
+ * @throws Exception
+ */
+ public static AnalysisEngineDescription createAggregateDescription(String flowController,
+ boolean multipleDeploymentAllowed, List<List<String>> overrides,
+ String... descriptorPaths) throws Exception {
+
+ // create the descriptor and set configuration parameters
+ AnalysisEngineDescription desc = new AnalysisEngineDescription_impl();
+ resolver.setPathResolverClassLoader(desc.getClass().getClassLoader());
+ desc.setFrameworkImplementation(Constants.JAVA_FRAMEWORK_NAME);
+ desc.setPrimitive(false);
+ ResourceSpecifier[] specifiers = new ResourceSpecifier[descriptorPaths.length];
+
+ // Allow scale up
+ desc.getAnalysisEngineMetaData().getOperationalProperties()
+ .setMultipleDeploymentAllowed(multipleDeploymentAllowed);
+ // Stores component names derived from implementation class
+ List<String> flowNames = new ArrayList<String>();
+ int inx = 0;
+ // First produce ResourceSpecifiers from provided descriptors
+ for (String aeDescription : descriptorPaths) {
+ /*
+ * aeDescription = Utils.resolvePlaceholderIfExists(aeDescription, System.getProperties());
+ * XMLInputSource in = null; if (!aeDescription.endsWith(".xml")) { aeDescription =
+ * aeDescription.replace('.', '/') + ".xml"; URL relativeURL =
+ * resolver.resolveRelativePath(getRelativePathWithProtocol(aeDescription)); // URL
+ * relativeURL = resolveRelativePath(aeDescription); in = new XMLInputSource(relativeURL); }
+ * else { in = new XMLInputSource(aeDescription); } // XMLInputSource in = new
+ * XMLInputSource(aeDescription); ResourceSpecifier specifier = UIMAFramework.getXMLParser()
+ * .parseResourceSpecifier(in); specifiers[inx++] = specifier;
+ */
+ specifiers[inx++] = getResourceSpecifier(aeDescription);
+ // UimaClassFactory.produceResourceSpecifier(aeDescription);
+ }
+
+ for (String aeDescription : descriptorPaths) {
+ Import descriptorImport = new Import_impl();
+ // If user provides a descriptor with .xml at the end, assume he
+ // wants import by location
+ if (aeDescription.endsWith(".xml")) {
+ aeDescription = Utils.resolvePlaceholderIfExists(aeDescription, System.getProperties());
+ if (!aeDescription.startsWith("file:")) {
+ aeDescription = "file:" + aeDescription;
+ }
+ descriptorImport.setLocation(aeDescription);
+ } else {
+ // uima import by name expects dot separated path as in
+ // a.b.descriptor and no .xml at the end
+ descriptorImport.setName(aeDescription);
+ }
+ String key = new String(aeDescription);
+ if (key.startsWith("file:")) {
+ key = key.substring(5); // skip "file:"
+ }
+ if (key.endsWith(".xml")) {
+ key = key.substring(0, key.indexOf(".xml")); // strip ".xml"
+ }
+ // preprocess the ae descriptor name to replace "/" and
+ // "\" with ".". We will use the ae
+ // descriptor name as AE key in the aggregate
+ if (key.indexOf("/") != -1) {
+ key = key.replaceAll("/", ".");
+ }
+ if (key.indexOf("\\") != -1) {
+ key = key.replaceAll("\\\\", ".");
+ }
+ key = key.substring(key.lastIndexOf(".") + 1);
+ desc.getDelegateAnalysisEngineSpecifiersWithImports().put(key, descriptorImport);
+ flowNames.add(key);
+
+ }
+ if (flowController != null) {
+ FlowControllerDeclaration fcd = new FlowControllerDeclaration_impl();
+ desc.setFlowControllerDeclaration(fcd);
+ fcd.setImport(new Import_impl());
+ fcd.setKey(FlowControllerKey);
+ fcd.getImport().setName(flowController);
+ }
+
+ FixedFlow fixedFlow = new FixedFlow_impl();
+ fixedFlow.setFixedFlow(flowNames.toArray(new String[flowNames.size()]));
+ desc.getAnalysisEngineMetaData().setFlowConstraints(fixedFlow);
+ addOverrides(overrides, desc, specifiers, flowNames);
+
+ return desc;
+ }
+
+ private static void addOverrides(List<List<String>> overrides, AnalysisEngineDescription desc,
+ ResourceSpecifier[] specifiers, List<String> flowNames) throws Exception {
+
+ ConfigurationParameterDeclarations aggregateDeclarations = desc.getAnalysisEngineMetaData()
+ .getConfigurationParameterDeclarations();
+ ConfigurationParameterSettings aggregateSetttings = desc.getAnalysisEngineMetaData()
+ .getConfigurationParameterSettings();
+ int indx = 0;
+ for (List<String> componentOverrides : overrides) {
+ if (specifiers[indx] instanceof ResourceCreationSpecifier) {
+ addComponentOverrides(flowNames.get(indx), componentOverrides,
+ (ResourceCreationSpecifier) specifiers[indx], aggregateDeclarations,
+ aggregateSetttings);
+ }
+ indx++;
+ }
+
+ }
+
+ /**
+ * Modifies aggregate descriptor by adding component specific overrides.
+ *
+ * @param key
+ * - component key
+ * @param componentOverrides
+ * - List of override params where element is expressed as String with format
+ * <name>=<value>
+ * @param specifier
+ * - component resource specifier
+ * @param aggregateDeclarations
+ * - aggregate ConfigurationParameterDeclarations
+ * @param aggregateSetttings
+ * - aggregate ConfigurationParameterSettings
+ */
+ private static void addComponentOverrides(String key, List<String> componentOverrides,
+ // AnalysisEngineDescription specifier,
+ ResourceCreationSpecifier specifier,
+ ConfigurationParameterDeclarations aggregateDeclarations,
+ ConfigurationParameterSettings aggregateSetttings) throws Exception {
+
+ if (componentOverrides == null || componentOverrides.isEmpty()) { // no
+ // overrides
+ return; // nothing to do
+ }
+ processOverrides(key, componentOverrides, specifier, aggregateDeclarations,
+ // (ResourceCreationSpecifier) specifier, aggregateDeclarations,
+ aggregateSetttings);
+
+ }
+
+ private static void processOverrides(String key, List<String> componentOverrides,
+ ResourceCreationSpecifier specifier,
+ ConfigurationParameterDeclarations aggregateDeclarations,
+ ConfigurationParameterSettings aggregateSetttings) throws Exception {
+ // Process overrides
+ for (String cmOverride : componentOverrides) {
+ System.out.println(".... Processing Override:" + cmOverride);
+ // each override is expressed as <name>=<value> pair, so split on
+ // the first '=' found ... in case the value contains an '='
+ String[] nvp = cmOverride.split("=", 2);
+ // Fetch component parameter declarations to get the primitive type
+ // of the parameter
+ ConfigurationParameterDeclarations componentParameterDeclarations = specifier.getMetaData()
+ .getConfigurationParameterDeclarations();
+ // Iterate over component parameter declarations looking to find one
+ // with the same name
+ // as provided in the override. On match, add an override to the
+ // aggregate and preserve
+ // the type defined for the parameter in the component descriptor.
+ // If no match, throw
+ // an exception
+ boolean found = false;
+ for (ConfigurationParameter parameter : componentParameterDeclarations
+ .getConfigurationParameters()) {
+ if (nvp[0].equals(parameter.getName())) {
+ addParam(key, nvp, parameter, aggregateDeclarations);
+ addParamValue(nvp, parameter, aggregateSetttings);
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ throw new UIMARuntimeException(new InvalidOverrideParameterException("Override Parameter:"
+ + nvp[0] + " is not defined for the component with key: " + key));
+ }
+ }
+
+ }
+
+ /**
+ * Adds parameter to aggregate ConfigurationParameterDeclarations.
+ *
+ * @param key
+ * - component key
+ * @param nvp
+ * - override name value pair
+ * @param parameter
+ * - matching ConfigurationParameter instance from component descriptor or null
+ * @param aggregateDeclarations
+ * - aggregate ConfigurationParameterDeclarations instance
+ */
+ private static void addParam(String key, String[] nvp, ConfigurationParameter parameter,
+ ConfigurationParameterDeclarations aggregateDeclarations) {
+ ConfigurationParameter cfgParam = new ConfigurationParameter_impl();
+ cfgParam.setName(nvp[0]);
+ if (parameter == null) { // component descriptor doesnt contain a
+ // parameter provided in the override list.
+ // Default to String
+ cfgParam.setType("String"); // create String param as default
+ } else {
+ cfgParam.setType(parameter.getType());
+ }
+ // if ( key.equals(FlowControllerKey)) {
+ // cfgParam.addOverride(key + "/ActionAfterCasMultiplier");
+ // } else {
+ // cfgParam.addOverride(key + "/" + nvp[0]);
+ // }
+ cfgParam.addOverride(key + "/" + nvp[0]);
+ aggregateDeclarations.addConfigurationParameter(cfgParam);
+
+ }
+
+ private static void addParamValue(String[] nvp, ConfigurationParameter parameter,
+ ConfigurationParameterSettings aggregateSettings) {
+
+ Object value = nvp[1]; // default is String value
+ if (parameter != null) {
+ if (parameter.getType().equals("Integer")) {
+ value = Integer.parseInt(nvp[1]);
+ } else if (parameter.getType().equals("Boolean")) {
+ value = Boolean.parseBoolean(nvp[1]);
+ } else if (parameter.getType().equals("Float")) {
+ value = Float.parseFloat(nvp[1]);
+ }
+ aggregateSettings.setParameterValue(nvp[0], value);
+ } else {
+ aggregateSettings.setParameterValue(nvp[0], value);
+ }
+ }
}
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/utils/Utils.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/utils/Utils.java?rev=1864248&r1=1864247&r2=1864248&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/utils/Utils.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/utils/Utils.java Fri Aug 2 17:30:46 2019
@@ -32,308 +32,302 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Utils {
-
- public static String getTimestamp() {
- Date now = new Date();
- return DateFormat.getDateTimeInstance().format(now);
- }
-
- public static String getShortClassname(Class clz) {
- return clz.getName().substring(clz.getName().lastIndexOf(".")+1);
- }
- /**
- * Create an array of parameters from a whitespace-delimited list (e.g. JVM args or environment assignments.)
- * Values containing whitespace must be single- or double-quoted:
- * TERM=xterm DISPLAY=:1.0 LD_LIBRARY_PATH="/my/path/with blanks/" EMPTY= -Dxyz="a b c" -Dabc='x y z'
- * Quotes may be stripped or preserved.
- * Values containing both types of quotes are NOT supported.
- *
- * @param options
- * - string of blank-delimited options
- * @param stripQuotes
- * - true if balanced quotes are to be removed
- * @return - array of options
- */
- public static ArrayList<String> tokenizeList(String options, boolean stripQuotes) {
-
- ArrayList<String> tokens = new ArrayList<String>();
- if (options == null) {
- return tokens;
+
+ public static String getTimestamp() {
+ Date now = new Date();
+ return DateFormat.getDateTimeInstance().format(now);
+ }
+
+ public static String getShortClassname(Class clz) {
+ return clz.getName().substring(clz.getName().lastIndexOf(".") + 1);
+ }
+
+ /**
+ * Create an array of parameters from a whitespace-delimited list (e.g. JVM args or environment
+ * assignments.) Values containing whitespace must be single- or double-quoted: TERM=xterm
+ * DISPLAY=:1.0 LD_LIBRARY_PATH="/my/path/with blanks/" EMPTY= -Dxyz="a b c" -Dabc='x y z' Quotes
+ * may be stripped or preserved. Values containing both types of quotes are NOT supported.
+ *
+ * @param options
+ * - string of blank-delimited options
+ * @param stripQuotes
+ * - true if balanced quotes are to be removed
+ * @return - array of options
+ */
+ public static ArrayList<String> tokenizeList(String options, boolean stripQuotes) {
+
+ ArrayList<String> tokens = new ArrayList<String>();
+ if (options == null) {
+ return tokens;
+ }
+
+ // Pattern matches a non-quoted region or a double-quoted region or a single-quoted region
+ // 1st part matches one or more non-whitespace characters but not " or '
+ // 2nd part matches a "quoted" region containing any character except "
+ // 3rd part matches a 'quoted' region containing any character except '
+ // See:
+ // http://stackoverflow.com/questions/3366281/tokenizing-a-string-but-ignoring-delimiters-within-quotes
+
+ String noSpaceRegex = "[^\\s\"']+";
+ String doubleQuoteRegex = "\"([^\"]*)\"";
+ String singleQuoteRegex = "'([^']*)'";
+ final String regex = noSpaceRegex + "|" + doubleQuoteRegex + "|" + singleQuoteRegex;
+ Pattern patn = Pattern.compile(regex);
+ Matcher matcher = patn.matcher(options);
+ StringBuilder sb = new StringBuilder();
+
+ // If stripping quotes extract the capturing group (without the quotes)
+ // When preserving quotes extract the full region
+ // Combine the pieces of a token until the match ends with whitespace
+ if (stripQuotes) {
+ while (matcher.find()) {
+ if (matcher.group(1) != null) {
+ sb.append(matcher.group(1));
+ } else if (matcher.group(2) != null) {
+ sb.append(matcher.group(2));
+ } else {
+ sb.append(matcher.group());
+ }
+ if (matcher.end() >= options.length()
+ || Character.isWhitespace(options.charAt(matcher.end()))) {
+ tokens.add(sb.toString());
+ sb.setLength(0);
+ }
}
+ } else {
+ while (matcher.find()) {
+ sb.append(matcher.group());
+ if (matcher.end() >= options.length()
+ || Character.isWhitespace(options.charAt(matcher.end()))) {
+ tokens.add(sb.toString());
+ sb.setLength(0);
+ }
+ }
+ }
+ return tokens;
+ }
- // Pattern matches a non-quoted region or a double-quoted region or a single-quoted region
- // 1st part matches one or more non-whitespace characters but not " or '
- // 2nd part matches a "quoted" region containing any character except "
- // 3rd part matches a 'quoted' region containing any character except '
- // See: http://stackoverflow.com/questions/3366281/tokenizing-a-string-but-ignoring-delimiters-within-quotes
-
- String noSpaceRegex = "[^\\s\"']+";
- String doubleQuoteRegex = "\"([^\"]*)\"";
- String singleQuoteRegex = "'([^']*)'";
- final String regex = noSpaceRegex + "|" + doubleQuoteRegex + "|" + singleQuoteRegex;
- Pattern patn = Pattern.compile(regex);
- Matcher matcher = patn.matcher(options);
- StringBuilder sb = new StringBuilder();
-
- // If stripping quotes extract the capturing group (without the quotes)
- // When preserving quotes extract the full region
- // Combine the pieces of a token until the match ends with whitespace
- if (stripQuotes) {
- while (matcher.find()) {
- if (matcher.group(1) != null) {
- sb.append(matcher.group(1));
- } else if (matcher.group(2) != null) {
- sb.append(matcher.group(2));
- } else {
- sb.append(matcher.group());
- }
- if (matcher.end() >= options.length() || Character.isWhitespace(options.charAt(matcher.end()))) {
- tokens.add(sb.toString());
- sb.setLength(0);
+ /**
+ * Resolves placeholders in provided contents using java's Matcher. Finds all occurances of
+ * ${<placeholder>} and resolves each using System properties which holds <placeholder>=<value>
+ * pairs.
+ *
+ * @param contents
+ * - target text containing placeholder(s)
+ * @param props
+ * - Properties object holding key/value pairs
+ * @return - text with resolved placeholders
+ *
+ * @throws Exception
+ */
+ public static String resolvePlaceholders(String contents) {
+ return resolvePlaceholders(contents, System.getProperties());
+ }
+
+ /**
+ * Resolves placeholders in provided contents using java's Matcher. Finds all occurances of
+ * ${<placeholder>} and resolves each using provided Properties object which holds
+ * <placeholder>=<value> pairs. If the placeholder not found then tries the System properties.
+ *
+ * @param contents
+ * - target text containing placeholder(s)
+ * @param props
+ * - Properties object holding key/value pairs
+ * @return - text with resolved placeholders
+ *
+ * @throws Exception
+ */
+ public static String resolvePlaceholders(String contents, Properties props) {
+ // Placeholders syntax ${<placeholder>}
+ Pattern placeHolderPattern = Pattern.compile("\\$\\{(.*?)\\}");
+
+ java.util.regex.Matcher matcher = placeHolderPattern.matcher(contents);
+
+ StringBuffer sb = new StringBuffer();
+ while (matcher.find()) {
+ // extract placeholder
+ final String key = matcher.group(1);
+ // Find value for extracted placeholder.
+ String placeholderValue = props.getProperty(key);
+ if (placeholderValue == null) {
+ placeholderValue = System.getProperty(key);
+ if (placeholderValue == null) {
+ throw new IllegalArgumentException("Missing value for placeholder: " + key);
+ }
+ }
+ matcher.appendReplacement(sb, placeholderValue);
+ }
+ matcher.appendTail(sb);
+ return sb.toString();
+ }
+
+ /**
+ * Resolves placeholder using Spring Framework utility class
+ *
+ *
+ * @param value
+ * @param props
+ * @return
+ */
+ public static String resolvePlaceholderIfExists(String value, Properties props) {
+ String retVal = value;
+ if (value != null && value.contains("${")) {
+ retVal = resolvePlaceholders(value, props);
+ }
+ return retVal;
+ }
+
+ public static URLClassLoader create(String classPath) throws MalformedURLException {
+ return create(classPath.split(":"));
+ }
+
+ public static URLClassLoader create(String[] classPathElements) throws MalformedURLException {
+ ArrayList<URL> urlList = new ArrayList<URL>(classPathElements.length);
+ for (String element : classPathElements) {
+ if (element.endsWith("*")) {
+ File dir = new File(element.substring(0, element.length() - 1));
+ File[] files = dir.listFiles(); // Will be null if missing or
+ // not a dir
+ if (files != null) {
+ for (File f : files) {
+ if (f.getName().endsWith(".jar")) {
+ urlList.add(f.toURI().toURL());
+ }
}
}
} else {
- while (matcher.find()) {
- sb.append(matcher.group());
- if (matcher.end() >= options.length() || Character.isWhitespace(options.charAt(matcher.end()))) {
- tokens.add(sb.toString());
- sb.setLength(0);
- }
+ File f = new File(element);
+ if (f.exists()) {
+ urlList.add(f.toURI().toURL());
}
}
- return tokens;
}
+ URL[] urls = new URL[urlList.size()];
+ return new URLClassLoader(urlList.toArray(urls),
+ ClassLoader.getSystemClassLoader().getParent());
+ }
+
+ /*
+ * Dump all the URLs
+ */
+ public static void dump(ClassLoader cl, int numLevels) {
+ int n = 0;
+ for (URLClassLoader ucl = (URLClassLoader) cl; ucl != null
+ && ++n <= numLevels; ucl = (URLClassLoader) ucl.getParent()) {
+ System.out.println("Class-loader " + n + " has " + ucl.getURLs().length + " urls:");
+ for (URL u : ucl.getURLs()) {
+ System.out.println(" " + u);
+ }
+ }
+ }
+
+ public static HashMap<String, String> hideLoggingProperties() {
+ String[] propsToSave = { "log4j.configuration", "java.util.logging.config.file",
+ "java.util.logging.config.class", "org.apache.uima.logger.class" };
+ HashMap<String, String> savedPropsMap = new HashMap<String, String>();
+ for (String prop : propsToSave) {
+ String val = System.getProperty(prop);
+ if (val != null) {
+ savedPropsMap.put(prop, val);
+ System.getProperties().remove(prop);
+ // System.out.println("!!!! Saved prop " + prop + " = " + val);
+ }
+ }
+ return savedPropsMap;
+ }
+
+ public static void restoreLoggingProperties(HashMap<String, String> savedPropsMap) {
+ for (String prop : savedPropsMap.keySet()) {
+ System.setProperty(prop, savedPropsMap.get(prop));
+ // System.out.println("!!!! Restored prop " + prop + " = " + System.getProperty(prop));
+ }
+ }
+
+ public static String getPID(final String fallback) {
+ // the following code returns '<pid>@<hostname>'
+ String name = ManagementFactory.getRuntimeMXBean().getName();
+ int pos = name.indexOf('@');
+
+ if (pos < 1) {
+ // pid not found
+ return fallback;
+ }
+
+ try {
+ return Long.toString(Long.parseLong(name.substring(0, pos)));
+ } catch (NumberFormatException e) {
+ // ignore
+ }
+ return fallback;
+ }
- /**
- * Resolves placeholders in provided contents using java's Matcher. Finds
- * all occurances of ${<placeholder>} and resolves each using System
- * properties which holds <placeholder>=<value> pairs.
- *
- * @param contents
- * - target text containing placeholder(s)
- * @param props
- * - Properties object holding key/value pairs
- * @return - text with resolved placeholders
- *
- * @throws Exception
- */
- public static String resolvePlaceholders(String contents) {
- return resolvePlaceholders(contents, System.getProperties());
- }
-
- /**
- * Resolves placeholders in provided contents using java's Matcher. Finds
- * all occurances of ${<placeholder>} and resolves each using provided
- * Properties object which holds <placeholder>=<value> pairs. If the
- * placeholder not found then tries the System properties.
- *
- * @param contents
- * - target text containing placeholder(s)
- * @param props
- * - Properties object holding key/value pairs
- * @return - text with resolved placeholders
- *
- * @throws Exception
- */
- public static String resolvePlaceholders(String contents, Properties props) {
- // Placeholders syntax ${<placeholder>}
- Pattern placeHolderPattern = Pattern.compile("\\$\\{(.*?)\\}");
-
- java.util.regex.Matcher matcher = placeHolderPattern.matcher(contents);
-
- StringBuffer sb = new StringBuffer();
- while (matcher.find()) {
- // extract placeholder
- final String key = matcher.group(1);
- // Find value for extracted placeholder.
- String placeholderValue = props.getProperty(key);
- if (placeholderValue == null) {
- placeholderValue = System.getProperty(key);
- if (placeholderValue == null) {
- throw new IllegalArgumentException(
- "Missing value for placeholder: " + key);
- }
- }
- matcher.appendReplacement(sb, placeholderValue);
- }
- matcher.appendTail(sb);
- return sb.toString();
- }
-
- /**
- * Resolves placeholder using Spring Framework utility class
- *
- *
- * @param value
- * @param props
- * @return
- */
- public static String resolvePlaceholderIfExists(String value,
- Properties props) {
- String retVal = value;
- if (value != null && value.contains("${")) {
- retVal = resolvePlaceholders(value, props);
- }
- return retVal;
- }
- public static URLClassLoader create(String classPath)
- throws MalformedURLException {
- return create(classPath.split(":"));
- }
-
- public static URLClassLoader create(String[] classPathElements)
- throws MalformedURLException {
- ArrayList<URL> urlList = new ArrayList<URL>(classPathElements.length);
- for (String element : classPathElements) {
- if (element.endsWith("*")) {
- File dir = new File(element.substring(0, element.length() - 1));
- File[] files = dir.listFiles(); // Will be null if missing or
- // not a dir
- if (files != null) {
- for (File f : files) {
- if (f.getName().endsWith(".jar")) {
- urlList.add(f.toURI().toURL());
- }
- }
- }
- } else {
- File f = new File(element);
- if (f.exists()) {
- urlList.add(f.toURI().toURL());
- }
- }
- }
- URL[] urls = new URL[urlList.size()];
- return new URLClassLoader(urlList.toArray(urls), ClassLoader
- .getSystemClassLoader().getParent());
- }
-
- /*
- * Dump all the URLs
- */
- public static void dump(ClassLoader cl, int numLevels) {
- int n = 0;
- for (URLClassLoader ucl = (URLClassLoader) cl; ucl != null
- && ++n <= numLevels; ucl = (URLClassLoader) ucl.getParent()) {
- System.out.println("Class-loader " + n + " has "
- + ucl.getURLs().length + " urls:");
- for (URL u : ucl.getURLs()) {
- System.out.println(" " + u);
- }
- }
- }
- public static HashMap<String,String> hideLoggingProperties() {
- String[] propsToSave = { "log4j.configuration",
- "java.util.logging.config.file",
- "java.util.logging.config.class",
- "org.apache.uima.logger.class"};
- HashMap<String, String> savedPropsMap = new HashMap<String,String>();
- for (String prop : propsToSave) {
- String val = System.getProperty(prop);
- if (val != null) {
- savedPropsMap.put(prop, val);
- System.getProperties().remove(prop);
- //System.out.println("!!!! Saved prop " + prop + " = " + val);
- }
- }
- return savedPropsMap;
- }
-
- public static void restoreLoggingProperties(HashMap<String,String> savedPropsMap) {
- for (String prop : savedPropsMap.keySet()) {
- System.setProperty(prop, savedPropsMap.get(prop));
- //System.out.println("!!!! Restored prop " + prop + " = " + System.getProperty(prop));
- }
- }
- public static String getPID(final String fallback) {
- // the following code returns '<pid>@<hostname>'
- String name = ManagementFactory.getRuntimeMXBean().getName();
- int pos = name.indexOf('@');
-
- if (pos < 1) {
- // pid not found
- return fallback;
- }
-
- try {
- return Long.toString(Long.parseLong(name.substring(0, pos)));
- } catch (NumberFormatException e) {
- // ignore
- }
- return fallback;
- }
- /**
- * 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
- */
- public 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
- */
- public 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
- */
- public 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;
- }
+ /**
+ * 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
+ */
+ public 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
+ */
+ public 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
+ */
+ public 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;
+ }
}
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/Client.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/Client.java?rev=1864248&r1=1864247&r2=1864248&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/Client.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/Client.java Fri Aug 2 17:30:46 2019
@@ -73,8 +73,8 @@ public class Client {
private int maxThreads = 50;
- private long howLongToBlock=60000;
-
+ private long howLongToBlock = 60000;
+
private volatile boolean print = true;
private static UimaSerializer uimaSerializer = new UimaSerializer();
@@ -131,39 +131,41 @@ public class Client {
return httpPort;
}
+
public void startJetty(boolean block, long howLong2Block) throws Exception {
- this.block = block;
- this.howLongToBlock = howLong2Block;
- QueuedThreadPool threadPool = new QueuedThreadPool();
- if (maxThreads < threadPool.getMinThreads()) {
- System.out.println("Invalid value for jetty MaxThreads(" + maxThreads
- + ") - it should be greater or equal to " + threadPool.getMinThreads()
- + ". Defaulting to jettyMaxThreads=" + threadPool.getMaxThreads());
- threadPool.setMaxThreads(threadPool.getMinThreads());
- } else {
- threadPool.setMaxThreads(maxThreads);
- }
-
- server = new Server(threadPool);
-
- // Server connector
- ServerConnector connector = new ServerConnector(server);
- System.out.println(">>>> Jetty Acceptors:" + connector.getAcceptors());
-
- connector.setPort(getJettyPort());
- server.setConnectors(new Connector[] { connector });
- System.out.println("launching Jetty on Port:" + connector.getPort());
- ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
- context.setContextPath("/");
- server.setHandler(context);
+ this.block = block;
+ this.howLongToBlock = howLong2Block;
+ QueuedThreadPool threadPool = new QueuedThreadPool();
+ if (maxThreads < threadPool.getMinThreads()) {
+ System.out.println("Invalid value for jetty MaxThreads(" + maxThreads
+ + ") - it should be greater or equal to " + threadPool.getMinThreads()
+ + ". Defaulting to jettyMaxThreads=" + threadPool.getMaxThreads());
+ threadPool.setMaxThreads(threadPool.getMinThreads());
+ } else {
+ threadPool.setMaxThreads(maxThreads);
+ }
- context.addServlet(new ServletHolder(new TaskHandlerServlet()), "/" + app);
+ server = new Server(threadPool);
- server.start();
- System.out.println("Jetty Started - Waiting for Messages ...");
+ // Server connector
+ ServerConnector connector = new ServerConnector(server);
+ System.out.println(">>>> Jetty Acceptors:" + connector.getAcceptors());
+
+ connector.setPort(getJettyPort());
+ server.setConnectors(new Connector[] { connector });
+ System.out.println("launching Jetty on Port:" + connector.getPort());
+ ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
+ context.setContextPath("/");
+ server.setHandler(context);
+
+ context.addServlet(new ServletHolder(new TaskHandlerServlet()), "/" + app);
+
+ server.start();
+ System.out.println("Jetty Started - Waiting for Messages ...");
}
+
public void startJetty(boolean block) throws Exception {
- startJetty(block, 30000);
+ startJetty(block, 30000);
}
@After
@@ -248,7 +250,8 @@ public class Client {
String nodeName = request.getHeader("Hostname");
String threadID = request.getHeader("ThreadID");
String pid = request.getHeader("PID");
- // System.out.println( "Sender ID:::Node IP"+nodeIP+" Node Name:"+nodeName+" PID:"+pid+" ThreadID:"+threadID);
+ // System.out.println( "Sender ID:::Node IP"+nodeIP+" Node Name:"+nodeName+" PID:"+pid+"
+ // ThreadID:"+threadID);
IMetaTaskTransaction imt = null;
long t1 = System.currentTimeMillis();
@@ -349,7 +352,8 @@ public class Client {
// String body = XStreamUtils.marshall(imt);
String body = localXStream.get().get(Thread.currentThread().getId()).toXML(imt);
if (block) {
- System.out.println("............. Client Blocking for "+howLongToBlock+" ms - Forcing Timeout");
+ System.out.println(
+ "............. Client Blocking for " + howLongToBlock + " ms - Forcing Timeout");
synchronized (this) {
this.wait(howLongToBlock);
}
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/StateMonitor.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/StateMonitor.java?rev=1864248&r1=1864247&r2=1864248&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/StateMonitor.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/StateMonitor.java Fri Aug 2 17:30:46 2019
@@ -23,75 +23,80 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
-
public class StateMonitor {
- private int port;
- private ServerSocket serviceStateUpdateServer;
- private Thread serverThread;
- private boolean running = false;
- public void stop() throws Exception {
- running = false;
- serviceStateUpdateServer.close();
- }
- public void start() throws Exception {
- serviceStateUpdateServer = new ServerSocket(0);
- serviceStateUpdateServer.setReuseAddress(true);
- port = serviceStateUpdateServer.getLocalPort();
- // Publish State Update Port for AP's. This port will be added to the AP
- // environment before a launch
- System.setProperty("DUCC_PROCESS_UNIQUEID", "1234");
- System.setProperty("DUCC_STATE_UPDATE_PORT", String.valueOf(port));
- // spin a server thread which will handle AP state update messages
- running = true;
- serverThread = new Thread( new Runnable() {
- public void run() {
- while(running) {
- try {
- Socket client = serviceStateUpdateServer.accept();
- // AP connected, get its status report. Handling of the status
- // will be done in a dedicated thread to allow concurrent processing.
- // When handling of the state update is done, the socket will be closed
- ServiceUpdateWorkerThread worker = new ServiceUpdateWorkerThread(client);
- worker.start();
- } catch( SocketException e) {
-
- break;
- } catch( Exception e) {
- e.printStackTrace();
- break;
- } finally {
- }
-
- }
- System.out.println("Monitor thread stopped");;
- }
- });
- serverThread.start();
- System.out.println("Started Monitor on Port"+port);
- }
-
-
- class ServiceUpdateWorkerThread extends Thread {
- private Socket socket;
- ServiceUpdateWorkerThread(Socket socket) {
- this.socket = socket;
- }
-
- public void run() {
- try {
- DataInputStream dis = new DataInputStream(socket.getInputStream());
- String state = dis.readUTF();
- //updateHandler.onProcessStateUpdate(state);
- System.out.println(">>>>> Monitor Received State Update:"+state);
- } catch( Exception e) {
- e.printStackTrace();
- } finally {
- try {
- socket.close();
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
+ private int port;
+
+ private ServerSocket serviceStateUpdateServer;
+
+ private Thread serverThread;
+
+ private boolean running = false;
+
+ public void stop() throws Exception {
+ running = false;
+ serviceStateUpdateServer.close();
+ }
+
+ public void start() throws Exception {
+ serviceStateUpdateServer = new ServerSocket(0);
+ serviceStateUpdateServer.setReuseAddress(true);
+ port = serviceStateUpdateServer.getLocalPort();
+ // Publish State Update Port for AP's. This port will be added to the AP
+ // environment before a launch
+ System.setProperty("DUCC_PROCESS_UNIQUEID", "1234");
+ System.setProperty("DUCC_STATE_UPDATE_PORT", String.valueOf(port));
+ // spin a server thread which will handle AP state update messages
+ running = true;
+ serverThread = new Thread(new Runnable() {
+ public void run() {
+ while (running) {
+ try {
+ Socket client = serviceStateUpdateServer.accept();
+ // AP connected, get its status report. Handling of the status
+ // will be done in a dedicated thread to allow concurrent processing.
+ // When handling of the state update is done, the socket will be closed
+ ServiceUpdateWorkerThread worker = new ServiceUpdateWorkerThread(client);
+ worker.start();
+ } catch (SocketException e) {
+
+ break;
+ } catch (Exception e) {
+ e.printStackTrace();
+ break;
+ } finally {
+ }
+
+ }
+ System.out.println("Monitor thread stopped");
+ ;
+ }
+ });
+ serverThread.start();
+ System.out.println("Started Monitor on Port" + port);
+ }
+
+ class ServiceUpdateWorkerThread extends Thread {
+ private Socket socket;
+
+ ServiceUpdateWorkerThread(Socket socket) {
+ this.socket = socket;
+ }
+
+ public void run() {
+ try {
+ DataInputStream dis = new DataInputStream(socket.getInputStream());
+ String state = dis.readUTF();
+ // updateHandler.onProcessStateUpdate(state);
+ System.out.println(">>>>> Monitor Received State Update:" + state);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ socket.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
}
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitErrorHandlingTestSuite.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitErrorHandlingTestSuite.java?rev=1864248&r1=1864247&r2=1864248&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitErrorHandlingTestSuite.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitErrorHandlingTestSuite.java Fri Aug 2 17:30:46 2019
@@ -29,122 +29,121 @@ import junit.framework.Assert;
public class JunitErrorHandlingTestSuite {
- public JunitErrorHandlingTestSuite() {
-
-
- }
- @Before
- public void setUp() throws Exception {
- System.setProperty(AbstractServiceProcessor.CLASSPATH_SWITCH_PROP,"true");
- }
- @After
- public void tearDown() throws Exception {
-
- }
- @Test
- public void testNoWindow() throws Exception {
- // fails on 3rd error
- WindowBasedErrorHandler errorHandler =
- new WindowBasedErrorHandler();
- errorHandler.withMaxFrameworkErrors(3).build();
- int taskCount = 10;
- int failures=0;
- for( int i = 0; i < taskCount; i++) {
- failures++;
- if ( errorHandler.exceededErrorWindow(i) ) {
- break;
- }
- }
- // there should be 3 failures
- Assert.assertEquals(3, failures);
- }
- @Test
- public void testDefaults() throws Exception {
- // fails on 1st error
- WindowBasedErrorHandler errorHandler =
- new WindowBasedErrorHandler();
- errorHandler.build();
- int taskCount = 10;
- int failures=0;
- for( int i = 0; i < taskCount; i++) {
- failures++;
- if ( errorHandler.exceededErrorWindow(i) ) {
- break;
- }
- }
- // there should be 1 failure
- Assert.assertEquals(1, failures);
- }
- @Test
- public void testErrorFirstTask() throws Exception {
- // fails on 3rd error
- WindowBasedErrorHandler errorHandler =
- new WindowBasedErrorHandler();
- errorHandler.withMaxFrameworkErrors(1).withProcessErrorWindow(1).build();
- int taskCount = 10;
- int failures=0;
- for( int i = 0; i < taskCount; i++) {
- failures++;
- if ( errorHandler.exceededErrorWindow(i) ) {
- break;
- }
- }
- // there should be 1 failure
- Assert.assertEquals(1, failures);
- }
- @Test
- public void testZeroThresholdWindow() throws Exception {
- WindowBasedErrorHandler errorHandler =
- new WindowBasedErrorHandler();
- errorHandler.withMaxFrameworkErrors(0).
- withProcessErrorWindow(5).build();
- int taskCount = 10;
- for( int i = 0; i < taskCount; i++) {
- // simulate failure on task3. The test should not fail since max errors is 0, meaning
- // don't ever fail.
- if ( i == 3 ) {
- if ( errorHandler.exceededErrorWindow(i) ) {
- Assert.fail("Unexpected test failure - window=5 maxErrors=0 taskCount:"+i);
- }
- }
- }
- }
- @Test
- public void testErrorsLessWindow() throws Exception {
- WindowBasedErrorHandler errorHandler =
- new WindowBasedErrorHandler();
- errorHandler.withMaxFrameworkErrors(3).
- withProcessErrorWindow(5).build();
- int taskCount = 10;
- for( int i = 0; i < taskCount; i++) {
- // simulate failure on task1, task3, and task9. Setup calls for failure
- // if 3 errors occur within 5 tasks window. In this case, task1 and task3
- // should not cause a failure. Also task9 should not cause error since
- // its a new window.
- if ( i == 1 || i == 3 || i == 9) {
- if ( errorHandler.exceededErrorWindow(i) ) {
- Assert.fail("Unexpected test failure - window=5 maxErrors=3 taskCount:"+i);
- }
- }
- }
- }
- @Test
- public void testErrorsExceedingWindow() throws Exception {
- WindowBasedErrorHandler errorHandler =
- new WindowBasedErrorHandler();
- errorHandler.withMaxFrameworkErrors(3).
- withProcessErrorWindow(8).build();
- int taskCount = 10;
- for( int i = 0; i < taskCount; i++) {
- // simulate failure on task1, task3, and task7. Setup calls for failure
- // if 3 errors occur within 8 tasks window. In this case, task1, task3, and task7
- // should cause failure.
- if ( i == 1 || i == 3 || i == 7) {
- if ( errorHandler.exceededErrorWindow(i) ) {
- return;
- }
- }
- }
- Assert.fail("Unexpected test success - Should have failed - window=8 maxErrors=3 taskCount:"+taskCount);
- }
+ public JunitErrorHandlingTestSuite() {
+
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ System.setProperty(AbstractServiceProcessor.CLASSPATH_SWITCH_PROP, "true");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+
+ }
+
+ @Test
+ public void testNoWindow() throws Exception {
+ // fails on 3rd error
+ WindowBasedErrorHandler errorHandler = new WindowBasedErrorHandler();
+ errorHandler.withMaxFrameworkErrors(3).build();
+ int taskCount = 10;
+ int failures = 0;
+ for (int i = 0; i < taskCount; i++) {
+ failures++;
+ if (errorHandler.exceededErrorWindow(i)) {
+ break;
+ }
+ }
+ // there should be 3 failures
+ Assert.assertEquals(3, failures);
+ }
+
+ @Test
+ public void testDefaults() throws Exception {
+ // fails on 1st error
+ WindowBasedErrorHandler errorHandler = new WindowBasedErrorHandler();
+ errorHandler.build();
+ int taskCount = 10;
+ int failures = 0;
+ for (int i = 0; i < taskCount; i++) {
+ failures++;
+ if (errorHandler.exceededErrorWindow(i)) {
+ break;
+ }
+ }
+ // there should be 1 failure
+ Assert.assertEquals(1, failures);
+ }
+
+ @Test
+ public void testErrorFirstTask() throws Exception {
+ // fails on 3rd error
+ WindowBasedErrorHandler errorHandler = new WindowBasedErrorHandler();
+ errorHandler.withMaxFrameworkErrors(1).withProcessErrorWindow(1).build();
+ int taskCount = 10;
+ int failures = 0;
+ for (int i = 0; i < taskCount; i++) {
+ failures++;
+ if (errorHandler.exceededErrorWindow(i)) {
+ break;
+ }
+ }
+ // there should be 1 failure
+ Assert.assertEquals(1, failures);
+ }
+
+ @Test
+ public void testZeroThresholdWindow() throws Exception {
+ WindowBasedErrorHandler errorHandler = new WindowBasedErrorHandler();
+ errorHandler.withMaxFrameworkErrors(0).withProcessErrorWindow(5).build();
+ int taskCount = 10;
+ for (int i = 0; i < taskCount; i++) {
+ // simulate failure on task3. The test should not fail since max errors is 0, meaning
+ // don't ever fail.
+ if (i == 3) {
+ if (errorHandler.exceededErrorWindow(i)) {
+ Assert.fail("Unexpected test failure - window=5 maxErrors=0 taskCount:" + i);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testErrorsLessWindow() throws Exception {
+ WindowBasedErrorHandler errorHandler = new WindowBasedErrorHandler();
+ errorHandler.withMaxFrameworkErrors(3).withProcessErrorWindow(5).build();
+ int taskCount = 10;
+ for (int i = 0; i < taskCount; i++) {
+ // simulate failure on task1, task3, and task9. Setup calls for failure
+ // if 3 errors occur within 5 tasks window. In this case, task1 and task3
+ // should not cause a failure. Also task9 should not cause error since
+ // its a new window.
+ if (i == 1 || i == 3 || i == 9) {
+ if (errorHandler.exceededErrorWindow(i)) {
+ Assert.fail("Unexpected test failure - window=5 maxErrors=3 taskCount:" + i);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testErrorsExceedingWindow() throws Exception {
+ WindowBasedErrorHandler errorHandler = new WindowBasedErrorHandler();
+ errorHandler.withMaxFrameworkErrors(3).withProcessErrorWindow(8).build();
+ int taskCount = 10;
+ for (int i = 0; i < taskCount; i++) {
+ // simulate failure on task1, task3, and task7. Setup calls for failure
+ // if 3 errors occur within 8 tasks window. In this case, task1, task3, and task7
+ // should cause failure.
+ if (i == 1 || i == 3 || i == 7) {
+ if (errorHandler.exceededErrorWindow(i)) {
+ return;
+ }
+ }
+ }
+ Assert.fail("Unexpected test success - Should have failed - window=8 maxErrors=3 taskCount:"
+ + taskCount);
+ }
}
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitPullServiceTestCase.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitPullServiceTestCase.java?rev=1864248&r1=1864247&r2=1864248&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitPullServiceTestCase.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/JunitPullServiceTestCase.java Fri Aug 2 17:30:46 2019
@@ -47,12 +47,14 @@ public class JunitPullServiceTestCase ex
@Before
public void setUp() throws Exception {
- System.setProperty(AbstractServiceProcessor.CLASSPATH_SWITCH_PROP,"true");
+ System.setProperty(AbstractServiceProcessor.CLASSPATH_SWITCH_PROP, "true");
}
+
@After
public void tearDown() throws Exception {
-
+
}
+
@Test
public void testPullService() throws Exception {
System.out.println("----------------- testPullService -------------------");
@@ -303,4 +305,3 @@ public class JunitPullServiceTestCase ex
}
}
-
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/wrapper/JUnitServiceWrapperTestCase.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/wrapper/JUnitServiceWrapperTestCase.java?rev=1864248&r1=1864247&r2=1864248&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/wrapper/JUnitServiceWrapperTestCase.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/test/java/org/apache/uima/ducc/ps/service/wrapper/JUnitServiceWrapperTestCase.java Fri Aug 2 17:30:46 2019
@@ -38,14 +38,17 @@ public class JUnitServiceWrapperTestCase
// sending READY to a monitor
System.setProperty("ducc.service.init.delay", "3000");
}
+
@Before
public void setUp() throws Exception {
- System.setProperty(AbstractServiceProcessor.CLASSPATH_SWITCH_PROP,"true");
+ System.setProperty(AbstractServiceProcessor.CLASSPATH_SWITCH_PROP, "true");
}
+
@After
public void tearDown() throws Exception {
-
+
}
+
@Test
public void testPullServiceWrapperNoTask() throws Exception {
// make client return null task in response to GET