KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > daemon > impl > util > diskcachedaemon > URLRefresher


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.jetspeed.daemon.impl.util.diskcachedaemon;
18
19 //jetspeed stuff
20
import org.apache.jetspeed.om.registry.PortletEntry;
21 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
22 import org.apache.jetspeed.services.logging.JetspeedLogger;
23 import org.apache.jetspeed.services.Registry;
24 import org.apache.jetspeed.services.urlmanager.URLFetcher;
25
26 //Java stuff
27
import java.util.Enumeration;
28
29 /**
30 <p>
31 URLRefresher that checks if a URL is updated remotely. If it is then it will
32 pull the new URL down and try to reinstantiate all Portlets that depend on this
33 URL.
34 </p>
35
36 @author <A HREF="mailto:burton@apache.org">Kevin A. Burton</A>
37 @version $Id: URLRefresher.java,v 1.16 2004/02/23 02:47:00 jford Exp $
38 */

39 public class URLRefresher implements Runnable {
40
41     private String url = null;
42     
43     /**
44      * Static initialization of the logger for this class
45      */

46     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(URLRefresher.class.getName());
47     
48     /**
49     default constructor
50     */

51     public URLRefresher( String url ) {
52         
53         this.url = url;
54         
55     }
56     
57     /**
58     Used within the ThreadPool... IE Runnable interface.
59     */

60     public void run() {
61         
62         try {
63
64             //only update this if the URL on which it is based is newer
65
//than the one on disk.
66
if(URLFetcher.refresh(url)) {
67                 //now make sure that the entry that depends on this HREF
68
//is updated in the PortletFactory.
69

70                 
71                 //create a Runnable for updating this Portlet in the cache.
72

73                 Enumeration enum = Registry.get(Registry.PORTLET).getEntries();
74                     
75                 while( enum.hasMoreElements() ) {
76                     PortletEntry entry = (PortletEntry)enum.nextElement();
77                     
78                     if ( (entry.getURL()!= null) && entry.getURL().equals(url) )
79                     {
80                         try
81                         {
82                             PortletRefresher pr = new PortletRefresher( entry );
83                         
84                             //now put this Instantiator in the ThreadPool so that
85
//it can execute.
86
//SGP Trying to intersperse CPU intensive tasks with
87
// network intensive tasks
88
pr.run();
89                             //ThreadPool.process( pr );
90
}
91                         catch (Throwable t)
92                         {
93                             //FIXME: Put it in the bad URL list
94
logger.info( "DiskCacheDaemon: Error refreshing: " + url );
95                         }
96                     }
97                 }
98             }
99         } catch ( Throwable t ) {
100             logger.error("Error refreshing URL", t);
101         }
102     }
103 }
104
Popular Tags