Author: cwiklik
Date: Tue Jul 31 14:06:06 2018
New Revision: 1837148

URL: http://svn.apache.org/viewvc?rev=1837148&view=rev
Log:
UIMA-5815 modified to support clean shutdown

Added:
    
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/Application.java
Modified:
    
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/builders/PullServiceStepBuilder.java
    
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/PullService.java
    
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/builders/PullServiceStepBuilder.java
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/builders/PullServiceStepBuilder.java?rev=1837148&r1=1837147&r2=1837148&view=diff
==============================================================================
--- 
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/builders/PullServiceStepBuilder.java
 (original)
+++ 
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/builders/PullServiceStepBuilder.java
 Tue Jul 31 14:06:06 2018
@@ -18,11 +18,13 @@
 */
 package org.apache.uima.ducc.ps.service.builders;
 
+import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 
 import org.apache.uima.ducc.ps.service.IService;
 import org.apache.uima.ducc.ps.service.errors.ServiceException;
 import org.apache.uima.ducc.ps.service.errors.ServiceInitializationException;
+import org.apache.uima.ducc.ps.service.main.Application;
 import org.apache.uima.ducc.ps.service.main.PullService;
 import org.apache.uima.ducc.ps.service.processor.IServiceProcessor;
 import org.apache.uima.ducc.ps.service.processor.uima.UimaServiceProcessor;
@@ -30,8 +32,12 @@ import org.apache.uima.ducc.ps.service.r
 
 public final class PullServiceStepBuilder {
        private PullServiceStepBuilder() {}
-
+       private static Application app;
        public static ServiceProcessorStep newBuilder() {
+               return newBuilder(null);
+       }
+       public static ServiceProcessorStep newBuilder(Application application) {
+               app = application;
                return new ServiceSteps();
        }
        private static class ServiceSteps implements ServiceProcessorStep, 
RegistryStep, OptionalsStep, BuildStep {
@@ -47,8 +53,13 @@ public final class PullServiceStepBuilde
                
                @Override
                public IService build() {
-                       
-                       PullService service = new PullService(serviceType);
+                       PullService service = null;
+                       if ( Objects.nonNull(app)) {
+                               service = new PullService(serviceType, app);
+                       } else {
+                               service = new PullService(serviceType);
+                       }
+                        
                        service.setScaleout(scaleout);
                        if ( registryClient == null ) {
                                service.setClientURL(clientURL);        

Added: 
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/Application.java
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/Application.java?rev=1837148&view=auto
==============================================================================
--- 
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/Application.java
 (added)
+++ 
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/Application.java
 Tue Jul 31 14:06:06 2018
@@ -0,0 +1,24 @@
+/*
+ * 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;
+
+public interface Application {
+       public void onServiceStop();
+}

Modified: 
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/PullService.java
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/PullService.java?rev=1837148&r1=1837147&r2=1837148&view=diff
==============================================================================
--- 
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/PullService.java
 (original)
+++ 
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/main/PullService.java
 Tue Jul 31 14:06:06 2018
@@ -22,6 +22,7 @@ package org.apache.uima.ducc.ps.service.
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
@@ -33,6 +34,7 @@ import java.util.concurrent.locks.Reentr
 import org.apache.uima.UIMAFramework;
 import org.apache.uima.ducc.ps.ServiceThreadFactory;
 import org.apache.uima.ducc.ps.service.IService;
+//import org.apache.uima.ducc.ps.service.ServiceConfiguration;
 import org.apache.uima.ducc.ps.service.errors.IServiceErrorHandler;
 import org.apache.uima.ducc.ps.service.errors.ServiceException;
 import org.apache.uima.ducc.ps.service.errors.ServiceInitializationException;
@@ -87,10 +89,20 @@ public class PullService implements ISer
 
        private Lock initLock = new ReentrantLock();
 
+       private Application application=null;
+       
+       
        public PullService(String type) {
+               this(type,null);
+
+       }
+
+       public PullService(String type, Application  application ) {
                this.type = type;
 
+               this.application = application;
        }
+       
        public String getType() {
                return type;
        }
@@ -244,7 +256,7 @@ public class PullService implements ISer
        public void stop() {
                // process threads should stop first to avoid trying to pull new
                // work while threads are running
-               stopProcessThreads();
+               stopProcessThreadPool();
                // close connection to remote client and cleanup
                stopTransport();
                stopProtocolHandler(false);
@@ -269,8 +281,13 @@ public class PullService implements ISer
                        String result = future.get();
                        logger.log(Level.INFO, "Thread:" + 
Thread.currentThread().getName() + " Terminated " + new Date() + "::" + result);
                }
+               stopProcessThreadPool();
+               if ( Objects.nonNull(application) ) {
+                       application.onServiceStop();
+               }
        }
 
+       
        private void initializeTransport() throws 
ServiceInitializationException {
                try {
                        transport.initialize();
@@ -289,11 +306,16 @@ public class PullService implements ISer
                }
        }
 
-       private void stopProcessThreads() {
-               if (threadPool != null && !threadPool.isShutdown() && 
!threadPool.isTerminating() && !threadPool.isTerminated()) {
+       private void stopProcessThreadPool() {
+//             if (threadPool != null && !threadPool.isShutdown() && 
!threadPool.isTerminating() && !threadPool.isTerminated()) {
+               if (threadPool != null ) {
+
                        try {
+                               logger.log(Level.INFO, "Stopping Process Thread 
Pool");
                                threadPool.shutdownNow();
                                threadPool.awaitTermination(0, 
TimeUnit.MILLISECONDS);
+                               logger.log(Level.INFO, "Process Thread Pool 
Stopped");
+
                        } catch (InterruptedException e) {
                                Thread.currentThread().interrupt();
                        }

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=1837148&r1=1837147&r2=1837148&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 Jul 31 14:06:06 2018
@@ -41,7 +41,7 @@ import org.apache.uima.ducc.ps.service.r
 import org.apache.uima.util.Level;
 import org.apache.uima.util.Logger;
 
-public class ServiceWrapper {
+public class ServiceWrapper implements Application {
        private Logger logger = UIMAFramework.getLogger(ServiceWrapper.class);
        private IService service = null;
        // holds -D's and env variables needed at runtime
@@ -166,7 +166,7 @@ public class ServiceWrapper {
                Objects.requireNonNull(processor, "Unable to instantiate 
IServiceProcessor");
                
                if ( serviceConfiguration.getCustomRegistryClass() != null ) {
-                       service = PullServiceStepBuilder.newBuilder()
+                       service = PullServiceStepBuilder.newBuilder(this)
                                        .withProcessor(processor)
                                        .withRegistry(getRegistryClient())
                                        
.withType(serviceConfiguration.getServiceType())
@@ -174,7 +174,7 @@ public class ServiceWrapper {
                                        .withOptionalsDone().build();
 
                } else {
-                       service = PullServiceStepBuilder.newBuilder()
+                       service = PullServiceStepBuilder.newBuilder(this)
                                        .withProcessor(processor)
                                        
.withClientURL(serviceConfiguration.getClientURL())
                                        
.withType(serviceConfiguration.getServiceType())
@@ -215,7 +215,15 @@ public class ServiceWrapper {
        public void start() throws ServiceException, ExecutionException {
                service.start();
        }
-
+    public void stopJmx() {
+       try {
+               if ( Objects.nonNull(jmxAgent)) {
+                       jmxAgent.stop();
+               }
+       } catch( Exception e) {
+               
+       }
+    }
        public void stop() {
                try {
                        service.stop();
@@ -228,8 +236,10 @@ public class ServiceWrapper {
        }
        public void quiesceAndStop() {
                try {
-                       service.quiesceAndStop();
+                       logger.log(Level.INFO,"Stoppng JMX Agent");
                        jmxAgent.stop();
+
+                       service.quiesceAndStop();
                } catch( Exception e ) {
                        logger.log(Level.WARNING,"",e);
 
@@ -269,5 +279,10 @@ public class ServiceWrapper {
                      }
                    }
                  }
+       @Override
+       public void onServiceStop() {
+               stopJmx();
+               
+       }
 }
 


Reply via email to