2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import lib
.TestParameters
;
21 import java
.util
.StringTokenizer
;
24 public class OfficeWatcher
extends Thread
implements share
.Watcher
{
26 public boolean finish
;
27 private TestParameters params
;
28 private int StoredPing
= 0;
29 private boolean debug
= false;
31 /** Creates new OfficeWatcher
34 public OfficeWatcher(TestParameters param
) {
37 debug
= params
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
);
41 * pings the office watcher to check for changes
46 } catch (Exception e
) {
52 * returns the amount of pings
53 * @return returns the amount of pings
55 public int getPing() {
61 boolean isDone
= false;
62 final ProcessHandler ph
= (ProcessHandler
) params
.get("AppProvider");
63 int timeOut
= params
.getInt("TimeOut");
68 timeOut
= params
.getInt("TimeOut");
69 final int previous
= StoredPing
;
70 shortWait(timeOut
== 0 ?
30000 : timeOut
);
71 // a timeout with value 0 lets watcher not react.
72 if ((StoredPing
== previous
) && timeOut
!= 0) {
75 // execute in case the watcher is not needed anymore
81 dbg("the Office is idle for " + timeOut
/ 1000 +
82 " seconds, it probably hangs and is killed NOW.");
83 final String AppKillCommand
= (String
) params
.get(util
.PropertyName
.APP_KILL_COMMAND
);
84 if (AppKillCommand
!= null) {
85 final StringTokenizer aKillCommandToken
= new StringTokenizer(AppKillCommand
, ";");
86 while (aKillCommandToken
.hasMoreTokens()) {
87 final String sKillCommand
= aKillCommandToken
.nextToken();
89 dbg("User defined an application to destroy the started process.");
90 dbg("Trying to execute: " + sKillCommand
);
92 final ProcessHandler pHdl
= new ProcessHandler(sKillCommand
);
93 pHdl
.executeSynchronously();
94 // dbg("---> Output of killoffice:");
95 // dbg(pHdl.getOutputText());
96 // dbg("<--- Output of killoffice");
97 // dbg("---> Error output of killoffice:");
98 // dbg(pHdl.getErrorText());
99 // dbg("<--- Error output of killoffice");
105 dbg("reaeched timeout but ProcessHandler is NULL");
107 shortWait(timeOut
== 0 ?
30000 : timeOut
);
111 protected void shortWait(int timeOut
) {
113 OfficeWatcher
.sleep(timeOut
);
114 } catch (java
.lang
.InterruptedException ie
) {
118 protected void dbg(String message
) {
120 System
.out
.println(utils
.getDateTime() + "OfficeWatcher: " + message
);