1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 import lib
.TestParameters
;
30 import java
.util
.StringTokenizer
;
33 public class OfficeWatcher
extends Thread
implements share
.Watcher
{
35 public boolean finish
;
36 private TestParameters params
;
37 private int StoredPing
= 0;
38 private boolean debug
= false;
40 /** Creates new OfficeWatcher
43 public OfficeWatcher(TestParameters param
) {
46 debug
= params
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
);
50 * pings the office watcher to check for changes
55 } catch (Exception e
) {
61 * returns the amount of pings
62 * @return returns the amount of pings
64 public int getPing() {
70 boolean isDone
= false;
71 final ProcessHandler ph
= (ProcessHandler
) params
.get("AppProvider");
72 int timeOut
= params
.getInt("TimeOut");
77 timeOut
= params
.getInt("TimeOut");
78 final int previous
= StoredPing
;
79 shortWait(timeOut
== 0 ?
30000 : timeOut
);
80 // a timeout with value 0 lets watcher not react.
81 if ((StoredPing
== previous
) && timeOut
!= 0) {
84 // execute in case the watcher is not needed anymore
90 dbg("the Office is idle for " + timeOut
/ 1000 +
91 " seconds, it probably hangs and is killed NOW.");
92 final String AppKillCommand
= (String
) params
.get(util
.PropertyName
.APP_KILL_COMMAND
);
93 if (AppKillCommand
!= null) {
94 final StringTokenizer aKillCommandToken
= new StringTokenizer(AppKillCommand
, ";");
95 while (aKillCommandToken
.hasMoreTokens()) {
96 final String sKillCommand
= aKillCommandToken
.nextToken();
98 dbg("User defined an application to destroy the started process.");
99 dbg("Trying to execute: " + sKillCommand
);
101 final ProcessHandler pHdl
= new ProcessHandler(sKillCommand
);
102 pHdl
.executeSynchronously();
103 // dbg("---> Output of killoffice:");
104 // dbg(pHdl.getOutputText());
105 // dbg("<--- Output of killoffice");
106 // dbg("---> Error output of killoffice:");
107 // dbg(pHdl.getErrorText());
108 // dbg("<--- Error output of killoffice");
114 dbg("reaeched timeout but ProcessHandler is NULL");
116 shortWait(timeOut
== 0 ?
30000 : timeOut
);
120 protected void shortWait(int timeOut
) {
122 OfficeWatcher
.sleep(timeOut
);
123 } catch (java
.lang
.InterruptedException ie
) {
127 protected void dbg(String message
) {
129 System
.out
.println(utils
.getDateTime() + "OfficeWatcher: " + message
);