KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > applications > server > ProcessMonitor


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.applications.server;
21 import java.io.OutputStream JavaDoc;
22
23 public class ProcessMonitor {
24
25   String JavaDoc name;
26   Process JavaDoc process;
27
28   IOStreamConnector stdout;
29   IOStreamConnector stderr;
30
31   public ProcessMonitor(String JavaDoc name,
32                         Process JavaDoc process) {
33
34     this.process = process;
35     this.name = name;
36   }
37
38
39   public String JavaDoc getName() {
40     return name;
41   }
42
43   /**
44    * Watch and wait until the process has completed. Any output
45    * from the process will be written to the streams provided and
46    * the exit code will be returned when the process terminates.
47    *
48    * @param out an OutputStream to receive data from the stdout stream
49    * @param err an OutputStream to receive data from the stderr stream
50
51    * @return
52    * @throws java.lang.InterruptedException
53    */

54   public int watch(OutputStream JavaDoc out,
55                    OutputStream JavaDoc err)
56           throws InterruptedException JavaDoc {
57
58     stdout = new IOStreamConnector();
59     stdout.connect(process.getInputStream(), out);
60
61     stderr = new IOStreamConnector();
62     stderr.connect(process.getErrorStream(), err);
63
64     return process.waitFor();
65   }
66
67   /**
68    * Terminate the process
69    */

70   public void kill() {
71     process.destroy();
72   }
73
74
75
76
77
78 }
79
Popular Tags