Skip to content

Commit

Permalink
Basic CHASM registry implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshtin committed Jan 31, 2025
1 parent 9fe70b4 commit f4128b0
Show file tree
Hide file tree
Showing 10 changed files with 890 additions and 54 deletions.
2 changes: 2 additions & 0 deletions chasm/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:generate mockgen -copyright_file ../LICENSE -package $GOPACKAGE -source $GOFILE -destination component_mock.go

package chasm

import "context"
Expand Down
89 changes: 89 additions & 0 deletions chasm/component_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions chasm/library.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:generate mockgen -copyright_file ../LICENSE -package $GOPACKAGE -source $GOFILE -destination library_mock.go

package chasm

type (
Library interface {
Name() string
Components() []RegistrableComponent
Tasks() []RegistrableTask
// Service()

mustEmbedUnimplementedLibrary()
}

UnimplementedLibrary struct{}
)

func (UnimplementedLibrary) Components() []RegistrableComponent {
return nil
}

func (UnimplementedLibrary) Tasks() []RegistrableTask {
return nil
}

func (UnimplementedLibrary) mustEmbedUnimplementedLibrary() {}
117 changes: 117 additions & 0 deletions chasm/library_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions chasm/registrable_component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package chasm

import (
"reflect"
)

var (
EmptyRegistrableComponent = RegistrableComponent{}
)

type (
RegistrableComponent struct {
name string
goType reflect.Type

ephemeral bool
singleCluster bool
shardingFn func(EntityKey) string
}

RegistrableComponentOption func(*RegistrableComponent)
)

func NewRegistrableComponent[C Component](
name string,
opts ...RegistrableComponentOption,
) RegistrableComponent {
rc := RegistrableComponent{
name: name,
goType: reflect.TypeFor[C](),
shardingFn: func(_ EntityKey) string { return "" },
}
for _, opt := range opts {
opt(&rc)
}
return rc
}

func WithEphemeral() RegistrableComponentOption {
return func(rc *RegistrableComponent) {
rc.ephemeral = true
}
}

// Is there any use case where we don't want to replicate certain instances of a archetype?
func WithSingleCluster() RegistrableComponentOption {
return func(rc *RegistrableComponent) {
rc.singleCluster = true
}
}

func WithShardingFn(
shardingFn func(EntityKey) string,
) RegistrableComponentOption {
return func(rc *RegistrableComponent) {
rc.shardingFn = shardingFn
}
}

func (rc RegistrableComponent) Name() string {
return rc.name
}
Loading

0 comments on commit f4128b0

Please sign in to comment.