Skip to content

Commit fd366a2

Browse files
committed
copyedit gui coding section
1 parent 5ea52ee commit fd366a2

33 files changed

+410
-1557
lines changed

doc/client/coding/Activators.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Activators
2+
3+
An Activator is the entry-point for a Plug-in - it gets created by the Eclipse framework when the Plug-in is first used.
4+
5+
Activators are implemented using a singleton pattern; a simplified typical activator looks like:
6+
7+
```java
8+
import org.osgi.framework.BundleActivator;
9+
import org.osgi.framework.BundleContext;
10+
11+
public class Help implements BundleActivator {
12+
13+
private static BundleContext context;
14+
private static Help instance;
15+
16+
static BundleContext getContext() {
17+
return context;
18+
}
19+
20+
public Help() {
21+
instance = this;
22+
}
23+
24+
@Override
25+
public void start(BundleContext bundleContext) throws Exception {
26+
Help.context = bundleContext;
27+
}
28+
29+
public static Help getInstance() {
30+
return instance;
31+
}
32+
33+
@Override
34+
public void stop(BundleContext bundleContext) throws Exception {
35+
Help.context = null;
36+
}
37+
}
38+
```
39+
40+
Activators may create and hold references to static data - for example models - so that they can later be referenced by
41+
other plugins that need access to those models (for example, views).
42+
43+
:::{note}
44+
At first glance the above pattern may seem dangerous - in most cases a singleton would need to check whether an instance
45+
already exists and create one if not in `getInstance`, and would also need to use locking for thread safety.
46+
47+
However, this pattern is safe for Activators, because the Eclipse framework guarantees that `start` will
48+
be called exactly once for a singleton plugin, before any other code can use the plugin, and that `stop` will only be
49+
called when no other plugin will be able to access it afterwards (for example, during platform shutdown).
50+
:::

0 commit comments

Comments
 (0)