servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lh...@apache.org
Subject svn commit: r772839 - in /servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec: ExecEndpoint.java marshaler/DefaultExecMarshaler.java marshaler/ExecMarshalerSupport.java utils/ExecUtils.java utils/ExecutionData.java
Date Fri, 08 May 2009 04:36:11 GMT
Author: lhein
Date: Fri May  8 04:36:11 2009
New Revision: 772839

URL: http://svn.apache.org/viewvc?rev=772839&view=rev
Log:
did some tweaks for SMXCOMP-491

Added:
    servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecutionData.java
  (with props)
Modified:
    servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java
    servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/marshaler/DefaultExecMarshaler.java
    servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/marshaler/ExecMarshalerSupport.java
    servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecUtils.java

Modified: servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java?rev=772839&r1=772838&r2=772839&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java
(original)
+++ servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java
Fri May  8 04:36:11 2009
@@ -26,6 +26,7 @@
 import org.apache.servicemix.exec.marshaler.DefaultExecMarshaler;
 import org.apache.servicemix.exec.marshaler.ExecMarshalerSupport;
 import org.apache.servicemix.exec.utils.ExecUtils;
+import org.apache.servicemix.exec.utils.ExecutionData;
 import org.apache.servicemix.jbi.jaxp.StringSource;
 
 /**
@@ -124,10 +125,6 @@
 			done(exchange);
 			return;
 		} else {
-			// prepare the buffers
-			StringBuffer output = new StringBuffer();
-			StringBuffer error = new StringBuffer();
-
 			String exec = null;
 
 			// try to extract the command from the in message content
@@ -153,11 +150,10 @@
 			}
 
 			// execute the command
-			int exitValue = ExecUtils.execute(exec, output, error);
+			ExecutionData resultData = ExecUtils.execute(exec);
 
 			// prepare the output
-			String result = marshaler.formatExecutionResult(exitValue, output
-					.toString(), error.toString());
+			String result = marshaler.formatExecutionResult(resultData);
 
 			if (exchange instanceof InOut) {
 				// pushes the execution output in out message

Modified: servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/marshaler/DefaultExecMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/marshaler/DefaultExecMarshaler.java?rev=772839&r1=772838&r2=772839&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/marshaler/DefaultExecMarshaler.java
(original)
+++ servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/marshaler/DefaultExecMarshaler.java
Fri May  8 04:36:11 2009
@@ -19,6 +19,7 @@
 import javax.jbi.messaging.NormalizedMessage;
 import javax.xml.transform.TransformerException;
 
+import org.apache.servicemix.exec.utils.ExecutionData;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.w3c.dom.Document;
 import org.w3c.dom.NodeList;
@@ -36,8 +37,11 @@
     public static final String TAG_EXITCODE = "exitcode";
     public static final String TAG_OUTPUT = "output";
     public static final String TAG_ERROR = "error";
+    public static final String TAG_START_TIME = "started";
+    public static final String TAG_END_TIME = "finished";
+    public static final String TAG_DURATION = "duration";
     
-    public static final String RESULT_FORMAT = "<%s><%s>%d</%s><%s><![CDATA[%s]]></%s><%s><![CDATA[%s]]></%s></%s>";
+    public static final String RESULT_FORMAT = "<%s><%s>%d</%s><%s>%d</%s><%s>%d</%s><%s>%d</%s><%s><![CDATA[%s]]></%s><%s><![CDATA[%s]]></%s></%s>";
     
     /*
      * (non-Javadoc)
@@ -74,25 +78,32 @@
     }
 
     /* (non-Javadoc)
-     * @see org.apache.servicemix.exec.marshaler.ExecMarshalerSupport#formatExecutionResult(int,
java.lang.String, java.lang.String)
+     * @see org.apache.servicemix.exec.marshaler.ExecMarshalerSupport#formatExecutionResult(org.apache.servicemix.exec.utils.ExecutionData)
      */
-    public String formatExecutionResult(int exitValue, String output,
-    		String error) {
-    	
+    public String formatExecutionResult(ExecutionData executionData) {
     	String result = String.format(RESULT_FORMAT, 
-    					TAG_RESULT,
-    					TAG_EXITCODE,
-    					exitValue,
-    					TAG_EXITCODE,
-    					TAG_OUTPUT,
-    					output != null ? output : "",
-						TAG_OUTPUT,
-						TAG_ERROR,
-    					error != null ? error : "",
-						TAG_ERROR,
-						TAG_RESULT
-    					);
-    	
+				TAG_RESULT,
+				TAG_START_TIME,
+				executionData.getStartTime(),
+				TAG_START_TIME,
+				TAG_END_TIME,
+				executionData.getEndTime(),
+				TAG_END_TIME,
+				TAG_DURATION,
+				executionData.getExecutionDuration(),
+				TAG_DURATION,
+				TAG_EXITCODE,
+				executionData.getExitCode(),
+				TAG_EXITCODE,
+				TAG_OUTPUT,
+				executionData.getOutputData() != null ? executionData.getOutputData().toString() : "",
+				TAG_OUTPUT,
+				TAG_ERROR,
+				executionData.getErrorData() != null ? executionData.getErrorData().toString() : "",
+				TAG_ERROR,
+				TAG_RESULT
+				);
+
     	return result;
     }
 }

Modified: servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/marshaler/ExecMarshalerSupport.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/marshaler/ExecMarshalerSupport.java?rev=772839&r1=772838&r2=772839&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/marshaler/ExecMarshalerSupport.java
(original)
+++ servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/marshaler/ExecMarshalerSupport.java
Fri May  8 04:36:11 2009
@@ -19,6 +19,8 @@
 import javax.jbi.messaging.NormalizedMessage;
 import javax.xml.transform.TransformerException;
 
+import org.apache.servicemix.exec.utils.ExecutionData;
+
 /**
  * This interface describes the behavior of an exec marshaler.
  * 
@@ -43,10 +45,8 @@
      * Formats the execution command output to be embedded in the exchange out message.
      * </p>
      * 
-     * @param exitValue	the process exit value
-     * @param output the command execution output.
-     * @param error the command execution error output.
+     * @param executionData	an object containing all needed information about execution
      * @return the command execution output formatted to be embedded in the exchange out
message.
      */
-    public String formatExecutionResult(int exitValue, String output, String error);
+    public String formatExecutionResult(ExecutionData executionData);
 }

Modified: servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecUtils.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecUtils.java?rev=772839&r1=772838&r2=772839&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecUtils.java
(original)
+++ servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecUtils.java
Fri May  8 04:36:11 2009
@@ -41,17 +41,14 @@
 	 * 
 	 * @param command
 	 *            the system command to execute.
-	 * @param outputBuffer
-	 *            the buffer for storing the command output
-	 * @param errorBuffer
-	 *            the buffer for storing the command error output
-	 * @return the command return value
+	 * 
+	 * @return an execution data object containing all information
 	 * @throws ExecException
 	 */
-	public static int execute(String command, StringBuffer outputBuffer,
-			StringBuffer errorBuffer) throws ExecException {
-		int exitValue = -1;
+	public static ExecutionData execute(String command) throws ExecException {
 
+		ExecutionData result = new ExecutionData();
+		
 		LOG.info("Execute command " + command);
 		String[] shellCommand = null;
 		LOG.debug("Define the shell.");
@@ -99,39 +96,40 @@
 			}
 		}
 		try {
-			// check and create buffers if needed
-			if (errorBuffer == null) {
-				errorBuffer = new StringBuffer();
-			}
-			if (outputBuffer == null) {
-				outputBuffer = new StringBuffer();
-			}
+			// remember the start time
+			result.setStartTime(System.currentTimeMillis());
 			
 			// launch the system command
 			Process process = Runtime.getRuntime().exec(shellCommand);
 			
 			// get and start the error stream gobbler
 			StreamGobbler errorGobbler = new StreamGobbler(process
-					.getErrorStream(), errorBuffer);
+					.getErrorStream(), result.getErrorData());
 			errorGobbler.start();
 
 			// get and start the output stream gobbler
 			StreamGobbler outputGobbler = new StreamGobbler(process
-					.getInputStream(), outputBuffer);
+					.getInputStream(), result.getOutputData());
 			outputGobbler.start();
 			
 			// wait the end of the process
-			exitValue = process.waitFor();
+			int exitValue = process.waitFor();
+			
+			// remember the end time
+			result.setEndTime(System.currentTimeMillis());
+			
+			// store the exit code
+			result.setExitCode(exitValue);
 			
 			if (exitValue != 0) {
 				// an error occured
 				LOG.error("Command " + command
 						+ " execution failed with return code " + exitValue
-						+ " : " + errorBuffer.toString());
+						+ " : " + result.getErrorData().toString());
 			} else {
 				// command was successful
 				LOG.debug("Command " + command + " execution completed: "
-						+ outputBuffer.toString());
+						+ result.getOutputData().toString());
 			}
 		} catch (Exception exception) {
 			LOG.error("Command " + command + " execution failed.", exception);
@@ -139,8 +137,8 @@
 					"Command " + command + " execution failed.", exception);
 		}
 
-		// return the exit value of the process (defaults to -1)
-		return exitValue;
+		// return the result object
+		return result;
 	}
 }
 

Added: servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecutionData.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecutionData.java?rev=772839&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecutionData.java
(added)
+++ servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecutionData.java
Fri May  8 04:36:11 2009
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.exec.utils;
+
+/**
+ * helper object storing several important data for use after execution
+ * 
+ * @author lhein
+ */
+public class ExecutionData {
+	private StringBuffer outputData;
+	private StringBuffer errorData;
+	
+	private int exitCode;
+	
+	private long startTime;
+	private long endTime;
+	private long executionDuration;
+	
+	/**
+	 * constructs an execution data object
+	 */
+	public ExecutionData() {
+		this.outputData = new StringBuffer();
+		this.errorData = new StringBuffer();
+		this.exitCode = -1;
+	}
+
+	/**
+	 * @return the outputData
+	 */
+	public StringBuffer getOutputData() {
+		return this.outputData;
+	}
+
+	/**
+	 * @param outputData the outputData to set
+	 */
+	public void setOutputData(StringBuffer outputData) {
+		this.outputData = outputData;
+	}
+
+	/**
+	 * @return the errorData
+	 */
+	public StringBuffer getErrorData() {
+		return this.errorData;
+	}
+
+	/**
+	 * @param errorData the errorData to set
+	 */
+	public void setErrorData(StringBuffer errorData) {
+		this.errorData = errorData;
+	}
+
+	/**
+	 * @return the exitCode
+	 */
+	public int getExitCode() {
+		return this.exitCode;
+	}
+
+	/**
+	 * @param exitCode the exitCode to set
+	 */
+	public void setExitCode(int exitCode) {
+		this.exitCode = exitCode;
+	}
+
+	/**
+	 * @return the startTime
+	 */
+	public long getStartTime() {
+		return this.startTime;
+	}
+
+	/**
+	 * @param startTime the startTime to set
+	 */
+	public void setStartTime(long startTime) {
+		this.startTime = startTime;
+	}
+
+	/**
+	 * @return the endTime
+	 */
+	public long getEndTime() {
+		return this.endTime;
+	}
+
+	/**
+	 * @param endTime the endTime to set
+	 */
+	public void setEndTime(long endTime) {
+		this.endTime = endTime;
+		// calculate the execution duration
+		if (this.startTime > 0 && this.endTime >= this.startTime) {
+			this.executionDuration = this.endTime - this.startTime;
+		}
+	}
+
+	/**
+	 * @return the executionDuration
+	 */
+	public long getExecutionDuration() {
+		return this.executionDuration;
+	}
+}

Propchange: servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecutionData.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message