KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > daemon > impl > BadURLManagerDaemon


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;
18
19 //jetspeed stuff
20
import org.apache.jetspeed.daemon.Daemon;
21 import org.apache.jetspeed.daemon.DaemonConfig;
22 import org.apache.jetspeed.daemon.DaemonEntry;
23 import org.apache.jetspeed.cache.disk.DiskCacheUtils;
24 import org.apache.jetspeed.cache.disk.JetspeedDiskCache;
25 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
26 import org.apache.jetspeed.services.logging.JetspeedLogger;
27 import org.apache.jetspeed.services.urlmanager.URLManager;
28 import org.apache.jetspeed.services.urlmanager.URLFetcher;
29
30 //java stuff
31
import java.io.IOException JavaDoc;
32 import java.util.Iterator JavaDoc;
33
34 /**
35 Manages pulling URLs from the BadURLManager, and if they are available, removing
36 them from the BadURLManager and placing them in the DiskCache.
37
38 @author <A HREF="mailto:burton@apache.org">Kevin A. Burton</A>
39 @version $Id: BadURLManagerDaemon.java,v 1.14 2004/02/23 02:48:05 jford Exp $
40 */

41 public class BadURLManagerDaemon implements Daemon {
42     
43     private int status = Daemon.STATUS_NOT_PROCESSED;
44     private int result = Daemon.RESULT_UNKNOWN;
45     private DaemonConfig config = null;
46     private DaemonEntry entry = null;
47
48     /**
49      * Static initilization of the logger for this class
50      */

51     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(BadURLManagerDaemon.class.getName());
52     
53     /**
54     Go over all the documents on the system and if refresh them if necessary.
55     */

56     public void run() {
57         
58         logger.info("Checking for valid URLs within the URLManager");
59
60         this.setResult( Daemon.RESULT_PROCESSING );
61         
62         Iterator JavaDoc i = URLManager.list().iterator();
63         
64         while ( i.hasNext() ) {
65
66             String JavaDoc url = (String JavaDoc)i.next();
67             
68             // we only want to process bad URLs...
69
if ( URLManager.isOK( url ) ) continue;
70             
71             try {
72     
73                 URLManager.unregister(url);
74
75                 logger.info("Removing " + url + " from BadURL list" );
76                 this.save();
77
78                 //FIXME: It should check refresh of the portlets, like DiskCache...
79
URLFetcher.refresh(url);
80
81                 
82             } catch ( Throwable JavaDoc t ) {
83                 //don't do anything here because the URL for this has a good
84
//chance of being invalid anyway.
85
logger.error("Invalid URL?", t);
86                 if ( DiskCacheUtils.isCached( url ) ) {
87                     try {
88                         //To avoid interference with the Disk Cache refreshing
89
JetspeedDiskCache.getInstance().remove( url );
90                     } catch (IOException JavaDoc ioe) {}
91                 }
92                 logger.info("Failed to load: " + url + " from BadURL list");
93             }
94             
95         }
96         
97         this.setResult( Daemon.RESULT_SUCCESS );
98     }
99
100     /**
101     */

102     public void init( DaemonConfig config,
103                       DaemonEntry entry ) {
104         this.config = config;
105         this.entry = entry;
106     }
107     
108     /**
109     */

110     public DaemonConfig getDaemonConfig() {
111         return this.config;
112     }
113
114     /**
115     */

116     public DaemonEntry getDaemonEntry() {
117         return this.entry;
118     }
119     
120     /**
121     Return the status for this Daemon
122
123     @see Daemon#STATUS_NOT_PROCESSED
124     @see Daemon#STATUS_PROCESSED
125     @see Daemon#STATUS_PROCESSING
126     */

127     public int getStatus() {
128         return this.status;
129     }
130     
131     /**
132     Set the status for this Daemon
133
134     @see #STATUS_NOT_PROCESSED
135     @see #STATUS_PROCESSED
136     @see #STATUS_PROCESSING
137     */

138     public void setStatus(int status) {
139         this.status = status;
140     }
141
142     /**
143     @see Daemon#getResult()
144     */

145     public int getResult() {
146         return this.result;
147     }
148
149     /**
150     @see Daemon#setResult(int result)
151     */

152     public void setResult( int result ) {
153         this.result = result;
154     }
155     
156     /**
157     @see Daemon#getMessage()
158     */

159     public String JavaDoc getMessage() {
160         return null;
161     }
162
163     /**
164     Require that the BadURLManager save its configuration here.
165     */

166     public void save() {
167
168         // RL: What should be persisted here ?
169
// BadURLManager.getInstance().save();
170

171     }
172
173     public void restore() { /* noop */ }
174
175     
176     
177 }
178
179
Popular Tags