001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.kernel.deploy.hot;
022:
023: import com.liferay.portal.kernel.log.Log;
024: import com.liferay.portal.kernel.log.LogFactoryUtil;
025:
026: import java.util.Iterator;
027: import java.util.List;
028: import java.util.Vector;
029:
030: /**
031: * <a href="HotDeployUtil.java.html"><b><i>View Source</i></b></a>
032: *
033: * @author Ivica Cardic
034: * @author Brian Wing Shun Chan
035: *
036: */
037: public class HotDeployUtil {
038:
039: public static void fireDeployEvent(HotDeployEvent event) {
040: _instance._fireDeployEvent(event);
041: }
042:
043: public static void fireUndeployEvent(HotDeployEvent event) {
044: _instance._fireUndeployEvent(event);
045: }
046:
047: public static void flushEvents() {
048: _instance._flushEvents();
049: }
050:
051: public static void registerListener(HotDeployListener listener) {
052: _instance._registerListener(listener);
053: }
054:
055: public static void unregisterListeners() {
056: _instance._unregisterListeners();
057: }
058:
059: private HotDeployUtil() {
060: if (_log.isInfoEnabled()) {
061: _log.info("Initializing hot deploy manager "
062: + this .hashCode());
063: }
064:
065: _listeners = new Vector();
066: _events = new Vector();
067: }
068:
069: private synchronized void _fireDeployEvent(HotDeployEvent event) {
070:
071: // Capture events that are fired before the portal initialized. These
072: // events are later fired by flushEvents.
073:
074: if (_events != null) {
075: _events.add(event);
076:
077: return;
078: }
079:
080: // Fire current event
081:
082: Iterator itr = _listeners.iterator();
083:
084: while (itr.hasNext()) {
085: HotDeployListener listener = (HotDeployListener) itr.next();
086:
087: try {
088: listener.invokeDeploy(event);
089: } catch (HotDeployException hde) {
090: _log.error(hde, hde);
091: }
092: }
093: }
094:
095: private void _fireUndeployEvent(HotDeployEvent event) {
096: Iterator itr = _listeners.iterator();
097:
098: while (itr.hasNext()) {
099: HotDeployListener listener = (HotDeployListener) itr.next();
100:
101: try {
102: listener.invokeUndeploy(event);
103: } catch (HotDeployException hde) {
104: _log.error(hde, hde);
105: }
106: }
107: }
108:
109: private synchronized void _flushEvents() {
110: for (int i = 0; i < _events.size(); i++) {
111: HotDeployEvent event = (HotDeployEvent) _events.get(i);
112:
113: Iterator itr = _listeners.iterator();
114:
115: while (itr.hasNext()) {
116: HotDeployListener listener = (HotDeployListener) itr
117: .next();
118:
119: try {
120: listener.invokeDeploy(event);
121: } catch (HotDeployException hde) {
122: _log.error(hde, hde);
123: }
124: }
125: }
126:
127: _events = null;
128: }
129:
130: private void _registerListener(HotDeployListener listener) {
131: _listeners.add(listener);
132: }
133:
134: private void _unregisterListeners() {
135: _listeners.clear();
136: }
137:
138: private static Log _log = LogFactoryUtil
139: .getLog(HotDeployUtil.class);
140:
141: private static HotDeployUtil _instance = new HotDeployUtil();
142:
143: private List _listeners;
144: private List _events;
145:
146: }
|