From 0dd463ba384d780b39aaed01095999fd20e2fde2 Mon Sep 17 00:00:00 2001 From: gumartinm Date: Fri, 27 Jan 2012 00:54:04 +0100 Subject: [PATCH] Sorry, committing forgotten changes... Just deleting files, there is nothing important about this commit. --- JavaFork/Daemon/javafork | Bin 22839 -> 0 bytes .../src/main/java/de/fork/java/ForkDaemon.java | 166 ------------- .../src/main/java/de/fork/java/ForkParser.java | 141 ----------- .../main/java/de/fork/java/LauncherProcesses.java | 275 --------------------- .../src/main/java/de/fork/java/MainJavaFork.java | 35 --- 5 files changed, 617 deletions(-) delete mode 100755 JavaFork/Daemon/javafork delete mode 100644 JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/ForkDaemon.java delete mode 100644 JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/ForkParser.java delete mode 100644 JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/LauncherProcesses.java delete mode 100644 JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/MainJavaFork.java diff --git a/JavaFork/Daemon/javafork b/JavaFork/Daemon/javafork deleted file mode 100755 index 7277198a27261ffd239c9af74f50b817dffd38d2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 22839 zcmcJ13zSsFxo&kg1I=ruVR#LoG%!39W(Gt=gV+d-jSe^gyuoKr&veg2d%7pn-3TfH z9Y$>@m?6j9F#v zehE;Iz8=@<$LH5e+|WDe5JIn}Mvv}MPb}aGVL`nlh91<88EVSMvhkRy%Qw><07pJR zBG$?C5Tz_b-HCLR@s@d#1r5lEp|uJYh8n#uLr?mt)Bh`C{H%_*Hmq1)9gi-Fw zmh4!$V#$i-RjFjvGU>k$hFHW)HeDf2n);Xsj(JbQ!75|=GmrePE`QI(_skph`u(dP z>;2U~Y&r5ci*XK)={T0+(AAHa3R5*52YNOR$}ht)3&&YFnEw(Si*Qup7>lC{M>UQb z9J6tJ5eI|0Rv0hEF^v%f*2@=gun8CAU?^9laMsNz%VNM$CZg$R3vVu4LSrmAqvL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&++}KXJghCwVx3xKQnvp4(3Y4){k7c1EG#!`bKa^>BEV1HMk;XO5qj zI>=w+fODySxP13H;P*S=k2v5*flt7!-Hhkvd4r476VUI>qM*UwaIkaI0Uv>zy>FQ7 za{}<;%C*D+-{62>>wt3u!bJ2_v#ibMK89O0Zr1u2z;A}HJJ`7&IP1YInVNd|se?Q> z6%ALeV-EPc4)~`I_!KxW!CfJ?>G4o`k9|WDpCtIFYipk~|ILP1bfPcpU{~2%}?mK4uH!eNqApf!h{+0v&SBaMjvtWLW&R}%O z@a;9v0Y4u&{oGMh|EnG3>m2X~2YkB&ei!iJ>Sw=${0|-QUrW4Hn7t$?bv-<(akEak zN8`^r*m=VN|4`z?%s(3=@wnxiPNK0Rol0l$kB~+zMy%a>`Q~u#hAmt1si$ywosGM6 zttBa%3^&J<4Ust39`TAe9Len95=(nLmX1ZMR-ChZsbE65HM)b`IYPZ&j%M20cA9*G zo7Tx})?>vk7&aWUG4Y{X!U_beUxea+3G9gef>dKF6P7R0 z)pw?fWK=eVzlzvX<>q`lq`rA&$K(gC><|{cqG>x+^ntG7J})Le&SlrqU)8dM{2-Ve zVVzLaj;eC=Q)5MV@wc_?$^62Y9Z|bh?U?!;m>rWJ__9Oc4VRPu^OLHoDE>}l%1Ja&xLHC*Fb7kaJB*Xna=b{m!jTYkpO zp2)v~6d~#lLs*cHHx;E|-$fCkWzTG9)JQ6+cMO}3Z#tp;UK+1 z>*BHc>yO=;kZQL7 E12bH^XaE2J diff --git a/JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/ForkDaemon.java b/JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/ForkDaemon.java deleted file mode 100644 index 074318f..0000000 --- a/JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/ForkDaemon.java +++ /dev/null @@ -1,166 +0,0 @@ -package de.fork.java; - -import java.io.IOException; -import java.io.PrintWriter; -import java.net.InetAddress; -import java.net.Socket; -import java.net.UnknownHostException; -import javax.xml.parsers.FactoryConfigurationError; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import org.xml.sax.SAXException; - -/** - *

- * With this class we can run processes using the intended daemon which is - * waiting for TCP connections in a specified port. - *

- *

- * Receiving the results in a XML format from the daemon where we can find three - * kinds of different fields: error, out and ret. Every field is related to the - * stderr, stdout and return code respectively.
- *

- *

- *

- * Example, stream received from daemon:
- * {@code
- * 
- * }
- * 
- *

- *

- * This class has to process the above stream and it offers two methods wich can be used - * to retrieve the stderr and stdout in a right way without having to know about the XML stream - * received from the daemon. The user does not have to know about how the daemon sends the data, - * he or she will work directly with the strings related to each stream. Those methods - * are {@link ForkDaemon#getStdout()} and {@link ForkDaemon#getStderr()} The return code from the command - * executed by the daemon can be retrieved as a return parameter from the method - * {@link ForkDaemon#exec(String, String, int)} - *

- *

- * Instances of this class are mutable. To use them concurrently, clients must surround each - * method invocation (or invocation sequence) with external synchronization of the clients choosing. - *

- */ -public class ForkDaemon { - private final ForkParser handler; - - - /** - * Simple constructor. - * Nothing special here. - * - */ - public ForkDaemon () { - handler = new ForkParser(); - } - - - /** - * This method sends commands to the daemon. - *
- * It uses a TCP connection in order to send commands to the daemon and receive - * the results related to that command. - *
- * The mehtod retrieves the stdout, stderr and the return code of that command. - * - *

The host name can either be a machine name, such as - * "java.sun.com", or a textual representation of its - * IP address. If a literal IP address is supplied, only the - * validity of the address format is checked. - *

- *

For host specified in literal IPv6 address, - * either the form defined in RFC 2732 or the literal IPv6 address - * format defined in RFC 2373 is accepted. IPv6 scoped addresses are also - * supported. See here for a description of IPv6 - * scoped addresses. - *

- * @param command the command to be executed by the daemon. - * @param host the specified host. - * @param port the TCP port where the daemon accepts connections. - * - * @return the executed command's return code. - * - * @throws UnknownHostException if no IP address for the - * host could be found, or if a scope_id was specified - * @throws SecurityException if a security manager exists - * and its checkConnect method doesn't allow the operation - * @throws IOException if an I/O error occurs when creating the socket. - * @throws SAXException - * @throws FactoryConfigurationError if the implementation is not available or cannot be instantiated. - * @throws SAXException If any SAX errors occur during processing. - * @throws ParserConfigurationException - */ - public int exec(final String command, String host, int port) - throws UnknownHostException, IOException, SAXException, ParserConfigurationException { - final SAXParserFactory spf = SAXParserFactory.newInstance(); - final SAXParser saxParser = spf.newSAXParser(); - PrintWriter out = null; - - final Socket socket = new Socket(InetAddress.getByName(host), port); - try { - out = new PrintWriter(socket.getOutputStream(), true); - out.println(command); - saxParser.parse(socket.getInputStream(), handler); - } - finally { - if (out != null) { - out.close(); - } - socket.close(); - } - - //Just for testing the parser by using a file instead of a TCP connection. - //InputSource input = new InputSource(new FileReader("/tmp/xmlfromdaemon.xml")); - //saxParser.parse(input, handler); - - return new Integer(handler.getReturnValue()).intValue(); - } - - - /** - * Retrieve the standard output. - * - * @see {@link ForkDaemon#getStderr()} - * @return stdout - */ - public String getStdout() { - return handler.getStdout(); - } - - - /** - *

- * Retrieve the standard error. - *

- *

- *

-	 * Example, stream received from daemon:
-	 * {@code
-	 * 
-	 * }
-	 * 
- *

- *

- *

-	 * From that example with this method we are going to obtain this return parameter:
-	 * {@code
-	 * ls: no se puede acceder a bbb: No existe el fichero o el directorio
-	 * ls: no se puede acceder a aaa: No existe el fichero o el directorio
-	 * ls: no se puede acceder a dddd: No existe el fichero o el directorio
-	 * }
-	 * 
- *

- * @return stderr - */ - public String getStderr() { - return handler.getStderr(); - } -} \ No newline at end of file diff --git a/JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/ForkParser.java b/JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/ForkParser.java deleted file mode 100644 index c20ba15..0000000 --- a/JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/ForkParser.java +++ /dev/null @@ -1,141 +0,0 @@ -package de.fork.java; - -import org.apache.log4j.Logger; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.ext.DefaultHandler2; - -/** - *

- * Class intended to parse the XML stream received from the daemon which is - * waiting to run commands. These commands are sent by the method - * {@link es.dia.pos.n2a.util.os.unix.ForkDaemon#exec(String, String, int)} - *

- *

- * After processing one command the daemon sends a XML stream with the stderr, - * stdout and return status of that command. With this class we extract those values - * and we can retrieve them using the methods {@link #getStderr() }, {@link #getStdout()} - * and {@link #getReturnValue()} - *

- *

- *

- * Example, stream received from daemon:
- * {@code
- * 
- * }
- * 
- *

- */ -public class ForkParser extends DefaultHandler2{ - private static final Logger logger = Logger.getLogger(ForkParser.class); - private StringBuffer accumulator = new StringBuffer(); - private String stderr = new String(); - private String stdout = new String(); - private String returnCode = new String(); - - - @Override - public void endElement (String uri, String localName, String qName) { - if (qName.equals("error")) { - // After , we've got the stderror - stderr = stderr + accumulator.toString(); - } else if (qName.equals("out")) { - // After , we've got the stdout - stdout = stdout + accumulator.toString(); - } else if (qName.equals("ret")) { - returnCode = returnCode + accumulator.toString(); - } - } - - - @Override - public void endDocument () throws SAXException - { - if (stderr.length() != 0) { - String lastStderr = stderr.replaceFirst("\\\n$", ""); - stderr = lastStderr; - } - else { - stderr = null; - } - if (stdout.length() != 0) { - String lastStdout = stdout.replaceFirst("\\\n$", ""); - stdout = lastStdout; - } - else { - stdout = null; - } - } - - /** - * Retrieve the standard error. - * - *
-	 * From the above example with this method we are going to obtain this return parameter:
-	 * {@code
-	 * ls: no se puede acceder a bbb: No existe el fichero o el directorio
-	 * ls: no se puede acceder a aaa: No existe el fichero o el directorio
-	 * ls: no se puede acceder a dddd: No existe el fichero o el directorio
-	 * }
-	 * 
- * - * @return stderr - */ - public String getStderr() { - return stderr; - - } - - - /** - * Retrieve the standard output. - * - * @see {@link ForkParser#getStderr()} - * @return stdout - */ - public String getStdout() { - return stdout; - } - - - /** - * Retrieve the return code from the executed command. - * - * @return return status, usually 0 means the command went OK. - */ - public String getReturnValue() { - return returnCode; - } - - - @Override - public void startElement (String uri, String localName, String qName, Attributes attributes) { - accumulator.setLength(0); - } - - - @Override - public void characters(char[] buffer, int start, int length) { - accumulator.append(buffer, start, length); - } - - @Override - public void warning(SAXParseException exception) { - logger.error("WARNING line:" + exception.getLineNumber(), exception); - } - - @Override - public void error(SAXParseException exception) { - logger.error("ERROR line:" + exception.getLineNumber(), exception); - } - - @Override - public void fatalError(SAXParseException exception) throws SAXException { - logger.error("FATAL ERROR line:" + exception.getLineNumber(), exception); - throw (exception); - } -} \ No newline at end of file diff --git a/JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/LauncherProcesses.java b/JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/LauncherProcesses.java deleted file mode 100644 index 0f93fe2..0000000 --- a/JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/LauncherProcesses.java +++ /dev/null @@ -1,275 +0,0 @@ -package de.fork.java; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintStream; -import java.net.UnknownHostException; -import javax.xml.parsers.ParserConfigurationException; -import org.apache.log4j.Logger; -import org.xml.sax.SAXException; - - -public class LauncherProcesses { - - private static final Logger logger = Logger.getLogger(LauncherProcesses.class); - - // Exit process status - private static final int STATUS_ERR = -1; - - private static final int DEFAULT_PORT = 5193; - private static final String DEFAULT_HOST = "127.0.0.1"; - - /** - * Run a process. - * - * @param command system command to be executed. - * - * @return return code. - */ - public static int exec(final String command) throws IOException, InterruptedException { - - return exec(command, null, null); - } - - /** - * Run a process. - * - * @param command system command to execute. - * @param standarOutPut if not null, the standard output is redirected to this parameter. - * - * @return return code. - */ - public static int exec(final String command, final PrintStream standarOutPut) throws IOException, InterruptedException { - - return exec(command, standarOutPut, null); - } - - - /** - * Run a process. - * - * @param command system command to be executed. - * @param standarOutPut if not null, the standard output is redirected to this parameter. - * @param errorOutPut if not null, the error output is redirected to this parameter. - * - * @return return code from the executed system command. - */ - public static int exec(final String command, final PrintStream standarOutPut, final PrintStream errorOutPut) throws IOException, InterruptedException { - - return exec(command, standarOutPut, errorOutPut, DEFAULT_HOST, DEFAULT_PORT); - } - - /** - * Run a process. - * - * @param command system command to be executed. - * @param aLogger send the information to log. - */ - public static int exec(final String command, final Logger aLogger) throws IOException, InterruptedException { - - //calling private method to handle logger input/ouput in a common method - return execHandlingLogger(command, aLogger, DEFAULT_HOST, DEFAULT_PORT); - } - - - /** - * @param commandAndArguments String array containing system command and its - * arguments to be executed.
- * For example: - *
-	 * commandAndArguments[0]="ls";
-	 * commandAndArguments[1]="-lr";
-	 * 
- * @param aLogger - * - * @return return code from the executed system command. - * - * @throws IOException - * @throws InterruptedException - */ - public static int exec(final String[] commandAndArguments, final Logger aLogger) throws IOException, InterruptedException { - String wholeCommand=""; - - for(String argument : commandAndArguments) { - wholeCommand = wholeCommand + " " + argument; - } - - //calling private method to handle logger input/ouput in a common method - return execHandlingLogger(wholeCommand, aLogger, DEFAULT_HOST, DEFAULT_PORT); - } - - - /** - * - * @param command system command to be executed. - * @param standarOutPut the stdout stream from that command as a PrintStream - * @param errorOutPut the stderr stream from that command as a PrintStream - * @param host the specified host. - * @param port the TCP port where the daemon accepts connections. - * - *

The host name can either be a machine name, such as - * "java.sun.com", or a textual representation of its - * IP address. If a literal IP address is supplied, only the - * validity of the address format is checked. - *

- *

For host specified in literal IPv6 address, - * either the form defined in RFC 2732 or the literal IPv6 address - * format defined in RFC 2373 is accepted. IPv6 scoped addresses are also - * supported. See here for a description of IPv6 - * scoped addresses. - *

- * - * @return the executed command's return code. - * - * @throws UnknownHostException - * @throws IOException - */ - public static int exec(final String command, final PrintStream standarOutPut, - final PrintStream errorOutPut, final String host, int port) throws IOException { - int exitStatus = LauncherProcesses.STATUS_ERR; - - ForkDaemon process = new ForkDaemon(); - try { - exitStatus = process.exec(command, host, port); - } catch (SAXException e) { - // This is not a crazy thing, we are trying to insert this new method without - // breaking the old methods which did not throw SAXException or ParserConfigurationException - //[§EJ Item 61] Do not blame me. - throw new IOException(e); - } catch (ParserConfigurationException e) { - // This is not a crazy thing, we are trying to insert this new method without - // breaking the old methods which did not throw SAXException or ParserConfigurationException - //[§EJ Item 61] Do not blame me. - throw new IOException(e); - } - - if (standarOutPut != null) { - if (process.getStdout() != null) { - standarOutPut.println(process.getStdout()); - } - } - - if (errorOutPut != null) { - if (process.getStderr() != null) { - errorOutPut.println(process.getStderr()); - } - } - - return exitStatus; - } - - - /** - * - * @param command system command to be executed. - * @param aLogger - * @param host the specified host. - * @param port the TCP port where the daemon accepts connections. - * - * @return the executed command's return code. - * - * @throws IOException - * @throws InterruptedException - */ - private static int execHandlingLogger(final String command, final Logger aLogger, - final String host, int port) throws IOException, InterruptedException { - int exitStatus = LauncherProcesses.STATUS_ERR; - - ForkDaemon process = new ForkDaemon(); - try { - exitStatus = process.exec(command, host, port); - } catch (SAXException e) { - // This is not a crazy thing, we are trying to insert this new method without - // breaking the old methods which did not throw SAXException or ParserConfigurationException - // Do not blame me. - throw new IOException(e); - } catch (ParserConfigurationException e) { - // This is not a crazy thing, we are trying to insert this new method without - // breaking the old methods which did not throw SAXException or ParserConfigurationException - // Do not blame me. - throw new IOException(e); - } - - if (process.getStdout() != null) { - aLogger.info(process.getStdout()); - } - if (process.getStderr() != null) { - aLogger.error(process.getStderr()); - } - - return exitStatus; - } - - - /** - * @param command command and its arguments to be executed.
- * For example: - *
-	 * commandAndArguments[0]="ls";
-	 * commandAndArguments[1]="-lr";
-	 * 
- * @param aLogger send information to log - * - * @return the executed command's return code. - * - * @throws IOException - * @throws InterruptedException - */ - public static InputStream execStream (final String [] command, final Logger aLogger) - throws IOException, InterruptedException { - int exitStatus = LauncherProcesses.STATUS_ERR; - - InputStream stdInput = null; - - String wholeCommand=""; - for(String argument : command) { - wholeCommand = wholeCommand + " " + argument; - } - - ForkDaemon process = new ForkDaemon(); - try { - exitStatus = process.exec(wholeCommand, DEFAULT_HOST, DEFAULT_PORT); - } catch (SAXException e) { - // This is not a crazy thing, we are trying to insert this new method without - // breaking the old methods which did not throw SAXException or ParserConfigurationException - throw new IOException(e); - } catch (ParserConfigurationException e) { - // This is not a crazy thing, we are trying to insert this new method without - // breaking the old methods which did not throw SAXException or ParserConfigurationException - throw new IOException(e); - } - - if(exitStatus == 0) { - stdInput = new ByteArrayInputStream(process.getStdout().getBytes("UTF-8")); - } - else { - aLogger.error(process.getStderr()); - } - - - return stdInput; - } - - /** - *

The command is lunched from location - *

  • #>cd location
  • - *
  • #location> command
  • - * - * @param command the command to be executed by the daemon. - * @param location - * - * @return the executed command's return code.
    - * Usually 0 if execution is OK, otherwise !=0 - * - * @throws IOException - * @throws InterruptedException - */ - public static int execInLocation (final String command, final String location) throws IOException, InterruptedException { - int exitStatus = LauncherProcesses.STATUS_ERR; - final String wholeCommand = "cd " + location + " && " + command; - - exitStatus = exec(wholeCommand, null, null, DEFAULT_HOST, DEFAULT_PORT); - return exitStatus; - } -} \ No newline at end of file diff --git a/JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/MainJavaFork.java b/JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/MainJavaFork.java deleted file mode 100644 index a422cdd..0000000 --- a/JavaFork/JavaExample/javafork-example/src/main/java/de/fork/java/MainJavaFork.java +++ /dev/null @@ -1,35 +0,0 @@ -package de.fork.java; - -import java.io.ByteArrayOutputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.PrintStream; -import javax.xml.parsers.ParserConfigurationException; -import org.xml.sax.SAXException; - - -public class MainJavaFork { - - /** - * @param args - * @throws SAXException - * @throws ParserConfigurationException - * @throws FileNotFoundException - */ - public static void main(String[] args) - throws ParserConfigurationException, SAXException, FileNotFoundException, IOException { - - final ByteArrayOutputStream stdoutByteOut = new ByteArrayOutputStream(); - final PrintStream stdout = new PrintStream(stdoutByteOut); - final String command = "/home/gustavo/github/JavaForFun/JavaFork/Daemon/script.sh"; - final ByteArrayOutputStream stderrByteOut = new ByteArrayOutputStream(); - final PrintStream stderr = new PrintStream(stderrByteOut); - int result; - - result = LauncherProcesses.exec(command,stdout, stderr, "127.0.0.1", 5193); - System.out.println(result); - System.out.println("Stdout: " + stdoutByteOut.toString()); - System.out.println("Stderr: " + stderrByteOut.toString()); - } - -} \ No newline at end of file -- 2.1.4