Bump version to 24.04.3.4
[LibreOffice.git] / qadevOOo / runner / helper / OfficeWatcher.java
blob924a9e4af6d3dc60382e27ff5d811d60d22d8365
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 util.utils;
23 public class OfficeWatcher extends Thread implements share.Watcher {
25 public boolean finish;
26 private final TestParameters params;
27 private int StoredPing = 0;
28 private final boolean debug;
30 public OfficeWatcher(TestParameters param) {
31 this.finish = false;
32 this.params = param;
33 this.debug = params.getBool(util.PropertyName.DEBUG_IS_ACTIVE);
36 /**
37 * pings the office watcher to check for changes
39 public void ping() {
40 try {
41 StoredPing++;
42 } catch (Exception e) {
43 StoredPing = 0;
47 /**
48 * returns the amount of pings
49 * @return returns the amount of pings
51 public int getPing() {
52 return StoredPing;
55 @Override
56 public void run() {
57 dbg("started");
58 boolean isDone = false;
59 final ProcessHandler ph = (ProcessHandler) params.get("AppProvider");
60 int timeOut = params.getInt("TimeOut");
61 if (ph == null) {
62 isDone = true;
64 while (!isDone) {
65 timeOut = params.getInt("TimeOut");
66 final int previous = StoredPing;
67 util.utils.pause(timeOut == 0 ? 30000 : timeOut);
68 // a timeout with value 0 lets watcher not react.
69 if ((StoredPing == previous) && timeOut != 0) {
70 isDone = true;
72 // execute in case the watcher is not needed anymore
73 if (finish) {
74 return;
77 if (ph != null) {
78 dbg("the Office is idle for " + timeOut / 1000 +
79 " seconds, it probably hangs and is killed NOW.");
80 ph.kill();
81 } else {
82 dbg("reached timeout but ProcessHandler is NULL");
84 util.utils.pause(timeOut == 0 ? 30000 : timeOut);
85 dbg("finished");
88 private void dbg(String message) {
89 if (debug) {
90 System.out.println(utils.getDateTime() + "OfficeWatcher: " + message);