1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 ************************************************************************/
32 import lib
.TestParameters
;
33 import java
.util
.StringTokenizer
;
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
46 public OfficeWatcher(TestParameters param
) {
49 debug
= params
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
);
53 * pings the office watcher to check for changes
58 } catch (Exception e
) {
64 * returns the amount of pings
65 * @return returns the amount of pings
67 public int getPing() {
73 boolean isDone
= false;
74 final ProcessHandler ph
= (ProcessHandler
) params
.get("AppProvider");
75 int timeOut
= params
.getInt("TimeOut");
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) {
87 // execute in case the watcher is not needed anymore
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");
117 dbg("reaeched timeout but ProcessHandler is NULL");
119 shortWait(timeOut
== 0 ?
30000 : timeOut
);
123 protected void shortWait(int timeOut
) {
125 OfficeWatcher
.sleep(timeOut
);
126 } catch (java
.lang
.InterruptedException ie
) {
130 protected void dbg(String message
) {
132 System
.out
.println(utils
.getDateTime() + "OfficeWatcher: " + message
);