Class JettyPlugin

java.lang.Object
com.google.genkit.plugins.jetty.JettyPlugin
All Implemented Interfaces:
Plugin, ServerPlugin

public class JettyPlugin extends Object implements 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 Details

    • JettyPlugin

      public JettyPlugin()
      Creates a JettyPlugin with default options.
    • JettyPlugin

      public JettyPlugin(JettyPluginOptions options)
      Creates a JettyPlugin with the specified options.
      Parameters:
      options - the plugin options
  • Method Details

    • create

      public static JettyPlugin create(int port)
      Creates a JettyPlugin with the specified port.
      Parameters:
      port - the HTTP port
      Returns:
      a new JettyPlugin
    • getName

      public String getName()
      Description copied from interface: Plugin
      Returns the unique identifier for the plugin. This name is used for registration and lookup.
      Specified by:
      getName in interface Plugin
      Returns:
      the plugin name
    • init

      public List<Action<?,?,?>> init()
      Description copied from interface: Plugin
      Initializes the plugin. This method is called once during Genkit initialization. The plugin should return a list of actions that it provides.
      Specified by:
      init in interface Plugin
      Returns:
      list of actions provided by this plugin
    • init

      public List<Action<?,?,?>> init(Registry registry)
      Description copied from interface: Plugin
      Initializes 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).

      Specified by:
      init in interface Plugin
      Parameters:
      registry - the Genkit registry for resolving dependencies
      Returns:
      list of actions provided by this plugin
    • start

      public void start() throws Exception
      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:
      start in interface ServerPlugin
      Throws:
      Exception - if the server cannot be started or if interrupted while waiting
    • stop

      public void stop() throws Exception
      Stops the Jetty server.
      Specified by:
      stop in interface ServerPlugin
      Throws:
      Exception - if the server cannot be stopped
    • getPort

      public int getPort()
      Returns the port the server is listening on.
      Specified by:
      getPort in interface ServerPlugin
      Returns:
      the configured port
    • isRunning

      public boolean isRunning()
      Returns true if the server is currently running.
      Specified by:
      isRunning in interface ServerPlugin
      Returns:
      true if the server is running, false otherwise