1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
32
package com.sun.grid.jgdi.event;
34
import java.util.LinkedList;
35
import java.util.logging.Logger;
38
* Helper class for event test cases.
41
public class WaitForEventThread extends Thread implements EventListener {
43
private Logger log = Logger.getLogger("com.sun.grid.jgdi.event");
44
private Object object;
45
private LinkedList<Event> events = new LinkedList<Event>();
47
public WaitForEventThread(Object object) {
53
* @param evt the event
55
public void eventOccured(Event evt) {
56
log.entering(getClass().getName(), "eventOccured", evt.getClass());
57
synchronized (events) {
61
log.exiting(getClass().getName(), "eventOccured");
63
private Object addEventSync = new Object();
64
private boolean hasAddEvent = false;
66
public boolean waitForAddEvent(long timeout) throws InterruptedException {
67
log.entering(getClass().getName(), "waitForAddEvent", timeout);
68
synchronized (addEventSync) {
70
addEventSync.wait(timeout);
73
log.exiting(getClass().getName(), "waitForAddEvent", hasAddEvent);
76
private Object modEventSync = new Object();
77
private boolean hasModEvent = false;
79
public boolean waitForModEvent(long timeout) throws InterruptedException {
80
log.entering(getClass().getName(), "waitForModEvent", timeout);
81
synchronized (modEventSync) {
83
modEventSync.wait(timeout);
86
log.exiting(getClass().getName(), "waitForModEvent", hasModEvent);
89
private Object delEventSync = new Object();
90
private boolean hasDelEvent = false;
92
public boolean waitForDelEvent(long timeout) throws InterruptedException {
93
log.entering(getClass().getName(), "waitForDelEvent", timeout);
94
synchronized (delEventSync) {
96
delEventSync.wait(timeout);
99
log.exiting(getClass().getName(), "waitForDelEvent", hasDelEvent);
104
log.entering(getClass().getName(), "run");
108
synchronized (events) {
109
while (evt == null) {
110
while (events.isEmpty()) {
113
evt = events.removeFirst();
117
if (evt.getType().equals(EventType.SGE_EMA_ADD)) {
118
log.fine("got add event" + evt);
119
AddEvent addEvt = (AddEvent) evt;
120
if (this.object.equals(addEvt.getChangedObject())) {
121
synchronized (addEventSync) {
123
addEventSync.notifyAll();
126
} else if (evt.getType().equals(EventType.SGE_EMA_MOD)) {
127
log.fine("got modifiy event" + evt);
128
ModEvent modEvt = (ModEvent) evt;
129
if (this.object.equals(modEvt.getChangedObject())) {
130
synchronized (modEventSync) {
132
modEventSync.notifyAll();
136
} else if (evt.getType().equals(EventType.SGE_EMA_DEL)) {
137
log.fine("got delete event" + evt);
138
DelEvent delEvt = (DelEvent) evt;
139
if (delEvt.hasDeletedObject(object)) {
140
synchronized (delEventSync) {
142
delEventSync.notifyAll();
148
} catch (InterruptedException ire) {
149
log.fine("wait thread has been interrupted");
151
log.exiting(getClass().getName(), "run");