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
;
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
) {
33 this.debug
= params
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
);
37 * pings the office watcher to check for changes
42 } catch (Exception e
) {
48 * returns the amount of pings
49 * @return returns the amount of pings
51 public int getPing() {
58 boolean isDone
= false;
59 final ProcessHandler ph
= (ProcessHandler
) params
.get("AppProvider");
60 int timeOut
= params
.getInt("TimeOut");
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) {
72 // execute in case the watcher is not needed anymore
78 dbg("the Office is idle for " + timeOut
/ 1000 +
79 " seconds, it probably hangs and is killed NOW.");
82 dbg("reached timeout but ProcessHandler is NULL");
84 util
.utils
.pause(timeOut
== 0 ?
30000 : timeOut
);
88 private void dbg(String message
) {
90 System
.out
.println(utils
.getDateTime() + "OfficeWatcher: " + message
);