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:27:49 UTC

svn commit: r1864247 [8/10] - in /uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent: ./ config/ deploy/ deploy/uima/ event/ exceptions/ launcher/ metrics/collectors/ monitor/ processors/

Modified: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/Launcher.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/Launcher.java?rev=1864247&r1=1864246&r2=1864247&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/Launcher.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/Launcher.java Fri Aug  2 17:27:48 2019
@@ -35,126 +35,134 @@ import org.apache.uima.ducc.transport.ev
 import org.apache.uima.ducc.transport.event.common.IDuccProcess;
 import org.apache.uima.ducc.transport.event.common.IDuccProcessType.ProcessType;
 
-
 public class Launcher {
-    private ExecutorService executorService = null;
-    private DuccIdFactory duccIdFactory = new DuccIdFactory();
-    public Launcher() {
-    	executorService = Executors.newCachedThreadPool();
-    }
-    /**
-     * This method is used to launch multiple Agents on the same physical machine. It allows
-     * to scale up Agents on a single machine to simulate load. Each Agent instance will 
-     * assume a given name and IP address.
-     * 
-     * @param cmdLine - defines the command line used to exec Agent process
-     * @param howMany - how many Agents to exec
-     * @param ip - initial IP address to assign to first Agent instance. Subsequent Agent instances
-     *             will have this IP incremented as in XXX.XXX.XXX.XX+1,XXX.XXX.XXX.XX+2, etc
-     * @param nodeName - name of the physical machine. The Agents will be assigned this name plus 
-     *                   a suffix as in watson-1, watson-2, etc
-     * @throws Exception
-     */
-    public void start(ICommandLine cmdLine, int howMany, String ip, String nodeName) throws Exception {
-        //	Launch as many agents as requested  
-        for( int i=0; i < howMany; i++ ) {
-            String host = nodeName;
-            //	Append suffix to node name for each Agent instance
-            if ( host.indexOf(".") > -1 ) {
-                String tmp = host.substring(0,host.indexOf("."));
-                host = tmp+"-"+String.valueOf(i+1)+host.substring(host.indexOf("."));
-            } else {
-                host = host+"-"+String.valueOf(i+1);
-            }
-            launchProcess(host, ip, cmdLine);
-            //	Increment IP address for the next Agent
-            int uip = Integer.parseInt(ip.substring(ip.lastIndexOf(".")+1, ip.length()));
-            ip = ip.substring(0,ip.lastIndexOf(".")+1).concat(String.valueOf(uip+1));
-        }
+  private ExecutorService executorService = null;
 
+  private DuccIdFactory duccIdFactory = new DuccIdFactory();
+
+  public Launcher() {
+    executorService = Executors.newCachedThreadPool();
+  }
+
+  /**
+   * This method is used to launch multiple Agents on the same physical machine. It allows to scale
+   * up Agents on a single machine to simulate load. Each Agent instance will assume a given name
+   * and IP address.
+   * 
+   * @param cmdLine
+   *          - defines the command line used to exec Agent process
+   * @param howMany
+   *          - how many Agents to exec
+   * @param ip
+   *          - initial IP address to assign to first Agent instance. Subsequent Agent instances
+   *          will have this IP incremented as in XXX.XXX.XXX.XX+1,XXX.XXX.XXX.XX+2, etc
+   * @param nodeName
+   *          - name of the physical machine. The Agents will be assigned this name plus a suffix as
+   *          in watson-1, watson-2, etc
+   * @throws Exception
+   */
+  public void start(ICommandLine cmdLine, int howMany, String ip, String nodeName)
+          throws Exception {
+    // Launch as many agents as requested
+    for (int i = 0; i < howMany; i++) {
+      String host = nodeName;
+      // Append suffix to node name for each Agent instance
+      if (host.indexOf(".") > -1) {
+        String tmp = host.substring(0, host.indexOf("."));
+        host = tmp + "-" + String.valueOf(i + 1) + host.substring(host.indexOf("."));
+      } else {
+        host = host + "-" + String.valueOf(i + 1);
+      }
+      launchProcess(host, ip, cmdLine);
+      // Increment IP address for the next Agent
+      int uip = Integer.parseInt(ip.substring(ip.lastIndexOf(".") + 1, ip.length()));
+      ip = ip.substring(0, ip.lastIndexOf(".") + 1).concat(String.valueOf(uip + 1));
+    }
+
+  }
+
+  /**
+   * Submit request to exec a process. The process will be exec'd in a separate thread.
+   * 
+   * @param process
+   * @param commandLine
+   * 
+   * @throws Exception
+   */
+  public ManagedProcess launchProcess(NodeAgent agent, NodeIdentity nodeIdentity,
+          IDuccProcess process, ICommandLine commandLine, ProcessLifecycleObserver observer,
+          ManagedProcess managedProcess) throws Exception {
+    // Instantiate executor that will actually exec the process using java's ProcessBuilder
+    DuccCommandExecutor executor = new DuccCommandExecutor(agent, commandLine,
+            nodeIdentity.getCanonicalName(), nodeIdentity.getIp(), managedProcess);
+    Future<?> future = executorService.submit(executor);
+    // if we are launching a process, save the future object returned from Executor above
+    managedProcess.setFuture(future);
+    return managedProcess;
+  }
+
+  /**
+   * Submit request to exec a process. The process will be exec'd in a separate thread.
+   * 
+   * @param process
+   * @param commandLine
+   * 
+   * @throws Exception
+   */
+  public void launchOSCommand(ICommand command) {
+    try {
+      executorService.submit(command);
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+
+  }
+
+  /**
+   * This method is used for simulation only. It enables launching an agent with a given name and IP
+   * address which are different from a physical node name and IP address. With that multiple agents
+   * can be launched on the same physical machine simulating a cluster of nodes.
+   * 
+   */
+  public void launchProcess(String host, String ip, ICommandLine cmdLine) throws Exception {
+    IDuccProcess process = new DuccProcess(duccIdFactory.next(), new NodeIdentity(ip, host));
+    process.setProcessType(ProcessType.Pop);
+    ManagedProcess managedProcess = new ManagedProcess(process, cmdLine, true);
+    DuccCommandExecutor executor = new DuccCommandExecutor(cmdLine, host, ip, managedProcess);
+    executorService.submit(executor);
+  }
+
+  public static void main(String[] args) {
+    try {
+      int howMany = Integer.parseInt(args[0]); // how many agent processes to launch
+      String ip = System.getProperty(IDuccUser.EnvironmentVariable.DUCC_IP.value());
+      String nodeName = InetAddress.getLocalHost().getHostName();
+      Launcher launcher = new Launcher();
+      JavaCommandLine cmdLine = new JavaCommandLine("java");
+      String duccHome = Utils.findDuccHome();
+      cmdLine.addOption("-Dducc.deploy.configuration=" + duccHome + "/resources/ducc.properties");
+      cmdLine.addOption("-Dducc.deploy.components=agent");
+      cmdLine.addOption("-Djava.library.path=" + duccHome + "/lib/sigar");
+      cmdLine.addOption("-DDUCC_HOME=" + duccHome);
+
+      // System.out.println("Spawning with classpath: \n" + System.getProperty("java.class.path"));
+      // cmdLine.setClasspath(duccHome+"/lib/*:" +
+      // duccHome+"/lib/apache-activemq-5.5.0/*:" +
+      // duccHome+"/lib/apache-camel-2.7.1/*:" +
+      // duccHome+"/lib/commons-collections-3.2.1/*:" +
+      // duccHome+"/lib/apache-commons-lang-2.6/*:" +
+      // duccHome+"/lib/apache-log4j-1.2.16/*:" +
+      // duccHome+"/lib/guava-r09/*:" +
+      // duccHome+"/lib/joda-time-1.6/*:" +
+      // duccHome+"/lib/sigar/*:" +
+      // duccHome+"/lib/springframework-3.0.5/*:");
+
+      cmdLine.setClasspath(System.getProperty("java.class.path"));
+      cmdLine.setClassName("org.apache.uima.ducc.agent.common.main.DuccService");
+      launcher.start(cmdLine, howMany, ip, nodeName);
+    } catch (Exception e) {
+      e.printStackTrace();
     }
-	
-    /**
-     * Submit request to exec a process. The process will be exec'd in a separate thread.
-     * 
-     * @param process
-     * @param commandLine
-
-     * @throws Exception
-     */
-    public ManagedProcess launchProcess(NodeAgent agent, NodeIdentity nodeIdentity,IDuccProcess process, ICommandLine commandLine,ProcessLifecycleObserver observer, ManagedProcess managedProcess) 
-    		throws Exception {
-        //	Instantiate executor that will actually exec the process using java's ProcessBuilder
-        DuccCommandExecutor executor = 
-            new DuccCommandExecutor(agent, commandLine, nodeIdentity.getCanonicalName(),nodeIdentity.getIp(), managedProcess);
-        Future<?> future = executorService.submit(executor);
-        //	if we are launching a process, save the future object returned from Executor above
-    	managedProcess.setFuture(future);
-        return managedProcess;
-    }
-    /**
-     * Submit request to exec a process. The process will be exec'd in a separate thread.
-     * 
-     * @param process
-     * @param commandLine
-
-     * @throws Exception
-     */
-    public void launchOSCommand(ICommand command) {
-    	try {
-            executorService.submit(command);
-    	} catch( Exception e) {
-    		e.printStackTrace();
-    	}
-        
-    }
-    /**
-     * This method is used for simulation only. It enables launching an agent with 
-     * a given name and IP address which are different from a physical node name
-     * and IP address. With that multiple agents can be launched on the same 
-     * physical machine simulating a cluster of nodes.
-     * 
-     */
-    public void launchProcess(String host, String ip, ICommandLine cmdLine) throws Exception {
-        IDuccProcess process = 
-            new DuccProcess(duccIdFactory.next(), new NodeIdentity(ip, host));
-        process.setProcessType(ProcessType.Pop);
-        ManagedProcess managedProcess = new ManagedProcess(process, cmdLine, true);
-        DuccCommandExecutor executor = 
-            new DuccCommandExecutor(cmdLine, host, ip, managedProcess);
-        executorService.submit(executor);
-    }
-    public static void main(String[] args) {
-        try {
-            int howMany = Integer.parseInt(args[0]);   // how many agent processes to launch
-            String ip = System.getProperty(IDuccUser.EnvironmentVariable.DUCC_IP.value());
-            String nodeName = InetAddress.getLocalHost().getHostName();
-            Launcher launcher = new Launcher();
-            JavaCommandLine cmdLine = new JavaCommandLine("java");
-            String duccHome = Utils.findDuccHome();
-            cmdLine.addOption("-Dducc.deploy.configuration="+duccHome+"/resources/ducc.properties");
-            cmdLine.addOption("-Dducc.deploy.components=agent");
-            cmdLine.addOption("-Djava.library.path=" + duccHome +"/lib/sigar");
-            cmdLine.addOption("-DDUCC_HOME=" + duccHome);
-			
-            // System.out.println("Spawning with classpath: \n" + System.getProperty("java.class.path"));
-            // cmdLine.setClasspath(duccHome+"/lib/*:" + 
-            //                      duccHome+"/lib/apache-activemq-5.5.0/*:" + 
-            //                      duccHome+"/lib/apache-camel-2.7.1/*:" + 
-            //                      duccHome+"/lib/commons-collections-3.2.1/*:" + 
-            //                      duccHome+"/lib/apache-commons-lang-2.6/*:" + 
-            //                      duccHome+"/lib/apache-log4j-1.2.16/*:" + 
-            //                      duccHome+"/lib/guava-r09/*:" + 
-            //                      duccHome+"/lib/joda-time-1.6/*:" + 
-            //                      duccHome+"/lib/sigar/*:" + 
-            //                      duccHome+"/lib/springframework-3.0.5/*:");
-
-            cmdLine.setClasspath(System.getProperty("java.class.path"));
-            cmdLine.setClassName("org.apache.uima.ducc.agent.common.main.DuccService");
-            launcher.start(cmdLine, howMany, ip, nodeName);
-        } catch( Exception e) {
-            e.printStackTrace();
-        }
-    }
+  }
 
 }

Modified: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedProcess.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedProcess.java?rev=1864247&r1=1864246&r2=1864247&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedProcess.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedProcess.java Fri Aug  2 17:27:48 2019
@@ -43,764 +43,783 @@ import org.apache.uima.ducc.transport.ev
 
 public class ManagedProcess implements Process {
 
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = 1L;
-
-	private ServiceState state = ServiceState.STARTING;
-
-	public static enum ProcessType {
-		UIMA_SERVICE {
-		},
-		APPLICATION {
-		},
-		LAUNCHER {
-		};
-	};
-
-	public static enum StopPriority {
-		NONE,KILL_9, QUIESCE_AND_STOP, DONT_WAIT
-	}
-
-	StopPriority stopPriority = StopPriority.NONE;
-	
-	private volatile boolean destroyed = false;
-	private IDuccProcess duccProcess;
-	// Used to kill a process after it reports its PID.
-	private volatile boolean killAfterLaunch = false;
-	// private String pid;
-	private String processCorrelationId;
-	// JMX Port
-	private String port = null;
-	// Service socket endpoint
-	private String socketEndpoint = null;
-
-	private int tgCounter = 1;
-	// private String owner;
-	// log path for http access
-	private String logPath;
-	// absolute path to the process log
-	private String absoluteLogPath;
-
-	private String agentLogPath;
-	private boolean agentProcess = false;
-	private String nodeIp;
-	private String nodeName;
-	private String description;
-	private String parent;
-
-	private ProcessType processType;
-	private volatile boolean attached;
-	private String clientId;
-	// private volatile boolean killed;
-	private Throwable exceptionStackTrace;
-	// The following are transients to prevent serialization when sending
-	// heartbeat updates
-	// to the controller. This class exports its state via AgentManagedProcess
-	// interface.
-	private transient List<String> command;
-	private transient java.lang.Process process;
-
-	protected transient ProcessStreamConsumer stdOutReader;
-	protected transient ProcessStreamConsumer stdErrReader;
-	// private transient OutputStream processLogStream = null;
-	private transient CountDownLatch pidReadyCount = new CountDownLatch(1);
-
-	private ICommandLine commandLine;
-
-	private transient ProcessLifecycleObserver observer;
-
-	transient private Timer initTimer;
-
-	// timer used to cleanup UIMA pipeline initializations stats
-	transient private Timer cleanupTimer;
-
-	private DuccId workDuccId;
-
-	private IDuccStandardInfo processInfo;
-
-	private transient Future<?> future;
-
-	private transient volatile boolean isstopping;
-
-	private transient volatile boolean forceKill;
-
-	private transient DuccLogger logger;
-
-	// private long processMemoryAssignment;
-
-	private long maxSwapThreshold;
-
-	private ProcessMemoryAssignment processMemoryAssignment;
-
-	private transient LinuxProcessMetricsProcessor metricsProcessor;
-
-	private volatile boolean isJD;
-
-	private long initializationTimeout;
-
-	private volatile boolean isUimaAs;
-	private volatile boolean preemptable;
-	
-	public ManagedProcess(IDuccProcess process, ICommandLine commandLine) {
-		this(process, commandLine, null, null, new ProcessMemoryAssignment(), true);
-	}
-
-	public ManagedProcess(IDuccProcess process, ICommandLine commandLine,
-			boolean agentProcess) {
-		this(process, commandLine, null, null, new ProcessMemoryAssignment(), true);
-		this.agentProcess = agentProcess;
-	}
-
-	public ManagedProcess(IDuccProcess process, ICommandLine commandLine,
-			ProcessLifecycleObserver observer, DuccLogger logger,
-			ProcessMemoryAssignment processMemoryAssignment, boolean isPreemptable) {
-		this.commandLine = commandLine;
-		this.duccProcess = process;
-		this.observer = observer;
-		this.logger = logger;
-		this.processMemoryAssignment = processMemoryAssignment;
-		this.preemptable = isPreemptable;
-	}
-
-	public boolean isPreemptable() {
-		return preemptable;
-	}
-	public void setMetricsProcessor(LinuxProcessMetricsProcessor processor) {
-		metricsProcessor = processor;
-	}
-	public void setStopPriority(StopPriority sp ) {
-		stopPriority = sp;
-	}
-	public StopPriority getStopPriority() {
-		return stopPriority;
-	}
-	public LinuxProcessMetricsProcessor getMetricsProcessor() {
-		return metricsProcessor;
-	}
-
-	public ManagedProcess(java.lang.Process process, boolean agentProcess,
-			String correlationId) {
-		this.process = process;
-		this.agentProcess = agentProcess;
-	}
-
-	public ManagedProcess(java.lang.Process process, boolean agentProcess) {
-		this(process, agentProcess, null);
-	}
-
-	public boolean doKill() {
-		return forceKill;
-	}
-
-	public void kill() {
-		forceKill = true;
-	}
-
-	public void setStopping() {
-		isstopping = true;
-	}
-
-	public boolean isStopping() {
-		return isstopping;
-	}
-
-	public void setWorkDuccId(DuccId workDuccId) {
-		this.workDuccId = workDuccId;
-	}
-
-	public DuccId getWorkDuccId() {
-		return this.workDuccId;
-	}
-
-	public DuccId getDuccId() {
-		return duccProcess.getDuccId();
-	}
-
-	public void setParent(String parent) {
-		this.parent = parent;
-	}
-
-	public String getParent() {
-		return parent;
-	}
-
-	public void setClientId(String clientId) {
-		this.clientId = clientId;
-	}
-
-	public String getClientId() {
-		return clientId;
-	}
-
-	public boolean isAttached() {
-		return attached;
-	}
-
-	public void setAttached() {
-		this.attached = true;
-	}
-
-	public String getNodeName() {
-		return nodeName;
-	}
-
-	public void setNodeName(String nodeName) {
-		this.nodeName = nodeName;
-	}
-
-	public String getNodeIp() {
-		return nodeIp;
-	}
-
-	public void setNodeIp(String nodeIp) {
-		this.nodeIp = nodeIp;
-	}
-
-	/**
-	 * Return current state of this object.
-	 * 
-	 * @return Process - process object
-	 */
-	public Process getInstance() {
-		return this;
-	}
-
-	public ProcessType getProcessType() {
-		return processType;
-	}
-
-	public void setProcessType(ProcessType processType) {
-		this.processType = processType;
-	}
-
-	public void setLogStream(OutputStream os) {
-		// processLogStream = os;
-	}
-
-	public boolean isAgentProcess() {
-		return agentProcess;
-	}
-
-	/**
-	 * @param logPath
-	 *            the uimaLogPath to set
-	 */
-	public void setLogPath(String logPath) {
-		this.logPath = logPath;
-	}
-
-	/**
-	 * @return the stdErrLogPath
-	 */
-	public String getLogPath() {
-		return logPath;
-	}
-
-	public void setAgentLogPath(String logPath) {
-		this.agentLogPath = logPath;
-	}
-
-	/**
-	 * @return the stdErrLogPath
-	 */
-	public String getAgentLogPath() {
-		return agentLogPath;
-	}
-
-	/**
-	 * @return the owner
-	 */
-	public String getOwner() {
-		if (processInfo != null) {
-			return processInfo.getUser();
-		}
-		return null;
-	}
-
-	public void setOSProcess(java.lang.Process process) {
-		this.process = process;
-	}
-
-	private void log(String method, String message) {
-		if (logger != null) {
-			logger.info(method, null, message);
-		}
-	}
-
-	public void drainProcessStreams(java.lang.Process process,
-			DuccLogger logger, PrintStream pStream, boolean isKillCmd) { 
-		// Create dedicated Thread Group for the process stream consumer threads
-		ThreadGroup group = new ThreadGroup("AgentDeployer" + tgCounter++);
-		// Fetch stdin from the deployed process
-		InputStream stdin = process.getInputStream();
-		// Fetch stderr from the deployed process
-		InputStream stderr = process.getErrorStream();
-		// Create dedicated thread to consume std output stream from the process
-		stdOutReader = new ProcessStreamConsumer(logger, group,
-				"StdOutputReader", stdin, pStream, workDuccId);
-		// Create dedicated thread to consume std error stream from the process
-		stdErrReader = new ProcessStreamConsumer(logger, group,
-				"StdErrorReader", stderr, pStream, workDuccId);
-
-		// Start both stream consumer threads
-		stdOutReader.start();
-		stdErrReader.start();
-		// block until the process is terminated or the agent terminates
-		boolean finished = false;
-		int exitcode = 0;
-		while (!finished) {
-			try {
-				process.waitFor();
-				if (getMetricsProcessor() != null) {
-					// close open fds (stat and statm files
-					getMetricsProcessor().close(); 
-				}
-			} catch (InterruptedException e) {
-			}
-			try {
-				exitcode = process.exitValue();
-				finished = true;
-			} catch (IllegalThreadStateException e) {
-			}
-		}
-		// determine if this process is an Arbitrary Process (AP)
-		boolean isAP = isJd()
-				&& getDuccProcess()
-						.getProcessType()
-						.equals(org.apache.uima.ducc.transport.event.common.IDuccProcessType.ProcessType.Pop);
-		try {
-			// wait for stdout and stderr reader threads to finish. Join for max
-			// of 2 secs The process has exited and in theory the join should 
-			// return quickly. We do the join to make sure that the streams are 
-			// drained so that we can get a reason for failure if there was a 
-			// problem launching the process.
-			stdOutReader.join(2000);
-			stdErrReader.join(2000);
-		} catch (InterruptedException ie) {
-			log("ManagedProcess.drainProcessStreams",
-					"Interrupted While Awaiting Termination of StdOutReader and StdErrReader Threads");
-		}
-
-		String reason = getDuccProcess().getReasonForStoppingProcess();
-
-		ProcessState pstate = getDuccProcess().getProcessState();
-                boolean initError = (reason != null && (reason
-				.equals(ReasonForStoppingProcess.FailedInitialization
-						.toString()) || reason
-				.equals(ReasonForStoppingProcess.InitializationTimeout
-						.toString())));
-		if (isKillCmd
-				||
-				// if the process is to be killed due to init problems, set the
-				// state to Stopped
-				(reason != null && initError ) ) {
-		    //getDuccProcess().setProcessState(ProcessState.Stopped);
-			if ( !initError && ( exitcode - 128 == 9 || exitcode - 128 == 15 ) ) {  
-				getDuccProcess().setReasonForStoppingProcess(ReasonForStoppingProcess.KilledByDucc.toString());
-			}
-
-		} else {
-			// Process has terminated. Determine why the process terminated.
-			log("ManagedProcess.drainProcessStreams", "Ducc Process with PID:"
-					+ getPid() + " Terminated while in " + pstate + " State");
-			
-			// true if agent killed the process. Process either exceeded memory
-			// use or the PM state notifications stopped coming in.
-			if (doKill()) {
-				if ( isAP ) {
-					// Agent killed the AP process 
-					pstate = ProcessState.Stopped;
-					if ( exitcode - 128 == 9 || exitcode - 128 == 15 ) {   // kill -9 or -15?
-						getDuccProcess().setReasonForStoppingProcess(ReasonForStoppingProcess.KilledByDucc.toString());
-					}
-				} else {
-					// Agent killed the process due to timeout waiting for OR state
-					pstate = ProcessState.Killed;
-				}
-			} else {
-				if ( !isstopping ) {
-					// check if process exited while in Initializing state  
-					if ( ProcessState.Initializing.equals(pstate) || ProcessState.Starting.equals(pstate) 
-					        || ProcessState.Started.equals(pstate)) {
-						getDuccProcess().setReasonForStoppingProcess(ReasonForStoppingProcess.FailedInitialization.toString());
-		                log("ManagedProcess.drainProcessStreams",
-				    "Process Failed while in initializing state - setting reason to "+getDuccProcess().getReasonForStoppingProcess());
-				    }
-				}
-				// default state to Stopped. If the process died unexpectadly the state
-				// will be changed to Failed
-				pstate = ProcessState.Stopped;
-				// check if the process died due to an external cause. If that
-				// was the case isstopping = false. The isstopping=true iff the Agent
-				// initiated process stop because the process was deallocated
-				if (!isstopping) {
-					// fetch errors from stderr stream. If the process failed to
-					// start due to misconfiguration
-					// the reason for failure would be provided by the OS (wrong
-					// user id, bad directory,etc)
-					String errors = stdErrReader.getDataFromStream();
-					if (errors != null && errors.trim().length() > 0) {
-						getDuccProcess().setExtendedReasonForStoppingProcess(
-								errors.trim());
-
-			                log("ManagedProcess.drainProcessStreams",
-					    "Process Failed - stderr stream:"+getDuccProcess().getReasonForStoppingProcess());
-					} 
-
-					// APs can stop for any reason. There is 
-					// no way to determine why the AP terminated.
-					if ( !isAP ) {
-						// Unexpected process termination 
-						pstate = ProcessState.Failed;
-						// fetch errors from stderr stream. If the process failed to
-						// start due to misconfiguration
-						// the reason for failure would be provided by the OS (wrong
-						// user id, bad directory,etc)
-						if (errors != null && errors.trim().length() > 0) {
-                            // JP should not be marked as CROAKED if it terminates 
-							// due to a process error, failed initialization or initialization
-							// timeout. On such errors, a JP sends an event to its agent where
-							// the reason for failure is set
-							if ( getDuccProcess().getProcessState().equals(ProcessState.Stopping) ) {
-								// the reason was already set while handling JPs Stopping event
-								getDuccProcess().setProcessState(ProcessState.Stopped); // now the JP is dead
-							} else {
-								// Process terminated unexpectedly. It stopped on its own due to Ducc framework
-								// error or due to some external event not initiated by an agent
-								getDuccProcess().setReasonForStoppingProcess(
-										ReasonForStoppingProcess.Croaked.toString());
-							}
-							
-						} else if ( exitcode - 128 == 9 || exitcode - 128 == 15 ) {
-							// Process terminated unexpectedly. It stopped on its own due to Ducc framework
-							// error or due to some external event not initiated by an agent
-							getDuccProcess().setReasonForStoppingProcess(
-									ReasonForStoppingProcess.Croaked.toString());
-						} 
-					}
-				} else {
-					if ( exitcode - 128 == 9 || exitcode - 128 == 15 ) { // check if the process was killed with -9 or -15
-						addReasonForStopping(getDuccProcess(),
-								ReasonForStoppingProcess.KilledByDucc.toString());
-					} else {
-						addReasonForStopping(getDuccProcess(),
-								ReasonForStoppingProcess.Deallocated.toString());
-					}
-				}
-				notifyProcessObserver(pstate);
-				log("ManagedProcess.drainProcessStreams",
-						"************ Remote Process PID:" + getPid()
-								+ " Terminated *************** State:"+getDuccProcess().getProcessState().toString());
-			}
-		}
-	}
-
-	private void addReasonForStopping(IDuccProcess process, String reason) {
-		if (getDuccProcess().getReasonForStoppingProcess() == null
-				|| getDuccProcess().getReasonForStoppingProcess().trim()
-						.length() == 0) {
-			getDuccProcess().setReasonForStoppingProcess(reason);
-		}
-	}
-
-	/**
-	 * @return the state
-	 */
-	public ServiceState getStatus() {
-		return state;
-	}
-
-	/**
-	 * @return the pid
-	 */
-	public String getPid() {
-		return duccProcess.getPID();
-	}
-
-	/**
-	 * @param pid
-	 *            the pid to set
-	 */
-	public void setPid(String pid) {
-		// this.pid = pid;
-		duccProcess.setPID(pid);
-		pidReadyCount.countDown();
-	}
-
-	public void awaitPid() {
-		try {
-			pidReadyCount.await();
-		} catch (Exception e) {
-		}
-	}
-
-	public void releasePidLatch() {
-		pidReadyCount.countDown();
-	}
-
-	/**
-	 * @return the command
-	 */
-	public List<String> getCommand() {
-		return command;
-	}
-
-	
-	/**
-	 * @param commandToRun
-	 *            the command as List
-	 */
-	public void setCommand(List<String> commandToRun) {
-		this.command = commandToRun;
-	}
-
-	/**
-	 * @return the processCorrelationId
-	 */
-	public String getProcessId() {
-		return processCorrelationId;
-	}
-
-	/**
-	 * @param processId
-	 *            the processId to set
-	 */
-	public void setProcessId(String processId) {
-		this.processCorrelationId = processId;
-	}
-
-	/**
-	 * @return the jmxPort
-	 */
-	public String getPort() {
-		return port;
-	}
-
-	/**
-	 * @param port
-	 *            the jmxPort to set
-	 */
-	public void setPort(String port) {
-		this.port = port;
-	}
-
-	public void terminateRemoteProcess() throws Exception {
-		System.out.println("Stopping Remote Managed Process via JMX");
-		// Using JMX instruct the service to terminate
-		// if ( processMBean != null ) {
-		// processMBean.getManagedServiceMBean().terminate();
-		// }
-	}
-
-	public void failed() {
-		// setStatus(ServiceState.FAILED);
-		cleanup();
-		// managedProcessInfo.setState(state);
-		// if ( getEndDate() == null ) {
-		// setEndDate(new DateTime());
-		// }
-	}
-
-	private void cleanup() {
-		if (process != null) {
-			process.destroy();
-		}
-		destroyed = true;
-
-	}
-
-	public void stop() {
-		// if ( getStatus() != ServiceState.FAILED ) {
-		// setStatus(ServiceState.STOPPED);
-		// }
-		cleanup();
-		// if ( getEndDate() == null ) {
-		// setEndDate(new DateTime());
-		// }
-		// if ( process != null ) {
-		// process.destroy();
-		// }
-		// destroyed = true;
-	}
-
-	public void waitFor() throws InterruptedException {
-		process.waitFor();
-	}
-
-	public boolean isDestroyed() {
-		return destroyed;
-	}
-
-	public String getAbsoluteLogPath() {
-		return absoluteLogPath;
-	}
-
-	public void setAbsoluteLogPath(String absoluteLogPath) {
-		this.absoluteLogPath = absoluteLogPath;
-	}
-
-	public String getDescription() {
-		return description;
-	}
-
-	public void setDescription(String description) {
-		this.description = description;
-	}
-
-	public Throwable getExceptionStackTrace() {
-		return exceptionStackTrace;
-	}
-
-	public void setExceptionStackTrace(Throwable exceptionStackTrace) {
-		this.exceptionStackTrace = exceptionStackTrace;
-	}
-
-	/**
-	 * @return the processSpecification
-	 */
-	public ICommandLine getCommandLine() {
-		return commandLine;
-	}
-
-	/**
-	 * @return the duccProcess
-	 */
-	public IDuccProcess getDuccProcess() {
-		return duccProcess;
-	}
-
-	public void notifyProcessObserver(ProcessState state) {
-		if (observer != null && getDuccProcess() != null) {
-			if (ProcessState.InitializationTimeout.equals(state)) {
-				observer.onJPInitTimeout(getDuccProcess(), initializationTimeout);
-			} else {
-				getDuccProcess().setProcessState(state);
-	//			observer.onProcessExit(getDuccProcess());
-			}
-		}
-	}
-
-	public void startInitializationTimer(long timeout) {
-		initTimer = new Timer();
-		// long timeout = 7200*1000; // default timeout after 2 hours of
-		// initialization
-		try {
-			if (timeout == 0) {
-				String str_timeout;
-				if ((str_timeout = System.getProperty(DuccPropertiesResolver.ducc_default_process_init_time_max)) != null) {
-					timeout = Long.parseLong(str_timeout) * 60 * 1000;    // Minutes -> milliseconds
-				} else {
-					// max init timeout default=4hours
-					timeout = 3600 * 4 * 1000; 
-				}
-			}
-		} catch (NumberFormatException e) {
-
-		}
-		// timeout after 2 hours of initialization
-		initTimer.schedule(new InitializationTask(), timeout); 
-		initializationTimeout = timeout;    // Save just for the timeout message
-	}
-
-	/**
-	 * Stops service initialization timer and starts a new timer that will
-	 * cleanup UIMA pipeline initialization stats. These states are only needed
-	 * during the initialization of a service.
-	 */
-	public void stopInitializationTimer() {
-		if (initTimer != null) {
-			initTimer.cancel();
-			long timeout = 60000; // default timeout after 60 seconds
-			if (getDuccProcess().getUimaPipelineComponents() != null
-					&& getDuccProcess().getUimaPipelineComponents().size() > 0) {
-				cleanupTimer = new Timer();
-				try {
-					String inv_publish_rate;
-					if ((inv_publish_rate = System
-							.getProperty("ducc.agent.node.inventory.publish.rate")) != null) {
-						// allow sufficient time to publish init stats
-						timeout = Long.parseLong(inv_publish_rate) * 4; 
-					}
-				} catch (NumberFormatException e) {
-				}
-				// timeout and remove UIMA pipeline stats
-				cleanupTimer.schedule(new CleanupTask(), timeout); 			}
-		}
-	}
-
-	private class InitializationTask extends TimerTask {
-		public void run() {
-			initTimer.cancel();
-			notifyProcessObserver(ProcessState.InitializationTimeout);
-		}
-	}
-
-	private class CleanupTask extends TimerTask {
-		public void run() {
-			cleanupTimer.cancel();
-			((DuccProcess) getDuccProcess()).setUimaPipelineComponents(null);
-		}
-	}
-
-	public IDuccStandardInfo getProcessInfo() {
-		return processInfo;
-	}
-
-	public void setProcessInfo(IDuccStandardInfo processInfo) {
-		this.processInfo = processInfo;
-	}
-
-	public boolean killAfterLaunch() {
-		return killAfterLaunch;
-	}
-
-	public void killAfterLaunch(boolean killAfterLaunch) {
-		this.killAfterLaunch = killAfterLaunch;
-	}
-
-	public Future<?> getFuture() {
-		return future;
-	}
-
-	public void setFuture(Future<?> future) {
-		this.future = future;
-	}
-
-	public ProcessMemoryAssignment getProcessMemoryAssignment() {
-		return processMemoryAssignment;
-	}
-
-	public String getSocketEndpoint() {
-		return socketEndpoint;
-	}
-
-	public void setSocketEndpoint(String socketEndpoint) {
-		this.socketEndpoint = socketEndpoint;
-	}
-
-	public long getMaxSwapThreshold() {
-		return maxSwapThreshold;
-	}
-
-	public void setMaxSwapThreshold(long maxSwapThreshold) {
-		this.maxSwapThreshold = maxSwapThreshold;
-	}
-
-	public void setIsJD() {
-		isJD = true;
-	}
-
-	public boolean isJd() {
-		return isJD;
-	}
-	
-	public void setUimaAs() {
-		isUimaAs = true;
-	}
-
-	public boolean isUimaAs() {
-		return isUimaAs;
-	}
+  /**
+   * 
+   */
+  private static final long serialVersionUID = 1L;
+
+  private ServiceState state = ServiceState.STARTING;
+
+  public static enum ProcessType {
+    UIMA_SERVICE {
+    },
+    APPLICATION {
+    },
+    LAUNCHER {
+    };
+  };
+
+  public static enum StopPriority {
+    NONE, KILL_9, QUIESCE_AND_STOP, DONT_WAIT
+  }
+
+  StopPriority stopPriority = StopPriority.NONE;
+
+  private volatile boolean destroyed = false;
+
+  private IDuccProcess duccProcess;
+
+  // Used to kill a process after it reports its PID.
+  private volatile boolean killAfterLaunch = false;
+
+  // private String pid;
+  private String processCorrelationId;
+
+  // JMX Port
+  private String port = null;
+
+  // Service socket endpoint
+  private String socketEndpoint = null;
+
+  private int tgCounter = 1;
+
+  // private String owner;
+  // log path for http access
+  private String logPath;
+
+  // absolute path to the process log
+  private String absoluteLogPath;
+
+  private String agentLogPath;
+
+  private boolean agentProcess = false;
+
+  private String nodeIp;
+
+  private String nodeName;
+
+  private String description;
+
+  private String parent;
+
+  private ProcessType processType;
+
+  private volatile boolean attached;
+
+  private String clientId;
+
+  // private volatile boolean killed;
+  private Throwable exceptionStackTrace;
+
+  // The following are transients to prevent serialization when sending
+  // heartbeat updates
+  // to the controller. This class exports its state via AgentManagedProcess
+  // interface.
+  private transient List<String> command;
+
+  private transient java.lang.Process process;
+
+  protected transient ProcessStreamConsumer stdOutReader;
+
+  protected transient ProcessStreamConsumer stdErrReader;
+
+  // private transient OutputStream processLogStream = null;
+  private transient CountDownLatch pidReadyCount = new CountDownLatch(1);
+
+  private ICommandLine commandLine;
+
+  private transient ProcessLifecycleObserver observer;
+
+  transient private Timer initTimer;
+
+  // timer used to cleanup UIMA pipeline initializations stats
+  transient private Timer cleanupTimer;
+
+  private DuccId workDuccId;
+
+  private IDuccStandardInfo processInfo;
+
+  private transient Future<?> future;
+
+  private transient volatile boolean isstopping;
+
+  private transient volatile boolean forceKill;
+
+  private transient DuccLogger logger;
+
+  // private long processMemoryAssignment;
+
+  private long maxSwapThreshold;
+
+  private ProcessMemoryAssignment processMemoryAssignment;
+
+  private transient LinuxProcessMetricsProcessor metricsProcessor;
+
+  private volatile boolean isJD;
+
+  private long initializationTimeout;
+
+  private volatile boolean isUimaAs;
+
+  private volatile boolean preemptable;
+
+  public ManagedProcess(IDuccProcess process, ICommandLine commandLine) {
+    this(process, commandLine, null, null, new ProcessMemoryAssignment(), true);
+  }
+
+  public ManagedProcess(IDuccProcess process, ICommandLine commandLine, boolean agentProcess) {
+    this(process, commandLine, null, null, new ProcessMemoryAssignment(), true);
+    this.agentProcess = agentProcess;
+  }
+
+  public ManagedProcess(IDuccProcess process, ICommandLine commandLine,
+          ProcessLifecycleObserver observer, DuccLogger logger,
+          ProcessMemoryAssignment processMemoryAssignment, boolean isPreemptable) {
+    this.commandLine = commandLine;
+    this.duccProcess = process;
+    this.observer = observer;
+    this.logger = logger;
+    this.processMemoryAssignment = processMemoryAssignment;
+    this.preemptable = isPreemptable;
+  }
+
+  public boolean isPreemptable() {
+    return preemptable;
+  }
+
+  public void setMetricsProcessor(LinuxProcessMetricsProcessor processor) {
+    metricsProcessor = processor;
+  }
+
+  public void setStopPriority(StopPriority sp) {
+    stopPriority = sp;
+  }
+
+  public StopPriority getStopPriority() {
+    return stopPriority;
+  }
+
+  public LinuxProcessMetricsProcessor getMetricsProcessor() {
+    return metricsProcessor;
+  }
+
+  public ManagedProcess(java.lang.Process process, boolean agentProcess, String correlationId) {
+    this.process = process;
+    this.agentProcess = agentProcess;
+  }
+
+  public ManagedProcess(java.lang.Process process, boolean agentProcess) {
+    this(process, agentProcess, null);
+  }
+
+  public boolean doKill() {
+    return forceKill;
+  }
+
+  public void kill() {
+    forceKill = true;
+  }
+
+  public void setStopping() {
+    isstopping = true;
+  }
+
+  public boolean isStopping() {
+    return isstopping;
+  }
+
+  public void setWorkDuccId(DuccId workDuccId) {
+    this.workDuccId = workDuccId;
+  }
+
+  public DuccId getWorkDuccId() {
+    return this.workDuccId;
+  }
+
+  public DuccId getDuccId() {
+    return duccProcess.getDuccId();
+  }
+
+  public void setParent(String parent) {
+    this.parent = parent;
+  }
+
+  public String getParent() {
+    return parent;
+  }
+
+  public void setClientId(String clientId) {
+    this.clientId = clientId;
+  }
+
+  public String getClientId() {
+    return clientId;
+  }
+
+  public boolean isAttached() {
+    return attached;
+  }
+
+  public void setAttached() {
+    this.attached = true;
+  }
+
+  public String getNodeName() {
+    return nodeName;
+  }
+
+  public void setNodeName(String nodeName) {
+    this.nodeName = nodeName;
+  }
+
+  public String getNodeIp() {
+    return nodeIp;
+  }
+
+  public void setNodeIp(String nodeIp) {
+    this.nodeIp = nodeIp;
+  }
+
+  /**
+   * Return current state of this object.
+   * 
+   * @return Process - process object
+   */
+  public Process getInstance() {
+    return this;
+  }
+
+  public ProcessType getProcessType() {
+    return processType;
+  }
+
+  public void setProcessType(ProcessType processType) {
+    this.processType = processType;
+  }
+
+  public void setLogStream(OutputStream os) {
+    // processLogStream = os;
+  }
+
+  public boolean isAgentProcess() {
+    return agentProcess;
+  }
+
+  /**
+   * @param logPath
+   *          the uimaLogPath to set
+   */
+  public void setLogPath(String logPath) {
+    this.logPath = logPath;
+  }
+
+  /**
+   * @return the stdErrLogPath
+   */
+  public String getLogPath() {
+    return logPath;
+  }
+
+  public void setAgentLogPath(String logPath) {
+    this.agentLogPath = logPath;
+  }
+
+  /**
+   * @return the stdErrLogPath
+   */
+  public String getAgentLogPath() {
+    return agentLogPath;
+  }
+
+  /**
+   * @return the owner
+   */
+  public String getOwner() {
+    if (processInfo != null) {
+      return processInfo.getUser();
+    }
+    return null;
+  }
+
+  public void setOSProcess(java.lang.Process process) {
+    this.process = process;
+  }
+
+  private void log(String method, String message) {
+    if (logger != null) {
+      logger.info(method, null, message);
+    }
+  }
+
+  public void drainProcessStreams(java.lang.Process process, DuccLogger logger, PrintStream pStream,
+          boolean isKillCmd) {
+    // Create dedicated Thread Group for the process stream consumer threads
+    ThreadGroup group = new ThreadGroup("AgentDeployer" + tgCounter++);
+    // Fetch stdin from the deployed process
+    InputStream stdin = process.getInputStream();
+    // Fetch stderr from the deployed process
+    InputStream stderr = process.getErrorStream();
+    // Create dedicated thread to consume std output stream from the process
+    stdOutReader = new ProcessStreamConsumer(logger, group, "StdOutputReader", stdin, pStream,
+            workDuccId);
+    // Create dedicated thread to consume std error stream from the process
+    stdErrReader = new ProcessStreamConsumer(logger, group, "StdErrorReader", stderr, pStream,
+            workDuccId);
+
+    // Start both stream consumer threads
+    stdOutReader.start();
+    stdErrReader.start();
+    // block until the process is terminated or the agent terminates
+    boolean finished = false;
+    int exitcode = 0;
+    while (!finished) {
+      try {
+        process.waitFor();
+        if (getMetricsProcessor() != null) {
+          // close open fds (stat and statm files
+          getMetricsProcessor().close();
+        }
+      } catch (InterruptedException e) {
+      }
+      try {
+        exitcode = process.exitValue();
+        finished = true;
+      } catch (IllegalThreadStateException e) {
+      }
+    }
+    // determine if this process is an Arbitrary Process (AP)
+    boolean isAP = isJd() && getDuccProcess().getProcessType()
+            .equals(org.apache.uima.ducc.transport.event.common.IDuccProcessType.ProcessType.Pop);
+    try {
+      // wait for stdout and stderr reader threads to finish. Join for max
+      // of 2 secs The process has exited and in theory the join should
+      // return quickly. We do the join to make sure that the streams are
+      // drained so that we can get a reason for failure if there was a
+      // problem launching the process.
+      stdOutReader.join(2000);
+      stdErrReader.join(2000);
+    } catch (InterruptedException ie) {
+      log("ManagedProcess.drainProcessStreams",
+              "Interrupted While Awaiting Termination of StdOutReader and StdErrReader Threads");
+    }
+
+    String reason = getDuccProcess().getReasonForStoppingProcess();
+
+    ProcessState pstate = getDuccProcess().getProcessState();
+    boolean initError = (reason != null
+            && (reason.equals(ReasonForStoppingProcess.FailedInitialization.toString())
+                    || reason.equals(ReasonForStoppingProcess.InitializationTimeout.toString())));
+    if (isKillCmd ||
+    // if the process is to be killed due to init problems, set the
+    // state to Stopped
+            (reason != null && initError)) {
+      // getDuccProcess().setProcessState(ProcessState.Stopped);
+      if (!initError && (exitcode - 128 == 9 || exitcode - 128 == 15)) {
+        getDuccProcess()
+                .setReasonForStoppingProcess(ReasonForStoppingProcess.KilledByDucc.toString());
+      }
+
+    } else {
+      // Process has terminated. Determine why the process terminated.
+      log("ManagedProcess.drainProcessStreams",
+              "Ducc Process with PID:" + getPid() + " Terminated while in " + pstate + " State");
+
+      // true if agent killed the process. Process either exceeded memory
+      // use or the PM state notifications stopped coming in.
+      if (doKill()) {
+        if (isAP) {
+          // Agent killed the AP process
+          pstate = ProcessState.Stopped;
+          if (exitcode - 128 == 9 || exitcode - 128 == 15) { // kill -9 or -15?
+            getDuccProcess()
+                    .setReasonForStoppingProcess(ReasonForStoppingProcess.KilledByDucc.toString());
+          }
+        } else {
+          // Agent killed the process due to timeout waiting for OR state
+          pstate = ProcessState.Killed;
+        }
+      } else {
+        if (!isstopping) {
+          // check if process exited while in Initializing state
+          if (ProcessState.Initializing.equals(pstate) || ProcessState.Starting.equals(pstate)
+                  || ProcessState.Started.equals(pstate)) {
+            getDuccProcess().setReasonForStoppingProcess(
+                    ReasonForStoppingProcess.FailedInitialization.toString());
+            log("ManagedProcess.drainProcessStreams",
+                    "Process Failed while in initializing state - setting reason to "
+                            + getDuccProcess().getReasonForStoppingProcess());
+          }
+        }
+        // default state to Stopped. If the process died unexpectadly the state
+        // will be changed to Failed
+        pstate = ProcessState.Stopped;
+        // check if the process died due to an external cause. If that
+        // was the case isstopping = false. The isstopping=true iff the Agent
+        // initiated process stop because the process was deallocated
+        if (!isstopping) {
+          // fetch errors from stderr stream. If the process failed to
+          // start due to misconfiguration
+          // the reason for failure would be provided by the OS (wrong
+          // user id, bad directory,etc)
+          String errors = stdErrReader.getDataFromStream();
+          if (errors != null && errors.trim().length() > 0) {
+            getDuccProcess().setExtendedReasonForStoppingProcess(errors.trim());
+
+            log("ManagedProcess.drainProcessStreams", "Process Failed - stderr stream:"
+                    + getDuccProcess().getReasonForStoppingProcess());
+          }
+
+          // APs can stop for any reason. There is
+          // no way to determine why the AP terminated.
+          if (!isAP) {
+            // Unexpected process termination
+            pstate = ProcessState.Failed;
+            // fetch errors from stderr stream. If the process failed to
+            // start due to misconfiguration
+            // the reason for failure would be provided by the OS (wrong
+            // user id, bad directory,etc)
+            if (errors != null && errors.trim().length() > 0) {
+              // JP should not be marked as CROAKED if it terminates
+              // due to a process error, failed initialization or initialization
+              // timeout. On such errors, a JP sends an event to its agent where
+              // the reason for failure is set
+              if (getDuccProcess().getProcessState().equals(ProcessState.Stopping)) {
+                // the reason was already set while handling JPs Stopping event
+                getDuccProcess().setProcessState(ProcessState.Stopped); // now the JP is dead
+              } else {
+                // Process terminated unexpectedly. It stopped on its own due to Ducc framework
+                // error or due to some external event not initiated by an agent
+                getDuccProcess()
+                        .setReasonForStoppingProcess(ReasonForStoppingProcess.Croaked.toString());
+              }
+
+            } else if (exitcode - 128 == 9 || exitcode - 128 == 15) {
+              // Process terminated unexpectedly. It stopped on its own due to Ducc framework
+              // error or due to some external event not initiated by an agent
+              getDuccProcess()
+                      .setReasonForStoppingProcess(ReasonForStoppingProcess.Croaked.toString());
+            }
+          }
+        } else {
+          if (exitcode - 128 == 9 || exitcode - 128 == 15) { // check if the process was killed with
+                                                             // -9 or -15
+            addReasonForStopping(getDuccProcess(),
+                    ReasonForStoppingProcess.KilledByDucc.toString());
+          } else {
+            addReasonForStopping(getDuccProcess(), ReasonForStoppingProcess.Deallocated.toString());
+          }
+        }
+        notifyProcessObserver(pstate);
+        log("ManagedProcess.drainProcessStreams",
+                "************ Remote Process PID:" + getPid() + " Terminated *************** State:"
+                        + getDuccProcess().getProcessState().toString());
+      }
+    }
+  }
+
+  private void addReasonForStopping(IDuccProcess process, String reason) {
+    if (getDuccProcess().getReasonForStoppingProcess() == null
+            || getDuccProcess().getReasonForStoppingProcess().trim().length() == 0) {
+      getDuccProcess().setReasonForStoppingProcess(reason);
+    }
+  }
+
+  /**
+   * @return the state
+   */
+  public ServiceState getStatus() {
+    return state;
+  }
+
+  /**
+   * @return the pid
+   */
+  public String getPid() {
+    return duccProcess.getPID();
+  }
+
+  /**
+   * @param pid
+   *          the pid to set
+   */
+  public void setPid(String pid) {
+    // this.pid = pid;
+    duccProcess.setPID(pid);
+    pidReadyCount.countDown();
+  }
+
+  public void awaitPid() {
+    try {
+      pidReadyCount.await();
+    } catch (Exception e) {
+    }
+  }
+
+  public void releasePidLatch() {
+    pidReadyCount.countDown();
+  }
+
+  /**
+   * @return the command
+   */
+  public List<String> getCommand() {
+    return command;
+  }
+
+  /**
+   * @param commandToRun
+   *          the command as List
+   */
+  public void setCommand(List<String> commandToRun) {
+    this.command = commandToRun;
+  }
+
+  /**
+   * @return the processCorrelationId
+   */
+  public String getProcessId() {
+    return processCorrelationId;
+  }
+
+  /**
+   * @param processId
+   *          the processId to set
+   */
+  public void setProcessId(String processId) {
+    this.processCorrelationId = processId;
+  }
+
+  /**
+   * @return the jmxPort
+   */
+  public String getPort() {
+    return port;
+  }
+
+  /**
+   * @param port
+   *          the jmxPort to set
+   */
+  public void setPort(String port) {
+    this.port = port;
+  }
+
+  public void terminateRemoteProcess() throws Exception {
+    System.out.println("Stopping Remote Managed Process via JMX");
+    // Using JMX instruct the service to terminate
+    // if ( processMBean != null ) {
+    // processMBean.getManagedServiceMBean().terminate();
+    // }
+  }
+
+  public void failed() {
+    // setStatus(ServiceState.FAILED);
+    cleanup();
+    // managedProcessInfo.setState(state);
+    // if ( getEndDate() == null ) {
+    // setEndDate(new DateTime());
+    // }
+  }
+
+  private void cleanup() {
+    if (process != null) {
+      process.destroy();
+    }
+    destroyed = true;
+
+  }
+
+  public void stop() {
+    // if ( getStatus() != ServiceState.FAILED ) {
+    // setStatus(ServiceState.STOPPED);
+    // }
+    cleanup();
+    // if ( getEndDate() == null ) {
+    // setEndDate(new DateTime());
+    // }
+    // if ( process != null ) {
+    // process.destroy();
+    // }
+    // destroyed = true;
+  }
+
+  public void waitFor() throws InterruptedException {
+    process.waitFor();
+  }
+
+  public boolean isDestroyed() {
+    return destroyed;
+  }
+
+  public String getAbsoluteLogPath() {
+    return absoluteLogPath;
+  }
+
+  public void setAbsoluteLogPath(String absoluteLogPath) {
+    this.absoluteLogPath = absoluteLogPath;
+  }
+
+  public String getDescription() {
+    return description;
+  }
+
+  public void setDescription(String description) {
+    this.description = description;
+  }
+
+  public Throwable getExceptionStackTrace() {
+    return exceptionStackTrace;
+  }
+
+  public void setExceptionStackTrace(Throwable exceptionStackTrace) {
+    this.exceptionStackTrace = exceptionStackTrace;
+  }
+
+  /**
+   * @return the processSpecification
+   */
+  public ICommandLine getCommandLine() {
+    return commandLine;
+  }
+
+  /**
+   * @return the duccProcess
+   */
+  public IDuccProcess getDuccProcess() {
+    return duccProcess;
+  }
+
+  public void notifyProcessObserver(ProcessState state) {
+    if (observer != null && getDuccProcess() != null) {
+      if (ProcessState.InitializationTimeout.equals(state)) {
+        observer.onJPInitTimeout(getDuccProcess(), initializationTimeout);
+      } else {
+        getDuccProcess().setProcessState(state);
+        // observer.onProcessExit(getDuccProcess());
+      }
+    }
+  }
+
+  public void startInitializationTimer(long timeout) {
+    initTimer = new Timer();
+    // long timeout = 7200*1000; // default timeout after 2 hours of
+    // initialization
+    try {
+      if (timeout == 0) {
+        String str_timeout;
+        if ((str_timeout = System
+                .getProperty(DuccPropertiesResolver.ducc_default_process_init_time_max)) != null) {
+          timeout = Long.parseLong(str_timeout) * 60 * 1000; // Minutes -> milliseconds
+        } else {
+          // max init timeout default=4hours
+          timeout = 3600 * 4 * 1000;
+        }
+      }
+    } catch (NumberFormatException e) {
+
+    }
+    // timeout after 2 hours of initialization
+    initTimer.schedule(new InitializationTask(), timeout);
+    initializationTimeout = timeout; // Save just for the timeout message
+  }
+
+  /**
+   * Stops service initialization timer and starts a new timer that will cleanup UIMA pipeline
+   * initialization stats. These states are only needed during the initialization of a service.
+   */
+  public void stopInitializationTimer() {
+    if (initTimer != null) {
+      initTimer.cancel();
+      long timeout = 60000; // default timeout after 60 seconds
+      if (getDuccProcess().getUimaPipelineComponents() != null
+              && getDuccProcess().getUimaPipelineComponents().size() > 0) {
+        cleanupTimer = new Timer();
+        try {
+          String inv_publish_rate;
+          if ((inv_publish_rate = System
+                  .getProperty("ducc.agent.node.inventory.publish.rate")) != null) {
+            // allow sufficient time to publish init stats
+            timeout = Long.parseLong(inv_publish_rate) * 4;
+          }
+        } catch (NumberFormatException e) {
+        }
+        // timeout and remove UIMA pipeline stats
+        cleanupTimer.schedule(new CleanupTask(), timeout);
+      }
+    }
+  }
+
+  private class InitializationTask extends TimerTask {
+    public void run() {
+      initTimer.cancel();
+      notifyProcessObserver(ProcessState.InitializationTimeout);
+    }
+  }
+
+  private class CleanupTask extends TimerTask {
+    public void run() {
+      cleanupTimer.cancel();
+      ((DuccProcess) getDuccProcess()).setUimaPipelineComponents(null);
+    }
+  }
+
+  public IDuccStandardInfo getProcessInfo() {
+    return processInfo;
+  }
+
+  public void setProcessInfo(IDuccStandardInfo processInfo) {
+    this.processInfo = processInfo;
+  }
+
+  public boolean killAfterLaunch() {
+    return killAfterLaunch;
+  }
+
+  public void killAfterLaunch(boolean killAfterLaunch) {
+    this.killAfterLaunch = killAfterLaunch;
+  }
+
+  public Future<?> getFuture() {
+    return future;
+  }
+
+  public void setFuture(Future<?> future) {
+    this.future = future;
+  }
+
+  public ProcessMemoryAssignment getProcessMemoryAssignment() {
+    return processMemoryAssignment;
+  }
+
+  public String getSocketEndpoint() {
+    return socketEndpoint;
+  }
+
+  public void setSocketEndpoint(String socketEndpoint) {
+    this.socketEndpoint = socketEndpoint;
+  }
+
+  public long getMaxSwapThreshold() {
+    return maxSwapThreshold;
+  }
+
+  public void setMaxSwapThreshold(long maxSwapThreshold) {
+    this.maxSwapThreshold = maxSwapThreshold;
+  }
+
+  public void setIsJD() {
+    isJD = true;
+  }
+
+  public boolean isJd() {
+    return isJD;
+  }
+
+  public void setUimaAs() {
+    isUimaAs = true;
+  }
+
+  public boolean isUimaAs() {
+    return isUimaAs;
+  }
 }

Modified: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedServiceInfo.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedServiceInfo.java?rev=1864247&r1=1864246&r2=1864247&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedServiceInfo.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedServiceInfo.java Fri Aug  2 17:27:48 2019
@@ -21,39 +21,50 @@ package org.apache.uima.ducc.agent.launc
 import java.io.Serializable;
 
 public class ManagedServiceInfo implements Serializable {
-	public enum ServiceState { STARTING, INITIALIZING, READY, FAILED, STOPPING, STOPPED, KILLED };
+  public enum ServiceState {
+    STARTING, INITIALIZING, READY, FAILED, STOPPING, STOPPED, KILLED
+  };
 
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = 1L;
-	private String pid;
-	private ServiceState state;
-	/**
-	 * @return the state
-	 */
-	public ServiceState getState() {
-		return state;
-	}
-	/**
-	 * @param state the state to set
-	 */
-	public void setState(ServiceState state) {
-		this.state = state;
-	}
-	/**
-	 * @return the pid
-	 */
-	public String getPid() {
-		return pid;
-	}
-	/**
-	 * @param pid the pid to set
-	 */
-	public void setPid(String pid) {
-		this.pid = pid;
-	}
-	public String toString() {
-		return "PID:"+getPid()+" State:"+getState();
-	}
+  /**
+   * 
+   */
+  private static final long serialVersionUID = 1L;
+
+  private String pid;
+
+  private ServiceState state;
+
+  /**
+   * @return the state
+   */
+  public ServiceState getState() {
+    return state;
+  }
+
+  /**
+   * @param state
+   *          the state to set
+   */
+  public void setState(ServiceState state) {
+    this.state = state;
+  }
+
+  /**
+   * @return the pid
+   */
+  public String getPid() {
+    return pid;
+  }
+
+  /**
+   * @param pid
+   *          the pid to set
+   */
+  public void setPid(String pid) {
+    this.pid = pid;
+  }
+
+  public String toString() {
+    return "PID:" + getPid() + " State:" + getState();
+  }
 }

Modified: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/Process.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/Process.java?rev=1864247&r1=1864246&r2=1864247&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/Process.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/Process.java Fri Aug  2 17:27:48 2019
@@ -23,37 +23,63 @@ import java.io.Serializable;
 import java.util.List;
 
 public interface Process extends Serializable {
-	public String getLogPath();
-	public void setLogPath(String logPath);
-	public String getPid();
-	public void setPid(String pid);
-	public List<String> getCommand();
-	public String getProcessId();
-	public void setProcessId(String processId);
-	public String getPort();
-	public void setPort(String port);
-	public String getNodeIp();
-	public void setNodeIp( String nodeIp);
-	public boolean isAgentProcess();
-//	public void setOSProcess(java.lang.Process target );
-	public void setLogStream(OutputStream ps);
-	public String getNodeName();
-	public void setNodeName(String nodeName);
-	public void setAgentLogPath(String logPath);
-	public String getAgentLogPath();
-	public boolean isAttached();
-	public void setAttached();
-    public void setClientId(String clientId);
-    public String getClientId();
+  public String getLogPath();
+
+  public void setLogPath(String logPath);
+
+  public String getPid();
+
+  public void setPid(String pid);
+
+  public List<String> getCommand();
+
+  public String getProcessId();
+
+  public void setProcessId(String processId);
+
+  public String getPort();
+
+  public void setPort(String port);
+
+  public String getNodeIp();
+
+  public void setNodeIp(String nodeIp);
+
+  public boolean isAgentProcess();
+
+  // public void setOSProcess(java.lang.Process target );
+  public void setLogStream(OutputStream ps);
+
+  public String getNodeName();
+
+  public void setNodeName(String nodeName);
+
+  public void setAgentLogPath(String logPath);
+
+  public String getAgentLogPath();
+
+  public boolean isAttached();
+
+  public void setAttached();
+
+  public void setClientId(String clientId);
+
+  public String getClientId();
+
   public String getAbsoluteLogPath();
+
   public void setAbsoluteLogPath(String absoluteLogPath);
-	public String getDescription();
-	public void setDescription(String description);
-	
-	public void setParent( String parent);
-	public String getParent();
+
+  public String getDescription();
+
+  public void setDescription(String description);
+
+  public void setParent(String parent);
+
+  public String getParent();
+
   public Throwable getExceptionStackTrace();
+
   public void setExceptionStackTrace(Throwable exceptionStackTrace);
-  
 
 }

Modified: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ProcessStreamConsumer.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ProcessStreamConsumer.java?rev=1864247&r1=1864246&r2=1864247&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ProcessStreamConsumer.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ProcessStreamConsumer.java Fri Aug  2 17:27:48 2019
@@ -27,70 +27,76 @@ import java.io.PrintStream;
 import org.apache.uima.ducc.common.utils.DuccLogger;
 import org.apache.uima.ducc.common.utils.id.DuccId;
 
-
 public class ProcessStreamConsumer extends Thread {
-	public static final String LS = System.getProperty("line.separator");
+  public static final String LS = System.getProperty("line.separator");
+
+  private InputStream is;
+
+  private PrintStream os;
+
+  DuccLogger logger;
+
+  private DuccId workDuccId;
+
+  private StringBuffer errStreamBuffer = new StringBuffer();
+
+  public ProcessStreamConsumer(DuccLogger logger, ThreadGroup threadGroup, final String threadName,
+          InputStream is, PrintStream os, DuccId workDuccId) {
+    super(threadGroup, threadName);
+    this.os = os;
+    this.is = is;
+    this.logger = logger;
+    setDaemon(true);
+    this.workDuccId = workDuccId;
+  }
 
-	private InputStream is;
-	private PrintStream os;
-	DuccLogger logger;
-	private DuccId workDuccId;
-	
-	private StringBuffer errStreamBuffer = new StringBuffer();
-	public ProcessStreamConsumer(DuccLogger logger, ThreadGroup threadGroup,
-				final String threadName, InputStream is, PrintStream os, DuccId workDuccId) {
-		super(threadGroup, threadName);
-		this.os = os;
-		this.is = is;
-		this.logger = logger;
-		setDaemon(true);
-		this.workDuccId = workDuccId;
-	}
   public String getDataFromStream() {
     return errStreamBuffer.toString();
   }
-	public void run() {
-		try {
 
-			InputStreamReader in = new InputStreamReader(is);
-			BufferedReader reader = new BufferedReader(in);
-			String line;
-			while ((line = reader.readLine()) != null) {
-				line += LS;
-				if ( "StdErrorReader".equals(Thread.currentThread().getName())) {
-					logger.error("ProcessStreamConsumer.run()", workDuccId, line.trim());
-					os.print("ERR>>>"+line);
-					// Save stderr stream into a local buffer. When the process exits unexpectedly
-					// errors will be copied to a Process object.
-					errStreamBuffer.append(line.trim());  
-				} else {
-					logger.info("ProcessStreamConsumer.run()", workDuccId, line.trim());
-					os.print("OUT>>>"+line);
-				}
-				// Check if duccling redirected its output streams to a log. If so, it would put
-				// out a marker that starts with "1200 Redirecting stdout". This is a clue to
-				// stop consuming from the process streams. Just close streams and
-				// return.
-				if (line.trim().startsWith("1200 Redirecting stdout")) {
-					break;
-				}
-			}
-		} catch (Exception x) {
-		} finally {
-			try {
-				os.flush();
-			} catch (Exception e) {
-				System.out.println("Caught Exception While Flushing "
-						+ Thread.currentThread().getName() + " Output Stream");
-			}
-			try {
-				if (is != null) {
-					is.close();
-				}
-				logger.debug("ProcessStreamConsumer.run()", workDuccId, "Stream Consumer Thread Terminated - Process Streams Redirected to a Log");
-			} catch (IOException e) {
-				// ignore
-			}
-		}
-	}
+  public void run() {
+    try {
+
+      InputStreamReader in = new InputStreamReader(is);
+      BufferedReader reader = new BufferedReader(in);
+      String line;
+      while ((line = reader.readLine()) != null) {
+        line += LS;
+        if ("StdErrorReader".equals(Thread.currentThread().getName())) {
+          logger.error("ProcessStreamConsumer.run()", workDuccId, line.trim());
+          os.print("ERR>>>" + line);
+          // Save stderr stream into a local buffer. When the process exits unexpectedly
+          // errors will be copied to a Process object.
+          errStreamBuffer.append(line.trim());
+        } else {
+          logger.info("ProcessStreamConsumer.run()", workDuccId, line.trim());
+          os.print("OUT>>>" + line);
+        }
+        // Check if duccling redirected its output streams to a log. If so, it would put
+        // out a marker that starts with "1200 Redirecting stdout". This is a clue to
+        // stop consuming from the process streams. Just close streams and
+        // return.
+        if (line.trim().startsWith("1200 Redirecting stdout")) {
+          break;
+        }
+      }
+    } catch (Exception x) {
+    } finally {
+      try {
+        os.flush();
+      } catch (Exception e) {
+        System.out.println("Caught Exception While Flushing " + Thread.currentThread().getName()
+                + " Output Stream");
+      }
+      try {
+        if (is != null) {
+          is.close();
+        }
+        logger.debug("ProcessStreamConsumer.run()", workDuccId,
+                "Stream Consumer Thread Terminated - Process Streams Redirected to a Log");
+      } catch (IOException e) {
+        // ignore
+      }
+    }
+  }
 }

Modified: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/SigKillCommand.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/SigKillCommand.java?rev=1864247&r1=1864246&r2=1864247&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/SigKillCommand.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/SigKillCommand.java Fri Aug  2 17:27:48 2019
@@ -23,51 +23,49 @@ import org.apache.uima.ducc.transport.cm
 import org.apache.uima.ducc.transport.cmdline.NonJavaCommandLine;
 
 public class SigKillCommand implements ICommand {
-	private static final String SIGKILL="-9";
-	private String[] sigKillCmdLine;
-	private final DuccLogger logger;
-	private final ManagedProcess deployProcess;
-	
-	public SigKillCommand(ManagedProcess managedProcess, DuccLogger logger) {
-	    ICommandLine cmdL = new NonJavaCommandLine("/bin/kill");
-	    this.logger = logger;
-	    this.deployProcess = managedProcess;
-		cmdL.addArgument(SIGKILL);
-	    cmdL.addArgument(managedProcess.getPid());
-	    sigKillCmdLine = 
-	    		CommandBuilder.deployableStopCommand(cmdL,managedProcess);
-	}
-
-	@Override
-	public Integer call() {
-		String methodName = "SigKillCommand.call";
-		ProcessBuilder processBuilder = 
-				new ProcessBuilder(sigKillCmdLine);
-		try {
-			StringBuilder sb = new StringBuilder("--->Killing Process ");
-			sb.append(" Using command line:");
-			int inx = 0;
-			for (String cmdPart : sigKillCmdLine) {
-				sb.append("\n\t[")
-						.append(inx++)
-						.append("]")
-						.append(cmdPart);
-				// Not sure why place-holders are replaced just for this msg?
-			}
-			logger.info(methodName,	deployProcess.getDuccId(), sb.toString());
-
-			java.lang.Process process = processBuilder.start();
-			// Drain process streams in dedicated threads.
-			
-			deployProcess.drainProcessStreams(process, logger, System.out, true);
-			// wait for the kill command to complete
-			return process.waitFor();
-			
-		} catch( Exception  e) {
-			// Log this
-			logger.warn(methodName, null, e);
-		}
-		return -1;
-	}
+  private static final String SIGKILL = "-9";
+
+  private String[] sigKillCmdLine;
+
+  private final DuccLogger logger;
+
+  private final ManagedProcess deployProcess;
+
+  public SigKillCommand(ManagedProcess managedProcess, DuccLogger logger) {
+    ICommandLine cmdL = new NonJavaCommandLine("/bin/kill");
+    this.logger = logger;
+    this.deployProcess = managedProcess;
+    cmdL.addArgument(SIGKILL);
+    cmdL.addArgument(managedProcess.getPid());
+    sigKillCmdLine = CommandBuilder.deployableStopCommand(cmdL, managedProcess);
+  }
+
+  @Override
+  public Integer call() {
+    String methodName = "SigKillCommand.call";
+    ProcessBuilder processBuilder = new ProcessBuilder(sigKillCmdLine);
+    try {
+      StringBuilder sb = new StringBuilder("--->Killing Process ");
+      sb.append(" Using command line:");
+      int inx = 0;
+      for (String cmdPart : sigKillCmdLine) {
+        sb.append("\n\t[").append(inx++).append("]").append(cmdPart);
+        // Not sure why place-holders are replaced just for this msg?
+      }
+      logger.info(methodName, deployProcess.getDuccId(), sb.toString());
+
+      java.lang.Process process = processBuilder.start();
+      // Drain process streams in dedicated threads.
+
+      deployProcess.drainProcessStreams(process, logger, System.out, true);
+      // wait for the kill command to complete
+      return process.waitFor();
+
+    } catch (Exception e) {
+      // Log this
+      logger.warn(methodName, null, e);
+    }
+    return -1;
+  }
 
 }

Modified: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/SigTermCommand.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/SigTermCommand.java?rev=1864247&r1=1864246&r2=1864247&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/SigTermCommand.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/SigTermCommand.java Fri Aug  2 17:27:48 2019
@@ -23,51 +23,48 @@ import org.apache.uima.ducc.transport.cm
 import org.apache.uima.ducc.transport.cmdline.NonJavaCommandLine;
 
 public class SigTermCommand implements ICommand {
-	private static final String SIGTERM="-15";
-	private final String[] sigTermCmdLine;
-	private final DuccLogger logger;
-	private final ManagedProcess deployProcess;
-	
-	public SigTermCommand(ManagedProcess managedProcess, DuccLogger logger) {
-	    ICommandLine cmdL = new NonJavaCommandLine("/bin/kill");
-	    this.logger = logger;
-	    this.deployProcess = managedProcess;
-		cmdL.addArgument(SIGTERM);
-	    cmdL.addArgument(deployProcess.getPid());
-	    sigTermCmdLine = 
-	    		CommandBuilder.deployableStopCommand(cmdL,managedProcess);
-	}
-
-	@Override
-	public Integer call() {
-		String methodName = "SigTermCommand.call";
-		ProcessBuilder processBuilder = 
-				new ProcessBuilder(sigTermCmdLine);
-		try {
-			StringBuilder sb = new StringBuilder("--->Killing Process ");
-			sb.append(" Using command line:");
-			int inx = 0;
-			for (String cmdPart : sigTermCmdLine) {
-				sb.append("\n\t[")
-						.append(inx++)
-						.append("]")
-						.append(cmdPart);
-				// Not sure why place-holders are replaced just for this msg?
-			}
-			logger.info(methodName,	deployProcess.getDuccId(), sb.toString());
-			
-			java.lang.Process process = 
-					processBuilder.start();
-		    // Drain process streams in dedicated threads.
-			deployProcess.drainProcessStreams(process, logger, System.out, true);
-			// wait for the kill command to complete
-			return process.waitFor();
-			
-		} catch( Exception  e) {
-			// Log this
-			logger.warn(methodName, null, e);
-		}
-		return -1;
-	}
+  private static final String SIGTERM = "-15";
+
+  private final String[] sigTermCmdLine;
+
+  private final DuccLogger logger;
+
+  private final ManagedProcess deployProcess;
+
+  public SigTermCommand(ManagedProcess managedProcess, DuccLogger logger) {
+    ICommandLine cmdL = new NonJavaCommandLine("/bin/kill");
+    this.logger = logger;
+    this.deployProcess = managedProcess;
+    cmdL.addArgument(SIGTERM);
+    cmdL.addArgument(deployProcess.getPid());
+    sigTermCmdLine = CommandBuilder.deployableStopCommand(cmdL, managedProcess);
+  }
+
+  @Override
+  public Integer call() {
+    String methodName = "SigTermCommand.call";
+    ProcessBuilder processBuilder = new ProcessBuilder(sigTermCmdLine);
+    try {
+      StringBuilder sb = new StringBuilder("--->Killing Process ");
+      sb.append(" Using command line:");
+      int inx = 0;
+      for (String cmdPart : sigTermCmdLine) {
+        sb.append("\n\t[").append(inx++).append("]").append(cmdPart);
+        // Not sure why place-holders are replaced just for this msg?
+      }
+      logger.info(methodName, deployProcess.getDuccId(), sb.toString());
+
+      java.lang.Process process = processBuilder.start();
+      // Drain process streams in dedicated threads.
+      deployProcess.drainProcessStreams(process, logger, System.out, true);
+      // wait for the kill command to complete
+      return process.waitFor();
+
+    } catch (Exception e) {
+      // Log this
+      logger.warn(methodName, null, e);
+    }
+    return -1;
+  }
 
 }

Modified: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/AbstractMetricCollector.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/AbstractMetricCollector.java?rev=1864247&r1=1864246&r2=1864247&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/AbstractMetricCollector.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/AbstractMetricCollector.java Fri Aug  2 17:27:48 2019
@@ -23,13 +23,20 @@ import java.io.RandomAccessFile;
 
 public abstract class AbstractMetricCollector implements MetricCollector {
   private int howManyFields;
+
   protected int[] metricFieldOffsets;
+
   protected int[] metricFieldLengths;
+
   protected byte[] metricFileContents = new byte[1024];
+
   protected RandomAccessFile metricFile;
+
   private int mField;
+
   private int fieldOffset;
-  private int currentOffset=0;
+
+  private int currentOffset = 0;
 
   public AbstractMetricCollector(RandomAccessFile metricFile, int howMany, int offset) {
     this.howManyFields = howMany;
@@ -38,22 +45,24 @@ public abstract class AbstractMetricColl
     metricFieldOffsets = new int[howMany];
     metricFieldLengths = new int[howMany];
   }
+
   public void parseMetricFile() throws IOException {
     metricFile.seek(0);
     metricFile.read(metricFileContents);
-    if ( fieldOffset > 0 ) {
-      //  Advance the pointer just beyond the field name
+    if (fieldOffset > 0) {
+      // Advance the pointer just beyond the field name
       while (metricFileContents[currentOffset] != ' ') {
         ++currentOffset;
       }
     }
-    int currentFieldIndx=0;
-    while( currentFieldIndx++ < howManyFields ) {
+    int currentFieldIndx = 0;
+    while (currentFieldIndx++ < howManyFields) {
       readNextField();
     }
   }
+
   private void readNextField() {
- // Skip column padding.
+    // Skip column padding.
     while (metricFileContents[currentOffset] == ' ') {
       ++currentOffset;
     }

Modified: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/CallableMemoryCollector.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/CallableMemoryCollector.java?rev=1864247&r1=1864246&r2=1864247&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/CallableMemoryCollector.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/CallableMemoryCollector.java Fri Aug  2 17:27:48 2019
@@ -22,7 +22,6 @@ import java.util.concurrent.Callable;
 
 import org.apache.uima.ducc.common.agent.metrics.memory.NodeMemory;
 
-
-public interface CallableMemoryCollector extends Callable<NodeMemory>{
+public interface CallableMemoryCollector extends Callable<NodeMemory> {
 
 }

Modified: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/CallableNodeUsersCollector.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/CallableNodeUsersCollector.java?rev=1864247&r1=1864246&r2=1864247&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/CallableNodeUsersCollector.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/CallableNodeUsersCollector.java Fri Aug  2 17:27:48 2019
@@ -23,6 +23,6 @@ import java.util.concurrent.Callable;
 
 import org.apache.uima.ducc.common.node.metrics.NodeUsersInfo;
 
-public interface CallableNodeUsersCollector extends Callable<TreeMap<String,NodeUsersInfo>>{
+public interface CallableNodeUsersCollector extends Callable<TreeMap<String, NodeUsersInfo>> {
 
 }

Modified: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/DefaultNodeLoadAverageCollector.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/DefaultNodeLoadAverageCollector.java?rev=1864247&r1=1864246&r2=1864247&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/DefaultNodeLoadAverageCollector.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/DefaultNodeLoadAverageCollector.java Fri Aug  2 17:27:48 2019
@@ -24,20 +24,18 @@ import java.util.concurrent.Callable;
 import org.apache.uima.ducc.common.node.metrics.DefaultNodeLoadAverageInfo;
 import org.apache.uima.ducc.common.node.metrics.NodeLoadAverage;
 
+public class DefaultNodeLoadAverageCollector implements Callable<NodeLoadAverage>, Serializable {
 
-public class DefaultNodeLoadAverageCollector  
-    implements Callable<NodeLoadAverage>, Serializable {
-  
-    /**
-	 * 
-	 */
-	private static final long serialVersionUID = 1L;
-	
-    public DefaultNodeLoadAverageCollector() {
-    }
-    public NodeLoadAverage call() throws Exception {
-        return new DefaultNodeLoadAverageInfo(new double[] {0.0,0.0,0.0});
-    }
+  /**
+  * 
+  */
+  private static final long serialVersionUID = 1L;
 
+  public DefaultNodeLoadAverageCollector() {
+  }
+
+  public NodeLoadAverage call() throws Exception {
+    return new DefaultNodeLoadAverageInfo(new double[] { 0.0, 0.0, 0.0 });
+  }
 
 }

Modified: uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/DefaultNodeMemoryCollector.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/DefaultNodeMemoryCollector.java?rev=1864247&r1=1864246&r2=1864247&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/DefaultNodeMemoryCollector.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/DefaultNodeMemoryCollector.java Fri Aug  2 17:27:48 2019
@@ -29,82 +29,85 @@ import java.util.concurrent.Future;
 import org.apache.uima.ducc.common.agent.metrics.memory.DuccNodeMemory;
 import org.apache.uima.ducc.common.agent.metrics.memory.NodeMemory;
 
+public class DefaultNodeMemoryCollector implements CallableMemoryCollector {
+  // private static final String TOTAL_MEMORY_SIZE="getTotalPhysicalMemorySize";
+  private static final String FREE_PHYSICAL_MEMORY_SIZE = "getFreePhysicalMemorySize";
 
-public class DefaultNodeMemoryCollector implements CallableMemoryCollector{
-	//private static final String TOTAL_MEMORY_SIZE="getTotalPhysicalMemorySize";
-	private static final String FREE_PHYSICAL_MEMORY_SIZE="getFreePhysicalMemorySize";
-	private static final String FREE_SWAP_MEMORY_SIZE="getFreeSwapSpaceSize";
-	private static final String TOTAL_SWAP_SPACE_SIZE="getTotalSwapSpaceSize";
-	private long fakeMemorySize = -1;
-
-	public DefaultNodeMemoryCollector() {
-		String tmp;
-		if ((tmp = System
-				.getProperty("ducc.agent.node.metrics.fake.memory.size")) != null) {
-			try {
-				fakeMemorySize = Long.parseLong(tmp);
-			} catch (NumberFormatException e) {
-				e.printStackTrace();
-			}
-		}
-	}
-	  public NodeMemory call() throws Exception {
-		    return collect();
-	  }
-	  private void setMetric(String metricName, long metricValue, DuccNodeMemory nodeMemory) {
-		  try {
-              if ( fakeMemorySize != -1 ) {
-                  nodeMemory.setMemTotal(fakeMemorySize);
-              } else {
-                  nodeMemory.setMemTotal(Runtime.getRuntime().totalMemory());
-              }
-		  } catch( Exception e) {
-			  e.printStackTrace();
-		  }
-		  if ( metricName.equalsIgnoreCase(FREE_PHYSICAL_MEMORY_SIZE)) {
-              if ( fakeMemorySize != -1 ) {               // UIMA-4114
-                  nodeMemory.setMemFree(fakeMemorySize);
-              } else {
-                  nodeMemory.setMemFree(metricValue);
-              }
-		  } else if ( metricName.equalsIgnoreCase(FREE_SWAP_MEMORY_SIZE)) {
-			  nodeMemory.setSwapFree(metricValue);
-		  } else if ( metricName.equalsIgnoreCase(TOTAL_SWAP_SPACE_SIZE)) {
-			  nodeMemory.setSwapTotal(metricValue);
-		  } 
-	  }
-	  private DuccNodeMemory collect() {
-		  DuccNodeMemory nodeMemory = new DuccNodeMemory();
-		  OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
-		  for (Method method : operatingSystemMXBean.getClass().getDeclaredMethods()) {
-		    method.setAccessible(true);
-		    if (method.getName().startsWith("get") 
-		        && Modifier.isPublic(method.getModifiers())) {
-		            Long value;
-		        try {
-		            value = (Long)method.invoke(operatingSystemMXBean);
-		        } catch (Exception e) {
-		            value = 0L;
-		        } // try
-		        setMetric(method.getName(), value, nodeMemory);
-		    } // if
-		  } // for
-		  return nodeMemory;
-		}
-
-	  public static void main(String[] args) {
-		  try {
-			  DefaultNodeMemoryCollector collector = new DefaultNodeMemoryCollector();
-			  ExecutorService pool = Executors.newFixedThreadPool(1);
-		      Future<NodeMemory> nmiFuture = pool.submit(collector);
-		      NodeMemory nodeMemory = nmiFuture.get();
-		      System.out.println("Total Memory:"+nodeMemory.getMemTotal());
-		      System.out.println("Total Free Memory:"+nodeMemory.getMemFree());
-		      System.out.println("Total Swap Space Size:"+nodeMemory.getSwapTotal());
-		      System.out.println("Total Free Swap Space Size:"+nodeMemory.getSwapFree());
-		      
-		  } catch( Exception e) {
-			  e.printStackTrace();
-		  }
-	  }
+  private static final String FREE_SWAP_MEMORY_SIZE = "getFreeSwapSpaceSize";
+
+  private static final String TOTAL_SWAP_SPACE_SIZE = "getTotalSwapSpaceSize";
+
+  private long fakeMemorySize = -1;
+
+  public DefaultNodeMemoryCollector() {
+    String tmp;
+    if ((tmp = System.getProperty("ducc.agent.node.metrics.fake.memory.size")) != null) {
+      try {
+        fakeMemorySize = Long.parseLong(tmp);
+      } catch (NumberFormatException e) {
+        e.printStackTrace();
+      }
+    }
+  }
+
+  public NodeMemory call() throws Exception {
+    return collect();
+  }
+
+  private void setMetric(String metricName, long metricValue, DuccNodeMemory nodeMemory) {
+    try {
+      if (fakeMemorySize != -1) {
+        nodeMemory.setMemTotal(fakeMemorySize);
+      } else {
+        nodeMemory.setMemTotal(Runtime.getRuntime().totalMemory());
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+    if (metricName.equalsIgnoreCase(FREE_PHYSICAL_MEMORY_SIZE)) {
+      if (fakeMemorySize != -1) { // UIMA-4114
+        nodeMemory.setMemFree(fakeMemorySize);
+      } else {
+        nodeMemory.setMemFree(metricValue);
+      }
+    } else if (metricName.equalsIgnoreCase(FREE_SWAP_MEMORY_SIZE)) {
+      nodeMemory.setSwapFree(metricValue);
+    } else if (metricName.equalsIgnoreCase(TOTAL_SWAP_SPACE_SIZE)) {
+      nodeMemory.setSwapTotal(metricValue);
+    }
+  }
+
+  private DuccNodeMemory collect() {
+    DuccNodeMemory nodeMemory = new DuccNodeMemory();
+    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
+    for (Method method : operatingSystemMXBean.getClass().getDeclaredMethods()) {
+      method.setAccessible(true);
+      if (method.getName().startsWith("get") && Modifier.isPublic(method.getModifiers())) {
+        Long value;
+        try {
+          value = (Long) method.invoke(operatingSystemMXBean);
+        } catch (Exception e) {
+          value = 0L;
+        } // try
+        setMetric(method.getName(), value, nodeMemory);
+      } // if
+    } // for
+    return nodeMemory;
+  }
+
+  public static void main(String[] args) {
+    try {
+      DefaultNodeMemoryCollector collector = new DefaultNodeMemoryCollector();
+      ExecutorService pool = Executors.newFixedThreadPool(1);
+      Future<NodeMemory> nmiFuture = pool.submit(collector);
+      NodeMemory nodeMemory = nmiFuture.get();
+      System.out.println("Total Memory:" + nodeMemory.getMemTotal());
+      System.out.println("Total Free Memory:" + nodeMemory.getMemFree());
+      System.out.println("Total Swap Space Size:" + nodeMemory.getSwapTotal());
+      System.out.println("Total Free Swap Space Size:" + nodeMemory.getSwapFree());
+
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
 }