001
014
015 package com.liferay.portal.osgi;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019
020 import org.osgi.framework.Bundle;
021 import org.osgi.framework.FrameworkEvent;
022
023
026 public class FrameworkListener implements org.osgi.framework.FrameworkListener {
027
028 private static Log _log = LogFactoryUtil.getLog(FrameworkListener.class);
029
030 public void frameworkEvent(FrameworkEvent frameworkEvent) {
031 try {
032 int type = frameworkEvent.getType();
033
034 if (type == FrameworkEvent.ERROR) {
035 frameworkEventError(frameworkEvent);
036 }
037 else if (type == FrameworkEvent.INFO) {
038 frameworkEventInfo(frameworkEvent);
039 }
040 else if (type == FrameworkEvent.PACKAGES_REFRESHED) {
041 frameworkEventPackagesRefreshed(frameworkEvent);
042 }
043 else if (type == FrameworkEvent.STARTED) {
044 frameworkEventStarted(frameworkEvent);
045 }
046 else if (type == FrameworkEvent.STARTLEVEL_CHANGED) {
047 frameworkEventStartLevelChanged(frameworkEvent);
048 }
049 else if (type == FrameworkEvent.STOPPED) {
050 frameworkEventStopped(frameworkEvent);
051 }
052 else if (type == FrameworkEvent.STOPPED_BOOTCLASSPATH_MODIFIED) {
053 frameworkEventStoppedBootClasspathModified(frameworkEvent);
054 }
055 else if (type == FrameworkEvent.STOPPED_UPDATE) {
056 frameworkEventStoppedUpdate(frameworkEvent);
057 }
058 else if (type == FrameworkEvent.WAIT_TIMEDOUT) {
059 frameworkEventWaitTimedout(frameworkEvent);
060 }
061 else if (type == FrameworkEvent.WARNING) {
062 frameworkEventWarning(frameworkEvent);
063 }
064 }
065 catch (Exception e) {
066 _log.error(e, e);
067 }
068 }
069
070 protected void frameworkEventError(FrameworkEvent frameworkEvent)
071 throws Exception {
072
073 Bundle bundle = frameworkEvent.getBundle();
074
075 Log log = LogFactoryUtil.getLog(bundle.getSymbolicName());
076
077 if (!log.isErrorEnabled()) {
078 return;
079 }
080
081 log.error("[ERROR]", frameworkEvent.getThrowable());
082 }
083
084 protected void frameworkEventInfo(FrameworkEvent frameworkEvent)
085 throws Exception {
086
087 Bundle bundle = frameworkEvent.getBundle();
088
089 Log log = LogFactoryUtil.getLog(bundle.getSymbolicName());
090
091 if (!log.isInfoEnabled()) {
092 return;
093 }
094
095 log.info("[INFO]", frameworkEvent.getThrowable());
096 }
097
098 protected void frameworkEventPackagesRefreshed(
099 FrameworkEvent frameworkEvent)
100 throws Exception {
101
102 Bundle bundle = frameworkEvent.getBundle();
103
104 Log log = LogFactoryUtil.getLog(bundle.getSymbolicName());
105
106 if (!log.isInfoEnabled()) {
107 return;
108 }
109
110 log.info("[PACKAGES_REFRESHED]", frameworkEvent.getThrowable());
111 }
112
113 protected void frameworkEventStarted(FrameworkEvent frameworkEvent)
114 throws Exception {
115
116 Bundle bundle = frameworkEvent.getBundle();
117
118 Log log = LogFactoryUtil.getLog(bundle.getSymbolicName());
119
120 if (!log.isInfoEnabled()) {
121 return;
122 }
123
124 log.info("[STARTED]", frameworkEvent.getThrowable());
125 }
126
127 protected void frameworkEventStartLevelChanged(
128 FrameworkEvent frameworkEvent)
129 throws Exception {
130
131 Bundle bundle = frameworkEvent.getBundle();
132
133 Log log = LogFactoryUtil.getLog(bundle.getSymbolicName());
134
135 if (!log.isInfoEnabled()) {
136 return;
137 }
138
139 log.info("[STARTLEVEL_CHANGED]", frameworkEvent.getThrowable());
140 }
141
142 protected void frameworkEventStopped(FrameworkEvent frameworkEvent)
143 throws Exception {
144
145 Bundle bundle = frameworkEvent.getBundle();
146
147 Log log = LogFactoryUtil.getLog(bundle.getSymbolicName());
148
149 if (!log.isInfoEnabled()) {
150 return;
151 }
152
153 log.info("[STOPPED]", frameworkEvent.getThrowable());
154 }
155
156 protected void frameworkEventStoppedBootClasspathModified(
157 FrameworkEvent frameworkEvent)
158 throws Exception {
159
160 Bundle bundle = frameworkEvent.getBundle();
161
162 Log log = LogFactoryUtil.getLog(bundle.getSymbolicName());
163
164 if (!log.isInfoEnabled()) {
165 return;
166 }
167
168 log.info(
169 "[STOPPED_BOOTCLASSPATH_MODIFIED]", frameworkEvent.getThrowable());
170 }
171
172 protected void frameworkEventStoppedUpdate(FrameworkEvent frameworkEvent)
173 throws Exception {
174
175 Bundle bundle = frameworkEvent.getBundle();
176
177 Log log = LogFactoryUtil.getLog(bundle.getSymbolicName());
178
179 if (!log.isInfoEnabled()) {
180 return;
181 }
182
183 log.info("[STOPPED_UPDATE]", frameworkEvent.getThrowable());
184 }
185
186 protected void frameworkEventWaitTimedout(FrameworkEvent frameworkEvent)
187 throws Exception {
188
189 Bundle bundle = frameworkEvent.getBundle();
190
191 Log log = LogFactoryUtil.getLog(bundle.getSymbolicName());
192
193 if (!log.isInfoEnabled()) {
194 return;
195 }
196
197 log.info("[WAIT_TIMEDOUT]", frameworkEvent.getThrowable());
198 }
199
200 protected void frameworkEventWarning(FrameworkEvent frameworkEvent)
201 throws Exception {
202
203 Bundle bundle = frameworkEvent.getBundle();
204
205 Log log = LogFactoryUtil.getLog(bundle.getSymbolicName());
206
207 if (!log.isWarnEnabled()) {
208 return;
209 }
210
211 log.warn("[WARNING]", frameworkEvent.getThrowable());
212 }
213
214 }