3909N/A * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * An ImageFetcher is a thread used to fetch ImageFetchable objects. 0N/A * Once an ImageFetchable object has been fetched, the ImageFetcher 0N/A * thread may also be used to animate it if necessary, via the 0N/A * startingAnimation() / stoppingAnimation() methods. 0N/A * There can be up to FetcherInfo.MAX_NUM_FETCHERS_PER_APPCONTEXT 0N/A * ImageFetcher threads for each AppContext. A per-AppContext queue 0N/A * of ImageFetchables is used to track objects to fetch. 0N/A * @author Jim Graham 0N/A static final int TIMEOUT =
5000;
// Time in milliseconds to wait for an 0N/A // ImageFetchable to be added to the 0N/A // queue before an ImageFetcher dies 0N/A * Constructor for ImageFetcher -- only called by add() below. 0N/A * Adds an ImageFetchable to the queue of items to fetch. Instantiates 0N/A * a new ImageFetcher if it's reasonable to do so. 3536N/A * If there is no available fetcher to process an ImageFetchable, then 3536N/A * reports failure to caller. 3536N/A /* Creation of new fetcher may fail due to high vm load 3536N/A * If there is already exist, but busy, fetcher, we leave 3536N/A * the src in queue (it will be handled by existing 3536N/A * Otherwise, we report failure: there is no fetcher 0N/A * Removes an ImageFetchable from the queue of items to fetch. 0N/A * Checks to see if the given thread is one of the ImageFetchers. 0N/A * Checks to see if the current thread is one of the ImageFetchers. 0N/A * Returns the next ImageFetchable to be processed. If TIMEOUT 0N/A * elapses in the mean time, or if the ImageFetcher is interrupted, 0N/A // A normal occurrence as an AppContext is disposed 0N/A * The main run() method of an ImageFetcher Thread. Calls fetchloop() 0N/A * to do the work, then removes itself from the array of ImageFetchers. 0N/A * The main ImageFetcher loop. Repeatedly calls nextImage(), and 0N/A * fetches the returned ImageFetchable objects until nextImage() 0N/A // we're ignoring the return value and just clearing 0N/A // the interrupted flag, instead of bailing out if 0N/A // the fetcher was interrupted, as we used to, 0N/A // because there may be other images waiting 0N/A // to be fetched (see 4789067) 0N/A * Recycles this ImageFetcher thread as an image animator thread. 0N/A * Removes this ImageFetcher from the array of ImageFetchers, and 0N/A * resets the thread name to "ImageAnimator". 0N/A * Returns this image animator thread back to service as an ImageFetcher 0N/A * if possible. Puts it back into the array of ImageFetchers and sets 0N/A * the thread name back to "Image Fetcher". If there are already the 0N/A * maximum number of ImageFetchers, this method simply returns, and 0N/A * fetchloop() will drop out when it sees that this thread isn't one of 0N/A * the ImageFetchers, and this thread will die. 0N/A * Create and start ImageFetcher threads in the appropriate ThreadGroup. 0N/A // We need to instantiate a new ImageFetcher thread. 0N/A // First, figure out which ThreadGroup we'll put the 0N/A // new ImageFetcher into 0N/A // threadGroup is not the root, so we proceed 0N/A // threadGroup is the root ("system") ThreadGroup. 0N/A // We instead want to use its child: the "main" 0N/A // ThreadGroup. Thus, we start with the current 0N/A // ThreadGroup, and go up the tree until 0N/A // threadGroup.getParent().getParent() == null. 0N/A // Not allowed access to parent ThreadGroup -- just use 0N/A // the AppContext's ThreadGroup 0N/A * The FetcherInfo class encapsulates the per-AppContext ImageFetcher 0N/A * information. This includes the array of ImageFetchers, as well as 0N/A * the queue of ImageFetchable objects. 0N/A /* The key to put()/get() the FetcherInfo into/from the AppContext. */