-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add configurator implementation
- Loading branch information
1 parent
2866189
commit a3e2bc2
Showing
3 changed files
with
44 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package gogctuner | ||
|
||
import ( | ||
"log" | ||
"sync/atomic" | ||
) | ||
|
||
func NewGcConfigurator() *gcConfigurator { | ||
return &gcConfigurator{ | ||
configUpdateCh: make(chan interface{}, 1), | ||
} | ||
} | ||
|
||
type gcConfigurator struct { | ||
config atomic.Value | ||
configUpdateCh chan interface{} | ||
} | ||
|
||
func (g *gcConfigurator) GetConfig() (Config, error) { | ||
c, _ := g.config.Load().(Config) | ||
return c, nil | ||
} | ||
|
||
func (g *gcConfigurator) Updates() <-chan interface{} { | ||
return g.configUpdateCh | ||
} | ||
|
||
func (g *gcConfigurator) SetConfig(value Config) { | ||
g.config.Store(value) | ||
|
||
select { | ||
case g.configUpdateCh <- struct{}{}: | ||
log.Printf("gctuner: gc config update event dispatched, config: %v", value) | ||
default: | ||
log.Printf("gctuner: gc config update event is dropped due to previous task not done, config: %v", value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters