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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.daemon.impl;
1819//jetspeed stuff20import org.apache.jetspeed.daemon.Daemon;
21import org.apache.jetspeed.daemon.DaemonConfig;
22import org.apache.jetspeed.daemon.DaemonEntry;
23import org.apache.jetspeed.cache.disk.DiskCacheUtils;
24import org.apache.jetspeed.cache.disk.JetspeedDiskCache;
25import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
26import org.apache.jetspeed.services.logging.JetspeedLogger;
27import org.apache.jetspeed.services.urlmanager.URLManager;
28import org.apache.jetspeed.services.urlmanager.URLFetcher;
2930//java stuff31import java.io.IOException;
32import java.util.Iterator;
3334/***35Manages pulling URLs from the BadURLManager, and if they are available, removing36them from the BadURLManager and placing them in the DiskCache.3738@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*/41publicclassBadURLManagerDaemon implements Daemon {
4243privateint status = Daemon.STATUS_NOT_PROCESSED;
44privateint result = Daemon.RESULT_UNKNOWN;
45privateDaemonConfig config = null;
46privateDaemonEntry entry = null;
4748/***49 * Static initilization of the logger for this class50 */51privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(BadURLManagerDaemon.class.getName());
5253/***54 Go over all the documents on the system and if refresh them if necessary.55 */56publicvoid run() {
5758 logger.info("Checking for valid URLs within the URLManager");
5960this.setResult( Daemon.RESULT_PROCESSING );
6162 Iterator i = URLManager.list().iterator();
6364while ( i.hasNext() ) {
6566 String url = (String)i.next();
6768// we only want to process bad URLs...69if ( URLManager.isOK( url ) ) continue;
7071try {
7273 URLManager.unregister(url);
7475 logger.info("Removing " + url + " from BadURL list" );
76this.save();
7778//FIXME: It should check refresh of the portlets, like DiskCache...79 URLFetcher.refresh(url);
808182 } catch ( Throwable t ) {
83//don't do anything here because the URL for this has a good84//chance of being invalid anyway.85 logger.error("Invalid URL?", t);
86if ( DiskCacheUtils.isCached( url ) ) {
87try {
88//To avoid interference with the Disk Cache refreshing89 JetspeedDiskCache.getInstance().remove( url );
90 } catch (IOException ioe) {}
91 }
92 logger.info("Failed to load: " + url + " from BadURL list");
93 }
9495 }
9697this.setResult( Daemon.RESULT_SUCCESS );
98 }
99100/***101 */102publicvoid init( DaemonConfig config,
103DaemonEntry entry ) {
104this.config = config;
105this.entry = entry;
106 }
107108/***109 */110publicDaemonConfig getDaemonConfig() {
111returnthis.config;
112 }
113114/***115 */116publicDaemonEntry getDaemonEntry() {
117returnthis.entry;
118 }
119120/***121 Return the status for this Daemon122123 @see Daemon#STATUS_NOT_PROCESSED124 @see Daemon#STATUS_PROCESSED125 @see Daemon#STATUS_PROCESSING126 */127publicint getStatus() {
128returnthis.status;
129 }
130131/***132 Set the status for this Daemon133134 @see #STATUS_NOT_PROCESSED135 @see #STATUS_PROCESSED136 @see #STATUS_PROCESSING137 */138publicvoid setStatus(int status) {
139this.status = status;
140 }
141142/***143 @see Daemon#getResult()144 */145publicint getResult() {
146returnthis.result;
147 }
148149/***150 @see Daemon#setResult(int result)151 */152publicvoid setResult( int result ) {
153this.result = result;
154 }
155156/***157 @see Daemon#getMessage()158 */159public String getMessage() {
160returnnull;
161 }
162163/***164 Require that the BadURLManager save its configuration here.165 */166publicvoid save() {
167168// RL: What should be persisted here ?169// BadURLManager.getInstance().save();170171 }
172173publicvoid restore() { /* noop */ }174175176177 }
178