public interface Gateway extends RichPlugin, Disposable
Context
to provide
one-line access to a suite of Service
s.
The get(java.lang.Class<S>)
methods provide consistent Service
instantiation,
while throwing NoSuchServiceException
if the requested
Service
is not found.
Let's say we have a Kraken
service and a Cow
service. Using
the Context
directly, the code would look like:
Context context = new Context(); context.getService(Cow.class).feedToKraken(); context.getService(Kraken.class).burp();
To perform these actions, you have to know a priori to ask for a
Cow
and a Kraken
; i.e., your IDE's code completion will not
give you a hint. Further, if either service is unavailable, a
NullPointerException
is thrown.
But if we create a Gateway
class called Animals
with the
following signatures:
public Cow cow() { return get(Cow.class); } public Kraken kraken() { return get(Kraken.class); }
We can now access our services through the new Animals
gateway:
Animals animals = new Animals(); animals.cow().feedToKraken(); animals.kraken().burp();
This provides succinct yet explicit access to the Cow
and
Kraken
services; it is a simple two-layer access to functionality,
which an IDE can auto-complete. And if one of the services is not available,
a NoSuchServiceException
is thrown, which facilitates appropriate
(but optional) handling of missing services.
Gateways discoverable at runtime must implement this interface and be
annotated with @Gateway
with attribute Plugin.type()
=
Gateway
.class. While it possible to create a gateway merely by
implementing this interface, it is encouraged to instead extend
AbstractGateway
, for convenience.
Context
Modifier and Type | Method and Description |
---|---|
AppService |
app()
Gets this application context's
AppService . |
AppEventService |
appEvent()
Gets this application context's
AppEventService . |
CommandService |
command()
Gets this application context's
CommandService . |
ConsoleService |
console()
Gets this application context's
ConsoleService . |
DisplayService |
display()
Gets this application context's
DisplayService . |
default void |
dispose()
Performs any needed cleanup of the object's services, in preparation for
the object being retired (e.g., to make garbage collection possible).
|
EventService |
event()
Gets this application context's
EventService . |
EventHistory |
eventHistory()
Gets this application context's
EventHistory . |
<S extends Service> |
get(Class<S> serviceClass)
|
Service |
get(String serviceClassName)
|
App |
getApp() |
String |
getInfo(boolean mem) |
String |
getShortName()
Gets a very succinct name for use referring to this gateway, e.g.
|
String |
getTitle() |
IconService |
icon()
Gets this application context's
IconService . |
InputService |
input()
Gets this application context's
InputService . |
IOService |
io()
Gets this application context's
IOService . |
void |
launch(String... args)
Perform launch operations associated with this gateway.
|
LogService |
log()
Gets this application context's
LogService . |
MainService |
main()
Gets this application context's
MainService . |
MenuService |
menu()
Gets this application context's
MenuService . |
ModuleService |
module()
Gets this application context's
ModuleService . |
ObjectService |
object()
Gets this application context's
ObjectService . |
OptionsService |
options()
Gets this application context's
OptionsService . |
PlatformService |
platform()
Gets this application context's
PlatformService . |
PluginService |
plugin()
Gets this application context's
PluginService . |
RecentFileService |
recentFile()
Gets this application context's
RecentFileService . |
ScriptService |
script()
Gets this application context's
ScriptService . |
StartupService |
startup()
Gets this application context's
StartupService . |
StatusService |
status()
Gets this application context's
StatusService . |
TextService |
text()
Gets this application context's
TextService . |
ThreadService |
thread()
Gets this application context's
ThreadService . |
ToolService |
tool()
Gets this application context's
ToolService . |
UIService |
ui()
Gets this application context's
UIService . |
WidgetService |
widget()
Gets this application context's
WidgetService . |
getIdentifier
context, getContext, setContext
compareTo, getPriority, setPriority
getInfo, setInfo
getLocation
getVersion
void launch(String... args)
Typical operations might include:
ConsoleService
.MainService
.UIService
.args
- The arguments to pass to the application.String getShortName()
<S extends Service> S get(Class<S> serviceClass)
serviceClass
- the requested Service
NullContextException
- if the application context is not set.NoSuchServiceException
- if there is no service of the given class.Service get(String serviceClassName)
Service
with the given class name,
if it exists in the underlying Context
.serviceClassName
- name of the requested Service
Service
NullContextException
- if the application context is not set.NoSuchServiceException
- if there is no service matching
serviceClassName
.AppEventService appEvent()
AppEventService
.AppEventService
of this application context.AppService app()
AppService
.AppService
of this application context.CommandService command()
CommandService
.CommandService
of this application context.ConsoleService console()
ConsoleService
.ConsoleService
of this application context.DisplayService display()
DisplayService
.DisplayService
of this application context.EventHistory eventHistory()
EventHistory
.EventHistory
of this application context.EventService event()
EventService
.EventService
of this application context.IconService icon()
IconService
.IconService
of this application context.InputService input()
InputService
.InputService
of this application context.IOService io()
IOService
.IOService
of this application context.LogService log()
LogService
.log
in interface Logged
log
in interface RichPlugin
LogService
of this application context.MainService main()
MainService
.MainService
of this application context.MenuService menu()
MenuService
.MenuService
of this application context.ModuleService module()
ModuleService
.ModuleService
of this application context.ObjectService object()
ObjectService
.ObjectService
of this application context.OptionsService options()
OptionsService
.OptionsService
of this application context.PlatformService platform()
PlatformService
.PlatformService
of this application context.PluginService plugin()
PluginService
.PluginService
of this application context.RecentFileService recentFile()
RecentFileService
.RecentFileService
of this application context.ScriptService script()
ScriptService
.ScriptService
of this application context.StartupService startup()
StartupService
.StartupService
of this application context.StatusService status()
StatusService
.StatusService
of this application context.TextService text()
TextService
.TextService
of this application context.ThreadService thread()
ThreadService
.ThreadService
of this application context.ToolService tool()
ToolService
.ToolService
of this application context.UIService ui()
UIService
.UIService
of this application context.WidgetService widget()
WidgetService
.WidgetService
of this application context.App getApp()
AppService
String getTitle()
App.getTitle()
String getInfo(boolean mem)
App.getInfo(boolean)
default void dispose()
Disposable
dispose
in interface Disposable
Copyright © 2015–2022 SciJava. All rights reserved.