Skip to content

Commit b917ce3

Browse files
committed
Make pre- and post-processor plugins singletons
They are now each managed by a SingletonService. And the ModuleService uses those services to obtain the instances. Closes #232.
1 parent 7b39b2e commit b917ce3

File tree

8 files changed

+212
-8
lines changed

8 files changed

+212
-8
lines changed

src/main/java/org/scijava/module/DefaultModuleService.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@
5353
import org.scijava.module.process.ModulePostprocessor;
5454
import org.scijava.module.process.ModulePreprocessor;
5555
import org.scijava.module.process.PostprocessorPlugin;
56+
import org.scijava.module.process.PostprocessorService;
5657
import org.scijava.module.process.PreprocessorPlugin;
58+
import org.scijava.module.process.PreprocessorService;
5759
import org.scijava.object.ObjectService;
5860
import org.scijava.plugin.Parameter;
5961
import org.scijava.plugin.Plugin;
60-
import org.scijava.plugin.PluginService;
6162
import org.scijava.prefs.PrefService;
6263
import org.scijava.service.AbstractService;
6364
import org.scijava.service.Service;
@@ -84,7 +85,10 @@ public class DefaultModuleService extends AbstractService implements
8485
private EventService eventService;
8586

8687
@Parameter
87-
private PluginService pluginService;
88+
private PreprocessorService preprocessorService;
89+
90+
@Parameter
91+
private PostprocessorService postprocessorService;
8892

8993
@Parameter
9094
private ObjectService objectService;
@@ -364,13 +368,13 @@ public void initialize() {
364368
/** Creates the preprocessor chain. */
365369
private List<? extends PreprocessorPlugin> pre(final boolean process) {
366370
if (!process) return null;
367-
return pluginService.createInstancesOfType(PreprocessorPlugin.class);
371+
return preprocessorService.getInstances();
368372
}
369373

370374
/** Creates the postprocessor chain. */
371375
private List<? extends PostprocessorPlugin> post(final boolean process) {
372376
if (!process) return null;
373-
return pluginService.createInstancesOfType(PostprocessorPlugin.class);
377+
return postprocessorService.getInstances();
374378
}
375379

376380
/**
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* #%L
3+
* SCIFIO library for reading and converting scientific file formats.
4+
* %%
5+
* Copyright (C) 2011 - 2015 Board of Regents of the University of
6+
* Wisconsin-Madison
7+
* %%
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
* 2. Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
* #L%
29+
*/
30+
31+
package org.scijava.module.process;
32+
33+
import org.scijava.plugin.AbstractSingletonService;
34+
import org.scijava.plugin.Plugin;
35+
import org.scijava.service.Service;
36+
37+
/**
38+
* Default service for managing available {@link PostprocessorPlugin}s.
39+
*
40+
* @author Curtis Rueden
41+
*/
42+
@Plugin(type = Service.class)
43+
public class DefaultPostprocessorService extends
44+
AbstractSingletonService<PostprocessorPlugin> implements PostprocessorService
45+
{
46+
47+
// -- PTService methods --
48+
49+
@Override
50+
public Class<PostprocessorPlugin> getPluginType() {
51+
return PostprocessorPlugin.class;
52+
}
53+
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* #%L
3+
* SCIFIO library for reading and converting scientific file formats.
4+
* %%
5+
* Copyright (C) 2011 - 2015 Board of Regents of the University of
6+
* Wisconsin-Madison
7+
* %%
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
* 2. Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
* #L%
29+
*/
30+
31+
package org.scijava.module.process;
32+
33+
import org.scijava.plugin.AbstractSingletonService;
34+
import org.scijava.plugin.Plugin;
35+
import org.scijava.service.Service;
36+
37+
/**
38+
* Default service for managing available {@link PreprocessorPlugin}s.
39+
*
40+
* @author Curtis Rueden
41+
*/
42+
@Plugin(type = Service.class)
43+
public class DefaultPreprocessorService extends
44+
AbstractSingletonService<PreprocessorPlugin> implements PreprocessorService
45+
{
46+
47+
// -- PTService methods --
48+
49+
@Override
50+
public Class<PreprocessorPlugin> getPluginType() {
51+
return PreprocessorPlugin.class;
52+
}
53+
54+
}

src/main/java/org/scijava/module/process/PostprocessorPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
import org.scijava.Contextual;
3535
import org.scijava.plugin.Plugin;
36-
import org.scijava.plugin.SciJavaPlugin;
36+
import org.scijava.plugin.SingletonPlugin;
3737

3838
/**
3939
* A postprocessor plugin defines a step that occurs immediately following the
@@ -51,7 +51,7 @@
5151
* @author Curtis Rueden
5252
* @see ModulePostprocessor
5353
*/
54-
public interface PostprocessorPlugin extends SciJavaPlugin, Contextual,
54+
public interface PostprocessorPlugin extends SingletonPlugin, Contextual,
5555
ModulePostprocessor
5656
{
5757
// PostprocessorPlugin is a module postprocessor,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* #%L
3+
* SCIFIO library for reading and converting scientific file formats.
4+
* %%
5+
* Copyright (C) 2011 - 2015 Board of Regents of the University of
6+
* Wisconsin-Madison
7+
* %%
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
* 2. Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
* #L%
29+
*/
30+
31+
package org.scijava.module.process;
32+
33+
import org.scijava.plugin.SingletonService;
34+
import org.scijava.service.SciJavaService;
35+
36+
/**
37+
* Interface for service which manages available {@link PostprocessorPlugin}s.
38+
*
39+
* @author Curtis Rueden
40+
*/
41+
public interface PostprocessorService extends
42+
SingletonService<PostprocessorPlugin>, SciJavaService
43+
{
44+
// NB: No implementation needed.
45+
}

src/main/java/org/scijava/module/process/PreprocessorPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
import org.scijava.Contextual;
3535
import org.scijava.plugin.Plugin;
36-
import org.scijava.plugin.SciJavaPlugin;
36+
import org.scijava.plugin.SingletonPlugin;
3737

3838
/**
3939
* A preprocessor plugin defines a step that occurs just prior to the actual
@@ -51,7 +51,7 @@
5151
* @author Curtis Rueden
5252
* @see ModulePreprocessor
5353
*/
54-
public interface PreprocessorPlugin extends SciJavaPlugin, Contextual,
54+
public interface PreprocessorPlugin extends SingletonPlugin, Contextual,
5555
ModulePreprocessor
5656
{
5757
// PreprocessorPlugin is a module preprocessor,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* #%L
3+
* SCIFIO library for reading and converting scientific file formats.
4+
* %%
5+
* Copyright (C) 2011 - 2015 Board of Regents of the University of
6+
* Wisconsin-Madison
7+
* %%
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
* 2. Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
* #L%
29+
*/
30+
31+
package org.scijava.module.process;
32+
33+
import org.scijava.plugin.SingletonService;
34+
import org.scijava.service.SciJavaService;
35+
36+
/**
37+
* Interface for service which manages available {@link PreprocessorPlugin}s.
38+
*
39+
* @author Curtis Rueden
40+
*/
41+
public interface PreprocessorService extends
42+
SingletonService<PreprocessorPlugin>, SciJavaService
43+
{
44+
// NB: No implementation needed.
45+
}

src/test/java/org/scijava/ContextCreationTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ public void testFull() {
100100
org.scijava.main.DefaultMainService.class,
101101
org.scijava.menu.DefaultMenuService.class,
102102
org.scijava.module.DefaultModuleService.class,
103+
org.scijava.module.process.DefaultPostprocessorService.class,
104+
org.scijava.module.process.DefaultPreprocessorService.class,
103105
org.scijava.object.DefaultObjectService.class,
104106
org.scijava.options.DefaultOptionsService.class,
105107
org.scijava.parse.DefaultParseService.class,

0 commit comments

Comments
 (0)