Skip to content

Commit 3925f20

Browse files
committed
Merge branch 'initializable'
This migrates the Initializable interface, formerly part of ImageJ Ops, here to core SciJava Common, since it is probably generally useful.
2 parents b0c981b + a855314 commit 3925f20

File tree

3 files changed

+61
-13
lines changed

3 files changed

+61
-13
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<artifactId>scijava-common</artifactId>
13-
<version>2.61.1-SNAPSHOT</version>
13+
<version>2.62.0-SNAPSHOT</version>
1414

1515
<name>SciJava Common</name>
1616
<description>SciJava Common is a shared library for SciJava software. It provides a plugin framework, with an extensible mechanism for service discovery, backed by its own annotation processor, so that plugins can be loaded dynamically. It is used by downstream projects in the SciJava ecosystem, such as ImageJ and SCIFIO.</description>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* #%L
3+
* SciJava Common shared library for SciJava software.
4+
* %%
5+
* Copyright (C) 2009 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package org.scijava;
33+
34+
/**
35+
* Interface for objects which can be initialized.
36+
*
37+
* @author Curtis Rueden
38+
*/
39+
public interface Initializable {
40+
41+
/** Initializes the object. */
42+
default void initialize() {
43+
// NB: Do nothing by default.
44+
}
45+
}

src/main/java/org/scijava/service/Service.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
package org.scijava.service;
3333

3434
import org.scijava.Disposable;
35+
import org.scijava.Initializable;
3536
import org.scijava.event.EventService;
3637
import org.scijava.plugin.Plugin;
3738
import org.scijava.plugin.RichPlugin;
@@ -49,34 +50,36 @@
4950
* @author Curtis Rueden
5051
* @see Plugin
5152
*/
52-
public interface Service extends RichPlugin, Disposable {
53+
public interface Service extends RichPlugin, Initializable, Disposable {
5354

5455
/**
55-
* Performs any needed initialization when the service is first loaded.
56+
* Registers the service's event handler methods.
5657
* <p>
5758
* NB: This method is not intended to be called directly. It is called by
5859
* the service framework itself (specifically by the {@link ServiceHelper})
5960
* when initializing the service. It should not be called a second time.
6061
* </p>
6162
*/
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);
6469
}
6570

71+
// -- Initializable methods --
72+
6673
/**
67-
* Registers the service's event handler methods.
74+
* Performs any needed initialization when the service is first loaded.
6875
* <p>
6976
* NB: This method is not intended to be called directly. It is called by
7077
* the service framework itself (specifically by the {@link ServiceHelper})
7178
* when initializing the service. It should not be called a second time.
7279
* </p>
7380
*/
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.
8084
}
81-
8285
}

0 commit comments

Comments
 (0)