KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > staticexport > A_CmsOnDemandStaticExportHandler


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/staticexport/A_CmsOnDemandStaticExportHandler.java,v $
3  * Date : $Date: 2006/03/27 14:52:43 $
4  * Version: $Revision: 1.21 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.staticexport;
33
34 import org.opencms.main.CmsLog;
35 import org.opencms.main.OpenCms;
36 import org.opencms.report.I_CmsReport;
37 import org.opencms.util.CmsUUID;
38
39 import org.apache.commons.logging.Log;
40
41 /**
42  * Abstract implementation for the <code>{@link I_CmsStaticExportHandler}</code> interface.<p>
43  *
44  * This handler is most suitable for dynamic sites that use the static export
45  * as optimization for non-dynamic content.<p>
46  *
47  * @author Michael Moossen
48  *
49  * @version $Revision: 1.21 $
50  *
51  * @since 6.0.0
52  *
53  * @see I_CmsStaticExportHandler
54  */

55 public abstract class A_CmsOnDemandStaticExportHandler extends A_CmsStaticExportHandler
56 implements I_CmsStaticExportHandler {
57
58     /** The log object for this class. */
59     private static final Log LOG = CmsLog.getLog(A_CmsOnDemandStaticExportHandler.class);
60
61     /**
62      * @see org.opencms.staticexport.I_CmsStaticExportHandler#performEventPublishProject(org.opencms.util.CmsUUID, org.opencms.report.I_CmsReport)
63      */

64     public void performEventPublishProject(CmsUUID publishHistoryId, I_CmsReport report) {
65
66         int count = 0;
67         // if the handler is still running, we must wait up to 30 secounds until it is finished
68
while ((count < CmsStaticExportManager.HANDLER_FINISH_TIME) && isBusy()) {
69             count++;
70             try {
71                 if (LOG.isInfoEnabled()) {
72                     LOG.info(Messages.get().getBundle().key(
73                         Messages.LOG_WAITING_STATIC_EXPORT_3,
74                         getClass().getName(),
75                         new Integer JavaDoc(count),
76                         new Integer JavaDoc(CmsStaticExportManager.HANDLER_FINISH_TIME)));
77                 }
78                 Thread.sleep(1000);
79             } catch (InterruptedException JavaDoc e) {
80                 // if interrupted we ignore the handler, this will produce some log messages but should be ok
81
count = CmsStaticExportManager.HANDLER_FINISH_TIME;
82             }
83         }
84
85         if (isBusy()) {
86             // if the handler is still busy write a warning to the log and exit
87
Object JavaDoc[] arguments = new Object JavaDoc[] {
88                 publishHistoryId,
89                 new Integer JavaDoc(CmsStaticExportManager.HANDLER_FINISH_TIME)};
90             LOG.error(Messages.get().getBundle().key(Messages.LOG_SCRUBBING_FOLDER_FAILED_2, arguments));
91
92             return;
93         }
94
95         final CmsUUID id = publishHistoryId;
96
97         if (OpenCms.getRunLevel() >= OpenCms.RUNLEVEL_1_CORE_OBJECT) {
98             // only perform scrubbing if OpenCms is still running
99
m_busy = true;
100             Thread JavaDoc t = new Thread JavaDoc(new Runnable JavaDoc() {
101
102                 public void run() {
103
104                     try {
105                         scrubExportFolders(id);
106                     } finally {
107                         m_busy = false;
108                     }
109                 }
110             }, Messages.get().getBundle().key(Messages.GUI_THREAD_NAME_SCRUB_EXPORT_FOLDERS_1, String.valueOf(id)));
111             t.start();
112         }
113     }
114 }
Popular Tags