diff --git a/src/app/proxy/runner-full.go b/src/app/proxy/controller-full.go similarity index 69% rename from src/app/proxy/runner-full.go rename to src/app/proxy/controller-full.go index b1e9c46..c4b5793 100644 --- a/src/app/proxy/runner-full.go +++ b/src/app/proxy/controller-full.go @@ -5,11 +5,11 @@ import ( "github.com/snivilised/extendio/xfs/nav" ) -type FullRunner struct { - baseRunner +type FullController struct { + controller } -func (r *FullRunner) OnNewShrinkItem(item *nav.TraverseItem, +func (c *FullController) OnNewShrinkItem(item *nav.TraverseItem, positional []string, thirdPartyCL cobrass.ThirdPartyCommandLine, ) error { diff --git a/src/app/proxy/controller-registry.go b/src/app/proxy/controller-registry.go new file mode 100644 index 0000000..52d9e15 --- /dev/null +++ b/src/app/proxy/controller-registry.go @@ -0,0 +1,46 @@ +package proxy + +import ( + "sync" +) + +func NewControllerRegistry(shared *SharedControllerInfo) *ControllerRegistry { + return &ControllerRegistry{ + pool: sync.Pool{ + // see: https://www.sobyte.net/post/2022-03/think-in-sync-pool/ + // + New: func() interface{} { + switch shared.Type { + case ControllerTypeFullEn: + return &FullController{ + controller: controller{ + shared: shared, + }, + } + + case ControllerTypeSamplerEn: + return &SamplerController{ + controller: controller{ + shared: shared, + }, + } + } + + panic("undefined controller type") + }, + }, + } +} + +type ControllerRegistry struct { + pool sync.Pool +} + +func (cr *ControllerRegistry) Get() ItemController { + return cr.pool.Get().(ItemController) +} + +func (cr *ControllerRegistry) Put(controller ItemController) { + controller.Reset() + cr.pool.Put(controller) +} diff --git a/src/app/proxy/controller-sampler.go b/src/app/proxy/controller-sampler.go new file mode 100644 index 0000000..9128647 --- /dev/null +++ b/src/app/proxy/controller-sampler.go @@ -0,0 +1,33 @@ +package proxy + +import ( + "github.com/snivilised/extendio/xfs/nav" +) + +type SamplerController struct { + controller +} + +func (c *SamplerController) OnNewShrinkItem(item *nav.TraverseItem, + positional []string, +) error { + _ = positional + + profileName := c.shared.Inputs.Root.ProfileFam.Native.Profile + schemeName := c.shared.Inputs.Root.ProfileFam.Native.Scheme + + var sequence Sequence + + switch { + case profileName != "": + sequence = c.profileSequence(profileName, item.Path) + + case schemeName != "": + sequence = c.schemeSequence(schemeName, item.Path) + + default: + sequence = c.adhocSequence(item.Path) + } + + return c.Run(item, sequence) +} diff --git a/src/app/proxy/runner-sampler_test.go b/src/app/proxy/controller-sampler_test.go similarity index 97% rename from src/app/proxy/runner-sampler_test.go rename to src/app/proxy/controller-sampler_test.go index cd023b3..ff52947 100644 --- a/src/app/proxy/runner-sampler_test.go +++ b/src/app/proxy/controller-sampler_test.go @@ -159,7 +159,7 @@ func resetFS(index string, silent bool) (vfs storage.VirtualFS, root string) { return vfs, root } -type runnerTE struct { +type controllerTE struct { given string should string args []string @@ -169,11 +169,11 @@ type runnerTE struct { } type samplerTE struct { - runnerTE + controllerTE scheme string } -var _ = Describe("SamplerRunner", Ordered, func() { +var _ = Describe("SamplerController", Ordered, func() { var ( repo string l10nPath string @@ -280,7 +280,7 @@ var _ = Describe("SamplerRunner", Ordered, func() { }, Entry(nil, &samplerTE{ - runnerTE: runnerTE{ + controllerTE: controllerTE{ given: "profile", should: "sample(first) with glob filter using the defined profile", relative: backyardWorldsPlanet9Scan01, @@ -297,7 +297,7 @@ var _ = Describe("SamplerRunner", Ordered, func() { }), Entry(nil, &samplerTE{ - runnerTE: runnerTE{ + controllerTE: controllerTE{ given: "profile", should: "sample(last) with glob filter using the defined profile", relative: backyardWorldsPlanet9Scan01, @@ -313,7 +313,7 @@ var _ = Describe("SamplerRunner", Ordered, func() { }), Entry(nil, &samplerTE{ - runnerTE: runnerTE{ + controllerTE: controllerTE{ given: "profile without no-files in args", should: "sample(first) with glob filter, using no-files from config", relative: backyardWorldsPlanet9Scan01, @@ -327,7 +327,7 @@ var _ = Describe("SamplerRunner", Ordered, func() { }), XEntry(nil, &samplerTE{ - runnerTE: runnerTE{ + controllerTE: controllerTE{ given: "profile", should: "sample with regex filter using the defined profile", relative: backyardWorldsPlanet9Scan01, @@ -345,7 +345,7 @@ var _ = Describe("SamplerRunner", Ordered, func() { // === Entry(nil, &samplerTE{ - runnerTE: runnerTE{ + controllerTE: controllerTE{ given: "scheme", should: "sample all profiles in the scheme", relative: backyardWorldsPlanet9Scan01, diff --git a/src/app/proxy/runner-base.go b/src/app/proxy/controller.go similarity index 67% rename from src/app/proxy/runner-base.go rename to src/app/proxy/controller.go index 015e094..abcaf1a 100644 --- a/src/app/proxy/runner-base.go +++ b/src/app/proxy/controller.go @@ -13,17 +13,17 @@ import ( // scheme: adhoc and profile from a scheme // -type baseRunner struct { // rename to be a controller instead of a runner - shared *SharedRunnerInfo +type controller struct { + shared *SharedControllerInfo } -func (r *baseRunner) profileSequence( +func (c *controller) profileSequence( name, itemPath string, ) Sequence { - changed := r.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL - cl := r.composeProfileCL(name, changed) + changed := c.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL + cl := c.composeProfileCL(name, changed) step := &magickStep{ - shared: r.shared, + shared: c.shared, thirdPartyCL: cl, sourcePath: itemPath, profile: name, @@ -34,17 +34,17 @@ func (r *baseRunner) profileSequence( return Sequence{step} } -func (r *baseRunner) schemeSequence( +func (c *controller) schemeSequence( name, itemPath string, ) Sequence { - changed := r.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL - schemeCfg, _ := r.shared.sampler.Scheme(name) // scheme already validated + changed := c.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL + schemeCfg, _ := c.shared.sampler.Scheme(name) // scheme already validated sequence := make(Sequence, 0, len(schemeCfg.Profiles)) for _, current := range schemeCfg.Profiles { - cl := r.composeProfileCL(current, changed) + cl := c.composeProfileCL(current, changed) step := &magickStep{ - shared: r.shared, + shared: c.shared, thirdPartyCL: cl, sourcePath: itemPath, scheme: name, @@ -59,12 +59,12 @@ func (r *baseRunner) schemeSequence( return sequence } -func (r *baseRunner) adhocSequence( +func (c *controller) adhocSequence( itemPath string, ) Sequence { - changed := r.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL + changed := c.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL step := &magickStep{ - shared: r.shared, + shared: c.shared, thirdPartyCL: changed, sourcePath: itemPath, // outputPath: , @@ -74,20 +74,20 @@ func (r *baseRunner) adhocSequence( return Sequence{step} } -func (r *baseRunner) composeProfileCL( +func (c *controller) composeProfileCL( profileName string, secondary clif.ThirdPartyCommandLine, ) clif.ThirdPartyCommandLine { - primary, _ := r.shared.profiles.Profile(profileName) // profile already validated + primary, _ := c.shared.profiles.Profile(profileName) // profile already validated return cobrass.Evaluate( primary, - r.shared.Inputs.ParamSet.Native.ThirdPartySet.KnownBy, + c.shared.Inputs.ParamSet.Native.ThirdPartySet.KnownBy, secondary, ) } -func (r *baseRunner) Run(item *nav.TraverseItem, sequence Sequence) error { +func (c *controller) Run(item *nav.TraverseItem, sequence Sequence) error { var ( zero Step resultErr error @@ -95,7 +95,7 @@ func (r *baseRunner) Run(item *nav.TraverseItem, sequence Sequence) error { iterator := collections.ForwardRunIt[Step, error](sequence, zero) each := func(s Step) error { - return s.Run(r.shared) + return s.Run(c.shared) } while := func(_ Step, err error) bool { if resultErr == nil { @@ -115,14 +115,14 @@ func (r *baseRunner) Run(item *nav.TraverseItem, sequence Sequence) error { // Perhaps we have an error policy including one that implements // a retry. // - if err := r.shared.fileManager.Setup(item); err != nil { + if err := c.shared.fileManager.Setup(item); err != nil { return err } iterator.RunAll(each, while) - return r.shared.fileManager.Tidy() + return c.shared.fileManager.Tidy() } -func (r *baseRunner) Reset() { +func (c *controller) Reset() { } diff --git a/src/app/proxy/enter-shrink.go b/src/app/proxy/enter-shrink.go index 2700c02..7b94319 100644 --- a/src/app/proxy/enter-shrink.go +++ b/src/app/proxy/enter-shrink.go @@ -92,10 +92,10 @@ func (e *ShrinkEntry) PrincipalOptionsFn(o *nav.TraverseOptions) { fmt.Sprintf("'%v'", item.Path), } - runner := e.Registry.Get() - defer e.Registry.Put(runner) + controller := e.Registry.Get() + defer e.Registry.Put(controller) - return runner.OnNewShrinkItem(item, positional) + return controller.OnNewShrinkItem(item, positional) }, } } @@ -135,8 +135,8 @@ func (e *ShrinkEntry) ConfigureOptions(o *nav.TraverseOptions) { e.EntryBase.ConfigureOptions(o) finder := e.createFinder() - e.Registry = NewRunnerRegistry(&SharedRunnerInfo{ - Type: RunnerTypeSamplerEn, // TODO: to come from an arg !!! + e.Registry = NewControllerRegistry(&SharedControllerInfo{ + Type: ControllerTypeSamplerEn, // TODO: to come from an arg !!! Options: e.Options, program: e.Program, profiles: e.ProfilesCFG, @@ -194,10 +194,10 @@ func (e *ShrinkEntry) resumeFn(item *nav.TraverseItem) error { fmt.Sprintf("'%v'", item.Path), } - runner := e.Registry.Get() - defer e.Registry.Put(runner) + controller := e.Registry.Get() + defer e.Registry.Put(controller) - return runner.OnNewShrinkItem(item, positional) + return controller.OnNewShrinkItem(item, positional) } func (e *ShrinkEntry) run(_ configuration.ViperConfig) error { diff --git a/src/app/proxy/entry-base.go b/src/app/proxy/entry-base.go index 30979fe..802f15f 100644 --- a/src/app/proxy/entry-base.go +++ b/src/app/proxy/entry-base.go @@ -40,7 +40,7 @@ type EntryBase struct { Program Executor Config configuration.ViperConfig Options *nav.TraverseOptions - Registry *RunnerRegistry + Registry *ControllerRegistry ProfilesCFG ProfilesConfig SamplerCFG SamplerConfig Vfs storage.VirtualFS @@ -132,12 +132,12 @@ func (e *EntryBase) ConfigureOptions(o *nav.TraverseOptions) { } } - // TODO: get the runner type properly, instead of hard coding to Sampler + // TODO: get the controller type properly, instead of hard coding to Sampler // This should not be here; move to root // if e.Registry == nil { - e.Registry = NewRunnerRegistry(&SharedRunnerInfo{ - Type: RunnerTypeSamplerEn, // TODO: to come from an arg !!! + e.Registry = NewControllerRegistry(&SharedControllerInfo{ + Type: ControllerTypeSamplerEn, // TODO: to come from an arg !!! Options: e.Options, program: e.Program, profiles: e.ProfilesCFG, diff --git a/src/app/proxy/execution-step.go b/src/app/proxy/execution-step.go index 2dfecdb..c90b313 100644 --- a/src/app/proxy/execution-step.go +++ b/src/app/proxy/execution-step.go @@ -6,7 +6,7 @@ import ( // Step type Step interface { - Run(*SharedRunnerInfo) error + Run(*SharedControllerInfo) error } // Sequence @@ -14,10 +14,10 @@ type Sequence []Step // magickStep knows how to combine parameters together so that the program // can be invoked correctly; but it does not know how to compose the input -// and output file names; this is the responsibility of the runner, which uses +// and output file names; this is the responsibility of the controller, which uses // the path-finder to accomplish that task. type magickStep struct { - shared *SharedRunnerInfo + shared *SharedControllerInfo thirdPartyCL clif.ThirdPartyCommandLine scheme string profile string @@ -27,7 +27,7 @@ type magickStep struct { } // Run -func (s *magickStep) Run(*SharedRunnerInfo) error { +func (s *magickStep) Run(*SharedControllerInfo) error { positional := []string{s.sourcePath} return s.shared.program.Execute(clif.Expand(positional, s.thirdPartyCL, s.outputPath)...) diff --git a/src/app/proxy/path-finder.go b/src/app/proxy/path-finder.go index 088f7ef..a1f82f9 100644 --- a/src/app/proxy/path-finder.go +++ b/src/app/proxy/path-finder.go @@ -67,7 +67,7 @@ func (tc pfTemplatesCollection) evaluate( // EJECT: replicate the source directory struct but eject elsewhere // INLINE: create the file at the same location as the original but rename as required -// The runner is aware of the output strategy moving files accordingly, +// The controller is aware of the output strategy moving files accordingly, // using the path-finder to create the paths and the file-manager to interact // with the file system, using a vfs. @@ -114,7 +114,7 @@ so we have 3 parameters: * --output --trash [ous=eject; des=eject] */ -// PathFinder provides the common paths required, but its the runners that know +// PathFinder provides the common paths required, but its the controller that know // the specific paths based around this common framework type strategies struct { diff --git a/src/app/proxy/proxy-defs.go b/src/app/proxy/proxy-defs.go index c263e3d..5d60abd 100644 --- a/src/app/proxy/proxy-defs.go +++ b/src/app/proxy/proxy-defs.go @@ -4,16 +4,16 @@ import ( "github.com/snivilised/extendio/xfs/nav" ) -type RunnerTypeEnum uint +type ControllerTypeEnum uint const ( - _ RunnerTypeEnum = iota - RunnerTypeFullEn - RunnerTypeSamplerEn + _ ControllerTypeEnum = iota + ControllerTypeFullEn + ControllerTypeSamplerEn ) -type SharedRunnerInfo struct { - Type RunnerTypeEnum +type SharedControllerInfo struct { + Type ControllerTypeEnum Options *nav.TraverseOptions program Executor profiles ProfilesConfig @@ -24,7 +24,7 @@ type SharedRunnerInfo struct { } // ItemController -type ItemRunner interface { +type ItemController interface { OnNewShrinkItem(item *nav.TraverseItem, positional []string, ) error diff --git a/src/app/proxy/runner-registry.go b/src/app/proxy/runner-registry.go deleted file mode 100644 index 3cea11c..0000000 --- a/src/app/proxy/runner-registry.go +++ /dev/null @@ -1,46 +0,0 @@ -package proxy - -import ( - "sync" -) - -func NewRunnerRegistry(shared *SharedRunnerInfo) *RunnerRegistry { - return &RunnerRegistry{ - pool: sync.Pool{ - // see: https://www.sobyte.net/post/2022-03/think-in-sync-pool/ - // - New: func() interface{} { - switch shared.Type { - case RunnerTypeFullEn: - return &FullRunner{ - baseRunner: baseRunner{ - shared: shared, - }, - } - - case RunnerTypeSamplerEn: - return &SamplerRunner{ - baseRunner: baseRunner{ - shared: shared, - }, - } - } - - panic("undefined runner type") - }, - }, - } -} - -type RunnerRegistry struct { - pool sync.Pool -} - -func (rr *RunnerRegistry) Get() ItemRunner { - return rr.pool.Get().(ItemRunner) -} - -func (rr *RunnerRegistry) Put(runner ItemRunner) { - runner.Reset() - rr.pool.Put(runner) -} diff --git a/src/app/proxy/runner-sampler.go b/src/app/proxy/runner-sampler.go deleted file mode 100644 index 78c5488..0000000 --- a/src/app/proxy/runner-sampler.go +++ /dev/null @@ -1,33 +0,0 @@ -package proxy - -import ( - "github.com/snivilised/extendio/xfs/nav" -) - -type SamplerRunner struct { - baseRunner -} - -func (r *SamplerRunner) OnNewShrinkItem(item *nav.TraverseItem, - positional []string, -) error { - _ = positional - - profileName := r.shared.Inputs.Root.ProfileFam.Native.Profile - schemeName := r.shared.Inputs.Root.ProfileFam.Native.Scheme - - var sequence Sequence - - switch { - case profileName != "": - sequence = r.profileSequence(profileName, item.Path) - - case schemeName != "": - sequence = r.schemeSequence(schemeName, item.Path) - - default: - sequence = r.adhocSequence(item.Path) - } - - return r.Run(item, sequence) -}