KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > AdminNotificationHelper


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 package com.sun.enterprise.admin.server.core;
25
26 import java.util.List JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.logging.Level JavaDoc;
30 import java.util.logging.Logger JavaDoc;
31 import java.util.Properties JavaDoc;
32 import java.util.Enumeration JavaDoc;
33
34 import javax.management.ObjectName JavaDoc;
35 import javax.management.Attribute JavaDoc;
36
37 import com.sun.enterprise.admin.AdminContext;
38 import com.sun.enterprise.admin.event.AdminEvent;
39 import com.sun.enterprise.admin.event.AdminEventCache;
40 import com.sun.enterprise.admin.event.AdminEventMulticaster;
41 import com.sun.enterprise.admin.event.AdminEventResult;
42 import com.sun.enterprise.admin.event.ElementChangeHelper;
43 import com.sun.enterprise.admin.util.proxy.CallStack;
44 import com.sun.enterprise.admin.util.proxy.Call;
45 import com.sun.enterprise.admin.util.proxy.InterceptorImpl;
46 import com.sun.enterprise.admin.event.EventStack;
47 import com.sun.enterprise.admin.event.EventContext;
48 import com.sun.enterprise.config.ConfigContext;
49 import com.sun.enterprise.config.ConfigException;
50 import com.sun.enterprise.admin.event.ResourceDeployEvent;
51 import com.sun.enterprise.admin.event.BaseDeployEvent;
52 import com.sun.enterprise.security.SecurityContext;
53 import com.sun.enterprise.security.audit.AuditManager;
54 import com.sun.enterprise.security.audit.AuditManagerFactory;
55
56 import com.sun.enterprise.admin.event.pluggable.RestartEventHelper;
57 import com.sun.enterprise.server.pluggable.PluggableFeatureFactory;
58 import com.sun.enterprise.server.ApplicationServer;
59 import com.sun.enterprise.server.ServerContext;
60 import com.sun.enterprise.admin.event.pluggable.NotificationFactory;
61
62
63 /**
64  * Helper class for sending notifications
65  */

66 public class AdminNotificationHelper {
67
68     private AdminContext _adminContext;
69     private Logger JavaDoc _logger;
70
71     public AdminNotificationHelper(AdminContext ctx) {
72         _adminContext = ctx;
73         if (_adminContext != null) {
74             _logger = _adminContext.getAdminLogger();
75         } else {
76             _logger = Logger.getLogger("global");
77         }
78     }
79
80     public void sendNotification() {
81         ConfigContext context = _adminContext.getAdminConfigContext();
82         String JavaDoc instanceName = _adminContext.getServerName();
83         AdminEventCache cache =
84                 AdminEventCache.getInstance(instanceName);
85         cache.setAdminConfigContext(context);
86         ArrayList JavaDoc changeList = context.getConfigChangeList();
87         context.resetConfigChangeList();
88         ArrayList JavaDoc eventList = null;
89         if (changeList.size() <= 0) {
90             eventList = new ArrayList JavaDoc();
91             // Return, no changes to process
92
//return;
93
}
94         else
95         {
96             cache.processConfigChangeList(changeList, false, false);
97             eventList = cache.getAndResetCachedEvents();
98
99             //***********************************
100
//ElementChange events
101
try {
102             ElementChangeHelper elementHelper = new ElementChangeHelper(); //FIXME: need to put it as member
103
AdminEvent[] elementChangeEvents = elementHelper.generateElementChangeEventsFromChangeList(instanceName, changeList, context);
104             if(elementChangeEvents!=null)
105                 for(int i=0; i<elementChangeEvents.length; i++)
106                     eventList.add(elementChangeEvents[i]);
107             } catch (Exception JavaDoc e) {
108                 // ignore
109
}
110             //***********************************
111

112         }
113         EventStack stack = EventContext.getEventStackFromThreadLocal();
114         List JavaDoc newEventList = stack.getEvents();
115         newEventList.addAll(eventList);
116
117         boolean requiresRestart = false;
118
119         Iterator JavaDoc iter = newEventList.iterator();
120         while (iter.hasNext()) {
121             AdminEvent event = (AdminEvent)iter.next();
122             if (_logger.isLoggable(Level.FINEST)) {
123                 _logger.log(Level.FINEST, "mbean.event_sent",
124                         event.getEventInfo());
125             } else {
126                 _logger.log(Level.INFO, "mbean.send_event", event.toString());
127             }
128             AdminEventResult result=AdminEventMulticaster.multicastEvent(event);
129             _logger.log(Level.FINE, "mbean.event_res", result.getResultCode());
130             _logger.log(Level.FINEST, "mbean.event_reply",
131                     result.getAllMessagesAsString());
132             if (!AdminEventResult.SUCCESS.equals(result.getResultCode())) {
133                 requiresRestart = true;
134                 cache.setRestartNeeded(true);
135                 // if there was an error in the listener, admin event
136
// multicaster already sets the restart required to true
137
//_logger.log(Level.INFO, "mbean.notif_failed");
138
}
139
140         }
141         ServerContext svcCtx = ApplicationServer.getServerContext();
142         PluggableFeatureFactory featureFactory = null;
143         if (svcCtx != null) {
144             featureFactory = svcCtx.getPluggableFeatureFactory();
145             
146             // see if there were any non reconfigurabled changes
147
NotificationFactory nFactory =
148                 featureFactory.getNotificationFactory();
149             RestartEventHelper helper = nFactory.createRestartEventHelper();
150             helper.setRestartRequiredForTarget(context, changeList);
151             
152         }
153         stack.resetEvents();
154         
155         return;
156     }
157
158 }
159
Popular Tags