KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > applications > actions > UpdateCacheAction


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
24
25 package org.infoglue.deliver.applications.actions;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31
32 import org.apache.log4j.Logger;
33 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
34 import org.infoglue.cms.controllers.kernel.impl.simple.ServerNodeController;
35 import org.infoglue.cms.util.CmsPropertyHandler;
36 import org.infoglue.deliver.applications.databeans.CacheEvictionBean;
37 import org.infoglue.deliver.util.CacheController;
38 import org.infoglue.deliver.util.RequestAnalyser;
39 import org.infoglue.deliver.util.ThreadMonitor;
40
41
42 /**
43  * This is the action that takes care of all incoming update-calls. This action is
44  * called by either the system or by replication-program and the class the distibutes the
45  * update-call to all the listeners which have registered earlier.
46  *
47  * @author Mattias Bogeblad
48  */

49
50 public class UpdateCacheAction extends InfoGlueAbstractAction
51 {
52     private final static Logger logger = Logger.getLogger(UpdateCacheAction.class.getName());
53
54     /*
55     private String className = null;
56     private String objectId = null;
57     private String objectName = null;
58     private String typeId = null;
59     */

60     
61     private String JavaDoc repositoryName = null;
62     private Integer JavaDoc languageId = null;
63     private Integer JavaDoc siteNodeId = null;
64     
65     private static boolean cachingInProgress = false;
66     
67     private ThreadMonitor tk = null;
68
69     /**
70      * The constructor for this action - contains nothing right now.
71      */

72     
73     public UpdateCacheAction()
74     {
75     
76     }
77     
78     /**
79      * This method will just reply to a testcall.
80      */

81          
82     public String JavaDoc doTest() throws Exception JavaDoc
83     {
84         String JavaDoc operatingMode = CmsPropertyHandler.getOperatingMode();
85         
86         if(operatingMode != null && operatingMode.equalsIgnoreCase("3"))
87         {
88             if(!ServerNodeController.getController().getIsIPAllowed(this.getRequest()))
89             {
90                 this.getResponse().setContentType("text/plain");
91                 this.getResponse().setStatus(HttpServletResponse.SC_FORBIDDEN);
92                 this.getResponse().getWriter().println("You have no access to this view - talk to your administrator if you should.");
93                 
94                 return NONE;
95             }
96         }
97         
98         this.getResponse().getWriter().println("test ok - cache action available");
99         
100         //this.getHttpSession().invalidate();
101

102         return NONE;
103     }
104     
105     /**
106      * This method is the application entry-point. The parameters has been set through the setters
107      * and now we just have to render the appropriate output.
108      */

109          
110     public String JavaDoc doExecute() throws Exception JavaDoc
111     {
112         if(!CmsPropertyHandler.getOperatingMode().equals("3"))
113             tk = new ThreadMonitor(2000, this.getRequest(), "Update cache took to long", false);
114
115         logger.info("Update Cache starts..");
116         String JavaDoc operatingMode = CmsPropertyHandler.getOperatingMode();
117         
118         if(operatingMode != null && operatingMode.equalsIgnoreCase("3"))
119         {
120             long start = System.currentTimeMillis();
121             if(!ServerNodeController.getController().getIsIPAllowed(this.getRequest()))
122             {
123                 this.getResponse().setContentType("text/plain");
124                 this.getResponse().setStatus(HttpServletResponse.SC_FORBIDDEN);
125                 this.getResponse().getWriter().println("You have no access to this view - talk to your administrator if you should.");
126                 
127                 return NONE;
128             }
129             
130         }
131         
132         try
133         {
134             //Iterate through all registered listeners and call them... dont place logic here... have specialized handlers.
135

136             //logger.info("className:" + className);
137
//logger.info("objectId:" + objectId);
138
List JavaDoc newNotificationList = new ArrayList JavaDoc();
139             
140             int i = 0;
141             
142             String JavaDoc className = this.getRequest().getParameter(i + ".className");
143             String JavaDoc typeId = this.getRequest().getParameter(i + ".typeId");
144             String JavaDoc objectId = this.getRequest().getParameter(i + ".objectId");
145             String JavaDoc objectName = this.getRequest().getParameter(i + ".objectName");
146             while(className != null && !className.equals(""))
147             {
148                 logger.info("className:" + className);
149                 logger.info("objectId:" + objectId);
150                 
151                 CacheEvictionBean cacheEvictionBean = new CacheEvictionBean(className, typeId, objectId, objectName);
152                 newNotificationList.add(cacheEvictionBean);
153                 /*
154                 synchronized(CacheController.notifications)
155                 {
156                     CacheController.notifications.add(cacheEvictionBean);
157                 }
158                 */

159                 logger.info("Added a cacheEvictionBean " + cacheEvictionBean.getClassName() + ":" + cacheEvictionBean.getTypeId() + ":" + cacheEvictionBean.getObjectName() + ":" + cacheEvictionBean.getObjectId());
160                 
161                 i++;
162                 className = this.getRequest().getParameter(i + ".className");
163                 typeId = this.getRequest().getParameter(i + ".typeId");
164                 objectId = this.getRequest().getParameter(i + ".objectId");
165                 objectName = this.getRequest().getParameter(i + ".objectName");
166             }
167             
168             if(i == 0)
169             {
170                 className = this.getRequest().getParameter("className");
171                 typeId = this.getRequest().getParameter("typeId");
172                 objectId = this.getRequest().getParameter("objectId");
173                 objectName = this.getRequest().getParameter("objectName");
174                 CacheEvictionBean cacheEvictionBean = new CacheEvictionBean(className, typeId, objectId, objectName);
175                 newNotificationList.add(cacheEvictionBean);
176                 /*
177                 synchronized(CacheController.notifications)
178                 {
179                     CacheController.notifications.add(cacheEvictionBean);
180                 }
181                 logger.warn("Added an oldSchool cacheEvictionBean " + cacheEvictionBean.getClassName() + ":" + cacheEvictionBean.getTypeId() + ":" + cacheEvictionBean.getObjectName() + ":" + cacheEvictionBean.getObjectId());
182                 */

183                 
184             }
185             
186             /*
187             //TODO - place check here maybe??
188             synchronized(RequestAnalyser.getRequestAnalyser())
189             {
190                 if(RequestAnalyser.getRequestAnalyser().getBlockRequests())
191                 {
192                     logger.warn("evictWaitingCache allready in progress - returning to avoid conflict");
193                     return;
194                 }
195
196                 RequestAnalyser.getRequestAnalyser().setBlockRequests(true);
197             }
198             */

199             
200             //synchronized(this)
201
//{
202
synchronized(CacheController.notifications)
203                 {
204                     CacheController.notifications.addAll(newNotificationList);
205                 }
206             //}
207

208             logger.info("UpdateCache finished...");
209         }
210         catch(Exception JavaDoc e)
211         {
212             logger.error(e.getMessage(), e);
213         }
214         catch(Throwable JavaDoc t)
215         {
216             logger.error(t.getMessage());
217         }
218                 
219         //this.getHttpSession().invalidate();
220
logger.info("Update Cache stops..");
221
222         if(tk != null)
223             tk.done();
224
225         return NONE;
226     }
227     
228     
229     /**
230      * Setters and getters for all things sent to the page in the request
231      */

232     /*
233     public void setClassName(String className)
234     {
235         this.className = className;
236     }
237         
238     public void setObjectId(String objectId)
239     {
240         this.objectId = objectId;
241     }
242
243     public void setObjectName(String objectName)
244     {
245         this.objectName = objectName;
246     }
247
248     public void setTypeId(String typeId)
249     {
250         this.typeId = typeId;
251     }
252     */

253 }
254
Popular Tags