1 23 24 31 package com.sun.enterprise.admin.server.core.channel; 32 33 import java.io.File ; 34 import java.lang.reflect.InvocationTargetException ; 35 import java.lang.reflect.Method ; 36 37 import com.sun.enterprise.util.OS; 38 import com.sun.enterprise.util.ProcessExecutor; 39 import com.sun.enterprise.util.ExecException; 40 41 42 46 public class ReconfigHelper { 47 48 private static boolean reconfigEnabled = false; 49 private static Class j2eeRunnerClass = null; 50 private static Method reconfigMethod = null; 51 52 static void enableWebCoreReconfig() throws ClassNotFoundException , 53 NoSuchMethodException , SecurityException { 54 findReconfigMethod(); 55 if (reconfigMethod != null) { 56 reconfigEnabled = true; 57 } 58 } 59 60 63 public static void sendReconfigMessage(String instanceName) { 64 70 if (reconfigEnabled) { 71 try { 72 reconfigMethod.invoke(null, null); 73 } catch (IllegalAccessException access) { 74 AdminChannel.warn(RECONFIG_ERROR); 75 AdminChannel.debug(access); 76 } catch (IllegalArgumentException arg) { 77 AdminChannel.warn(RECONFIG_ERROR); 78 AdminChannel.debug(arg); 79 } catch (InvocationTargetException ite) { 80 AdminChannel.warn(RECONFIG_ERROR); 81 AdminChannel.debug(ite.getTargetException()); 82 AdminChannel.debug(ite); 83 } 84 } 85 } 86 87 private static int reconfig(String instanceName) { 88 int retval = 0; 89 String [] cmd = getReconfigCommand(instanceName); 90 if (cmd != null) { 91 ProcessExecutor pe = new ProcessExecutor(cmd); 92 try { 93 pe.execute(); 94 } catch (ExecException ee) { 95 AdminChannel.debug(ee); 96 retval = 1; 97 } 98 } 99 return retval; 100 } 101 102 private static String [] getReconfigCommand(String instance) { 103 String pfx = AdminChannel.instanceRoot + File.separator + instance 104 + File.separator; 105 if (OS.isUnix()) { 106 return new String []{pfx + "reconfig"}; 107 } else if (OS.isWindows()) { 108 return new String []{pfx + "reconfig.bat"}; 109 } else { 110 return null; 111 } 112 } 113 114 private static void findReconfigMethod() throws ClassNotFoundException , 115 NoSuchMethodException , SecurityException { 116 j2eeRunnerClass = Class.forName(J2EE_RUNNER_CLASS); 117 reconfigMethod = j2eeRunnerClass.getMethod(RECONFIG_METHOD, null); 118 } 119 120 private final static String J2EE_RUNNER_CLASS = 121 "com.sun.enterprise.server.J2EERunner"; 122 private final static String RECONFIG_METHOD = "requestReconfiguration"; 123 private final static String RECONFIG_ERROR = "channel.reconfig_error"; 124 } 125 | Popular Tags |