public class NgrokProcess
extends java.lang.Object
ngrok process. Can be configured with
JavaNgrokConfig.
ngrok process. This process will remain alive, and the tunnels open,
until stop() is invoked, or until the Java process terminates.
ngrok emits logs, java-ngrok can surface them to a callback function. To register this
callback, use JavaNgrokConfig.Builder.withLogEventCallback(java.util.function.Function<com.github.alexdlaird.ngrok.process.NgrokLog, java.lang.Void>).
If these events aren't necessary for our use case, some resources can be freed up by turning them off.
JavaNgrokConfig.Builder.withoutMonitoring() will disable logging, or we can
call NgrokProcess.ProcessMonitor.stop() to stop monitoring on a running process.
| Modifier and Type | Class and Description |
|---|---|
static class |
NgrokProcess.ProcessMonitor
A Runnable that monitors the
ngrok process. |
| Constructor and Description |
|---|
NgrokProcess(JavaNgrokConfig javaNgrokConfig,
NgrokInstaller ngrokInstaller)
|
NgrokProcess(JavaNgrokConfig javaNgrokConfig,
NgrokInstaller ngrokInstaller,
HttpClient httpClient)
If
ngrok is not already installed at JavaNgrokConfig.getNgrokPath(), the given
NgrokInstaller will install it. |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getApiUrl()
Get the API URL for the
ngrok web interface. |
java.util.List<NgrokLog> |
getLogs()
Get the
ngrok logs. |
NgrokInstaller |
getNgrokInstaller()
Get the class used to download and install
ngrok. |
NgrokProcess.ProcessMonitor |
getProcessMonitor()
Get the Runnable that is monitoring the
ngrok thread. |
java.lang.String |
getVersion()
Get the
ngrok version. |
boolean |
isRunning()
Whether this object is currently managing a running
ngrok process. |
void |
setApiKey(java.lang.String apiKey)
|
void |
setAuthToken(java.lang.String authToken)
|
void |
start()
If not already running, start a
ngrok process with no tunnels. |
void |
stop()
Terminate the
ngrok processes, if running. |
void |
update()
Update
ngrok, if an update is available. |
public NgrokProcess(JavaNgrokConfig javaNgrokConfig, NgrokInstaller ngrokInstaller, HttpClient httpClient)
ngrok is not already installed at JavaNgrokConfig.getNgrokPath(), the given
NgrokInstaller will install it. This will also provision a default ngrok config at
JavaNgrokConfig.getConfigPath(), if none exists.javaNgrokConfig - The config to use when interacting with the ngrok binary.ngrokInstaller - The class used to download and install ngrok.httpClient - The HTTP client.public NgrokProcess(JavaNgrokConfig javaNgrokConfig, NgrokInstaller ngrokInstaller)
javaNgrokConfig - The config to use when interacting with the ngrok binary.ngrokInstaller - The class used to download and install ngrok.public NgrokInstaller getNgrokInstaller()
ngrok.public NgrokProcess.ProcessMonitor getProcessMonitor()
ngrok thread.public java.util.List<NgrokLog> getLogs()
ngrok logs.public void start()
ngrok process with no tunnels. This will start the
ngrok web interface, against which HTTP requests can be made to create, interact with, and
destroy tunnels.NgrokException - ngrok could not start.JavaNgrokSecurityException - The URL was not supported.public boolean isRunning()
ngrok process.public void stop()
ngrok processes, if running. This method will not block, it will just issue a kill
request.public void setAuthToken(java.lang.String authToken)
authToken - The auth token.NgrokException - ngrok could not start.public void setApiKey(java.lang.String apiKey)
apiKey - The API key.NgrokException - ngrok could not start.public void update()
ngrok, if an update is available.NgrokException - ngrok could not start.public java.lang.String getVersion()
ngrok version.NgrokException - ngrok could not start.public java.lang.String getApiUrl()
ngrok web interface.JavaNgrokSecurityException - The URL was not supported.