- java.lang.Object
-
- com.github.alexdlaird.ngrok.process.NgrokProcess
-
public class NgrokProcess extends java.lang.Object
An object containing information about thengrok
process. Can be configured withJavaNgrokConfig
.Basic Usage
Opening a tunnel will start thengrok
process. This process will remain alive, and the tunnels open, untilstop()
is invoked, or until the Java process terminates.Event Logs
Whenngrok
emits logs,java-ngrok
can surface them to a callback function. To register this callback, useJavaNgrokConfig.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 callNgrokProcess.ProcessMonitor.stop()
to stop monitoring on a running process.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NgrokProcess.ProcessMonitor
A Runnable that monitors thengrok
process.
-
Constructor Summary
Constructors Constructor Description NgrokProcess(JavaNgrokConfig javaNgrokConfig, NgrokInstaller ngrokInstaller)
NgrokProcess(JavaNgrokConfig javaNgrokConfig, NgrokInstaller ngrokInstaller, HttpClient httpClient)
Ifngrok
is not already installed atJavaNgrokConfig.getNgrokPath()
, the givenNgrokInstaller
will install it.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getApiUrl()
Get the API URL for thengrok
web interface.java.util.List<NgrokLog>
getLogs()
Get thengrok
logs.NgrokInstaller
getNgrokInstaller()
Get the class used to download and installngrok
.NgrokProcess.ProcessMonitor
getProcessMonitor()
Get the Runnable that is monitoring thengrok
thread.java.lang.String
getVersion()
Get thengrok
version.boolean
isRunning()
Whether this object is currently managing a runningngrok
process.void
setApiKey(java.lang.String apiKey)
void
setAuthToken(java.lang.String authToken)
void
start()
If not already running, start angrok
process with no tunnels.void
stop()
Terminate thengrok
processes, if running.void
update()
Updatengrok
, if an update is available.
-
-
-
Constructor Detail
-
NgrokProcess
public NgrokProcess(JavaNgrokConfig javaNgrokConfig, NgrokInstaller ngrokInstaller, HttpClient httpClient)
Ifngrok
is not already installed atJavaNgrokConfig.getNgrokPath()
, the givenNgrokInstaller
will install it. This will also provision a defaultngrok
config atJavaNgrokConfig.getConfigPath()
, if none exists.- Parameters:
javaNgrokConfig
- The config to use when interacting with thengrok
binary.ngrokInstaller
- The class used to download and installngrok
.httpClient
- The HTTP client.
-
NgrokProcess
public NgrokProcess(JavaNgrokConfig javaNgrokConfig, NgrokInstaller ngrokInstaller)
- Parameters:
javaNgrokConfig
- The config to use when interacting with thengrok
binary.ngrokInstaller
- The class used to download and installngrok
.
-
-
Method Detail
-
getNgrokInstaller
public NgrokInstaller getNgrokInstaller()
Get the class used to download and installngrok
.
-
getProcessMonitor
public NgrokProcess.ProcessMonitor getProcessMonitor()
Get the Runnable that is monitoring thengrok
thread.
-
getLogs
public java.util.List<NgrokLog> getLogs()
Get thengrok
logs.
-
start
public void start()
If not already running, start angrok
process with no tunnels. This will start thengrok
web interface, against which HTTP requests can be made to create, interact with, and destroy tunnels.- Throws:
NgrokException
-ngrok
could not start.JavaNgrokSecurityException
- The URL was not supported.
-
isRunning
public boolean isRunning()
Whether this object is currently managing a runningngrok
process.
-
stop
public void stop()
Terminate thengrok
processes, if running. This method will not block, it will just issue a kill request.
-
setAuthToken
public void setAuthToken(java.lang.String authToken)
- Parameters:
authToken
- The auth token.- Throws:
NgrokException
-ngrok
could not start.
-
setApiKey
public void setApiKey(java.lang.String apiKey)
- Parameters:
apiKey
- The API key.- Throws:
NgrokException
-ngrok
could not start.
-
update
public void update()
Updatengrok
, if an update is available.- Throws:
NgrokException
-ngrok
could not start.
-
getVersion
public java.lang.String getVersion()
Get thengrok
version.- Returns:
- The version.
- Throws:
NgrokException
-ngrok
could not start.
-
getApiUrl
public java.lang.String getApiUrl()
Get the API URL for thengrok
web interface.- Throws:
JavaNgrokSecurityException
- The URL was not supported.
-
-