You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2018/05/01 17:30:00 UTC
svn commit: r1830697 -
/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/ServiceWrapper.java
Author: cwiklik
Date: Tue May 1 17:29:59 2018
New Revision: 1830697
URL: http://svn.apache.org/viewvc?rev=1830697&view=rev
Log:
UIMA-5756 modified to use reflection to instantiate custom processor and registry client
Modified:
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/ServiceWrapper.java
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/ServiceWrapper.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/ServiceWrapper.java?rev=1830697&r1=1830696&r2=1830697&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/ServiceWrapper.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/ServiceWrapper.java Tue May 1 17:29:59 2018
@@ -1,6 +1,25 @@
+/*
+ * 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.ps.service.main;
import java.io.IOException;
+import java.lang.reflect.Constructor;
import java.util.concurrent.ExecutionException;
import org.apache.uima.UIMAFramework;
@@ -12,6 +31,7 @@ import org.apache.uima.ducc.ps.service.e
import org.apache.uima.ducc.ps.service.jmx.JMXAgent;
import org.apache.uima.ducc.ps.service.processor.IServiceProcessor;
import org.apache.uima.ducc.ps.service.processor.uima.UimaServiceProcessor;
+import org.apache.uima.ducc.ps.service.registry.IRegistryClient;
import org.apache.uima.util.Level;
import org.apache.uima.util.Logger;
@@ -22,9 +42,6 @@ public class ServiceWrapper {
new ServiceConfiguration();
private JMXAgent jmxAgent;
- private String createAEdescriptorFromParts() {
- return "";
- }
private void addShutdownHook() {
ServiceShutdownHook shutdownHook = new ServiceShutdownHook(this, logger);
Runtime.getRuntime().addShutdownHook(shutdownHook);
@@ -35,34 +52,81 @@ public class ServiceWrapper {
return jmxAgent.start(rmiRegistryPort);
}
+ private IServiceProcessor createProcessor(String analysisEngineDescriptorPath)
+ throws ServiceInitializationException{
+ if ( serviceConfiguration.getCustomProcessorClass() != null ) {
+ try {
+ Class<?> clz = Class.forName(serviceConfiguration.getCustomProcessorClass());
+ if ( !IServiceProcessor.class.isAssignableFrom(clz) ) {
+ throw new ServiceInitializationException(serviceConfiguration.getCustomProcessorClass()+" Processor Class does not implement IServiceProcessor ");
+ }
+ return (IServiceProcessor) clz.newInstance();
+ } catch( Exception e) {
+ logger.log(Level.WARNING,"",e);
+ throw new ServiceInitializationException("Unable to instantiate Custom Processor from class:"+serviceConfiguration.getCustomProcessorClass());
+ }
+ } else {
+ return new UimaServiceProcessor(analysisEngineDescriptorPath, serviceConfiguration);
+ }
+ }
public void initialize(String[] args) throws ServiceInitializationException, ServiceException {
+ // collect -Ds and env vars
serviceConfiguration.collectProperties(args);
serviceConfiguration.validateProperties();
addShutdownHook();
+
String analysisEngineDescriptorPath =
serviceConfiguration.getAnalysisEngineDescriptorPath();
- if ( analysisEngineDescriptorPath == null) {
- //analysisEngineDescriptorPath = createAEdescriptorFromParts();
- }
-// jmxAgent = new JMXAgent(serviceConfiguration.getAssignedJmxPort(), logger);
-// int rmiRegistryPort = jmxAgent.initialize();
-// String serviceJmxConnectString = jmxAgent.start(rmiRegistryPort);
-//
+
+ // create JMX agent
String serviceJmxConnectString = startJmxAgent();
serviceConfiguration.setServiceJmxConnectURL(serviceJmxConnectString);
IServiceProcessor processor =
- new UimaServiceProcessor(analysisEngineDescriptorPath, serviceConfiguration);
+ createProcessor(analysisEngineDescriptorPath);
+ IRegistryClient registryClient= null;
+
+ if ( serviceConfiguration.getCustomRegistryClass() != null ) {
+ try {
+ Class<?> clz = Class.forName(serviceConfiguration.getCustomRegistryClass()) ;
+ if ( !IRegistryClient.class.isAssignableFrom(clz)) {
+ throw new ServiceInitializationException(serviceConfiguration.getCustomRegistryClass()+" Registry Client Class does not implement IRegistryClient ");
+ }
+ try {
+ // constructor with client URL argument
+ Constructor<?> ctor = clz.getConstructor(String.class);
+ registryClient = (IRegistryClient) ctor.newInstance(serviceConfiguration.getClientURL());
+ } catch(NoSuchMethodException ee) {
+ // zero arg constructor. User must initialize this registry via custom -D's or environment
+ registryClient = (IRegistryClient) clz.newInstance();
+ }
+
+
+ } catch( Exception e) {
+ logger.log(Level.WARNING,"",e);
+ throw new ServiceInitializationException("Unable to instantiate Custom Registry Client from class:"+serviceConfiguration.getCustomRegistryClass());
+
+ }
+ service = PullServiceStepBuilder.newBuilder()
+ .withProcessor(processor)
+ .withRegistry(registryClient)
+ .withType(serviceConfiguration.getServiceType())
+ .withScaleout(Integer.valueOf(serviceConfiguration.getThreadCount()))
+ .withOptionalsDone().build();
+
+ } else {
+ service = PullServiceStepBuilder.newBuilder()
+ .withProcessor(processor)
+ .withClientURL(serviceConfiguration.getClientURL())
+ .withType(serviceConfiguration.getServiceType())
+ .withScaleout(Integer.valueOf(serviceConfiguration.getThreadCount()))
+ .withOptionalsDone().build();
+
+ }
// String tasURL = "http://localhost:8080/test";
- service = PullServiceStepBuilder.newBuilder()
- .withProcessor(processor)
- .withClientURL(serviceConfiguration.getClientURL())
- .withType(serviceConfiguration.getServiceType())
- .withScaleout(Integer.valueOf(serviceConfiguration.getThreadCount()))
- .withOptionalsDone().build();
service.initialize();
@@ -82,7 +146,17 @@ public class ServiceWrapper {
}
-
+ public static void main(String[] args) {
+ ServiceWrapper wrapper = new ServiceWrapper();
+ try {
+
+ wrapper.initialize(args);
+ wrapper.start();
+ } catch( Exception e) {
+ UIMAFramework.getLogger().log(Level.WARNING, "", e);
+ wrapper.stop();
+ }
+ }
static class ServiceShutdownHook extends Thread {
private ServiceWrapper serviceWrapper;
private Logger logger;