Interface Plugin
-
public interface Plugin
« start hereEntry point to core API ofHekate
plugins.Overview
Plugin
is a kind of a micro application who's lifecycle is bound to the lifecycle of aHekate
instance. EachPlugin
has full access toHekate
services API and can customize services configuration during its startup (f.e. register messaging channels, cluster event listeners, custom metrics, etc) as well as register custom services.Registration
Plugins can be registered to a
Hekate
instance viaHekateBootstrap.setPlugins(List)
.Lifecycle
-
When
Hekate
instance is created it callsinstall(HekateBootstrap)
method on all of its plugins in their registration order. Plugins can use the providedHekateBootstrap
instance to customizeHekate
instance configuration. Note that this method gets called only once during the whole lifetime ofHekate
instance. -
When
Hekate
instance startsjoining
to a cluster it callsstart(Hekate)
method on all of its plugins in their registration order. This method gets called after servicesinitialization
but before actual joining to the cluster begins. -
When
Hekate
instance startsHekate.leave()
leaving the cluster it callsstop()
method on all of its plugins in the reveres order.
Note:
Plugin
should be implemented in such a way so that itsstart(Hekate)
andstop()
methods could be called multiple times on the same instance. Those methods are not required to be thread safe sincestop()
is always called by the same thread that calledstart(Hekate)
.Example
Below is a simple example of
Plugin
that manages cluster topology information within a text file:public class ClusterInfoPlugin implements Plugin { private Path file; @Override public void install(HekateBootstrap boot) { // Nothing to configure. } @Override public void start(Hekate hekate) throws HekateException { // Prepare file file = Paths.get(hekate.localNode().name() + "-cluster.txt"); // Register cluster event listener that will update file on join/change cluster events. hekate.cluster().addListener(this::updateFile, ClusterEventType.JOIN, ClusterEventType.CHANGE); } @Override public void stop() throws HekateException { try { Files.deleteIfExists(file); } catch (IOException e) { throw new HekateException("Failed to delete " + file, e); } } private void updateFile(ClusterEvent event) throws HekateException { List<String> nodesInfo = event.topology().stream().map(ClusterNode::toString).collect(Collectors.toList()); try { Files.write(file, nodesInfo); } catch (IOException e) { throw new HekateException("Failed to update " + file, e); } } }
... and register this plugin to a
Hekate
node:Hekate node = new HekateBootstrap() .withNodeName("example-node") .withPlugin(new ClusterInfoPlugin()) .join();
- See Also:
HekateBootstrap.setPlugins(List)
-
When
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
install(HekateBootstrap boot)
Gets called whenHekate
instance is constructed.void
start(Hekate hekate)
void
stop()
-
-
-
Method Detail
-
install
void install(HekateBootstrap boot)
Gets called whenHekate
instance is constructed.Implementation of this method can use the provided
HekateBootstrap
to modifyHekate
instance configuration.- Parameters:
boot
-HekateBootstrap
.
-
start
void start(Hekate hekate) throws HekateException
- Parameters:
hekate
- Instance that this plugin is bound to.- Throws:
HekateException
- If plugin failed to start.
-
stop
void stop() throws HekateException
- Throws:
HekateException
- If plugin failed to stop.
-
-