Package edu.wpi.grip.core.http
Class GripServer
- java.lang.Object
-
- edu.wpi.grip.core.http.GripServer
-
public class GripServer extends java.lang.Object
An internal HTTP server.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
GripServer.JettyServerFactory
static class
GripServer.JettyServerFactoryImpl
static class
GripServer.State
Possible lifecycle states of the server.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DATA_PATH
The path for requesting data.static int
DEFAULT_PORT
The default port the server should run on.static java.lang.String
IMAGE_UPLOAD_PATH
The path for uploading images.static java.lang.String
PIPELINE_UPLOAD_PATH
The path for setting which pipeline to run.static java.lang.String
ROOT_PATH
The root path for all GRIP-related HTTP activity.static java.lang.String
UPLOAD_PATH
The root path for uploading data to the server.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addHandler(org.eclipse.jetty.server.Handler handler)
Adds the given handler to the server.int
getPort()
Gets the port this server is running on.GripServer.State
getState()
Gets the current state of the server.static boolean
isPortValid(int port)
Checks if the given TCP port is valid for a server to run on.void
removeHandler(org.eclipse.jetty.server.Handler handler)
Removes the given handler from the server.void
restart()
Restarts the server on the current port.void
setPort(int port)
Stops the server (if it's running) and creates a new HTTP server on the given port.void
settingsChanged(AppSettingsChangedEvent event)
void
start()
Starts this server.void
stop()
Stops this server.
-
-
-
Field Detail
-
ROOT_PATH
public static final java.lang.String ROOT_PATH
The root path for all GRIP-related HTTP activity.- See Also:
- Constant Field Values
-
UPLOAD_PATH
public static final java.lang.String UPLOAD_PATH
The root path for uploading data to the server.- See Also:
- Constant Field Values
-
IMAGE_UPLOAD_PATH
public static final java.lang.String IMAGE_UPLOAD_PATH
The path for uploading images. To upload an image, post an HTTP event to/GRIP/upload/image
, with the image bytes as the data.- See Also:
- Constant Field Values
-
PIPELINE_UPLOAD_PATH
public static final java.lang.String PIPELINE_UPLOAD_PATH
The path for setting which pipeline to run. To set the pipeline, post an HTTP event to/GRIP/upload/pipeline
, with the content of the pipeline save file as the data.- See Also:
- Constant Field Values
-
DATA_PATH
public static final java.lang.String DATA_PATH
The path for requesting data. Data will be returned as a json-formatted map of the outputs of all requested data sets.For example, performing a
GET
request on the path/GRIP/data?foo&bar
will return a map such as
{ 'foo': { // data }, 'bar': { // data } }
- See Also:
- Constant Field Values
-
DEFAULT_PORT
public static final int DEFAULT_PORT
The default port the server should run on.- See Also:
- Constant Field Values
-
-
Method Detail
-
isPortValid
public static boolean isPortValid(int port)
Checks if the given TCP port is valid for a server to run on. This doesn't check availability.- Parameters:
port
- the port to check- Returns:
- true if the port is valid, false if not
-
addHandler
public void addHandler(org.eclipse.jetty.server.Handler handler)
Adds the given handler to the server. Does nothing if the server already has that handler.- Parameters:
handler
- the handler to add
-
removeHandler
public void removeHandler(org.eclipse.jetty.server.Handler handler)
Removes the given handler from the server. Does nothing if the server does not have that handler.- Parameters:
handler
- the handler to remove
-
start
public void start()
Starts this server. Has no effect if the server has already been started or if it's been stopped.
-
stop
public void stop()
-
restart
public void restart()
Restarts the server on the current port.- Throws:
GripServerException
- if the server was unable to be restarted.
-
getState
public GripServer.State getState()
Gets the current state of the server.
-
setPort
public void setPort(int port)
Stops the server (if it's running) and creates a new HTTP server on the given port.- Parameters:
port
- the new port to run on.
-
getPort
public int getPort()
Gets the port this server is running on.
-
settingsChanged
public void settingsChanged(AppSettingsChangedEvent event)
-
-