1 16 17 package org.apache.jetspeed.daemon.impl.util.feeddaemon; 18 19 import org.apache.jetspeed.cache.disk.DiskCacheUtils; 21 import org.apache.jetspeed.cache.disk.JetspeedDiskCache; 22 import org.apache.jetspeed.om.registry.PortletEntry; 23 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 24 import org.apache.jetspeed.services.logging.JetspeedLogger; 25 import org.apache.jetspeed.services.Registry; 26 import org.apache.jetspeed.services.PortletFactory; 27 import org.apache.jetspeed.services.urlmanager.URLManager; 28 import org.apache.jetspeed.services.urlmanager.URLManagerService; 29 import org.apache.jetspeed.services.urlmanager.URLFetcher; 30 import org.apache.jetspeed.services.resources.JetspeedResources; 31 32 import java.io.IOException ; 34 35 49 public class Instantiator implements Runnable { 50 51 55 public static final int MAX_WARN_SECONDS = 3; 56 57 60 public static final int LOG_INTERVAL = 100; 61 62 private PortletEntry entry = null; 63 private int id = 0; 64 65 private boolean forcePortet = false; 66 67 70 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(Instantiator.class.getName()); 71 72 75 public Instantiator( PortletEntry entry ) { 76 77 this.entry = entry; 78 79 } 80 81 84 public Instantiator( int id, 85 PortletEntry entry ) { 86 87 this(entry); 88 this.id = id; 89 90 } 91 92 95 public void getURL( String url ) throws IOException { 96 97 if ( JetspeedResources.getBoolean( JetspeedResources.CONTENTFEEDS_FETCHALL_KEY ) && 99 DiskCacheUtils.isCached( url ) == false ) { 100 101 long download_begin = System.currentTimeMillis(); 102 try { 103 104 JetspeedDiskCache.getInstance().getEntry( 107 url, 108 URLFetcher.fetch(url, true)); 109 110 long total = ( System.currentTimeMillis() - download_begin ) / 1000; 111 112 if ( total >= MAX_WARN_SECONDS ) { 113 logger.warn( this.getClass().getName() + " The following URL took too long (" + 114 total + 115 " second(s)) to download: " + url ); 116 } 117 118 } catch (IOException e) { 119 120 123 logger.error( "The following URL couldn't be downloaded " + 124 url + 125 " and took " + 126 ( System.currentTimeMillis() - download_begin ) / 1000 + 127 " seconds to download. " ); 128 throw new IOException ( e.getMessage() ); 129 } 130 131 } 132 133 } 134 135 139 public void run() { 140 141 try { 142 143 if(this.entry == null) 144 { 145 logger.error("Instantiator: Null Entry"); 146 return; 147 } 148 149 if(this.entry.getURL() == null) 150 { 151 logger.error("Instantiator: Null URL"); 152 return; 153 } 154 155 this.getURL( this.entry.getURL() ); 156 157 } catch ( IOException e ) { 158 return; 160 } catch ( Throwable t) { 161 logger.error( "Instantiator: Throwable", t); 163 } 164 165 org.apache.jetspeed.om.registry.Registry registry = 166 Registry.get(Registry.PORTLET); 167 168 try { 169 if(!registry.hasEntry(this.entry.getName())) 170 { 171 registry.addEntry( this.entry ); 172 173 if ( JetspeedResources.getBoolean( JetspeedResources.AUTOCREATE_PORTLETS_KEY ) ) 174 { 175 176 PortletFactory.getPortlet( this.entry.getName(), "0" ); 177 178 } 179 180 } 181 182 } catch ( Exception e ) { 183 logger.error( "InstantiatorThread: Couldn't create Portlet: ", e ); 184 185 URLManager.register( this.entry.getURL(), URLManagerService.STATUS_BAD, e.toString() ); 187 188 registry.removeEntry( this.entry.getName() ); 191 } 192 193 if ( id != 0 && 195 id % LOG_INTERVAL == 0 ) { 196 logger.info( "Instantiator: instanted " + id + " portlet(s)" ); 197 } 198 199 } 200 201 } 202 203 | Popular Tags |