Class ConsoleWeblet
- All Implemented Interfaces:
Iterable<ComponentType>,Channel,ComponentType,Eligible,Manager
- Direct Known Subclasses:
FreeMarkerConsoleWeblet
Its main tasks are to provide resources using
Request/Response events (see onGet(org.jgrapes.http.events.Request.In.Get, org.jgrapes.io.IOSubchannel)
for details about the different kinds of resources), to create
the ConsoleConnections for new WebSocket connections
(see onUpgraded(org.jgrapes.http.events.Upgraded, org.jgrapes.io.IOSubchannel)) and to convert the JSON RPC messages
received from the browser via the web socket to JsonInput
events and fire them on the corresponding ConsoleConnection
channel.
The class has a counter part in the browser, the jgconsole
JavaScript module (see
functions)
that can be loaded as console-base-resource/jgconsole.js
(relative to the configured prefix).
The class also provides handlers for some console related events
(i.e. fired on the attached WebConsole’s channel) that
affect the console representation in the browser. These handlers
are declared with class channel ConsoleConnection which
is replaced using the HandlerDefinition.ChannelReplacements mechanism.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classThe class used in handler annotations to represent the console channel.classThe channel used to sendPageResourceRequests andConletResourceRequests to the web console components (via the console).Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionConsoleWeblet(Channel webletChannel, Channel consoleChannel, URI consolePrefix) Instantiates a new console weblet. -
Method Summary
Modifier and TypeMethodDescriptionReturns the console connection inactivity timeout.Returns the console connection network timeout.Returns the console connection refresh interval.console()Returns the automatically generatedWebConsolecomponent.Return the list of classes that form the current console weblet implementation.consoleResourceBundle(Locale locale) Return the console resources for a given locale.voidonClosed(Closed<?> event, IOSubchannel wsChannel) Handles the closed event from the web socket.voidonConsoleCommand(ConsoleCommand event, ConsoleConnection channel) Sends a command to the console.voidonDiscardSession(DiscardSession event) Discard the session referenced in the event.voidonGet(Request.In.Get event, IOSubchannel channel) Handle theGETrequests for the various resources.voidonGetRedirect(Request.In.Get event, IOSubchannel channel) RedirectsGETrequests without trailing slash.voidonInput(Input<CharBuffer> event, IOSubchannel wsChannel) Handles network input (JSON data).voidonResourceRequestCompleted(ResourceRequestCompleted event, ConsoleWeblet.ConsoleResourceChannel channel) Handles theResourceRequestCompletedevent.voidonSetLocale(SetLocale event, ConsoleConnection channel) Handles a change of Locale for the console.voidonSetLocaleCompleted(SetLocaleCompleted event, ConsoleConnection channel) Sends a reload if the change of locale could not be handled by all conlets.voidonUpgraded(Upgraded event, IOSubchannel wsChannel) Called when the connection has been upgraded.prefix()prependConsoleResourceProvider(Class<?> cls) Prepends the given class to the list of classes searched byprovideConsoleResource(Request.In.Get, String, IOSubchannel).prependResourceBundleProvider(Class<?> cls) Prepends a class to the list of classes used to lookup console resources.protected voidprovideConsoleResource(Request.In.Get event, String requestPath, IOSubchannel channel) Provide a console resource.protected abstract voidrenderConsole(Request.In.Get event, IOSubchannel channel, UUID consoleConnectionId) Render the console page.protected RenderSupportProvides the render support.setConnectionInactivityTimeout(Duration timeout) Sets the console connection inactivity timeout.setConnectionNetworkTimeout(Duration timeout) Sets the console connection network timeout.setConnectionRefreshInterval(Duration interval) Sets the console connection refresh interval.voidsetUseMinifiedResources(boolean useMinifiedResources) Determines if resources should be minified.abstract Stringstyling()Returns the name of the styling library or toolkit used by the console.protected Map<Locale, ResourceBundle> Returns the supported locales and their resource bundles.protected final voidUpdate the supported locales.booleanReturns whether resources are minified.Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setNameMethods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, toString, unregisterAsGeneratorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ConsoleWeblet
Instantiates a new console weblet.The weblet handles
Request.In.Getevents for URIs that start with the specified prefix (seeonGet(org.jgrapes.http.events.Request.In.Get, IOSubchannel)).- Parameters:
webletChannel- the weblet channelconsoleChannel- the console channelconsolePrefix- the console prefix
-
-
Method Details
-
consoleHierarchy
Return the list of classes that form the current console weblet implementation.This consists of all classes from
getClass()up toConsoleWeblet.class.- Returns:
- the list
-
styling
Returns the name of the styling library or toolkit used by the console.This value is informative. It may, however, be used by a
PageResourceProviderFactoryto influence the creation ofPageResourceProviders.- Returns:
- the value
-
prefix
- Returns:
- the prefix
-
console
Returns the automatically generatedWebConsolecomponent.- Returns:
- the console
-
setConnectionNetworkTimeout
Sets the console connection network timeout.The console connection will be removed if no messages have been received from the console page for the given duration. The value defaults to 45 seconds.
- Parameters:
timeout- the timeout in milli seconds- Returns:
- the console view for easy chaining
-
connectionNetworkTimeout
Returns the console connection network timeout.- Returns:
- the timeout
-
setConnectionRefreshInterval
Sets the console connection refresh interval.The console code in the browser will send a keep alive packet if there has been no user activity for more than the given period. The value defaults to 30 seconds.
- Parameters:
interval- the interval- Returns:
- the console view for easy chaining
-
connectionRefreshInterval
Returns the console connection refresh interval.- Returns:
- the interval
-
setConnectionInactivityTimeout
Sets the console connection inactivity timeout.If there has been no user activity for more than the given duration the console code stops sending keep alive packets and displays a message to the user. The value defaults to -1 (no timeout).
- Parameters:
timeout- the timeout- Returns:
- the console view for easy chaining
-
connectionInactivityTimeout
Returns the console connection inactivity timeout.- Returns:
- the timeout
-
useMinifiedResources
Returns whether resources are minified.- Returns:
- the useMinifiedResources
-
setUseMinifiedResources
Determines if resources should be minified.- Parameters:
useMinifiedResources- the useMinifiedResources to set
-
renderSupport
Provides the render support.- Returns:
- the render support
-
prependResourceBundleProvider
Prepends a class to the list of classes used to lookup console resources.See
ConsoleResourceBundleControl.newBundle(java.lang.String, java.util.Locale, java.lang.String, java.lang.ClassLoader, boolean). Affects the content of the resource bundle returned byconsoleResourceBundle(Locale).- Parameters:
cls- the class to prepend.- Returns:
- the console weblet for easy chaining
-
updateSupportedLocales
Update the supported locales. -
consoleResourceBundle
Return the console resources for a given locale.- Parameters:
locale- the locale- Returns:
- the resource bundle
-
supportedLocales
Returns the supported locales and their resource bundles.- Returns:
- the set of locales supported by the console and their resource bundles
-
onGetRedirect
@RequestHandler(dynamic=true) public void onGetRedirect(Request.In.Get event, IOSubchannel channel) throws InterruptedException, IOException, ParseException RedirectsGETrequests without trailing slash.- Parameters:
event- the eventchannel- the channel- Throws:
InterruptedException- the interrupted exceptionIOException- Signals that an I/O exception has occurred.ParseException- the parse exception
-
onGet
@RequestHandler(dynamic=true) public void onGet(Request.In.Get event, IOSubchannel channel) throws InterruptedException, IOException, ParseException Handle theGETrequests for the various resources.The requests have to start with the prefix passed to the constructor. Further processing depends on the next path segment:
-
.../console-base-resource: Provide a resource associated with this class. The resources are:jgconsole.js: The JavaScript module with helper classesconsole.css: Some basic styles for conlets
-
.../console-resource: InvokesprovideConsoleResource(org.jgrapes.http.events.Request.In.Get, java.lang.String, org.jgrapes.io.IOSubchannel)with the remainder of the path. -
.../page-resource: InvokesprovidePageResource(org.jgrapes.http.events.Request.In.Get, org.jgrapes.io.IOSubchannel, java.lang.String)with the remainder of the path. -
.../conlet-resource: InvokesprovideConletResource(org.jgrapes.http.events.Request.In.Get, org.jgrapes.io.IOSubchannel, java.net.URI)with the remainder of the path. -
.../console-connection: Handled by this class. Used e.g. for initiating the web socket connection.
- Parameters:
event- the eventchannel- the channel- Throws:
InterruptedException- the interrupted exceptionIOException- Signals that an I/O exception has occurred.ParseException- the parse exception
-
-
renderConsole
protected abstract void renderConsole(Request.In.Get event, IOSubchannel channel, UUID consoleConnectionId) throws IOException, InterruptedException Render the console page.- Parameters:
event- the eventchannel- the channel- Throws:
IOException- Signals that an I/O exception has occurred.InterruptedException- the interrupted exception
-
provideConsoleResource
protected void provideConsoleResource(Request.In.Get event, String requestPath, IOSubchannel channel) Provide a console resource.The implementation tries to load the resource using
Class.getResource(String)for each class in the class hierarchy, starting with the finally derived class.- Parameters:
event- the eventrequestPath- the request path relativized to the common part for console resourceschannel- the channel
-
prependConsoleResourceProvider
Prepends the given class to the list of classes searched byprovideConsoleResource(Request.In.Get, String, IOSubchannel).- Parameters:
cls- the class to prepend- Returns:
- the console weblet for easy chaining
-
onResourceRequestCompleted
@Handler(channels=ConsoleChannel.class) public void onResourceRequestCompleted(ResourceRequestCompleted event, ConsoleWeblet.ConsoleResourceChannel channel) throws IOException, InterruptedException Handles theResourceRequestCompletedevent.- Parameters:
event- the eventchannel- the channel- Throws:
IOException- Signals that an I/O exception has occurred.InterruptedException- the interrupted exception
-
onSetLocale
@Handler(channels=ConsoleChannel.class, priority=10000) public void onSetLocale(SetLocale event, ConsoleConnection channel) throws InterruptedException, IOException Handles a change of Locale for the console.- Parameters:
event- the eventchannel- the channel- Throws:
InterruptedException- the interrupted exceptionIOException- Signals that an I/O exception has occurred.
-
onSetLocaleCompleted
@Handler(channels=ConsoleChannel.class) public void onSetLocaleCompleted(SetLocaleCompleted event, ConsoleConnection channel) Sends a reload if the change of locale could not be handled by all conlets.- Parameters:
event- the eventchannel- the channel
-
onUpgraded
Called when the connection has been upgraded.- Parameters:
event- the eventwsChannel- the ws channel- Throws:
IOException- Signals that an I/O exception has occurred.
-
onDiscardSession
@Handler(channels=org.jgrapes.core.Channel.class) public void onDiscardSession(DiscardSession event) Discard the session referenced in the event.- Parameters:
event- the event
-
onInput
Handles network input (JSON data).- Parameters:
event- the eventwsChannel- the ws channel- Throws:
IOException- Signals that an I/O exception has occurred.
-
onClosed
Handles the closed event from the web socket.- Parameters:
event- the eventwsChannel- the WebSocket channel- Throws:
IOException- Signals that an I/O exception has occurred.
-
onConsoleCommand
@Handler(channels=ConsoleChannel.class, priority=-1000) public void onConsoleCommand(ConsoleCommand event, ConsoleConnection channel) throws InterruptedException, IOException Sends a command to the console.- Parameters:
event- the eventchannel- the channel- Throws:
InterruptedException- the interrupted exceptionIOException- Signals that an I/O exception has occurred.
-