Skip to content
Snippets Groups Projects
Commit 11dcff0c authored by vito.he's avatar vito.he
Browse files

Mod:change to uber-go/atomic

parent 4bb87299
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ package cluster_impl
import (
gxnet "github.com/AlexStocks/goext/net"
jerrors "github.com/juju/errors"
"github.com/tevino/abool"
"go.uber.org/atomic"
)
import (
......@@ -16,14 +16,14 @@ import (
type baseClusterInvoker struct {
directory cluster.Directory
availablecheck bool
destroyed *abool.AtomicBool
destroyed *atomic.Bool
}
func newBaseClusterInvoker(directory cluster.Directory) baseClusterInvoker {
return baseClusterInvoker{
directory: directory,
availablecheck: true,
destroyed: abool.NewBool(false),
destroyed: atomic.NewBool(false),
}
}
func (invoker *baseClusterInvoker) GetUrl() common.URL {
......@@ -32,7 +32,7 @@ func (invoker *baseClusterInvoker) GetUrl() common.URL {
func (invoker *baseClusterInvoker) Destroy() {
//this is must atom operation
if invoker.destroyed.SetToIf(false, true) {
if invoker.destroyed.CAS(false, true) {
invoker.directory.Destroy()
}
}
......@@ -56,7 +56,7 @@ func (invoker *baseClusterInvoker) checkInvokers(invokers []protocol.Invoker, in
//check cluster invoker is destroyed or not
func (invoker *baseClusterInvoker) checkWhetherDestroyed() error {
if invoker.destroyed.IsSet() {
if invoker.destroyed.Load() {
ip, _ := gxnet.GetLocalIP()
return jerrors.Errorf("Rpc cluster invoker for %v on consumer %v use dubbo version %v is now destroyed! can not invoke any more. ",
invoker.directory.GetUrl().Service(), ip, version.Version)
......
......@@ -4,7 +4,7 @@ import (
"sync"
)
import (
"github.com/tevino/abool"
"go.uber.org/atomic"
)
import (
"github.com/dubbo/go-for-apache-dubbo/common"
......@@ -12,14 +12,14 @@ import (
type BaseDirectory struct {
url *common.URL
destroyed *abool.AtomicBool
destroyed *atomic.Bool
mutex sync.Mutex
}
func NewBaseDirectory(url *common.URL) BaseDirectory {
return BaseDirectory{
url: url,
destroyed: abool.NewBool(false),
destroyed: atomic.NewBool(false),
}
}
func (dir *BaseDirectory) GetUrl() common.URL {
......@@ -27,7 +27,7 @@ func (dir *BaseDirectory) GetUrl() common.URL {
}
func (dir *BaseDirectory) Destroy(doDestroy func()) {
if dir.destroyed.SetToIf(false, true) {
if dir.destroyed.CAS(false, true) {
dir.mutex.Lock()
doDestroy()
dir.mutex.Unlock()
......@@ -35,5 +35,5 @@ func (dir *BaseDirectory) Destroy(doDestroy func()) {
}
func (dir *BaseDirectory) IsAvailable() bool {
return !dir.destroyed.IsSet()
return !dir.destroyed.Load()
}
......@@ -8,7 +8,6 @@ require (
github.com/juju/errors v0.0.0-20190207033735-e65537c515d7
github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec
github.com/stretchr/testify v1.3.0
github.com/tevino/abool v0.0.0-20170917061928-9b9efcf221b5
go.uber.org/atomic v1.3.2
gopkg.in/yaml.v2 v2.2.2
)
package registry
import (
"github.com/tevino/abool"
"go.uber.org/atomic"
)
import (
"github.com/dubbo/go-for-apache-dubbo/common"
......@@ -9,12 +9,12 @@ import (
type MockRegistry struct {
listener *listener
destroyed *abool.AtomicBool
destroyed *atomic.Bool
}
func NewMockRegistry(url *common.URL) (Registry, error) {
registry := &MockRegistry{
destroyed: abool.NewBool(false),
destroyed: atomic.NewBool(false),
}
listener := &listener{count: 0, registry: registry, listenChan: make(chan *ServiceEvent)}
registry.listener = listener
......@@ -25,11 +25,11 @@ func (*MockRegistry) Register(url common.URL) error {
}
func (r *MockRegistry) Destroy() {
if r.destroyed.SetToIf(false, true) {
if r.destroyed.CAS(false, true) {
}
}
func (r *MockRegistry) IsAvailable() bool {
return !r.destroyed.IsSet()
return !r.destroyed.Load()
}
func (r *MockRegistry) GetUrl() common.URL {
return common.URL{}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment