Interface Gateway
-
- All Superinterfaces:
Comparable<Prioritized>,Contextual,Disposable,HasPluginInfo,Identifiable,Locatable,Logged,Prioritized,RichPlugin,SciJavaPlugin,Versioned
- All Known Implementing Classes:
AbstractGateway,SciJava
public interface Gateway extends RichPlugin, Disposable
Interface for convenience classes that wrap aContextto provide one-line access to a suite ofServices.The
get(java.lang.Class<S>)methods provide consistentServiceinstantiation, while throwingNoSuchServiceExceptionif the requestedServiceis not found.Sample implementation
Let's say we have a
Krakenservice and aCowservice. Using theContextdirectly, 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
Cowand aKraken; i.e., your IDE's code completion will not give you a hint. Further, if either service is unavailable, aNullPointerExceptionis thrown.But if we create a
Gatewayclass calledAnimalswith 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
Animalsgateway:Animals animals = new Animals(); animals.cow().feedToKraken(); animals.kraken().burp();
This provides succinct yet explicit access to the
CowandKrakenservices; it is a simple two-layer access to functionality, which an IDE can auto-complete. And if one of the services is not available, aNoSuchServiceExceptionis thrown, which facilitates appropriate (but optional) handling of missing services.Gateways discoverable at runtime must implement this interface and be annotated with @
Gatewaywith attributePlugin.type()=Gateway.class. While it possible to create a gateway merely by implementing this interface, it is encouraged to instead extendAbstractGateway, for convenience.- Author:
- Mark Hiner, Curtis Rueden
- See Also:
Context
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description AppServiceapp()Gets this application context'sAppService.AppEventServiceappEvent()Gets this application context'sAppEventService.CommandServicecommand()Gets this application context'sCommandService.ConsoleServiceconsole()Gets this application context'sConsoleService.DisplayServicedisplay()Gets this application context'sDisplayService.default voiddispose()Performs any needed cleanup of the object's services, in preparation for the object being retired (e.g., to make garbage collection possible).EventServiceevent()Gets this application context'sEventService.EventHistoryeventHistory()Gets this application context'sEventHistory.<S extends Service>
Sget(Class<S> serviceClass)Serviceget(String serviceClassName)AppgetApp()StringgetInfo(boolean mem)StringgetShortName()Gets a very succinct name for use referring to this gateway, e.g. as a variable name for scripting.StringgetTitle()IconServiceicon()Gets this application context'sIconService.InputServiceinput()Gets this application context'sInputService.IOServiceio()Gets this application context'sIOService.voidlaunch(String... args)Perform launch operations associated with this gateway.LocationServicelocation()Gets this application context'sLocationService.LogServicelog()Gets this application context'sLogService.MainServicemain()Gets this application context'sMainService.MenuServicemenu()Gets this application context'sMenuService.ModuleServicemodule()Gets this application context'sModuleService.ObjectServiceobject()Gets this application context'sObjectService.OptionsServiceoptions()Gets this application context'sOptionsService.PlatformServiceplatform()Gets this application context'sPlatformService.PluginServiceplugin()Gets this application context'sPluginService.RecentFileServicerecentFile()Gets this application context'sRecentFileService.ScriptServicescript()Gets this application context'sScriptService.StartupServicestartup()Gets this application context'sStartupService.StatusServicestatus()Gets this application context'sStatusService.TextServicetext()Gets this application context'sTextService.ThreadServicethread()Gets this application context'sThreadService.ToolServicetool()Gets this application context'sToolService.UIServiceui()Gets this application context'sUIService.WidgetServicewidget()Gets this application context'sWidgetService.-
Methods inherited from interface org.scijava.Contextual
context, getContext, setContext
-
Methods inherited from interface org.scijava.plugin.HasPluginInfo
getInfo, setInfo
-
Methods inherited from interface org.scijava.Locatable
getLocation
-
Methods inherited from interface org.scijava.Prioritized
compareTo, getPriority, setPriority
-
Methods inherited from interface org.scijava.plugin.RichPlugin
getIdentifier
-
Methods inherited from interface org.scijava.Versioned
getVersion
-
-
-
-
Method Detail
-
launch
void launch(String... args)
Perform launch operations associated with this gateway.Typical operations might include:
- Handle the given command line arguments using the
ConsoleService. - Execute registered main classes of the
MainService. - Display the default user interface using the
UIService. - In some circumstances (e.g., when running headless), dispose the context after launch operations are complete.
- Parameters:
args- The arguments to pass to the application.
- Handle the given command line arguments using the
-
getShortName
String getShortName()
Gets a very succinct name for use referring to this gateway, e.g. as a variable name for scripting.
-
get
<S extends Service> S get(Class<S> serviceClass)
- Parameters:
serviceClass- the requestedService- Returns:
- The singleton instance of the given class
- Throws:
NullContextException- if the application context is not set.NoSuchServiceException- if there is no service of the given class.
-
get
Service get(String serviceClassName)
Returns an implementation of theServicewith the given class name, if it exists in the underlyingContext.- Parameters:
serviceClassName- name of the requestedService- Returns:
- The singleton instance of the requested
Service - Throws:
NullContextException- if the application context is not set.NoSuchServiceException- if there is no service matchingserviceClassName.
-
appEvent
AppEventService appEvent()
Gets this application context'sAppEventService.- Returns:
- The
AppEventServiceof this application context.
-
app
AppService app()
Gets this application context'sAppService.- Returns:
- The
AppServiceof this application context.
-
command
CommandService command()
Gets this application context'sCommandService.- Returns:
- The
CommandServiceof this application context.
-
console
ConsoleService console()
Gets this application context'sConsoleService.- Returns:
- The
ConsoleServiceof this application context.
-
display
DisplayService display()
Gets this application context'sDisplayService.- Returns:
- The
DisplayServiceof this application context.
-
eventHistory
EventHistory eventHistory()
Gets this application context'sEventHistory.- Returns:
- The
EventHistoryof this application context.
-
event
EventService event()
Gets this application context'sEventService.- Returns:
- The
EventServiceof this application context.
-
icon
IconService icon()
Gets this application context'sIconService.- Returns:
- The
IconServiceof this application context.
-
input
InputService input()
Gets this application context'sInputService.- Returns:
- The
InputServiceof this application context.
-
io
IOService io()
Gets this application context'sIOService.- Returns:
- The
IOServiceof this application context.
-
location
LocationService location()
Gets this application context'sLocationService.- Returns:
- The
LocationServiceof this application context.
-
log
LogService log()
Gets this application context'sLogService.- Specified by:
login interfaceLogged- Specified by:
login interfaceRichPlugin- Returns:
- The
LogServiceof this application context.
-
main
MainService main()
Gets this application context'sMainService.- Returns:
- The
MainServiceof this application context.
-
menu
MenuService menu()
Gets this application context'sMenuService.- Returns:
- The
MenuServiceof this application context.
-
module
ModuleService module()
Gets this application context'sModuleService.- Returns:
- The
ModuleServiceof this application context.
-
object
ObjectService object()
Gets this application context'sObjectService.- Returns:
- The
ObjectServiceof this application context.
-
options
OptionsService options()
Gets this application context'sOptionsService.- Returns:
- The
OptionsServiceof this application context.
-
platform
PlatformService platform()
Gets this application context'sPlatformService.- Returns:
- The
PlatformServiceof this application context.
-
plugin
PluginService plugin()
Gets this application context'sPluginService.- Returns:
- The
PluginServiceof this application context.
-
recentFile
RecentFileService recentFile()
Gets this application context'sRecentFileService.- Returns:
- The
RecentFileServiceof this application context.
-
script
ScriptService script()
Gets this application context'sScriptService.- Returns:
- The
ScriptServiceof this application context.
-
startup
StartupService startup()
Gets this application context'sStartupService.- Returns:
- The
StartupServiceof this application context.
-
status
StatusService status()
Gets this application context'sStatusService.- Returns:
- The
StatusServiceof this application context.
-
text
TextService text()
Gets this application context'sTextService.- Returns:
- The
TextServiceof this application context.
-
thread
ThreadService thread()
Gets this application context'sThreadService.- Returns:
- The
ThreadServiceof this application context.
-
tool
ToolService tool()
Gets this application context'sToolService.- Returns:
- The
ToolServiceof this application context.
-
ui
UIService ui()
Gets this application context'sUIService.- Returns:
- The
UIServiceof this application context.
-
widget
WidgetService widget()
Gets this application context'sWidgetService.- Returns:
- The
WidgetServiceof this application context.
-
getApp
App getApp()
- See Also:
AppService
-
getTitle
String getTitle()
- See Also:
App.getTitle()
-
getInfo
String getInfo(boolean mem)
- See Also:
App.getInfo(boolean)
-
dispose
default void dispose()
Description copied from interface:DisposablePerforms any needed cleanup of the object's services, in preparation for the object being retired (e.g., to make garbage collection possible).- Specified by:
disposein interfaceDisposable
-
-