+++ /dev/null
-\r
-package jp.gr.java_conf.uguu.deployer;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.net.URL;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-import java.util.regex.Pattern;\r
-\r
-public class Main implements DeployerListener, DeployerClassLoaderListener {\r
-\r
- public static void main(String[] args) throws Exception {\r
- new Main().execute();\r
- }\r
-\r
- private Map<String, DeployerClassLoader> classLoaderMap = new HashMap<String, DeployerClassLoader>();\r
-\r
- public void execute() throws IOException {\r
- Deployer deployer = new Deployer(new File("E:\\work\\deploy"), Pattern.compile(".*\\.zip|.*\\.jar"), new File("E:\\work\\work"));\r
- deployer.addListener(this);\r
- while (true) {\r
- deployer.monitor();\r
- try {\r
- Thread.sleep(1000);\r
- } catch (InterruptedException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- }\r
-\r
- public void deployEnd(Deployer deployer, File file, File destDirectory) {\r
- try {\r
- final DeployerClassLoader cl = new DeployerClassLoader(destDirectory, "classes", "lib");\r
- cl.addListener(this);\r
- this.classLoaderMap.put(file.getAbsolutePath(), cl);\r
-\r
- Runnable runnable = new Runnable() {\r
-\r
- public void run() {\r
- try {\r
- Class<?> clazz = cl.loadClass("Main");\r
- Object obj = clazz.newInstance();\r
- clazz.getMethod("main").invoke(obj);\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- };\r
- Thread t = new Thread(runnable);\r
- t.start();\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- }\r
- // ログ。\r
- System.out.println("deployEnd: " + file.getAbsolutePath());\r
- }\r
-\r
- public void deployFile(Deployer deployer, File file, File destDirectory, File deployFile) {\r
- // ログ。\r
- System.out.println("deployFile: " + file.getAbsolutePath() + ", " + deployFile.getAbsolutePath());\r
- }\r
-\r
- public void deployStart(Deployer deployer, File file) {\r
- // ログ。\r
- System.out.println("deployStart: " + file.getAbsolutePath());\r
- }\r
-\r
- public void undeployEnd(Deployer deployer, File file) {\r
- DeployerClassLoader cl = this.classLoaderMap.remove(file.getAbsolutePath());\r
- cl.dispose();\r
- // ログ。\r
- System.out.println("undeployEnd: " + file.getAbsolutePath());\r
- }\r
-\r
- public void undeployStart(Deployer deployer, File file, File destDirectory) {\r
- // ログ。\r
- System.out.println("undeployStart: " + file.getAbsolutePath());\r
- }\r
-\r
- public void findClass(Class clazz, URL url) {\r
- // ログ。\r
- System.out.println("findClass: " + clazz.getName() + " [" + url.toExternalForm() + "]");\r
- }\r
-\r
-}\r
--- /dev/null
+\r
+package jp.sourceforge.deployer.server;\r
+\r
+import java.io.File;\r
+import java.net.URL;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.regex.Pattern;\r
+\r
+import jp.sourceforge.deployer.Deployer;\r
+import jp.sourceforge.deployer.DeployerClassLoader;\r
+import jp.sourceforge.deployer.DeployerClassLoaderListener;\r
+import jp.sourceforge.deployer.DeployerListener;\r
+\r
+public class DeployerServer implements Runnable, DeployerListener, DeployerClassLoaderListener {\r
+\r
+ public static void main(String[] args) throws Exception {\r
+ DeployerServer m = new DeployerServer();\r
+ Thread t = new Thread(m);\r
+ t.start();\r
+\r
+ Thread.sleep(1000000000);\r
+\r
+ System.in.read();\r
+\r
+ m.executing = false;\r
+ }\r
+\r
+ private boolean executing = true;\r
+\r
+ private Map<String, ApplicationInfo> classLoaderMap = new HashMap<String, ApplicationInfo>();\r
+\r
+ public void run() {\r
+ try {\r
+ File deployDir = new File("G:\\work\\deployer\\deploy");\r
+ Pattern filePattern = Pattern.compile(".*\\.zip|.*\\.jar");\r
+ File workDir = new File("G:\\work\\deployer\\work");\r
+ Deployer deployer = new Deployer(deployDir, filePattern, workDir);\r
+ deployer.addListener(this);\r
+ while (this.executing) {\r
+ deployer.monitor();\r
+ try {\r
+ Thread.sleep(1000);\r
+ } catch (InterruptedException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ public void deployEnd(Deployer deployer, File file, File destDirectory) {\r
+ final ApplicationInfo ai = new ApplicationInfo();\r
+ ai.classLoader = new DeployerClassLoader(destDirectory, "classes", "lib");\r
+ ai.classLoader.addListener(this);\r
+ ai.threadGroup = new ThreadGroup(file.getAbsolutePath());\r
+\r
+ this.classLoaderMap.put(file.getAbsolutePath(), ai);\r
+\r
+ Runnable runnable = new Runnable() {\r
+\r
+ public void run() {\r
+ try {\r
+ Class<?> clazz = ai.classLoader.loadClass("Main");\r
+ Object obj = clazz.newInstance();\r
+ clazz.getMethod("main").invoke(obj);\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ };\r
+ Thread t = new Thread(ai.threadGroup, runnable);\r
+ t.start();\r
+ // ログ。\r
+ System.out.println("deployEnd: " + file.getAbsolutePath());\r
+ }\r
+\r
+ public void deployFile(Deployer deployer, File file, File destDirectory, File deployFile) {\r
+ // ログ。\r
+ System.out.println("deployFile: " + file.getAbsolutePath() + ", " + deployFile.getAbsolutePath());\r
+ }\r
+\r
+ public void deployStart(Deployer deployer, File file) {\r
+ // ログ。\r
+ System.out.println("deployStart: " + file.getAbsolutePath());\r
+ }\r
+\r
+ public void undeployEnd(Deployer deployer, File file) {\r
+ ApplicationInfo ai = this.classLoaderMap.remove(file.getAbsolutePath());\r
+ if (ai != null) {\r
+ ai.classLoader.dispose();\r
+ ai.threadGroup.destroy();\r
+ }\r
+ // ログ。\r
+ System.out.println("undeployEnd: " + file.getAbsolutePath());\r
+ }\r
+\r
+ public void undeployStart(Deployer deployer, File file, File destDirectory) {\r
+ // ログ。\r
+ System.out.println("undeployStart: " + file.getAbsolutePath());\r
+ }\r
+\r
+ public void findClass(Class clazz, URL url) {\r
+ // ログ。\r
+ System.out.println("findClass: " + clazz.getName() + " [" + url.toExternalForm() + "]");\r
+ }\r
+\r
+ private class ApplicationInfo {\r
+\r
+ public DeployerClassLoader classLoader;\r
+\r
+ private ThreadGroup threadGroup;\r
+\r
+ }\r
+\r
+}\r