bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / runner / helper / OfficeWatcher.java
blobb7381b6657dbf07d2b4f5eb429f0fb030232f532
1 /*
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 .
18 package helper;
20 import lib.TestParameters;
21 import java.util.StringTokenizer;
22 import util.utils;
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
32 * @param param
34 public OfficeWatcher(TestParameters param) {
35 finish = false;
36 this.params = param;
37 debug = params.getBool(util.PropertyName.DEBUG_IS_ACTIVE);
40 /**
41 * pings the office watcher to check for changes
43 public void ping() {
44 try {
45 StoredPing++;
46 } catch (Exception e) {
47 StoredPing = 0;
51 /**
52 * returns the amount of pings
53 * @return returns the amount of pings
55 public int getPing() {
56 return StoredPing;
59 public void run() {
60 dbg("started");
61 boolean isDone = false;
62 final ProcessHandler ph = (ProcessHandler) params.get("AppProvider");
63 int timeOut = params.getInt("TimeOut");
64 if (ph == null) {
65 isDone = true;
67 while (!isDone) {
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) {
73 isDone = true;
75 // execute in case the watcher is not needed anymore
76 if (finish) {
77 return;
80 if (ph != null) {
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");
103 ph.kill();
104 } else {
105 dbg("reaeched timeout but ProcessHandler is NULL");
107 shortWait(timeOut == 0 ? 30000 : timeOut);
108 dbg("finished");
111 protected void shortWait(int timeOut) {
112 try {
113 OfficeWatcher.sleep(timeOut);
114 } catch (java.lang.InterruptedException ie) {
118 protected void dbg(String message) {
119 if (debug) {
120 System.out.println(utils.getDateTime() + "OfficeWatcher: " + message);