public abstract class AbstractDevServerRunner extends Object implements DevModeHandler
This class is meant to be used during developing time.
For internal use only. May be renamed or removed in a future release.
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractDevServerRunner(Lookup lookup,
int runningPort,
File npmFolder,
CompletableFuture<Void> waitFor)
Craete an instance that waits for the given task to complete before
starting or connecting to the server.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
checkConnection()
Check the connection to the dev server.
|
protected Process |
doStartDevServer()
Starts the dev server and returns the started process.
|
protected ApplicationConfiguration |
getApplicationConfiguration()
Gets the application configuration.
|
String |
getFailedOutput() |
int |
getPort()
Get the listening port of the dev server.
|
File |
getProjectRoot() |
protected abstract File |
getServerBinary()
Gets the binary that starts the dev server.
|
protected abstract File |
getServerConfig()
Gets the main configuration file for the dev server.
|
protected abstract Pattern |
getServerFailurePattern()
Gets a pattern to match with the output to determine that the server has
failed to start.
|
protected abstract String |
getServerName()
Gets the name of the dev server for outputting to the user and
statistics.
|
protected abstract List<String> |
getServerStartupCommand(String nodeExec)
Gets the commands to run to start the dev server.
|
protected abstract Pattern |
getServerSuccessPattern()
Gets a pattern to match with the output to determine that the server has
started successfully.
|
protected com.vaadin.base.devserver.DevServerWatchDog |
getWatchDog()
Gets the server watch dog.
|
boolean |
handleRequest(VaadinSession session,
VaadinRequest request,
VaadinResponse response) |
protected void |
onDevServerCompilation(DevServerOutputTracker.Result result)
Called whenever the dev server output matche the success or failure
pattern.
|
HttpURLConnection |
prepareConnection(String path,
String method) |
boolean |
serveDevModeRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Serve a file by proxying to the dev server.
|
void |
stop() |
protected void |
triggerLiveReload()
Triggers live reload.
|
protected void |
updateServerStartupEnvironment(FrontendTools frontendTools,
Map<String,String> environment)
Defines the environment variables to use when starting the dev server.
|
protected void |
validateFiles()
Validates that the needed server binary and config file(s) are available.
|
void |
waitForDevServer()
Waits for the dev server to start.
|
protected void |
writeStream(javax.servlet.ServletOutputStream outputStream,
InputStream inputStream) |
protected AbstractDevServerRunner(Lookup lookup, int runningPort, File npmFolder, CompletableFuture<Void> waitFor)
lookup - a lookup instancerunningPort - the port that a dev server is already running on or 0 to start
a new servernpmFolder - the project rootwaitFor - the task to wait for before running the server.protected void validateFiles()
throws ExecutionFailedException
ExecutionFailedException - if there is a problemprotected abstract File getServerBinary()
protected abstract File getServerConfig()
protected abstract String getServerName()
protected abstract List<String> getServerStartupCommand(String nodeExec)
nodeExec - the path to the node binaryprotected void updateServerStartupEnvironment(FrontendTools frontendTools, Map<String,String> environment)
frontendTools - frontend tools metadataenvironment - the environment variables to useprotected abstract Pattern getServerSuccessPattern()
protected abstract Pattern getServerFailurePattern()
protected Process doStartDevServer()
null if no process was startedprotected void onDevServerCompilation(DevServerOutputTracker.Result result)
public String getFailedOutput()
getFailedOutput in interface DevModeHandlerprotected com.vaadin.base.devserver.DevServerWatchDog getWatchDog()
protected void triggerLiveReload()
public File getProjectRoot()
getProjectRoot in interface DevModeHandlerprotected ApplicationConfiguration getApplicationConfiguration()
protected boolean checkConnection()
true if the dev server is responding correctly,
false otherwisepublic int getPort()
public void waitForDevServer()
Suspends the caller's thread until the dev mode server is started (or failed to start).
public void stop()
stop in interface DevModeHandlerpublic HttpURLConnection prepareConnection(String path, String method) throws IOException
prepareConnection in interface DevModeHandlerIOExceptionpublic boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException
handleRequest in interface RequestHandlerIOExceptionpublic boolean serveDevModeRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws IOException
Note: it considers the HttpServletRequest.getPathInfo() that will
be the path passed to the dev server which is running in the context root
folder of the application.
Method returns false immediately if dev server failed on its
startup.
serveDevModeRequest in interface DevModeHandlerrequest - the servlet requestresponse - the servlet responseIOException - in the case something went wrong like connection refusedprotected void writeStream(javax.servlet.ServletOutputStream outputStream,
InputStream inputStream)
throws IOException
IOExceptionCopyright © 2000–2022 Vaadin Ltd. All rights reserved.