Create your own plugin
This guide walks you through creating a plugin in Deephaven using Java or Groovy. Plugins in Deephaven are Java-based extensions that allow you to add custom functionality to the server, including custom object types, JavaScript plugins, and other extensions.
Deephaven plugins are implemented using the Java plugin API in the io.deephaven.plugin package. Plugins can extend the server's functionality by registering custom object types, JavaScript plugins, or other extensions.
This guide focuses on creating object type plugins, which allow you to register custom objects that can be exported from the server and accessed by clients.
Plugin structure
This example creates a plugin called ExampleObjectType that demonstrates how to create a custom object type plugin. The plugin will be implemented as a Java/Groovy class that extends the Deephaven plugin API.
Create the following directory and file structure for your plugin project:
Alternatively, if using Groovy:
Note
This guide uses Gradle for building the plugin. The plugin uses Java's ServiceLoader mechanism for registration, which requires the META-INF/services configuration.
Plugin implementation
Deephaven plugins are implemented using the Java plugin API. The main components are:
- ObjectType: Defines a custom object type that can be exported from the server.
- Registration: Registers the plugin with the Deephaven server using Java's ServiceLoader mechanism.
- Build configuration: Gradle build file to compile and package the plugin.
Creating an object type plugin
First, create the object type class. Here's an example in Java:
Or in Groovy:
Creating the example object
You'll also need to create the actual object class that your plugin manages:
Or in Groovy:
Plugin registration
Create a registration class that tells Deephaven about your plugin:
Or in Groovy:
ServiceLoader configuration
Create the ServiceLoader configuration file at src/main/resources/META-INF/services/io.deephaven.plugin.Registration:
This file tells Java's ServiceLoader mechanism where to find your plugin registration class.
Build configuration
Create a build.gradle file for your plugin:
Building and installing the plugin
Build the plugin
To build your plugin, run:
This creates a JAR file in the build/libs/ directory.
Install the plugin
To install your plugin in a Deephaven server:
- Copy the JAR file to the server's classpath or plugin directory
- Restart the server to load the plugin
- Create instances of your custom objects in Groovy scripts
Server setup
Local installation
If running Deephaven locally, you can install your plugin by:
- Building the plugin JAR as shown above
- Adding the JAR to Deephaven's classpath when starting the server
- Starting Deephaven with the plugin available
Docker deployment
For Docker deployments, create a Dockerfile that extends the Deephaven base image:
Create a Docker Compose file to run the server:
Important
The Docker Compose file below sets the pre-shared key to YOUR_PASSWORD_HERE for demonstration purposes. Change this to a more secure key in production.
With these files, run docker compose up to start the server with your plugin installed.
Server-side testing
Creating test objects
To test your plugin on the server side, create instances of your custom objects and export them so clients can access them. Create a Groovy script to set up test objects:
Local testing
When running Deephaven locally with your plugin installed, you can test the plugin by:
- Starting the Deephaven server with your plugin JAR in the classpath
- Opening the Deephaven IDE in your browser
- Running the test script above in the Groovy console
- Verifying that the objects are created and can be exported
Docker testing
When using Docker, add your test script to the container or run it through the IDE:
Client-side implementation
Groovy client setup
To interact with your plugin from a Groovy client, you'll need to create a client-side implementation that can connect to and communicate with your plugin objects on the server.
First, create a separate Groovy project for the client with its own build.gradle:
Client implementation
Create a Groovy client that can connect to your plugin objects:
Client-side testing
Running the client
To test your client-side implementation:
- Start the Deephaven server with your plugin installed
- Create test objects on the server using the server-side testing scripts above
- Build and run the client:
Complete test example
Here's a complete example that demonstrates the full plugin workflow:
Important
Replace YOUR_PASSWORD_HERE with the pre-shared key you set when starting the server.
Using the plugin
Once your plugin is installed, you can create and export instances of your custom objects:
Clients can then access these objects through the Deephaven client APIs. The object will be serialized according to the ObjectType's implementation.
Advanced features
Custom client-server communication
For plugins that need custom client-server communication beyond simple object export, you can implement a custom MessageStream in the compatibleClientConnection method. This allows you to handle bidirectional communication between the client and server.
The example above uses ObjectTypeBase.FetchOnly.INSTANCE, which is suitable for simple object types that only need to be fetched by clients without ongoing communication.
Multiple object types
A single plugin can register multiple object types by calling callback.register() multiple times in the registration class: