7f32fd6fb701cb0d6571a3884ab5c50033091023
[org.ibex.jinetd.git] / src / org / ibex / jinetd / Loader.java
1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package org.ibex.jinetd;
6 import org.ibex.io.*;
7 import org.ibex.util.*;
8 import java.io.*;
9 import java.util.*;
10 import java.text.*;
11 import java.net.*;
12 import java.util.zip.*;
13
14 /** represents a file or directory which is scanned for updates */
15 public class Loader extends Watcher {
16
17     public /*synchronized*/ void scan() throws IOException { super.scan(); }
18
19     private final TreeClassLoader classloader;
20     public synchronized ClassLoader getClassLoader() { return classloader; }
21     public Loader(String path) { this(path, Loader.class.getClassLoader()); }
22     public Loader(String path, ClassLoader parent) { super(path); classloader = new TreeClassLoader(this, parent); }
23     public void changed(Watched w) { /*FIXME*/ }
24
25     private void fill(Vec vec, File dir) {
26         if (!dir.exists()) return;
27         if (!dir.isDirectory()) {
28             if (!dir.getPath().endsWith(".java")) return;
29             vec.addElement(dir.getAbsolutePath());
30         } else {
31             String[] list = dir.list();
32             for(int i=0; i<list.length; i++)
33                 fill(vec, new File(dir.getAbsolutePath() + File.separatorChar + list[i]));
34         }
35     }
36
37     protected ThreadGroup tg = new ThreadGroup(getAbsolutePath());
38     private void nuke() {
39         if (tg.activeCount() == 0) return;
40         Log.info(this, "killing all threads for: " + path);
41         Log.info(this, "   thread count before interrupt: " + tg.activeCount());
42         tg.interrupt();
43         try { Thread.sleep(3000); } catch (Exception e) { Log.error(this, e); }
44         Log.info(this, "   thread count before kill: " + tg.activeCount());
45         Thread[] all = new Thread[tg.activeCount()];
46         tg.enumerate(all, true);
47         for(int i=0; i<all.length; i++) Stream.kill(all[i]);
48         try { Thread.sleep(3000); } catch (Exception e) { Log.error(this, e); }
49         Log.info(this, "   thread count after kill: " + tg.activeCount());
50         if (tg.activeCount() > 0) {
51             Log.warn(this, "    annoying threads:");
52             Thread[] annoying = new Thread[tg.activeCount()];
53             tg.enumerate(annoying, true);
54             for(int i=0; i<annoying.length; i++) {
55                 Log.warn(this, "      " + annoying[i]);
56                 StackTraceElement[] stack = annoying[i].getStackTrace();
57                 for(int j=0; j<stack.length; j++) Log.warn(this, "        " + stack[j]);
58                 Log.warn(this, " ");
59             }
60         }
61     }
62
63    
64 }