KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > event > ApplicationLoaderEventNotifier


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  * @(#) AbstractLoader.java
26  *
27  * Copyright 2000-2001 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  *
31  * This software is the confidential and proprietary information
32  * of iPlanet/Sun Microsystems, Inc. ("Confidential Information").
33  * You shall not disclose such Confidential Information and shall
34  * use it only in accordance with the terms of the license
35  * agreement you entered into with iPlanet/Sun Microsystems.
36  */

37 package com.sun.enterprise.server.event;
38
39 import java.util.ArrayList JavaDoc;
40
41 import java.util.logging.Level JavaDoc;
42 import java.util.logging.Logger JavaDoc;
43
44 import com.sun.logging.LogDomains;
45
46 public class ApplicationLoaderEventNotifier {
47
48     private static Logger JavaDoc _logger =
49     LogDomains.getLogger(LogDomains.LOADER_LOGGER);
50
51     private static ApplicationLoaderEventNotifier _notifier =
52     new ApplicationLoaderEventNotifier();
53
54     private ArrayList JavaDoc listeners = new ArrayList JavaDoc();
55     
56     private ArrayList JavaDoc appclientListeners = new ArrayList JavaDoc();
57
58     private ApplicationLoaderEventNotifier() {
59     }
60
61     public static ApplicationLoaderEventNotifier getInstance() {
62     return _notifier;
63     }
64
65     public void addListener(ApplicationLoaderEventListener listener) {
66     synchronized (listeners) {
67         listeners.add(listener);
68     }
69     }
70
71     public void removeListener(ApplicationLoaderEventListener listener) {
72     synchronized (listeners) {
73         listeners.remove(listener);
74     }
75     }
76     
77     public void addListener(ApplicationClientLoaderEventListener listener) {
78     synchronized (appclientListeners) {
79         appclientListeners.add(listener);
80     }
81     }
82
83     public void removeListener(ApplicationClientLoaderEventListener listener) {
84     synchronized (appclientListeners) {
85         appclientListeners.remove(listener);
86     }
87     }
88
89     public void notifyListeners(ApplicationEvent event) {
90     ArrayList JavaDoc myListeners = null;
91
92     _logger.log(Level.FINE, "LoaderEventNotifier: " + event);
93
94     synchronized (listeners) {
95         myListeners = (ArrayList JavaDoc) listeners.clone();
96     }
97
98     int sz = myListeners.size();
99     for (int i=0; i<sz; i++) {
100        ApplicationLoaderEventListener listener =
101            (ApplicationLoaderEventListener) myListeners.get(i);
102
103        try {
104            listener.handleApplicationEvent(event);
105        } catch (Exception JavaDoc ex) {
106            _logger.log(Level.WARNING, "Exception during "
107                + "handleApplicationEvent", ex);
108        }
109     }
110     }
111
112     public void notifyListeners(EjbContainerEvent event) {
113     ArrayList JavaDoc myListeners = null;
114
115     _logger.log(Level.FINE, "LoaderEventNotifier: " + event);
116
117     synchronized (listeners) {
118         myListeners = (ArrayList JavaDoc) listeners.clone();
119     }
120
121     int sz = myListeners.size();
122     for (int i=0; i<sz; i++) {
123        ApplicationLoaderEventListener listener =
124            (ApplicationLoaderEventListener) myListeners.get(i);
125
126        try {
127            listener.handleEjbContainerEvent(event);
128        } catch (Exception JavaDoc ex) {
129            _logger.log(Level.WARNING, "Exception during "
130                + "handleEjbContainerEvent", ex);
131        }
132     }
133     }
134
135     public void notifyListeners(ApplicationClientEvent event) {
136     ArrayList JavaDoc myListeners = null;
137
138     _logger.log(Level.FINE, "LoaderEventNotifier: " + event);
139
140     synchronized (appclientListeners) {
141         myListeners = (ArrayList JavaDoc) appclientListeners.clone();
142     }
143
144     int sz = myListeners.size();
145     for (int i=0; i<sz; i++) {
146        ApplicationClientLoaderEventListener listener =
147            (ApplicationClientLoaderEventListener) myListeners.get(i);
148
149        try {
150            listener.handleApplicationClientEvent(event);
151        } catch (Exception JavaDoc ex) {
152            _logger.log(Level.WARNING, "Exception during "
153                + "handleApplicationClientEvent", ex);
154        }
155     }
156     }
157 }
158
Popular Tags