KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > runtime > jobs > LockListener


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.runtime.jobs;
12
13 import org.eclipse.core.internal.jobs.JobManager;
14 import org.eclipse.core.internal.jobs.LockManager;
15
16 /**
17  * A lock listener is notified whenever a thread is about to wait
18  * on a lock, and when a thread is about to release a lock.
19  * <p>
20  * This class is for internal use by the platform-related plug-ins.
21  * Clients outside of the base platform should not reference or subclass this class.
22  * </p>
23  *
24  * @see IJobManager#setLockListener(LockListener)
25  * @since 3.0
26  */

27 public class LockListener {
28     private final LockManager manager = ((JobManager)Job.getJobManager()).getLockManager();
29
30     /**
31      * Notification that a thread is about to block on an attempt to acquire a lock.
32      * Returns whether the thread should be granted immediate access to the lock.
33      * <p>
34      * This default implementation always returns <code>false</code>.
35      * Subclasses may override.
36      *
37      * @param lockOwner the thread that currently owns the lock this thread is
38      * waiting for, or <code>null</code> if unknown.
39      * @return <code>true</code> if the thread should be granted immediate access,
40      * and <code>false</code> if it should wait for the lock to be available
41      */

42     public boolean aboutToWait(Thread JavaDoc lockOwner) {
43         return false;
44     }
45
46     /**
47      * Notification that a thread is about to release a lock.
48      * <p>
49      * This default implementation does nothing. Subclasses may override.
50      */

51     public void aboutToRelease() {
52         //do nothing
53
}
54
55     /**
56      * Returns whether this thread currently owns any locks
57      * @return <code>true</code> if this thread owns any locks, and
58      * <code>false</code> otherwise.
59      */

60     protected final boolean isLockOwnerThread() {
61         return manager.isLockOwner();
62     }
63 }
64
Popular Tags