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.List;
29 import java.util.Vector;
30
31
38 public class HotDeployUtil {
39
40 public static void fireDeployEvent(HotDeployEvent event) {
41 _instance._fireDeployEvent(event);
42 }
43
44 public static void fireUndeployEvent(HotDeployEvent event) {
45 _instance._fireUndeployEvent(event);
46 }
47
48 public static void flushEvents() {
49 _instance._flushEvents();
50 }
51
52 public static void registerListener(HotDeployListener listener) {
53 _instance._registerListener(listener);
54 }
55
56 public static void unregisterListeners() {
57 _instance._unregisterListeners();
58 }
59
60 private HotDeployUtil() {
61 if (_log.isInfoEnabled()) {
62 _log.info("Initializing hot deploy manager " + this.hashCode());
63 }
64
65 _listeners = new Vector<HotDeployListener>();
66 _events = new Vector<HotDeployEvent>();
67 }
68
69 private synchronized void _fireDeployEvent(HotDeployEvent event) {
70
71
74 if (_events != null) {
75 _events.add(event);
76
77 return;
78 }
79
80
82 for (HotDeployListener listener : _listeners) {
83 try {
84 listener.invokeDeploy(event);
85 }
86 catch (HotDeployException hde) {
87 _log.error(hde, hde);
88 }
89 }
90 }
91
92 private void _fireUndeployEvent(HotDeployEvent event) {
93 for (HotDeployListener listener : _listeners) {
94 try {
95 listener.invokeUndeploy(event);
96 }
97 catch (HotDeployException hde) {
98 _log.error(hde, hde);
99 }
100 }
101 }
102
103 private synchronized void _flushEvents() {
104 for (HotDeployEvent event : _events) {
105 for (HotDeployListener listener : _listeners) {
106 try {
107 listener.invokeDeploy(event);
108 }
109 catch (HotDeployException hde) {
110 _log.error(hde, hde);
111 }
112 }
113 }
114
115 _events = null;
116 }
117
118 private void _registerListener(HotDeployListener listener) {
119 _listeners.add(listener);
120 }
121
122 private void _unregisterListeners() {
123 _listeners.clear();
124 }
125
126 private static Log _log = LogFactoryUtil.getLog(HotDeployUtil.class);
127
128 private static HotDeployUtil _instance = new HotDeployUtil();
129
130 private List<HotDeployListener> _listeners;
131 private List<HotDeployEvent> _events;
132
133 }