KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > WarmUpSupport


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core;
21
22 import java.util.logging.Level JavaDoc;
23 import java.util.logging.Logger JavaDoc;
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 /**
32  * This class controls "warm-up" initialization after IDE startup (some time
33  * after main window is shown). It scans WarmUp folder for individual tasks
34  * to be performed. The tasks should be instance objects implementing Runnable.
35  *
36  * The tasks may be provided by modules via xml layer.
37  *
38  * @author Tomas Pavek
39  */

40
41 class WarmUpSupport implements Runnable JavaDoc {
42
43     static final String JavaDoc WARMUP_FOLDER = "WarmUp"; // NOI18N
44
static final int WARMUP_DELAY = 1500; // 1.5 sec after main window is shown
45

46     static boolean finished = false; // usefull for testability
47

48     private Logger JavaDoc err = Logger.getLogger("org.netbeans.core.WarmUpSupport");
49
50     static void warmUp() {
51         RequestProcessor.getDefault().post(new WarmUpSupport(), WARMUP_DELAY);
52     }
53
54     // -------
55

56     public void run() {
57         boolean willLog = err.isLoggable(Level.FINE) || StartLog.willLog();
58         if (willLog){
59             err.fine("Warmup starting..."); // NOI18N
60
StartLog.logStart("Warmup"); // NOI18N
61
}
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"); // NOI18N
71
}
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 JavaDoc warmer = ic.instanceCreate();
83
84                     if (warmer instanceof Runnable JavaDoc) {
85                         ((Runnable JavaDoc) warmer).run();
86                     }
87                 }
88                 catch (Exception JavaDoc ex) {
89                     Logger.getLogger(WarmUpSupport.class.getName()).log(Level.WARNING, null, ex);
90                 }
91             }
92         }
93         if (willLog){
94             err.fine("Warmup done."); // NOI18N
95
StartLog.logEnd("Warmup"); // NOI18N
96
}
97         
98         finished = true;
99     }
100 }
101
Popular Tags