Class InternalWebServer
java.lang.Object
org.eclipse.core.runtime.Plugin
org.eclipse.ui.plugin.AbstractUIPlugin
com.iizigo.webserver.InternalWebServer
- All Implemented Interfaces:
org.osgi.framework.BundleActivator
The activator class controls the plug-in life cycle for the Internal Web Server using Jetty.
- Author:
- Christopher Mindus
Field Summary
FieldsFields inherited from class Plugin
PLUGIN_PREFERENCE_SCOPE, PREFERENCES_DEFAULT_OVERRIDE_BASE_NAME, PREFERENCES_DEFAULT_OVERRIDE_FILE_NAMEConstructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionvoidaddStateListener(Runnable listener) Adds a listener told when the web server started or stopped; called on the thread that did it.voidForgets this workspace's sticky port and claim ("Forget" on the Preferences page): its next start begins at the first offset no other workspace claims.intGets the offset of the port ranges the server bound.Gets the other workspaces' claimed offsets, for the Preferences page.getFileUrl(String fileName) Gets the URL string for a file in the root using the File protocol.intGets the UDP port of HTTP/3.getHTTPFileUrl(String fileName) Gets the URL string for a file in the root using the HTTP protocol.static InternalWebServerReturns the shared instance.Gets the registry of the live iiziGo and the port claims.Gets the root directory.intGets the started secure (HTTPS) web server port.Gets the Integrated Jetty Server instance.Gets what made the last start fail.getWebServerMapping(String mappedFile) Gets the map of web server mappings for files.intGets the started web server port.static StringGets the path of this workspace.Loads the HTML file contents encoded in UTF-8 and returns it.voidremoveStateListener(Runnable listener) Removes a listener.Starts the web server again from the Preferences page, with the preferences as they are now (the identity included, read from the saved preferences): stops it first when it runs, and starts one that never started (P-D-6: until CC-FIX-PORT-RANGE-A "Apply and Restart" refused a server that had failed to start, and only a restart of iiziGo recovered it).voidstart(org.osgi.framework.BundleContext context) intstartWebServer(File parentDir, IExternalBrowserPages extPages, IWSFileProviderServer fileProvider, WebSocketAcceptor acceptor) Starts the web server.intstartWebServer(File parentDir, IExternalBrowserPages extPages, IWSFileProviderServer fileProvider, WebSocketAcceptor acceptor, Consumer<IntegratedWebServer> startedListener) Starts the web server.voidstop(org.osgi.framework.BundleContext context) booleanstopWebServer(long maxTime) Stops the web server.Methods inherited from class AbstractUIPlugin
createImageRegistry, getDialogSettings, getImageRegistry, getPreferenceStore, getWorkbench, imageDescriptorFromPlugin, initializeDefaultPluginPreferences, initializeDefaultPreferences, initializeImageRegistry, loadDialogSettings, loadPreferenceStore, refreshPluginActions, saveDialogSettings, savePreferenceStore, shutdown, startupMethods inherited from class Plugin
find, find, getBundle, getLog, getPluginPreferences, getStateLocation, internalInitializeDefaultPluginPreferences, isDebugging, openStream, openStream, savePluginPreferences, setDebugging, toString
Field Details
PLUGIN_ID
Constructor Details
InternalWebServer
public InternalWebServer()The constructor
Method Details
start
- Specified by:
startin interfaceorg.osgi.framework.BundleActivator- Overrides:
startin classAbstractUIPlugin- Throws:
Exception
getInstance
Returns the shared instance.- Returns:
- the shared instance.
startWebServer
public int startWebServer(File parentDir, IExternalBrowserPages extPages, IWSFileProviderServer fileProvider, WebSocketAcceptor acceptor) Starts the web server.- Parameters:
parentDir- The directory to use for the QUIC work directories,nullfor current directory.extPages- External pages implementor, null for none.fileProvider- File provider interface.acceptor- The acceptor for engine requests.- Returns:
- The port used, 0 for failure.
startWebServer
public int startWebServer(File parentDir, IExternalBrowserPages extPages, IWSFileProviderServer fileProvider, WebSocketAcceptor acceptor, Consumer<IntegratedWebServer> startedListener) Starts the web server.- Parameters:
parentDir- The directory to use for "quic-work" directory,nullfor current directory.extPages- External pages implementor, null for none.fileProvider- File provider interface.acceptor- The acceptor for engine requests.startedListener- Called with the server each time it has started, here or later from the Preferences page (P-D-6); null for none.- Returns:
- The port used, 0 for failure.
restartWebServer
Starts the web server again from the Preferences page, with the preferences as they are now (the identity included, read from the saved preferences): stops it first when it runs, and starts one that never started (P-D-6: until CC-FIX-PORT-RANGE-A "Apply and Restart" refused a server that had failed to start, and only a restart of iiziGo recovered it).- Returns:
- null for success, otherwise what failed.
getWorkspacePath
Gets the path of this workspace.- Returns:
- The path, empty when unknown.
getStartFailure
Gets what made the last start fail.- Returns:
- The text, null when the last start did not fail (or none was made).
getBoundOffset
public int getBoundOffset()Gets the offset of the port ranges the server bound.- Returns:
- The offset, -1 when not started.
getHttp3Port
public int getHttp3Port()Gets the UDP port of HTTP/3.- Returns:
- The port, zero when not started or without HTTP/3.
getInstances
Gets the registry of the live iiziGo and the port claims.- Returns:
- The registry.
forgetWorkspacePort
public void forgetWorkspacePort()Forgets this workspace's sticky port and claim ("Forget" on the Preferences page): its next start begins at the first offset no other workspace claims.getClaimedByOthers
addStateListener
Adds a listener told when the web server started or stopped; called on the thread that did it.- Parameters:
listener- The listener.
removeStateListener
Removes a listener.- Parameters:
listener- The listener.
stopWebServer
public boolean stopWebServer(long maxTime) Stops the web server.No web server running is not a failure: there is nothing to stop, and true is returned. That is the case at the plug-in's stop when iiziGo's own stop has stopped the server already (
WebSocketServer.dispose()).- Parameters:
maxTime- Max time to wait for server to stop, <=0 is forever.- Returns:
- true when no web server runs any more (stopped now, or none was running), false for a timeout: the running server did not stop within
maxTime.
getWebServerPort
public int getWebServerPort()Gets the started web server port.- Returns:
- The port number, zero for not started.
getSecureWebServerPort
public int getSecureWebServerPort()Gets the started secure (HTTPS) web server port.- Returns:
- The port number, zero for not started.
stop
- Specified by:
stopin interfaceorg.osgi.framework.BundleActivator- Overrides:
stopin classAbstractUIPlugin- Throws:
Exception
getRootDirectory
Gets the root directory.- Returns:
- The root directory, null if not started.
getHTTPFileUrl
loadHTML
getFileUrl
getServer
Gets the Integrated Jetty Server instance.- Returns:
- The integrated web server instance, or
nullif not yet started.
getWebServerMapping