update dev300-m58
[ooovba.git] / qadevOOo / runner / helper / OfficeWatcher.java
blob3142a642988dd2b2aaa196de0d14f29fde10cca8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OfficeWatcher.java,v $
10 * $Revision: 1.9.2.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package helper;
32 import lib.TestParameters;
33 import java.util.StringTokenizer;
34 import util.utils;
36 public class OfficeWatcher extends Thread implements share.Watcher {
38 public boolean finish;
39 private TestParameters params;
40 private int StoredPing = 0;
41 private boolean debug = false;
43 /** Creates new OfficeWatcher
44 * @param param
46 public OfficeWatcher(TestParameters param) {
47 finish = false;
48 this.params = param;
49 debug = params.getBool(util.PropertyName.DEBUG_IS_ACTIVE);
52 /**
53 * pings the office watcher to check for changes
55 public void ping() {
56 try {
57 StoredPing++;
58 } catch (Exception e) {
59 StoredPing = 0;
63 /**
64 * returns the amount of pings
65 * @return returns the amount of pings
67 public int getPing() {
68 return StoredPing;
71 public void run() {
72 dbg("started");
73 boolean isDone = false;
74 final ProcessHandler ph = (ProcessHandler) params.get("AppProvider");
75 int timeOut = params.getInt("TimeOut");
76 if (ph == null) {
77 isDone = true;
79 while (!isDone) {
80 timeOut = params.getInt("TimeOut");
81 final int previous = StoredPing;
82 shortWait(timeOut == 0 ? 30000 : timeOut);
83 // a timeout with value 0 lets watcher not react.
84 if ((StoredPing == previous) && timeOut != 0) {
85 isDone = true;
87 // execute in case the watcher is not needed anymore
88 if (finish) {
89 return;
92 if (ph != null) {
93 dbg("the Office is idle for " + timeOut / 1000 +
94 " seconds, it probably hangs and is killed NOW.");
95 final String AppKillCommand = (String) params.get(util.PropertyName.APP_KILL_COMMAND);
96 if (AppKillCommand != null) {
97 final StringTokenizer aKillCommandToken = new StringTokenizer(AppKillCommand, ";");
98 while (aKillCommandToken.hasMoreTokens()) {
99 final String sKillCommand = aKillCommandToken.nextToken();
101 dbg("User defined an application to destroy the started process.");
102 dbg("Trying to execute: " + sKillCommand);
104 final ProcessHandler pHdl = new ProcessHandler(sKillCommand);
105 pHdl.executeSynchronously();
106 // dbg("---> Output of killoffice:");
107 // dbg(pHdl.getOutputText());
108 // dbg("<--- Output of killoffice");
109 // dbg("---> Error output of killoffice:");
110 // dbg(pHdl.getErrorText());
111 // dbg("<--- Error output of killoffice");
115 ph.kill();
116 } else {
117 dbg("reaeched timeout but ProcessHandler is NULL");
119 shortWait(timeOut == 0 ? 30000 : timeOut);
120 dbg("finished");
123 protected void shortWait(int timeOut) {
124 try {
125 OfficeWatcher.sleep(timeOut);
126 } catch (java.lang.InterruptedException ie) {
130 protected void dbg(String message) {
131 if (debug) {
132 System.out.println(utils.getDateTime() + "OfficeWatcher: " + message);