1 19 20 package org.netbeans.core; 21 22 import java.util.logging.Level ; 23 import java.util.logging.Logger ; 24 import org.netbeans.core.startup.StartLog; 25 import org.openide.filesystems.*; 26 import org.openide.loaders.DataObject; 27 import org.openide.loaders.DataFolder; 28 import org.openide.cookies.InstanceCookie; 29 import org.openide.util.RequestProcessor; 30 31 40 41 class WarmUpSupport implements Runnable { 42 43 static final String WARMUP_FOLDER = "WarmUp"; static final int WARMUP_DELAY = 1500; 46 static boolean finished = false; 48 private Logger err = Logger.getLogger("org.netbeans.core.WarmUpSupport"); 49 50 static void warmUp() { 51 RequestProcessor.getDefault().post(new WarmUpSupport(), WARMUP_DELAY); 52 } 53 54 56 public void run() { 57 boolean willLog = err.isLoggable(Level.FINE) || StartLog.willLog(); 58 if (willLog){ 59 err.fine("Warmup starting..."); StartLog.logStart("Warmup"); } 62 63 FileObject fo = Repository.getDefault().getDefaultFileSystem() 64 .findResource(WARMUP_FOLDER); 65 DataObject[] warmObjects = 66 fo != null ? DataFolder.findFolder(fo).getChildren() : new DataObject[0]; 67 68 if (warmObjects.length == 0) { 69 if (willLog) { 70 err.fine("no warmp up task"); } 72 } 73 else { 74 for (int i = 0; i < warmObjects.length; i++) { 75 try { 76 InstanceCookie ic = (InstanceCookie) warmObjects[i].getCookie(InstanceCookie.class); 77 78 if (willLog) { 79 StartLog.logProgress("Warmup running " + 80 ic.instanceName()); 81 } 82 Object warmer = ic.instanceCreate(); 83 84 if (warmer instanceof Runnable ) { 85 ((Runnable ) warmer).run(); 86 } 87 } 88 catch (Exception ex) { 89 Logger.getLogger(WarmUpSupport.class.getName()).log(Level.WARNING, null, ex); 90 } 91 } 92 } 93 if (willLog){ 94 err.fine("Warmup done."); StartLog.logEnd("Warmup"); } 97 98 finished = true; 99 } 100 } 101 | Popular Tags |