Package com.google.genkit.plugins.jetty
Class JettyPlugin
java.lang.Object
com.google.genkit.plugins.jetty.JettyPlugin
- All Implemented Interfaces:
Plugin,ServerPlugin
JettyPlugin provides HTTP endpoints for Genkit flows.
This plugin exposes registered flows as HTTP endpoints, making it easy to deploy Genkit applications as web services.
Example usage:
Genkit genkit = Genkit.builder().plugin(new JettyPlugin(JettyPluginOptions.builder().port(8080).build())).build();
// Define your flows...
// Start the server and block (keeps application running)
genkit.start();
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a JettyPlugin with default options.JettyPlugin(JettyPluginOptions options) Creates a JettyPlugin with the specified options. -
Method Summary
Modifier and TypeMethodDescriptionstatic JettyPlugincreate(int port) Creates a JettyPlugin with the specified port.getName()Returns the unique identifier for the plugin.intgetPort()Returns the port the server is listening on.init()Initializes the plugin.Initializes the plugin with access to the registry.booleanReturns true if the server is currently running.voidstart()Starts the Jetty server and blocks until it is stopped.voidstop()Stops the Jetty server.
-
Constructor Details
-
JettyPlugin
public JettyPlugin()Creates a JettyPlugin with default options. -
JettyPlugin
Creates a JettyPlugin with the specified options.- Parameters:
options- the plugin options
-
-
Method Details
-
create
Creates a JettyPlugin with the specified port.- Parameters:
port- the HTTP port- Returns:
- a new JettyPlugin
-
getName
Description copied from interface:PluginReturns the unique identifier for the plugin. This name is used for registration and lookup. -
init
Description copied from interface:PluginInitializes the plugin. This method is called once during Genkit initialization. The plugin should return a list of actions that it provides. -
init
Description copied from interface:PluginInitializes the plugin with access to the registry. This method is called once during Genkit initialization. The plugin should return a list of actions that it provides.Override this method instead of
Plugin.init()when your plugin needs to resolve dependencies from the registry (e.g., embedders, models). -
start
Starts the Jetty server and blocks until it is stopped.This is the recommended way to start the server in a main() method. Similar to Express's app.listen() in JavaScript, this method will keep your application running until the server is explicitly stopped.
Example usage:
JettyPlugin jetty = new JettyPlugin(JettyPluginOptions.builder().port(8080).build()); Genkit genkit = Genkit.builder().plugin(jetty).build(); // Define your flows... // Start and block jetty.start();- Specified by:
startin interfaceServerPlugin- Throws:
Exception- if the server cannot be started or if interrupted while waiting
-
stop
Stops the Jetty server.- Specified by:
stopin interfaceServerPlugin- Throws:
Exception- if the server cannot be stopped
-
getPort
public int getPort()Returns the port the server is listening on.- Specified by:
getPortin interfaceServerPlugin- Returns:
- the configured port
-
isRunning
public boolean isRunning()Returns true if the server is currently running.- Specified by:
isRunningin interfaceServerPlugin- Returns:
- true if the server is running, false otherwise
-