|
32 | 32 | package org.scijava.service; |
33 | 33 |
|
34 | 34 | import org.scijava.Disposable; |
| 35 | +import org.scijava.Initializable; |
35 | 36 | import org.scijava.event.EventService; |
36 | 37 | import org.scijava.plugin.Plugin; |
37 | 38 | import org.scijava.plugin.RichPlugin; |
|
49 | 50 | * @author Curtis Rueden |
50 | 51 | * @see Plugin |
51 | 52 | */ |
52 | | -public interface Service extends RichPlugin, Disposable { |
| 53 | +public interface Service extends RichPlugin, Initializable, Disposable { |
53 | 54 |
|
54 | 55 | /** |
55 | | - * Performs any needed initialization when the service is first loaded. |
| 56 | + * Registers the service's event handler methods. |
56 | 57 | * <p> |
57 | 58 | * NB: This method is not intended to be called directly. It is called by |
58 | 59 | * the service framework itself (specifically by the {@link ServiceHelper}) |
59 | 60 | * when initializing the service. It should not be called a second time. |
60 | 61 | * </p> |
61 | 62 | */ |
62 | | - default void initialize() { |
63 | | - // NB: Do nothing by default. |
| 63 | + default void registerEventHandlers() { |
| 64 | + // TODO: Consider removing this method in scijava-common 3.0.0. |
| 65 | + // Instead, the ServiceHelper could just invoke the lines below directly, |
| 66 | + // and there would be one less boilerplate Service method to implement. |
| 67 | + final EventService eventService = context().getService(EventService.class); |
| 68 | + if (eventService != null) eventService.subscribe(this); |
64 | 69 | } |
65 | 70 |
|
| 71 | + // -- Initializable methods -- |
| 72 | + |
66 | 73 | /** |
67 | | - * Registers the service's event handler methods. |
| 74 | + * Performs any needed initialization when the service is first loaded. |
68 | 75 | * <p> |
69 | 76 | * NB: This method is not intended to be called directly. It is called by |
70 | 77 | * the service framework itself (specifically by the {@link ServiceHelper}) |
71 | 78 | * when initializing the service. It should not be called a second time. |
72 | 79 | * </p> |
73 | 80 | */ |
74 | | - default void registerEventHandlers() { |
75 | | - // TODO: Consider removing this method in scijava-common 3.0.0. |
76 | | - // Instead, the ServiceHelper could just invoke the lines below directly, |
77 | | - // and there would be one less boilerplate Service method to implement. |
78 | | - final EventService eventService = context().getService(EventService.class); |
79 | | - if (eventService != null) eventService.subscribe(this); |
| 81 | + @Override |
| 82 | + default void initialize() { |
| 83 | + // NB: Do nothing by default. |
80 | 84 | } |
81 | | - |
82 | 85 | } |
0 commit comments