Search in sources :

Example 1 with ProgressItem

use of org.apache.wiki.ui.progress.ProgressItem in project jspwiki by apache.

the class SearchManagerBean method reload.

/**
 *  Starts a background thread which goes through all the pages and adds them
 *  to the reindex queue.
 *  <p>
 *  This method prevents itself from being called twice.
 */
public synchronized void reload() {
    if (m_updater == null) {
        m_updater = new WikiBackgroundThread(m_engine, 0) {

            int m_count;

            int m_max;

            public void startupTask() throws Exception {
                super.startupTask();
                setName("Reindexer started");
            }

            @SuppressWarnings("unchecked")
            public void backgroundTask() throws Exception {
                Collection<WikiPage> allPages = m_engine.getPageManager().getAllPages();
                SearchManager mgr = m_engine.getSearchManager();
                m_max = allPages.size();
                ProgressItem pi = new ProgressItem() {

                    public int getProgress() {
                        return 100 * m_count / m_max;
                    }
                };
                m_engine.getProgressManager().startProgress(pi, PROGRESS_ID);
                for (WikiPage page : allPages) {
                    mgr.reindexPage(page);
                    m_count++;
                }
                m_engine.getProgressManager().stopProgress(PROGRESS_ID);
                shutdown();
                m_updater = null;
            }
        };
        m_updater.start();
    }
}
Also used : SearchManager(org.apache.wiki.search.SearchManager) WikiPage(org.apache.wiki.WikiPage) Collection(java.util.Collection) WikiBackgroundThread(org.apache.wiki.WikiBackgroundThread) ProgressItem(org.apache.wiki.ui.progress.ProgressItem) NotCompliantMBeanException(javax.management.NotCompliantMBeanException)

Aggregations

Collection (java.util.Collection)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 WikiBackgroundThread (org.apache.wiki.WikiBackgroundThread)1 WikiPage (org.apache.wiki.WikiPage)1 SearchManager (org.apache.wiki.search.SearchManager)1 ProgressItem (org.apache.wiki.ui.progress.ProgressItem)1