KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > util > WorkingPublicationThread


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23 package org.infoglue.deliver.util;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.apache.log4j.Logger;
30 import org.exolab.castor.jdo.Database;
31 import org.infoglue.cms.controllers.kernel.impl.simple.CastorDatabaseService;
32 import org.infoglue.cms.entities.content.impl.simple.ContentImpl;
33 import org.infoglue.cms.entities.content.impl.simple.DigitalAssetImpl;
34 import org.infoglue.cms.entities.content.impl.simple.MediumContentImpl;
35 import org.infoglue.cms.entities.content.impl.simple.SmallContentImpl;
36 import org.infoglue.cms.entities.management.impl.simple.AvailableServiceBindingImpl;
37 import org.infoglue.cms.entities.management.impl.simple.GroupImpl;
38 import org.infoglue.cms.entities.management.impl.simple.RoleImpl;
39 import org.infoglue.cms.entities.management.impl.simple.SmallAvailableServiceBindingImpl;
40 import org.infoglue.cms.entities.management.impl.simple.SystemUserImpl;
41 import org.infoglue.cms.entities.publishing.impl.simple.PublicationDetailImpl;
42 import org.infoglue.cms.entities.structure.impl.simple.SiteNodeImpl;
43 import org.infoglue.cms.entities.structure.impl.simple.SmallSiteNodeImpl;
44 import org.infoglue.cms.util.CmsPropertyHandler;
45 import org.infoglue.cms.util.NotificationMessage;
46 import org.infoglue.deliver.applications.databeans.CacheEvictionBean;
47 import org.infoglue.deliver.controllers.kernel.impl.simple.DigitalAssetDeliveryController;
48
49 /**
50  * @author mattias
51  *
52  * TODO To change the template for this generated type comment go to
53  * Window - Preferences - Java - Code Style - Code Templates
54  */

55 public class WorkingPublicationThread extends Thread JavaDoc
56 {
57     public final static Logger logger = Logger.getLogger(WorkingPublicationThread.class.getName());
58
59     private List JavaDoc cacheEvictionBeans = new ArrayList JavaDoc();
60     
61     public WorkingPublicationThread()
62     {
63     }
64     
65     public List JavaDoc getCacheEvictionBeans()
66     {
67         return cacheEvictionBeans;
68     }
69
70     public void run()
71     {
72         System.out.println("Hepp...");
73
74         work();
75     }
76     
77     
78     public void work()
79     {
80         //synchronized (cacheEvictionBeans)
81
//{
82

83         logger.info("cacheEvictionBeans.size:" + cacheEvictionBeans.size() + ":" + RequestAnalyser.getRequestAnalyser().getBlockRequests());
84         if(cacheEvictionBeans.size() > 0)
85         {
86             //logger.warn("setting block");
87
//RequestAnalyser.setBlockRequests(true);
88

89             //Database db = null;
90

91             try
92             {
93                 //db = CastorDatabaseService.getDatabase();
94

95                 //int publicationDelay = 50;
96

97                 //logger.info("\n\n\nSleeping " + publicationDelay + "ms.\n\n\n");
98
//sleep(publicationDelay);
99

100                 Iterator JavaDoc i = cacheEvictionBeans.iterator();
101                 while(i.hasNext())
102                 {
103                     CacheEvictionBean cacheEvictionBean = (CacheEvictionBean)i.next();
104                     String JavaDoc className = cacheEvictionBean.getClassName();
105                     String JavaDoc objectId = cacheEvictionBean.getObjectId();
106                     String JavaDoc objectName = cacheEvictionBean.getObjectName();
107                     String JavaDoc typeId = cacheEvictionBean.getTypeId();
108                     
109                     logger.info("className:" + className);
110                     logger.info("objectId:" + objectId);
111                     logger.info("objectName:" + objectName);
112                     logger.info("typeId:" + typeId);
113     
114                     boolean isDependsClass = false;
115                     if(className != null && className.equalsIgnoreCase(PublicationDetailImpl.class.getName()))
116                         isDependsClass = true;
117             
118                     CacheController.clearCaches(className, objectId, null);
119         
120                     logger.info("Updating className with id:" + className + ":" + objectId);
121                     if(className != null && !typeId.equalsIgnoreCase("" + NotificationMessage.SYSTEM))
122                     {
123                         Class JavaDoc type = Class.forName(className);
124         
125                         if(!isDependsClass && className.equalsIgnoreCase(SystemUserImpl.class.getName()) || className.equalsIgnoreCase(RoleImpl.class.getName()) || className.equalsIgnoreCase(GroupImpl.class.getName()))
126                         {
127                             Object JavaDoc[] ids = {objectId};
128                             CacheController.clearCache(type, ids);
129                         }
130                         else if(!isDependsClass)
131                         {
132                             Object JavaDoc[] ids = {new Integer JavaDoc(objectId)};
133                             CacheController.clearCache(type, ids);
134                         }
135         
136                         //If it's an contentVersion we should delete all images it might have generated from attributes.
137
if(Class.forName(className).getName().equals(ContentImpl.class.getName()))
138                         {
139                             logger.info("We clear all small contents as well " + objectId);
140                             Class JavaDoc typesExtra = SmallContentImpl.class;
141                             Object JavaDoc[] idsExtra = {new Integer JavaDoc(objectId)};
142                             CacheController.clearCache(typesExtra, idsExtra);
143             
144                             logger.info("We clear all medium contents as well " + objectId);
145                             Class JavaDoc typesExtraMedium = MediumContentImpl.class;
146                             Object JavaDoc[] idsExtraMedium = {new Integer JavaDoc(objectId)};
147                             CacheController.clearCache(typesExtraMedium, idsExtraMedium);
148                         }
149                         else if(Class.forName(className).getName().equals(AvailableServiceBindingImpl.class.getName()))
150                         {
151                             Class JavaDoc typesExtra = SmallAvailableServiceBindingImpl.class;
152                             Object JavaDoc[] idsExtra = {new Integer JavaDoc(objectId)};
153                             CacheController.clearCache(typesExtra, idsExtra);
154                         }
155                         else if(Class.forName(className).getName().equals(SiteNodeImpl.class.getName()))
156                         {
157                             Class JavaDoc typesExtra = SmallSiteNodeImpl.class;
158                             Object JavaDoc[] idsExtra = {new Integer JavaDoc(objectId)};
159                             CacheController.clearCache(typesExtra, idsExtra);
160                         }
161                         else if(Class.forName(className).getName().equals(DigitalAssetImpl.class.getName()))
162                         {
163                             logger.info("We should delete all images with digitalAssetId " + objectId);
164                             DigitalAssetDeliveryController.getDigitalAssetDeliveryController().deleteDigitalAssets(new Integer JavaDoc(objectId));
165                         }
166                         logger.info("4");
167                     }
168                 }
169             }
170             catch (Exception JavaDoc e)
171             {
172                 logger.error("An error occurred in the WorkingPublicationThread:" + e.getMessage(), e);
173             }
174             /*
175             finally
176             {
177                 try
178                 {
179                     if(db != null)
180                         db.close();
181                 }
182                 catch(Exception e)
183                 {
184                     logger.error("An error occurred in the WorkingPublicationThread:" + e.getMessage(), e);
185                 }
186             }
187             */

188         }
189
190         RequestAnalyser.getRequestAnalyser().setBlockRequests(false);
191         logger.info("released block");
192     }
193 }
194
Popular Tags