diff --git a/cluster/cluster_impl/base_cluster_invoker.go b/cluster/cluster_impl/base_cluster_invoker.go index c46460fc427e60c70eb216a30b282adc9fd2205b..ed8ed5803e0bedae13b04fb33561e305969b743f 100644 --- a/cluster/cluster_impl/base_cluster_invoker.go +++ b/cluster/cluster_impl/base_cluster_invoker.go @@ -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) diff --git a/cluster/directory/base_directory.go b/cluster/directory/base_directory.go index 1d6556849154e52f63787b36fb38ffd49537b186..93ff9ebc8c1f495676dd5cd0ddae25e1bb0c6987 100644 --- a/cluster/directory/base_directory.go +++ b/cluster/directory/base_directory.go @@ -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() } diff --git a/go.mod b/go.mod index 793fe406ad4358f3509994741c33ececfb275611..37c5d2a3cd99a0ca0e3f956ca8b65d7b1b6a9c7f 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index bc22846cb1e5d7ea6b0d0b6b337d9cbe35694f3e..ecf9e2bf55d6c275aaf8cf663fd8cbd18ad74146 100644 --- a/go.sum +++ b/go.sum @@ -116,8 +116,6 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0 github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/tevino/abool v0.0.0-20170917061928-9b9efcf221b5 h1:hNna6Fi0eP1f2sMBe/rJicDmaHmoXGe1Ta84FPYHLuE= -github.com/tevino/abool v0.0.0-20170917061928-9b9efcf221b5/go.mod h1:f1SCnEOt6sc3fOJfPQDRDzHOtSXuTtnz0ImG9kPRDV0= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.2/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ= github.com/ugorji/go/codec v0.0.0-20190320090025-2dc34c0b8780/go.mod h1:iT03XoTwV7xq/+UGwKO3UbC1nNNlopQiY61beSdrtOA= diff --git a/registry/mock_registry.go b/registry/mock_registry.go index 8e92b5c8f6095e90327bcfadf0637e46258e2981..c84fa1a8c60a78bc816b3916ad64a11e070a9d4b 100644 --- a/registry/mock_registry.go +++ b/registry/mock_registry.go @@ -1,7 +1,7 @@ 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{}