1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package helper;
25 
26 import share.*;
27 import lib.TestParameters;
28 import util.PropertyName;
29 import util.utils;
30 
31 /**
32  * This class is printing to a <CODE>LogWriter</CODE>. This could be usefull if a UNO-API
33  * function runns longer the the time out. To avoid the assumption of death applikation
34  * a simple string is logged for 100 times of time out.</br>
35  * Example:</br>
36  *          logger = new LoggingThread((LogWriter)log, tParam);
37  *          logger.start();
38  *          oObj.longRunningFunction();
39  *          logger.finish();
40  *
41  */
42 public class LoggingThread extends Thread {
43 
44     TestParameters param;
45     LogWriter log = null;
46     boolean finished = false;
47     boolean debug = false;
48 
49     /**
50      *
51      * @param log
52      * @param tParam
53      */
LoggingThread(LogWriter log, TestParameters tParam)54     public LoggingThread(LogWriter log, TestParameters tParam) {
55         this.log = log;
56         this.param = tParam;
57         this.debug = tParam.getBool(PropertyName.DEBUG_IS_ACTIVE);
58     }
59 
run()60     public void run() {
61         final int timeOut = param.getInt(PropertyName.TIME_OUT) / 2;
62         int count = 0;
63         finished = false;
64         if (debug) log.println("TimeOutLogger: " + utils.getDateTime() + " start");
65         while (!finished && count < 200) {
66             try {
67                 if (debug) log.println("TimeOutLogger: "+utils.getDateTime() + count);
68                 synchronized (this) {
69                     wait(timeOut);
70                 }
71                 count++;
72             } catch (InterruptedException ex) {
73             }
74         }
75         if (debug) log.println("TimeOutLogger: " + utils.getDateTime() + " finished");
76     }
77 
78     /**
79      * finished the LoggingThread
80      */
finish()81     public void finish() {
82         try {
83             finished = true;
84             synchronized (this) {
85                 notify();
86             }
87             if (debug) log.println("TimeOutLogger: " + utils.getDateTime() + " try to finish ");
88             sleep(1000);
89         } catch (InterruptedException ex) {
90         }
91     }
92 }
93