Skip to content

Commit

Permalink
feat: add message bus handlers for bootstrap (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed May 9, 2024
1 parent 4a9967e commit 89c9175
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 31 deletions.
35 changes: 35 additions & 0 deletions core/broker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package core

import (
"github.com/snivilised/extendio/bus"
)

const (
format = "%03d"
TopicOptionsAnnounce = "options.announce"
TopicOptionsBefore = "options.before"
TopicOptionsComplete = "options.complete"
)

var (
Broker *bus.Broker
topics = []string{
TopicOptionsAnnounce,
TopicOptionsBefore,
TopicOptionsComplete,
}
)

func init() {
b, err := bus.New(&bus.Sequential{
Format: format,
})

if err != nil {
panic(err)
}

b.RegisterTopics(topics...)

Broker = b
}
9 changes: 7 additions & 2 deletions cycle/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ type (
Stop Event[HibernateHandler]
}

// since the Controls are only required internally as they are used
// by registry, they should be moved to an internal package. this
// would also necessitate moving the handler definitions to core
// so that they can be shared.

Controls struct { // --> registry
Ascend NotificationCtrl[NodeHandler]
Begin NotificationCtrl[BeginHandler]
Expand Down Expand Up @@ -101,8 +106,8 @@ func (c *NotificationCtrl[F]) On(handler F) {
}

if c.listeners == nil {
const alloc = 2
c.listeners = make([]F, 0, alloc)
const size = 2
c.listeners = make([]F, 0, size)
c.listeners = append(c.listeners, c.Dispatch.Invoke)
}

Expand Down
3 changes: 0 additions & 3 deletions filtering/filtering-defs.go

This file was deleted.

17 changes: 9 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@ module github.com/snivilised/traverse
go 1.22.0

require (
github.com/onsi/ginkgo/v2 v2.17.2
github.com/onsi/ginkgo/v2 v2.17.3
github.com/onsi/gomega v1.33.1
github.com/snivilised/extendio v0.6.1
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f
github.com/snivilised/extendio v0.7.0
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
)

require (
github.com/avfs/avfs v0.33.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20240430035430-e4905b036c4e // indirect
github.com/google/pprof v0.0.0-20240508145209-1db217f89380 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/nicksnyder/go-i18n/v2 v2.4.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/samber/lo v1.39.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.20.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
34 changes: 18 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1v
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20240430035430-e4905b036c4e h1:RsXNnXE59RTt8o3DcA+w7ICdRfR2l+Bb5aE0YMpNTO8=
github.com/google/pprof v0.0.0-20240430035430-e4905b036c4e/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
github.com/google/pprof v0.0.0-20240508145209-1db217f89380 h1:DVHL33OE5pGk/5NzcooTFrgFC73NXLf+vApFzs3Vj0E=
github.com/google/pprof v0.0.0-20240508145209-1db217f89380/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand All @@ -23,8 +23,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/nicksnyder/go-i18n/v2 v2.4.0 h1:3IcvPOAvnCKwNm0TB0dLDTuawWEj+ax/RERNC+diLMM=
github.com/nicksnyder/go-i18n/v2 v2.4.0/go.mod h1:nxYSZE9M0bf3Y70gPQjN9ha7XNHX7gMc814+6wVyEI4=
github.com/onsi/ginkgo/v2 v2.17.2 h1:7eMhcy3GimbsA3hEnVKdw/PQM9XN9krpKVXsZdph0/g=
github.com/onsi/ginkgo/v2 v2.17.2/go.mod h1:nP2DPOQoNsQmsVyv5rDA8JkXQoCs6goXIvr/PRJ1eCc=
github.com/onsi/ginkgo/v2 v2.17.3 h1:oJcvKpIb7/8uLpDDtnQuf18xVnwKp8DTD7DQ6gTd/MU=
github.com/onsi/ginkgo/v2 v2.17.3/go.mod h1:nP2DPOQoNsQmsVyv5rDA8JkXQoCs6goXIvr/PRJ1eCc=
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
Expand All @@ -33,12 +33,14 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/snivilised/extendio v0.6.1 h1:8IIJ4rryKcRv796QxfHcMnuWl4erFMqJF4Rqcj8eY/k=
github.com/snivilised/extendio v0.6.1/go.mod h1:LbMvItdNqN8oZI4yUENxM459OkTP+W+hYXxKrc9l8ZQ=
github.com/snivilised/extendio v0.7.0 h1:MY6w9qCK5wVEvP2WpMT5ywJwpDJe97WHDGuwrsTLpek=
github.com/snivilised/extendio v0.7.0/go.mod h1:l8MwJOy9ojMQYJrSKRbQS3WfDylevnRtBp/zwAmFEKc=
github.com/snivilised/lorax v0.4.4 h1:fxuuew+88yUC9JkTq2iQhGx8tvECBzj2ugjssWlTI6A=
github.com/snivilised/lorax v0.4.4/go.mod h1:82r6nAoXWo1sdLXpj5RxYbAmiomu+xYVIXPn+cgG7I4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
Expand All @@ -49,16 +51,16 @@ go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
go.uber.org/zap/exp v0.2.0 h1:FtGenNNeCATRB3CmB/yEUnjEFeJWpB/pMcy7e2bKPYs=
go.uber.org/zap/exp v0.2.0/go.mod h1:t0gqAIdh1MfKv9EwN/dLwfZnJxe9ITAZN78HEWPFWDQ=
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY=
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY=
golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
32 changes: 32 additions & 0 deletions hiber/hibernation-defs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package hiber

import (
"context"

"github.com/snivilised/extendio/bus"
"github.com/snivilised/traverse/core"
)

const (
badge = "hibernator"
)

// hiber represents the facility to be able to start navigation in hibernated state,
// ie we navigate but dont invoke a client action, until a certain condition occurs,
// specified by a node matching a filter. This is what used to be called listening
Expand All @@ -8,3 +19,24 @@ package hiber
//
// Hibernation depends on filtering.
//

func init() {
h := bus.Handler{
Handle: func(_ context.Context, m bus.Message) {
// The data field will contain the appropriate
// object (represented behind an interface of some kind) that is related
// to the topic.
//
_ = m.Data
},
Matcher: core.TopicOptionsAnnounce,
}

core.Broker.RegisterHandler(badge, h)
}

// subscribe to options.before
func RestoreOptions() {
// called bny resume to load options from json file and
// setup registry to reflect this
}
46 changes: 46 additions & 0 deletions kernel/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,52 @@ type BootStrapper interface {
}

// bootstrap is the coordinator of initialisation events
// ==> handshake phase, allows other features to see how bootstrap has been established
// ==> use bus (maybe we create a local version of bus) ??
// (https://dev.to/mustafaturan/decoupled-package-communication-in-go-g39)
//
// ==> perhaps we have a new life cycle event "initialised" => indicates things like,
// * "l10n language used": this will confirm what language is in play (language.Tag,
// not string), useful when client
// * session type (standard or resume)
// * sampling active
// * requests an unsupported language, and informs the lang defaulted to
// these are the features that need to be considered:
//
// i18n: defined by the client
// log setup: defined by the client
// options: primary or resume
// hibernation
// filter
// sampling
// options
// resume
//
// * remember, hooks are different to events and there is a distinction
// between life-cycle events, which only the kernel can emit and the events
// that can also be emitted by the hooks or features(plugins)
//
// to make this a bit clearer, perhaps we define a bus and comms to and
// from it use messages instead of events. That allows us to have a clearer
// vocabulary within traverse. Messages are dynamic and can be sent to a topic.
// Whereas events are fixed in nature. We have a clear definition of each message,
// which is bound to a topic.
//
// * chain of responsibility? built into messaging structure; ie a message maybe consumed
// or ignored (return a bool from the function to determine if other listeners are
// able to see the message)
//
// if you build your own bus, then is no need to use an asynchronous model
//
// the term "callback" always refers to the client navigation callback function
//
// * we really ought to strive building this as a series of layers. The only
// problem with the features(plugins) and the core functionality in kernel
// is that it seems that they depend on each other. It's gonna be a fight
// to prevent this from happening.
// To achieve this, we must place common definitions in core and ensure
// that any feature does not depend on the kernel. Each feature must subscribe
// to topics they're interested in, and emit a message to indicate completion.

type bootstrap struct {
// should allow other entities to customise the boot phase, eg
Expand Down
18 changes: 18 additions & 0 deletions pref/options.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
package pref

import (
"context"
"log/slog"

"github.com/snivilised/extendio/bus"
"github.com/snivilised/traverse/core"
"github.com/snivilised/traverse/cycle"
"github.com/snivilised/traverse/enums"
)

// package: pref contains user option definitions; do not use anything in kernel (cyclic)

const (
badge = "option-requester"
)

func init() {
h := bus.Handler{
Handle: func(_ context.Context, m bus.Message) {
_ = m.Data
},
Matcher: core.TopicOptionsAnnounce,
}

core.Broker.RegisterHandler(badge, h)
}

type (
Options struct {
Core CoreOptions
Expand Down
2 changes: 2 additions & 0 deletions pref/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/snivilised/traverse/cycle"
)

// this package should be internal

type (
// Registry contains items derived from Options
Registry struct {
Expand Down
3 changes: 3 additions & 0 deletions refine/refine-defs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package refine

// refine defines filters and should be used by rx to alter observables
4 changes: 2 additions & 2 deletions resume/resume-defs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package resume
package refine

// resume should also contain persistence concerns. Depends on hiber, filtering
// refine should also contain persistence concerns. Depends on hiber, refine
// and persist.

0 comments on commit 89c9175

Please sign in to comment.