File tree Expand file tree Collapse file tree
src/main/java/org/scijava/service Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3232package org .scijava .service ;
3333
3434import org .scijava .Context ;
35- import org .scijava .event .EventService ;
3635import org .scijava .plugin .AbstractRichPlugin ;
3736
3837/**
@@ -59,22 +58,6 @@ public abstract class AbstractService extends AbstractRichPlugin implements
5958 */
6059 private Context context ;
6160
62- // -- Service methods --
63-
64- @ Override
65- public void initialize () {
66- // NB: Do nothing by default.
67- }
68-
69- @ Override
70- public void registerEventHandlers () {
71- // TODO: Consider removing this method in scijava-common 3.0.0.
72- // Instead, the ServiceHelper could just invoke the lines below directly,
73- // and there would be one less boilerplate Service method to implement.
74- final EventService eventService = context ().getService (EventService .class );
75- if (eventService != null ) eventService .subscribe (this );
76- }
77-
7861 // -- Contextual methods --
7962
8063 @ Override
Original file line number Diff line number Diff line change 3232package org .scijava .service ;
3333
3434import org .scijava .Disposable ;
35+ import org .scijava .event .EventService ;
3536import org .scijava .plugin .Plugin ;
3637import org .scijava .plugin .RichPlugin ;
3738
@@ -58,7 +59,9 @@ public interface Service extends RichPlugin, Disposable {
5859 * when initializing the service. It should not be called a second time.
5960 * </p>
6061 */
61- void initialize ();
62+ default void initialize () {
63+ // NB: Do nothing by default.
64+ }
6265
6366 /**
6467 * Registers the service's event handler methods.
@@ -68,6 +71,12 @@ public interface Service extends RichPlugin, Disposable {
6871 * when initializing the service. It should not be called a second time.
6972 * </p>
7073 */
71- void registerEventHandlers ();
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 );
80+ }
7281
7382}
You can’t perform that action at this time.
0 commit comments