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 com.sun.star.lib.uno.environments.remote;
25 
26 class TestWorkAt implements TestIWorkAt {
27 	/**
28 	 * When set to true, enables various debugging output.
29 	 */
30 	private static final boolean DEBUG = false;
31 
32 	static final int MESSAGES = 35;
33 
34 
35 	int _counter;
36 
37 	int _sync_counter;
38 	int _async_counter;
39 
40 	Thread _sync_thread;
41 	Thread _async_thread;
42 
43 	boolean _passedAync = true;
44 	boolean _notified = false;
45 
syncCall()46 	public void syncCall() throws Throwable {
47 		++ _sync_counter;
48 
49 		if(_async_counter != MESSAGES)
50 			_passedAync = false;
51 
52 		if(_sync_thread == null)
53 			_sync_thread = Thread.currentThread();
54 
55 //  		if(_sync_thread != Thread.currentThread())
56 //  			_passedAync = false;
57 
58 		if(DEBUG) System.err.println("syncCall:" + _sync_counter + " " + _passedAync + " " + Thread.currentThread());
59 	}
60 
asyncCall()61 	public void asyncCall() throws Throwable {
62 //  		Thread.sleep(50);
63 
64 		++ _async_counter;
65 
66 		if(_async_thread == null)
67 			_async_thread = Thread.currentThread();
68 
69 //  		if(_async_thread != Thread.currentThread())
70 //  			_passedAync = false;
71 
72 		if(DEBUG) System.err.println("asyncCall:" + _async_counter + " " + Thread.currentThread());
73 	}
74 
increment()75 	public synchronized void increment() throws Throwable {
76 		if(DEBUG) System.err.println("increment - " + Thread.currentThread());
77 
78 		++ _counter;
79 		notifyAll();
80 	}
81 
notifyme()82 	public synchronized void notifyme() {
83 		if(DEBUG) System.err.println("\t\t\tnotifying me" + Thread.currentThread());
84 
85 		notifyAll();
86 
87 		_notified = true;
88 	}
89 
passedAsyncTest()90 	public boolean passedAsyncTest() {
91 		return  _passedAync && (_sync_counter == MESSAGES);
92 	}
93 }
94