KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > event > RRPersistenceHelper


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 package com.sun.enterprise.admin.event;
24
25 import com.sun.logging.LogDomains;
26 import java.util.Set JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.logging.Level JavaDoc;
31 import java.util.logging.Logger JavaDoc;
32
33 import com.sun.enterprise.admin.target.Target;
34 import com.sun.enterprise.admin.server.core.channel.RMIClient;
35 import com.sun.enterprise.admin.server.core.channel.AdminChannel;
36
37 import com.sun.enterprise.admin.event.AdminEvent;
38 import com.sun.enterprise.admin.event.AdminEventResult;
39
40 import com.sun.enterprise.admin.server.core.AdminService;
41 import com.sun.enterprise.admin.target.TargetBuilder;
42 import com.sun.enterprise.admin.target.Target;
43 import com.sun.enterprise.admin.target.TargetType;
44 import com.sun.enterprise.config.serverbeans.Server;
45 import com.sun.enterprise.admin.event.ElementChangeHelper;
46 import com.sun.enterprise.config.ConfigContext;
47
48 import com.sun.enterprise.server.ApplicationServer;
49 import com.sun.enterprise.server.ServerContext;
50
51 //i18n import
52
import com.sun.enterprise.util.i18n.StringManager;
53
54 /**
55  * Restart event Helper - class providing support for informing
56  * server(s) to set its(their) restart required state to true or false.
57  *
58  * @author: Satish Viswanatham
59  */

60 public class RRPersistenceHelper{
61
62     // i18n StringManager
63
private static Logger JavaDoc _logger = null;
64     
65     public RRPersistenceHelper() {
66     }
67
68     /**
69      * Set the restart required status in the given instance name
70      * if the result code is not success
71      *
72      * @param evt Admin Event that is being sent
73      * @param result Result of the Admin Event
74      */

75     public void setRestartRequiredForServer(AdminEvent event,
76         AdminEventResult result ) {
77
78         if (AdminService.getAdminService() == null) {
79             // This instance does not have admin service return null
80
return;
81         }
82
83         String JavaDoc resCode = null;
84         // the follows tests this is server or DAS
85
try {
86             if (result != null) {
87                 resCode = result.getResultCode();
88             }
89             if ((resCode == null) ||
90                 (!resCode.equals(AdminEventResult.SUCCESS)) ){
91
92                 if (event != null) {
93                     setRestartRequired( event.getInstanceName(), true);
94                 }
95             }
96         } catch (Throwable JavaDoc t) {
97            getLogger().log(Level.INFO,
98                     "event.exception_during_restart_reset",t);
99         }
100
101     }
102
103     /**
104      * Set the restart required status in the given instance name
105      *
106      * @param inst Local server instance name
107      * @param restart boolen value for restart required flag
108      */

109     public void setRestartRequired(String JavaDoc inst, boolean restart) {
110
111         try {
112             RMIClient client = AdminChannel.getRMIClient(inst);
113             if (client == null) {
114                 getLogger().log(Level.INFO, "event.rmi_client_not_found");
115             } else {
116                 client.setRestartNeeded(restart);
117             }
118         } catch (Throwable JavaDoc t) {
119             getLogger().log(Level.INFO,
120                 "event.exception_during_restart_reset", t);
121         }
122     }
123     
124     /**
125      * Set the restart required status in the current instance.
126      * Server Runtime MBean calls this method to set the restart
127      * required state from DAS.
128      *
129      * @param restart boolen value for restart required flag
130      */

131     public void setRestartRequired(boolean restart) {
132         String JavaDoc inst = null;
133         ServerContext svrCtx = ApplicationServer.getServerContext();
134         if (svrCtx !=null) {
135             inst = svrCtx.getInstanceName();
136         }
137         setRestartRequired(inst, restart);
138     }
139
140     private static Logger JavaDoc getLogger() {
141         if (_logger == null) {
142             _logger = Logger.getLogger(LogDomains.ADMIN_LOGGER);
143         }
144         return _logger;
145     }
146
147 }
148
Popular Tags