1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.osgi.boot.utils;
20
21 import java.util.Dictionary;
22 import java.util.Hashtable;
23
24 import org.osgi.framework.Bundle;
25 import org.osgi.framework.FrameworkUtil;
26 import org.osgi.framework.ServiceReference;
27 import org.osgi.service.event.Event;
28 import org.osgi.service.event.EventAdmin;
29
30
31
32
33
34
35
36 public class EventSender
37 {
38
39 public static final String DEPLOYING_EVENT = "org/osgi/service/web/DEPLOYING";
40 public static final String DEPLOYED_EVENT = "org/osgi/service/web/DEPLOYED";
41 public static final String UNDEPLOYING_EVENT = "org/osgi/service/web/UNDEPLOYING";
42 public static final String UNDEPLOYED_EVENT = "org/osgi/service/web/UNDEPLOYED";
43 public static final String FAILED_EVENT = "org/osgi/service/web/FAILED";
44
45
46 private static final EventSender __instance = new EventSender();
47 private Bundle _myBundle;
48 private EventAdmin _eventAdmin;
49
50
51
52
53
54
55
56
57 private EventSender ()
58 {
59 _myBundle = FrameworkUtil.getBundle(EventSender.class);
60 ServiceReference ref = _myBundle.getBundleContext().getServiceReference(EventAdmin.class.getName());
61 if (ref != null)
62 _eventAdmin = (EventAdmin)_myBundle.getBundleContext().getService(ref);
63 }
64
65
66
67
68
69
70
71
72 public static EventSender getInstance()
73 {
74 return __instance;
75 }
76
77
78
79
80
81
82
83
84
85 public void send (String topic, Bundle wab, String contextPath)
86 {
87 if (topic==null || wab==null || contextPath==null)
88 return;
89
90 send(topic, wab, contextPath, null);
91 }
92
93
94
95
96
97
98
99
100
101
102 public void send (String topic, Bundle wab, String contextPath, Exception ex)
103 {
104 if (_eventAdmin == null)
105 return;
106
107 Dictionary<String,Object> props = new Hashtable<String,Object>();
108 props.put("bundle.symbolicName", wab.getSymbolicName());
109 props.put("bundle.id", wab.getBundleId());
110 props.put("bundle", wab);
111 props.put("bundle.version", wab.getVersion());
112 props.put("context.path", contextPath);
113 props.put("timestamp", System.currentTimeMillis());
114 props.put("extender.bundle", _myBundle);
115 props.put("extender.bundle.symbolicName", _myBundle.getSymbolicName());
116 props.put("extender.bundle.id", _myBundle.getBundleId());
117 props.put("extender.bundle.version", _myBundle.getVersion());
118
119 if (FAILED_EVENT.equalsIgnoreCase(topic) && ex != null)
120 props.put("exception", ex);
121
122 _eventAdmin.sendEvent(new Event(topic, props));
123 }
124 }