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.
5 package org.ibex.jinetd;
7 import org.ibex.util.*;
12 import java.util.zip.*;
14 /** represents a file or directory which is scanned for updates */
15 public class Loader extends Watcher {
17 public /*synchronized*/ void scan() throws IOException { super.scan(); }
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*/ }
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());
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]));
37 protected ThreadGroup tg = new ThreadGroup(getAbsolutePath());
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());
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]);