Tier: Platform · Status: Full · Java original:
firefly-platform-plugins· .NET project:FireflyFramework.Plugins.{Api,Core}
plugins ships the framework's plugin lifecycle SPI — a typed
Plugin interface and a composite Registry that starts every
plugin in registration order and stops them in reverse on shutdown.
Go's static-binary model does not support hot reload out of the box.
The Java port uses PF4J; the .NET port uses
McMaster.NETCore.Plugins. This module focuses on the lifecycle
contract — services that need dynamic reload integrate Go's plugin
package (cgo-only) at the application entry point and feed the
discovered values into the same Registry.
type Plugin interface {
Name() string
Start(ctx context.Context) error
Stop(ctx context.Context) error
}
type Registry struct{ ... }
func New() *Registry
func (*Registry) Register(Plugin) // re-registering by name overwrites
func (*Registry) StartAll(ctx) error // ordered; rolls back already-started on first failure
func (*Registry) StopAll(ctx) error // reverse order; joins errors
func (*Registry) Names() []stringimport (
"context"
"github.com/fireflyframework/fireflyframework-go/plugins"
)
type schedulerPlugin struct{ name string }
func (p *schedulerPlugin) Name() string { return p.name }
func (p *schedulerPlugin) Start(ctx context.Context) error {
log.Println("scheduler starting")
return nil
}
func (p *schedulerPlugin) Stop(ctx context.Context) error {
log.Println("scheduler stopping")
return nil
}
reg := plugins.New()
reg.Register(&schedulerPlugin{name: "scheduler"})
if err := reg.StartAll(ctx); err != nil {
log.Fatal(err)
}
defer reg.StopAll(ctx)starterapplication.Application exposes a pre-wired Registry ready
to receive plugins.
cd plugins
go test ./...Covers ordered start, reverse-order stop, rollback when a downstream start fails, and replace-by-name registration.