/** * @see org.opencms.report.A_CmsReportThread#getReportUpdate() */ @Override public String getReportUpdate() { switch (m_phase) { case 1: return m_deleteThread.getReportUpdate(); case 2: String content; if (m_reportContent != null) { content = m_reportContent; m_reportContent = null; } else { content = ""; } return content + m_importThread.getReportUpdate(); default: // noop } return ""; }
/** * Returns true if this thread is already "doomed" to be deleted.<p> * * A OpenCms deamon Thread (the "Grim Reaper") will collect all * doomed Threads, i.e. threads that are not longer active for some * time.<p> * * @return true if this thread is already "doomed" to be deleted */ public synchronized boolean isDoomed() { if (isAlive()) { // as long as the Thread is still active it is never doomed return false; } if (m_doomed) { // not longer active, and already doomed, so rest in peace... return true; } // condemn the Thread to be collected by the grim reaper next time m_starttime = getRuntime(); m_doomed = true; return false; }
CmsUUID key = (CmsUUID)i.next(); A_CmsReportThread thread = (A_CmsReportThread)m_threads.get(key); if (thread.isDoomed()) { doomed.add(key); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key( Messages.LOG_THREADSTORE_DOOMED_2, thread.getName(), thread.getUUID())); if (thread != null) { if (CmsStringUtil.isEmptyOrWhitespaceOnly(thread.getReportUpdate())) { thread.getName(), thread.getUUID())); thread.interrupt();
m_deleteThread.start(); try { m_deleteThread.join(); } catch (InterruptedException e) { m_reportContent = m_deleteThread.getReportUpdate(); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_REPLACE_THREAD_START_IMPORT_0)); m_importThread.start(); try { m_importThread.join(); } catch (InterruptedException e) {
/** * @see org.opencms.ui.shared.rpc.I_CmsReportServerRpc#requestReportUpdate() */ public void requestReportUpdate() { String reportUpdate = null; if (!m_threadFinished && (m_thread != null)) { // if thread is not alive at this point, there may still be report updates reportUpdate = m_thread.getReportUpdate(); if (!m_thread.isAlive()) { m_threadFinished = true; for (Runnable handler : m_reportFinishedHandlers) { handler.run(); } } } getRpcProxy(I_CmsReportClientRpc.class).handleReportUpdate(reportUpdate); }
/** * Constructs a new report Thread with the given name.<p> * * @param cms the current OpenCms context object * @param name the name of the Thread */ protected A_CmsReportThread(CmsObject cms, String name) { super(OpenCms.getThreadStore().getThreadGroup(), name); // report Threads are never daemon Threads setDaemon(false); // the session in the cms context must not be updated when it is used in a report m_cms = cms; m_cms.getRequestContext().setUpdateSessionEnabled(false); // generate the report Thread id m_id = new CmsUUID(); setName(name + " [" + m_id + "]"); // new Threads are not doomed m_doomed = false; // set start time m_starttime = System.currentTimeMillis(); // add this Thread to the main Thread store OpenCms.getThreadStore().addThread(this); }
/** * Method to dump all currently known Threads.<p> */ private void dumpThreads() { if (LOG.isDebugEnabled()) { StringBuffer b = new StringBuffer(512); Iterator i = m_threads.keySet().iterator(); while (i.hasNext()) { CmsUUID key = (CmsUUID)i.next(); A_CmsReportThread thread = (A_CmsReportThread)m_threads.get(key); b.append(thread.getName()); b.append(" - "); b.append(thread.getUUID()); b.append('\n'); } LOG.debug(Messages.get().getBundle().key( Messages.LOG_THREADSTORE_POOL_CONTENT_2, new Integer(m_threads.size()), b.toString())); } } }
/** * Returns true if the report Thread is still alive (i.e. running), false otherwise.<p> * * @return true if the report Thread is still alive */ public boolean isAlive() { A_CmsReportThread thread = OpenCms.getThreadStore().retrieveThread(m_paramThread); if (thread != null) { return thread.isAlive(); } else { return false; } }
/** * Adds a Thread to this Thread store.<p> * * @param thread the Thread to add */ public void addThread(A_CmsReportThread thread) { m_threads.put(thread.getUUID(), thread); if (LOG.isDebugEnabled()) { dumpThreads(); } }
/** * Returns if the report generated an error output.<p> * * @return true if the report generated an error, otherwise false */ public boolean hasError() { A_CmsReportThread thread = OpenCms.getThreadStore().retrieveThread(m_paramThread); if (thread != null) { return thread.hasError(); } else { return false; } }
m_deleteThread.start(); try { m_deleteThread.join(); } catch (InterruptedException e) { m_reportContent = m_deleteThread.getReportUpdate(); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_REPLACE_THREAD_START_IMPORT_0)); m_importThread.start(); try { m_importThread.join(); } catch (InterruptedException e) {
/** * Constructs a new report Thread with the given name.<p> * * @param cms the current OpenCms context object * @param name the name of the Thread */ protected A_CmsReportThread(CmsObject cms, String name) { super(OpenCms.getThreadStore().getThreadGroup(), name); // report Threads are never daemon Threads setDaemon(false); // the session in the cms context must not be updated when it is used in a report m_cms = cms; m_cms.getRequestContext().setUpdateSessionEnabled(false); // generate the report Thread id m_id = new CmsUUID(); setName(name + " [" + m_id + "]"); // new Threads are not doomed m_doomed = false; // set start time m_starttime = System.currentTimeMillis(); // add this Thread to the main Thread store OpenCms.getThreadStore().addThread(this); }
/** * Method to dump all currently known Threads.<p> */ private void dumpThreads() { if (LOG.isDebugEnabled()) { StringBuffer b = new StringBuffer(512); Iterator<CmsUUID> i = m_threads.keySet().iterator(); while (i.hasNext()) { CmsUUID key = i.next(); A_CmsReportThread thread = m_threads.get(key); b.append(thread.getName()); b.append(" - "); b.append(thread.getUUID()); b.append('\n'); } LOG.debug( Messages.get().getBundle().key( Messages.LOG_THREADSTORE_POOL_CONTENT_2, new Integer(m_threads.size()), b.toString())); } } }
/** * Returns true if the report Thread is still alive (i.e. running), false otherwise.<p> * * @return true if the report Thread is still alive */ public boolean isAlive() { A_CmsReportThread thread = OpenCms.getThreadStore().retrieveThread(m_paramThread); if (thread != null) { return thread.isAlive(); } else { return false; } }
/** * Adds a Thread to this Thread store.<p> * * @param thread the Thread to add */ public void addThread(A_CmsReportThread thread) { m_threads.put(thread.getUUID(), thread); if (LOG.isDebugEnabled()) { dumpThreads(); } }
/** * Returns if the report generated an error output.<p> * * @return true if the report generated an error, otherwise false */ public boolean hasError() { A_CmsReportThread thread = OpenCms.getThreadStore().retrieveThread(m_paramThread); if (thread != null) { return thread.hasError(); } else { return false; } }
/** * Returns true if this thread is already "doomed" to be deleted.<p> * * A OpenCms deamon Thread (the "Grim Reaper") will collect all * doomed Threads, i.e. threads that are not longer active for some * time.<p> * * @return true if this thread is already "doomed" to be deleted */ public synchronized boolean isDoomed() { if (isAlive()) { // as long as the Thread is still active it is never doomed return false; } if (m_doomed) { // not longer active, and already doomed, so rest in peace... return true; } // condemn the Thread to be collected by the grim reaper next time m_starttime = getRuntime(); m_doomed = true; return false; }
/** * @see org.opencms.report.A_CmsReportThread#getReportUpdate() */ @Override public String getReportUpdate() { switch (m_phase) { case 1: return m_deleteThread.getReportUpdate(); case 2: String content; if (m_reportContent != null) { content = m_reportContent; m_reportContent = null; } else { content = ""; } return content + m_importThread.getReportUpdate(); default: // noop } return ""; }