[maven-release-plugin]  copy for tag uima-ducc-2.2.1

git-svn-id: https://svn.apache.org/repos/asf/uima/uima-ducc/tags/uima-ducc-2.2.1@1805665 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml
index 0888c1d..182ffe9 100644
--- a/src/main/resources/log4j.xml
+++ b/src/main/resources/log4j.xml
@@ -189,12 +189,12 @@
    </category>
 
    <category name="org.apache.uima.ducc.agent" additivity="false">
-     <priority value="debug"/>
+     <priority value="info"/>
      <appender-ref ref="agentlog" />
    </category>
 
    <category name="org.apache.uima.ducc.agent.deploy" additivity="false">
-     <priority value="off"/>
+     <priority value="info"/>
      <appender-ref ref="agentlog" />
    </category>
 
diff --git a/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/DuccGarbageStatsCollector.java b/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/DuccGarbageStatsCollector.java
index 7bb616b..5cbbd64 100644
--- a/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/DuccGarbageStatsCollector.java
+++ b/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/metrics/collectors/DuccGarbageStatsCollector.java
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
-*/
+ */
 package org.apache.uima.ducc.agent.metrics.collectors;
 
 import java.util.Set;
@@ -31,57 +31,114 @@
 import org.apache.uima.ducc.common.utils.DuccLogger;
 import org.apache.uima.ducc.transport.event.common.IDuccProcess;
 
-
 public class DuccGarbageStatsCollector {
-  MBeanServerConnection connection = null;
-  DuccLogger logger=null;
-  IDuccProcess process=null;
-	public DuccGarbageStatsCollector(DuccLogger logger,IDuccProcess process)  {
-	  this.logger = logger;
-	  this.process = process;
-	  try {
-		  if (process != null && process.getProcessJmxUrl() != null && process.getProcessJmxUrl().trim().length() > 0 ) {
-			    connection = getServerConnection();
-		  }
-	  } catch( Exception e) {
-		  logger.error("DuccGarbageStatsCollector.ctor", null,e);
-		  logger.error("DuccGarbageStatsCollector.ctor", null, "Failed to Connect via JMX to PID:"+process.getPID()+" Reason:\n"+e);
-	  }
-	  
-	}
-  private MBeanServerConnection getServerConnection() throws Exception {
-    System.out.println("Connecting Monitor To Broker - URL:"+process.getProcessJmxUrl());
-    JMXServiceURL url = new JMXServiceURL(process.getProcessJmxUrl());
-    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
-    return jmxc.getMBeanServerConnection();
-  }
-	public ProcessGarbageCollectionStats collect() {
-		ProcessGarbageCollectionStats gcStats =
-	            new ProcessGarbageCollectionStats();
-    if ( connection != null) {
-		  
-		  try {
-		    Set<ObjectInstance> mbeans= 
-		            connection.queryMBeans(new ObjectName("java.lang:type=GarbageCollector,*"),null );
-		    Long totalCollectionCount= new Long(0);
-		    Long totalCollectionTime=new Long(0);
-		    
-		    for( ObjectInstance gcObject : mbeans) {
-		      String gcCollectorName = gcObject.getObjectName().getCanonicalKeyPropertyListString();
-		      ObjectName memoryManagerMXBean = 
-		              new ObjectName("java.lang:" + gcCollectorName);
-		      totalCollectionCount += (Long) connection.getAttribute(memoryManagerMXBean,"CollectionCount");
-		      totalCollectionTime += (Long) connection.getAttribute(memoryManagerMXBean,"CollectionTime");
-		    }
-	      // Returns the total number of collections that have occurred.
-	      gcStats.setCollectionCount(totalCollectionCount);
-	      // Returns the approximate accumulated collection elapsed time in milliseconds.
-	      gcStats.setCollectionTime(totalCollectionTime);
+	MBeanServerConnection connection = null;
+	DuccLogger logger = null;
+	IDuccProcess process = null;
+	JmxUrl jmxUrl = null;
+	private boolean reportJmxUrl = true;
 
-		  } catch( Exception e) {
-		    logger.error("", null, "Failed to Fetch JMX GC Stats From PID:"+process.getPID()+" Reason:\n"+e);
-		  }
-    }
-	  return gcStats;
+	public DuccGarbageStatsCollector(DuccLogger logger, IDuccProcess process) {
+		this.logger = logger;
+		this.process = process;
+		try {
+			jmxUrl = new JmxUrl(process);
+		} catch (Exception e) {
+			logger.error("DuccGarbageStatsCollector.ctor", null, e);
+		}
+
+	}
+
+	private MBeanServerConnection getServerConnection() throws Exception {
+		logger.info("DuccGarbageStatsCollector.getServerConnection()", null,
+				"Connecting GC collector to remote child process - URL:"
+						+ jmxUrl.get());
+		JMXServiceURL url = new JMXServiceURL(jmxUrl.get()); // process.getProcessJmxUrl());
+		JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
+		return jmxc.getMBeanServerConnection();
+	}
+
+	public ProcessGarbageCollectionStats collect() {
+		ProcessGarbageCollectionStats gcStats = new ProcessGarbageCollectionStats();
+		try {
+			if (connection == null) {
+				connection = getServerConnection();
+			}
+		} catch (Throwable e) {
+			logger.info("DuccGarbageStatsCollector.collect()", null,
+					"GC Collector Failed to Connect via JMX to child process PID:"
+							+ process.getPID() + " JmxUrl:" + jmxUrl.get()
+							+ " Will try to reconnect later");
+			// will retry this connection again
+		}
+		if (connection != null) {
+
+			try {
+				Set<ObjectInstance> mbeans = connection.queryMBeans(
+						new ObjectName("java.lang:type=GarbageCollector,*"),
+						null);
+				Long totalCollectionCount = new Long(0);
+				Long totalCollectionTime = new Long(0);
+
+				for (ObjectInstance gcObject : mbeans) {
+					String gcCollectorName = gcObject.getObjectName()
+							.getCanonicalKeyPropertyListString();
+					ObjectName memoryManagerMXBean = new ObjectName(
+							"java.lang:" + gcCollectorName);
+					totalCollectionCount += (Long) connection.getAttribute(
+							memoryManagerMXBean, "CollectionCount");
+					totalCollectionTime += (Long) connection.getAttribute(
+							memoryManagerMXBean, "CollectionTime");
+				}
+				// Returns the total number of collections that have occurred.
+				gcStats.setCollectionCount(totalCollectionCount);
+				// Returns the approximate accumulated collection elapsed time
+				// in milliseconds.
+				gcStats.setCollectionTime(totalCollectionTime);
+				logger.info("DuccGarbageStatsCollector.collect()", null,
+						"GC Collector Fetch Stats For PID:" + process.getPID()
+								+ " GC Count:" + gcStats.getCollectionCount()
+								+ " GC Time:" + gcStats.getCollectionTime());
+
+			} catch (Throwable e) {
+				logger.error("", null, "Failed to Fetch JMX GC Stats From PID:"
+						+ process.getPID() + " Reason:\n" + e);
+			}
+		} else {
+			logger.info(
+					"DuccGarbageStatsCollector.collect()",
+					null,
+					"Unable to connect Agent to remote child process via JMX - The child has not yet reported its JMX port");
+		}
+		return gcStats;
+	}
+
+	private class JmxUrl {
+		IDuccProcess process = null;;
+
+		public JmxUrl(IDuccProcess remoteProcess) {
+			this.process = remoteProcess;
+		}
+
+		public boolean isAvailable() {
+			if (process != null && process.getProcessJmxUrl() != null
+					&& process.getProcessJmxUrl().trim().length() > 0) {
+				return true;
+			}
+			return false;
+		}
+
+		public String get() {
+			if (isAvailable()) {
+				if (reportJmxUrl) {
+					reportJmxUrl = false; // report this once
+					logger.info("JmxUrl.get()", null, "Remote Process JMX URL:"
+							+ process.getProcessJmxUrl());
+				}
+				return process.getProcessJmxUrl();
+			} else {
+				return "";
+			}
+		}
 	}
 }
diff --git a/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/processors/DefaultNodeInventoryProcessor.java b/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/processors/DefaultNodeInventoryProcessor.java
index 7ba3b0b..20c36c9 100644
--- a/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/processors/DefaultNodeInventoryProcessor.java
+++ b/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/processors/DefaultNodeInventoryProcessor.java
@@ -213,7 +213,16 @@
 					int pipelineInitStats = (p.getValue()
 							.getUimaPipelineComponents() == null) ? 0 : p
 							.getValue().getUimaPipelineComponents().size();
+					StringBuffer gcInfo = new StringBuffer();
+					if (p.getValue().getGarbageCollectionStats() != null ) {
+						gcInfo.append(" GC Total=")
+								.append(p.getValue().getGarbageCollectionStats().getCollectionCount())
+								.append(" GC Time=")
+								.append(p.getValue().getGarbageCollectionStats().getCollectionTime())
+								.append(" ");
 
+
+					}
 					sb.append("\n\t[Process Type=")
 							.append(p.getValue().getProcessType())
 							.append(" DUCC ID=")
@@ -224,6 +233,7 @@
 							.append(p.getValue().getProcessState())
 							.append(" Resident Memory=")
 							.append(p.getValue().getResidentMemory())
+							.append(gcInfo.toString())
 							.append(" Init Stats List Size:"
 									+ pipelineInitStats)
 							.append(" Reason: "+p.getValue().getReasonForStoppingProcess())		
diff --git a/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/processors/LinuxProcessMetricsProcessor.java b/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/processors/LinuxProcessMetricsProcessor.java
index be394ce..ca445d5 100644
--- a/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/processors/LinuxProcessMetricsProcessor.java
+++ b/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/processors/LinuxProcessMetricsProcessor.java
@@ -331,6 +331,7 @@
 
 	private ProcessGarbageCollectionStats getGCStats() throws Exception {
 		if (!process.getProcessType().equals(ProcessType.Pop)) {
+			logger.info("LinuxProcessMetricsProcessor.getGCStats",	null, "Collecting GC Stats");
 			ProcessGarbageCollectionStats gcStats = gcStatsCollector
 					.collect();
 		   return gcStats;