KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > channel > ReconfigHelper


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /**
25  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
26  *
27  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  */

31 package com.sun.enterprise.admin.server.core.channel;
32
33 import java.io.File JavaDoc;
34 import java.lang.reflect.InvocationTargetException JavaDoc;
35 import java.lang.reflect.Method JavaDoc;
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 /**
43  * ReconfigHelper executes reconfig command in a sub-process, which triggers
44  * refresh within web container.
45  */

46 public class ReconfigHelper {
47
48     private static boolean reconfigEnabled = false;
49     private static Class JavaDoc j2eeRunnerClass = null;
50     private static Method JavaDoc reconfigMethod = null;
51
52     static void enableWebCoreReconfig() throws ClassNotFoundException JavaDoc,
53             NoSuchMethodException JavaDoc, SecurityException JavaDoc {
54         findReconfigMethod();
55         if (reconfigMethod != null) {
56             reconfigEnabled = true;
57         }
58     }
59
60     /**
61      * Send reconfigure message to specified instance
62      */

63     public static void sendReconfigMessage(String JavaDoc instanceName) {
64 /*
65         int ret = reconfig(instanceName);
66         if (ret != 0) {
67             AdminChannel.warn(RECONFIG_ERROR);
68         }
69 */

70         if (reconfigEnabled) {
71             try {
72                 reconfigMethod.invoke(null, null);
73             } catch (IllegalAccessException JavaDoc access) {
74                 AdminChannel.warn(RECONFIG_ERROR);
75                 AdminChannel.debug(access);
76             } catch (IllegalArgumentException JavaDoc arg) {
77                 AdminChannel.warn(RECONFIG_ERROR);
78                 AdminChannel.debug(arg);
79             } catch (InvocationTargetException JavaDoc 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 JavaDoc instanceName) {
88         int retval = 0;
89         String JavaDoc[] 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 JavaDoc[] getReconfigCommand(String JavaDoc instance) {
103         String JavaDoc pfx = AdminChannel.instanceRoot + File.separator + instance
104                 + File.separator;
105         if (OS.isUnix()) {
106             return new String JavaDoc[]{pfx + "reconfig"};
107         } else if (OS.isWindows()) {
108             return new String JavaDoc[]{pfx + "reconfig.bat"};
109         } else {
110             return null;
111         }
112     }
113
114     private static void findReconfigMethod() throws ClassNotFoundException JavaDoc,
115             NoSuchMethodException JavaDoc, SecurityException JavaDoc {
116         j2eeRunnerClass = Class.forName(J2EE_RUNNER_CLASS);
117         reconfigMethod = j2eeRunnerClass.getMethod(RECONFIG_METHOD, null);
118     }
119
120     private final static String JavaDoc J2EE_RUNNER_CLASS =
121             "com.sun.enterprise.server.J2EERunner";
122     private final static String JavaDoc RECONFIG_METHOD = "requestReconfiguration";
123     private final static String JavaDoc RECONFIG_ERROR = "channel.reconfig_error";
124 }
125
Popular Tags