1
22
23 package com.liferay.portal.kernel.deploy.hot;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Vector;
31
32
39 public class HotDeployUtil {
40
41 public static void fireDeployEvent(HotDeployEvent event) {
42 _instance._fireDeployEvent(event);
43 }
44
45 public static void fireUndeployEvent(HotDeployEvent event) {
46 _instance._fireUndeployEvent(event);
47 }
48
49 public static void flushEvents() {
50 _instance._flushEvents();
51 }
52
53 public static void registerListener(HotDeployListener listener) {
54 _instance._registerListener(listener);
55 }
56
57 public static void unregisterListeners() {
58 _instance._unregisterListeners();
59 }
60
61 private HotDeployUtil() {
62 if (_log.isInfoEnabled()) {
63 _log.info("Initializing hot deploy manager " + this.hashCode());
64 }
65
66 _listeners = new Vector();
67 _events = new Vector();
68 }
69
70 private synchronized void _fireDeployEvent(HotDeployEvent event) {
71
72
75 if (_events != null) {
76 _events.add(event);
77
78 return;
79 }
80
81
83 Iterator itr = _listeners.iterator();
84
85 while (itr.hasNext()) {
86 HotDeployListener listener = (HotDeployListener)itr.next();
87
88 try {
89 listener.invokeDeploy(event);
90 }
91 catch (HotDeployException hde) {
92 _log.error(hde, hde);
93 }
94 }
95 }
96
97 private void _fireUndeployEvent(HotDeployEvent event) {
98 Iterator itr = _listeners.iterator();
99
100 while (itr.hasNext()) {
101 HotDeployListener listener = (HotDeployListener)itr.next();
102
103 try {
104 listener.invokeUndeploy(event);
105 }
106 catch (HotDeployException hde) {
107 _log.error(hde, hde);
108 }
109 }
110 }
111
112 private synchronized void _flushEvents() {
113 for (int i = 0; i < _events.size(); i++) {
114 HotDeployEvent event = (HotDeployEvent)_events.get(i);
115
116 Iterator itr = _listeners.iterator();
117
118 while (itr.hasNext()) {
119 HotDeployListener listener = (HotDeployListener)itr.next();
120
121 try {
122 listener.invokeDeploy(event);
123 }
124 catch (HotDeployException hde) {
125 _log.error(hde, hde);
126 }
127 }
128 }
129
130 _events = null;
131 }
132
133 private void _registerListener(HotDeployListener listener) {
134 _listeners.add(listener);
135 }
136
137 private void _unregisterListeners() {
138 _listeners.clear();
139 }
140
141 private static Log _log = LogFactoryUtil.getLog(HotDeployUtil.class);
142
143 private static HotDeployUtil _instance = new HotDeployUtil();
144
145 private List _listeners;
146 private List _events;
147
148 }