public class HotWebSocketHandler extends Object implements WebSocketHandler
A hot handler is a "shell" that forwards handle(request)
calls to
the app handler that does the actual work. When source files are changed,
a new app handler instance is created. Reloading is done by a HotReloader
.
Typically a HotWebSocketHandler works together with a HotHttpHandler, and they should share the same HotReloader. For example:
HotReloader reloader = new HotReloader().onJavaFiles(SRC_DIR); HotHttpHandler httpHandler = new HotHttpHandler(reloader, MyHttpHandler.class); HotWebSocketHandler wsHandler = new HotWebSocketHandler(reloader, MyWsHandler.class);
Constructor and Description |
---|
HotWebSocketHandler(Class appHandlerClass)
Create a hot handler.
|
HotWebSocketHandler(HotReloader reloader,
Class appHandlerClass)
Create a hot handler.
|
HotWebSocketHandler(HotReloader reloader,
String appHandlerClassName)
Create a hot handler.
|
Instance Methods | |
---|---|
Async<WebSocketResponse> |
handle(WebSocketRequest request)
Handle a WebSocket request.
|
HotReloader |
reloader()
Get the HotReloader.
|
HotWebSocketHandler |
onJavaFiles(String... srcDirs)
Reload on java file changes.
|
HotWebSocketHandler |
onClassFiles()
Reload on class file changes.
|
HotWebSocketHandler |
onFiles(String fileDesc,
String filePattern,
String... srcDirs)
Reload on file changes.
|
public HotWebSocketHandler(Class appHandlerClass)
This constructor is equivalent to
HotWebSocketHandler( new HotReloader(), appHandlerClass.getName() )
.
public HotWebSocketHandler(HotReloader reloader, Class appHandlerClass)
This constructor is equivalent to
HotWebSocketHandler( reloader, appHandlerClass.getName() )
.
public HotWebSocketHandler(HotReloader reloader, String appHandlerClassName)
The app handler class must implement WebSocketHandler and have a public 0-arg constructor.
public Async<WebSocketResponse> handle(WebSocketRequest request)
This method obtains the app handler by
reloader().getAppInstance(appHandlerClassName)
,
then forwards the call to the app handler.
handle
in interface WebSocketHandler
public HotReloader reloader()
public HotWebSocketHandler onJavaFiles(String... srcDirs) throws Exception
This method is equivalent to reloader().
onJavaFiles(srcDirs)
.
Exception
public HotWebSocketHandler onClassFiles()
This method is equivalent to reloader().
onClassFiles(srcDirs)
.
public HotWebSocketHandler onFiles(String fileDesc, String filePattern, String... srcDirs)
This method is equivalent to reloader().
onFiles(srcDirs)
.