/** Processes requests on the main thread. */ @Override public boolean handleMessage(Message msg) { switch (msg.what) { case MESSAGE_REQUEST_LOADING: { mLoadingRequested = false; if (!mPaused) { if (mLoaderThread == null) { mLoaderThread = new LoaderThread(mContext.getContentResolver()); mLoaderThread.start(); } mLoaderThread.requestLoading(); } return true; } case MESSAGE_PHOTOS_LOADED: { if (!mPaused) { processLoadedImages(); } return true; } } return false; }
private void startLoaderThreadIfStopped() { if (loaderThread == null) { loaderThread = new LoaderThread(); loaderThread.start(); } }
private void dispose() { lock.lock(); if (loaderThread != null) { loaderThread.isCancelled = true; loaderThread = null; } condition.signal(); lock.unlock(); }
/** Stops loading images, kills the image loader thread and clears all caches. */ public void stop() { pause(); if (mLoaderThread != null) { mLoaderThread.quit(); mLoaderThread = null; } mPendingRequests.clear(); mBitmapCache.clear(); }
/** Shutdown the build-in indexing thread and wait until it dies. */ public void shutdown() { synchronized (this) { _stop = true; this.notifyAll(); } try { _loadMgrThread.join(); } catch (InterruptedException e) { log.error(e.getMessage(), e); } }
/** @see proj.zoie.api.DataConsumer#consume(java.util.Collection) */ public void consume(Collection<DataEvent<V>> events) throws ZoieException { if (events != null) { // PriorityQueue<DataEvent<ZoieIndexable>> indexableList = new // PriorityQueue<DataEvent<ZoieIndexable>>(data.size(), DataEvent.getComparator()); ArrayList<DataEvent<ZoieIndexable>> indexableList = new ArrayList<DataEvent<ZoieIndexable>>(events.size()); Iterator<DataEvent<V>> iter = events.iterator(); while (iter.hasNext()) { try { DataEvent<V> event = iter.next(); ZoieIndexable indexable = ((ZoieIndexableInterpreter<V>) _interpreter).convertAndInterpret(event.getData()); DataEvent<ZoieIndexable> newEvent = new DataEvent<ZoieIndexable>(event.getVersion(), indexable); indexableList.add(newEvent); } catch (Exception e) { log.error(e.getMessage(), e); } } synchronized (this) // this blocks the batch disk loader thread while indexing to RAM { while (_batchList.size() > _maxBatchSize) { // check if load manager thread is alive if (_loadMgrThread == null || !_loadMgrThread.isAlive()) { throw new ZoieException("load manager has stopped"); } try { this.wait(60000); // 1 min } catch (InterruptedException e) { continue; } } _eventCount += indexableList.size(); _batchList.addAll(indexableList); this.notifyAll(); } } }
/** * @param dataLoader * @param batchSize * @param maxBatchSize * @param delay * @param idxMgr * @param lsnrList the list of IndexingEventListeners. This should be a <b>Synchronized</b> list * if the content of this list is mutable. */ public BatchedIndexDataLoader( DataConsumer<ZoieIndexable> dataLoader, int batchSize, int maxBatchSize, long delay, SearchIndexManager<R> idxMgr, ZoieIndexableInterpreter<V> interpreter, Queue<IndexingEventListener> lsnrList) { _maxBatchSize = Math.max(maxBatchSize, 1); _batchSize = Math.min(batchSize, _maxBatchSize); _delay = delay; _dataLoader = dataLoader; _batchList = new LinkedList<DataEvent<ZoieIndexable>>(); _lastFlushTime = 0L; _eventCount = 0; _loadMgrThread = new LoaderThread(); _loadMgrThread.setName("disk indexer data loader"); _stop = false; _flush = false; _idxMgr = idxMgr; _interpreter = interpreter; _lsnrList = lsnrList; }
/** Call this from the activity's onPause() */ public void stopBackgroundThread() { mLoaderThread.shutdown(); }
/** Call this from the activity's onResume() */ public void startBackgroundThread() { mLoaderThread = new LoaderThread(mLoaderQueue, this); mLoaderThread.start(); }
/** Starts the build-in indexing thread. */ public void start() { _loadMgrThread.setName(String.valueOf(this)); _loadMgrThread.start(); }