if ((m_offlineIndexThread == null) || !m_offlineIndexThread.isAlive()) { m_offlineIndexThread = new CmsSearchOfflineIndexThread(this); m_offlineIndexThread.start(); if ((m_offlineIndexThread != null) && m_offlineIndexThread.isAlive()) { m_offlineIndexThread.shutDown(); m_offlineIndexThread = null;
/** * Shuts down this offline index thread.<p> */ protected void shutDown() { m_isAlive = false; interrupt(); if (m_isUpdating) { long waitTime = getOfflineUpdateFrequency() / 2; int waitSteps = 0; do { try { // wait half the time of the offline index frequency for the thread to finish Thread.sleep(waitTime); } catch (InterruptedException e) { // continue LOG.info(e.getLocalizedMessage(), e); } waitSteps++; // wait 5 times then stop waiting } while ((waitSteps < 5) && m_isUpdating); } }
/** * Obtains the list of resource to update in the offline index, * then optimizes the list by removing duplicate entries.<p> * * @return the list of resource to update in the offline index */ protected List<CmsPublishedResource> getResourcesToIndex() { List<CmsPublishedResource> resourcesToIndex = m_handler.getResourcesToIndex(); List<CmsPublishedResource> result = new ArrayList<CmsPublishedResource>(resourcesToIndex.size()); // Reverse to always keep the last list entries Collections.reverse(resourcesToIndex); for (CmsPublishedResource pubRes : resourcesToIndex) { boolean addResource = true; for (CmsPublishedResource resRes : result) { if (pubRes.equals(resRes) && (pubRes.getState() == resRes.getState()) && (pubRes.getMovedState() == resRes.getMovedState()) && pubRes.getRootPath().equals(resRes.getRootPath())) { // resource already in the update list addResource = false; break; } } if (addResource) { result.add(pubRes); } } Collections.reverse(result); return changeStateOfMoveOriginsToDeleted(result); }
if (!m_updateTriggered) { try { sleep(offlineUpdateFrequency); } catch (InterruptedException e) { List<CmsPublishedResource> resourcesToIndex = getResourcesToIndex(); if (resourcesToIndex.size() > 0) { startOfflineUpdateThread(report, resourcesToIndex); } else { getWaitHandle().release(); interrupted();
if ((m_offlineIndexThread == null) || !m_offlineIndexThread.isAlive()) { m_offlineIndexThread = new CmsSearchOfflineIndexThread(this); m_offlineIndexThread.start(); if ((m_offlineIndexThread != null) && m_offlineIndexThread.isAlive()) { m_offlineIndexThread.shutDown(); m_offlineIndexThread = null;
/** * Shuts down the search manager.<p> * * This will cause all search indices to be shut down.<p> */ public void shutDown() { if (m_offlineIndexThread != null) { m_offlineIndexThread.shutDown(); } if (m_offlineHandler != null) { OpenCms.removeCmsEventListener(m_offlineHandler); } Iterator<CmsSearchIndex> i = m_indexes.iterator(); while (i.hasNext()) { CmsSearchIndex index = i.next(); index.shutDown(); index = null; } m_indexes.clear(); shutDownSolrContainer(); if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SHUTDOWN_MANAGER_0)); } }
/** * @see java.lang.Thread#run() */ @Override public void run() { // create a log report for the output I_CmsReport report = new CmsLogReport(m_adminCms.getRequestContext().getLocale(), CmsSearchManager.class); try { while (m_isAlive) { List<CmsPublishedResource> resourcesToIndex = getResourcesToIndex(); if (resourcesToIndex.size() > 0) { // only start indexing if there is at least one resource updateIndexOffline(report, resourcesToIndex); } try { sleep(OpenCms.getSearchManager().getOfflineUpdateFrequency()); } catch (InterruptedException e) { // continue the thread after interruption } } } finally { // make sure that live status is reset in case of Exceptions m_isAlive = false; } }
/** * Shuts down the search manager.<p> * * This will cause all search indices to be shut down.<p> */ public void shutDown() { if (m_offlineIndexThread != null) { m_offlineIndexThread.shutDown(); } Iterator<CmsSearchIndex> i = m_indexes.iterator(); while (i.hasNext()) { CmsSearchIndex index = i.next(); try { index.shutDown(); } catch (IOException e) { LOG.error(Messages.get().getBundle().key(Messages.ERR_INDEX_SHUTDOWN_1, index.getName()), e); } } if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SHUTDOWN_MANAGER_0)); } }
/** * Updates all offline indexes.<p> * * Can be used to force an index update when it's not convenient to wait until the * offline update interval has eclipsed.<p> * * Since the offline index will still need some time to update the new resources even if it runs directly, * a wait time of 2500 or so should be given in order to make sure the index finished updating. * * @param waitTime milliseconds to wait after the offline update index was notified of the changes */ public void updateOfflineIndexes(long waitTime) { if ((m_offlineIndexThread != null) && m_offlineIndexThread.isAlive()) { // notify existing thread of update frequency change if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_OI_UPDATE_INTERRUPT_0)); } m_offlineIndexThread.interrupt(); if (waitTime > 0) { m_offlineIndexThread.getWaitHandle().enter(waitTime); } } }
/** * @see java.lang.Thread#run() */ @Override public void run() { updateIndexOffline(m_report, m_resourcesToIndex); if (m_offlineIndexThread != null) { m_offlineIndexThread.getWaitHandle().release(); } } }
/** * Shuts down this offline index thread.<p> */ protected void shutDown() { m_isAlive = false; interrupt(); } }