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 registerListener(HotDeployListener listener) {
50 _instance._registerListener(listener);
51 }
52
53 public static void flushEvents() {
54 _instance._flushEvents();
55 }
56
57 private HotDeployUtil() {
58 if (_log.isInfoEnabled()) {
59 _log.info("Initializing hot deploy manager " + this.hashCode());
60 }
61
62 _listeners = new Vector();
63 _events = new Vector();
64 }
65
66 private synchronized void _fireDeployEvent(HotDeployEvent event) {
67
68
71 if (_events != null) {
72 _events.add(event);
73
74 return;
75 }
76
77
79 Iterator itr = _listeners.iterator();
80
81 while (itr.hasNext()) {
82 HotDeployListener listener = (HotDeployListener)itr.next();
83
84 try {
85 listener.invokeDeploy(event);
86 }
87 catch (HotDeployException hde) {
88 _log.error(hde, hde);
89 }
90 }
91 }
92
93 private void _fireUndeployEvent(HotDeployEvent event) {
94 Iterator itr = _listeners.iterator();
95
96 while (itr.hasNext()) {
97 HotDeployListener listener = (HotDeployListener)itr.next();
98
99 try {
100 listener.invokeUndeploy(event);
101 }
102 catch (HotDeployException hde) {
103 _log.error(hde, hde);
104 }
105 }
106 }
107
108 private void _registerListener(HotDeployListener listener) {
109 _listeners.add(listener);
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 static Log _log = LogFactoryUtil.getLog(HotDeployUtil.class);
134
135 private static HotDeployUtil _instance = new HotDeployUtil();
136
137 private List _listeners;
138 private List _events;
139
140 }