This class is to let AWT shutdown automatically when a user is done
with AWT. It tracks AWT state using the following parameters:
| Method from sun.awt.AWTAutoShutdown Detail: |
final void dumpPeers(Logger aLog) {
synchronized (activationLock) {
synchronized (mainLock) {
aLog.fine("Mapped peers:");
for (Object key : peerMap.keySet()) {
aLog.fine(key + "- >" + peerMap.get(key));
}
}
}
}
|
public static AWTAutoShutdown getInstance() {
return theInstance;
}
Returns reference to a single AWTAutoShutdown instance. |
final Object getPeer(Object target) {
synchronized (activationLock) {
synchronized (mainLock) {
return peerMap.get(target);
}
}
}
|
static AWTEvent getShutdownEvent() {
return new AWTEvent(getInstance(), 0) {};
}
|
void notifyPeerMapUpdated() {
synchronized (activationLock) {
synchronized (mainLock) {
if (!isReadyToShutdown() && blockerThread == null) {
activateBlockerThread();
} else {
mainLock.notifyAll();
timeoutPassed = false;
}
}
}
}
Notify that the peermap has been updated, that means a new peer
has been created or some existing peer has been disposed. |
public void notifyThreadBusy(Thread thread) {
synchronized (activationLock) {
synchronized (mainLock) {
if (blockerThread == null) {
activateBlockerThread();
} else if (isReadyToShutdown()) {
mainLock.notifyAll();
timeoutPassed = false;
}
busyThreadSet.add(thread);
}
}
}
Add a specified thread to the set of busy event dispatch threads.
If this set already contains the specified thread, the call leaves
this set unchanged and returns silently. |
public void notifyThreadFree(Thread thread) {
synchronized (activationLock) {
synchronized (mainLock) {
busyThreadSet.remove(thread);
if (isReadyToShutdown()) {
mainLock.notifyAll();
timeoutPassed = false;
}
}
}
}
Remove a specified thread from the set of busy event dispatch threads.
If this set doesn't contain the specified thread, the call leaves
this set unchanged and returns silently. |
public static void notifyToolkitThreadBusy() {
getInstance().setToolkitBusy(true);
}
Notify that the toolkit thread is not waiting for a native event
to appear in its queue. |
public static void notifyToolkitThreadFree() {
getInstance().setToolkitBusy(false);
}
Notify that the toolkit thread is waiting for a native event
to appear in its queue. |
final void registerPeer(Object target,
Object peer) {
synchronized (activationLock) {
synchronized (mainLock) {
peerMap.put(target, peer);
notifyPeerMapUpdated();
}
}
}
|
public void run() {
Thread currentThread = Thread.currentThread();
boolean interrupted = false;
synchronized (mainLock) {
try {
/* Notify that the thread is started. */
mainLock.notifyAll();
while (blockerThread == currentThread) {
mainLock.wait();
timeoutPassed = false;
/*
* This loop is introduced to handle the following case:
* it is possible that while we are waiting for the
* safety timeout to pass AWT state can change to
* not-ready-to-shutdown and back to ready-to-shutdown.
* In this case we have to wait once again.
* NOTE: we shouldn't break into the outer loop
* in this case, since we may never be notified
* in an outer infinite wait at this point.
*/
while (isReadyToShutdown()) {
if (timeoutPassed) {
timeoutPassed = false;
blockerThread = null;
break;
}
timeoutPassed = true;
mainLock.wait(SAFETY_TIMEOUT);
}
}
} catch (InterruptedException e) {
interrupted = true;
} finally {
if (blockerThread == currentThread) {
blockerThread = null;
}
}
}
if (!interrupted) {
AppContext.stopEventDispatchThreads();
}
}
Implementation of the Runnable interface.
Incapsulates the blocker thread functionality. |
final void unregisterPeer(Object target,
Object peer) {
synchronized (activationLock) {
synchronized (mainLock) {
if (peerMap.get(target) == peer) {
peerMap.remove(target);
notifyPeerMapUpdated();
}
}
}
}
|