KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > threads > ConfigUpdateThread


1 package com.dotmarketing.threads;
2
3 import java.io.File JavaDoc;
4
5
6 public class ConfigUpdateThread extends Thread JavaDoc {
7     private int WAIT_TIME = 5000; //5 sec
8
private String JavaDoc webXmlPath = null;
9
10     public ConfigUpdateThread(String JavaDoc name, String JavaDoc webXmlPath) {
11         super(name);
12         this.webXmlPath = webXmlPath;
13     }
14
15     public void run() {
16         System.out.println("Restarting the web app");
17         
18         /* This code restart the application using the orion api but donīt works, it restart the app but donīt reload the properties files :(
19          
20          Hashtable hashtable = new Hashtable();
21         hashtable.put("java.naming.provider.url", "ormi://localhost:23791");
22         hashtable.put("java.naming.security.principal", "admin");
23         hashtable.put("java.naming.security.credentials", "123");
24         hashtable.put("java.naming.factory.initial", "com.evermind.server.rmi.RMIInitialContextFactory");
25         Context context = null;
26         try {
27             context = (new RMIInitialContextFactory()).getInitialContext(hashtable);
28         } catch (NamingException e) {
29             System.err.println("Error intanciating the intial context: " + e.getMessage());
30             return;
31         }
32
33         ApplicationServerAdministrator applicationserveradministrator = null;
34         try {
35             applicationserveradministrator = (ApplicationServerAdministrator)context.lookup("java:comp/ServerAdministrator");
36         } catch (NamingException e1) {
37             System.err.println("Error looking up the ApplicationServerAdministrator object: " + e1.getMessage());
38             return;
39         }
40         
41         ApplicationAdministrator applicationadministrator;
42
43         String appName = "default";
44         
45         try
46         {
47             applicationadministrator = applicationserveradministrator.getApplication(appName, null);
48         }
49         catch(Exception instantiationexception)
50         {
51             System.err.println("Error loading application " + appName + ": " + instantiationexception.getMessage() + " (use 'default' as application name if using the default installation configuration)");
52             return;
53         }
54         
55         try
56         {
57             applicationadministrator.restart();
58         }
59         catch(Exception instantiationexception1)
60         {
61             System.err.println("Error restarting application: " + instantiationexception1.getMessage());
62         }
63         */

64         try {
65             sleep(WAIT_TIME);
66             
67             System.out.println("Touching the web.xml file to force the resource file reload");
68             String JavaDoc webConfigFilePath = webXmlPath;
69             File JavaDoc webConfigFile = new File JavaDoc (webConfigFilePath);
70             long curr_time = System.currentTimeMillis();
71             webConfigFile.setLastModified(curr_time);
72         } catch (InterruptedException JavaDoc e) {
73             e.printStackTrace();
74         }
75         
76     }
77     
78   
79     /* (non-Javadoc)
80      * @see java.lang.Thread#destroy()
81      */

82     public void destroy() {
83         //super.destroy();
84
}
85 }
86
Popular Tags