99
1010public class KoanClassLoader extends DynamicClassLoader {
1111
12- private static DynamicClassLoader instance ;
13- private FileMonitor fileMonitor ;
12+ private static KoanClassLoader instance ;
13+ private final FileMonitor fileMonitor ;
1414
1515 private KoanClassLoader (){
16- super (DirectoryManager .getBinDir (),
17- DirectoryManager .getSourceDir (),
18- buildClassPath (),
19- DynamicClassLoader .class .getClassLoader (),
20- ApplicationSettings .getFileCompilationTimeoutInMs ());
21- this .fileMonitor = FileMonitorFactory .getInstance (new File (DirectoryManager .getMainDir ()), new File (DirectoryManager .getDataFile ()));
16+ this (DirectoryManager .getBinDir (),
17+ DirectoryManager .getSourceDir (),
18+ buildClassPath (),
19+ DynamicClassLoader .class .getClassLoader (),
20+ ApplicationSettings .getFileCompilationTimeoutInMs (),
21+ FileMonitorFactory .getInstance (new File (DirectoryManager .getMainDir ()), new File (DirectoryManager .getDataFile ())));
22+ }
23+
24+ private KoanClassLoader (String binDir , String sourceDir ,
25+ String [] classPath , ClassLoader parent ,
26+ long timeout , FileMonitor fileMonitor ) {
27+ super (binDir , sourceDir , classPath , parent , timeout );
28+ this .fileMonitor = fileMonitor ;
29+ }
30+
31+ @ Override
32+ public boolean isFileModifiedSinceLastPoll (String sourcePath , long lastModified ) {
33+ return fileMonitor .isFileModifiedSinceLastPoll (sourcePath , lastModified );
34+ }
35+
36+ @ Override
37+ public void updateFileSavedTime (File sourceFile ) {
38+ fileMonitor .updateFileSaveTime (sourceFile );
2239 }
2340
2441 private static String [] buildClassPath () {
@@ -32,25 +49,16 @@ private static String[] buildClassPath() {
3249 return classPath ;
3350 }
3451
35- public static void setInstance (DynamicClassLoader loader ){
36- instance = loader ;
37- }
38-
3952 synchronized public static DynamicClassLoader getInstance (){
4053 if (instance == null ){
4154 instance = new KoanClassLoader ();
4255 }
43- return instance ;
44- }
45-
46- @ Override
47- public boolean isFileModifiedSinceLastPoll (String sourcePath , long lastModified ) {
48- return fileMonitor .isFileModifiedSinceLastPoll (sourcePath , lastModified );
56+ return instance .clone ();
4957 }
5058
5159 @ Override
52- public void updateFileSavedTime ( File sourceFile ) {
53- fileMonitor . updateFileSaveTime ( sourceFile );
60+ public KoanClassLoader clone () {
61+ return new KoanClassLoader ( getBinDir (), getSourceDir (), getClassPath (), getClass (). getClassLoader (), getTimeout (), fileMonitor );
5462 }
5563
5664}
0 commit comments