From 70cfe0d3ae2fadaf9a79e48134b56985e1b65e5e Mon Sep 17 00:00:00 2001 From: zonghaishang <yiji@apache.org> Date: Wed, 12 Jun 2019 15:29:53 +0800 Subject: [PATCH] format code --- cluster/loadbalance/least_active.go | 21 +++++++++++---------- filter/impl/active_filter.go | 4 ++-- {filter => protocol}/RpcStatus.go | 9 ++++++--- 3 files changed, 19 insertions(+), 15 deletions(-) rename {filter => protocol}/RpcStatus.go (94%) diff --git a/cluster/loadbalance/least_active.go b/cluster/loadbalance/least_active.go index 588793578..092b62a9f 100644 --- a/cluster/loadbalance/least_active.go +++ b/cluster/loadbalance/least_active.go @@ -13,20 +13,22 @@ // @author yiji@apache.org package loadbalance +import ( + "math/rand" +) + import ( "github.com/dubbo/go-for-apache-dubbo/cluster" "github.com/dubbo/go-for-apache-dubbo/common/extension" - "github.com/dubbo/go-for-apache-dubbo/filter" "github.com/dubbo/go-for-apache-dubbo/protocol" - "math/rand" ) const ( - leastActive = "leastactive" + LeastActive = "leastactive" ) func init() { - extension.SetLoadbalance(leastActive, NewLeastActiveLoadBalance) + extension.SetLoadbalance(LeastActive, NewLeastActiveLoadBalance) } type leastActiveLoadBalance struct { @@ -37,9 +39,8 @@ func NewLeastActiveLoadBalance() cluster.LoadBalance { } func (lb *leastActiveLoadBalance) Select(invokers []protocol.Invoker, invocation protocol.Invocation) protocol.Invoker { - count := len(invokers) - if invokers == nil || count == 0 { + if count == 0 { return nil } if count == 1 { @@ -48,17 +49,17 @@ func (lb *leastActiveLoadBalance) Select(invokers []protocol.Invoker, invocation var ( leastActive int32 = -1 // The least active value of all invokers - totalWeight int64 = 0 // The number of invokers having the same least active value (leastActive) + totalWeight int64 = 0 // The number of invokers having the same least active value (LEAST_ACTIVE) firstWeight int64 = 0 // Initial value, used for comparision - leastIndexes = make([]int, count) // The index of invokers having the same least active value (leastActive) - leastCount = 0 // The number of invokers having the same least active value (leastActive) + leastIndexes = make([]int, count) // The index of invokers having the same least active value (LEAST_ACTIVE) + leastCount = 0 // The number of invokers having the same least active value (LEAST_ACTIVE) sameWeight = true // Every invoker has the same weight value? ) for i := 0; i < count; i++ { invoker := invokers[i] // Active number - active := filter.GetStatus(invoker.GetUrl(), invocation.MethodName()).GetActive() + active := protocol.GetStatus(invoker.GetUrl(), invocation.MethodName()).GetActive() // current weight (maybe in warmUp) weight := GetWeight(invoker, invocation) // There are smaller active services diff --git a/filter/impl/active_filter.go b/filter/impl/active_filter.go index eaaaeabd2..7ef1b2f70 100644 --- a/filter/impl/active_filter.go +++ b/filter/impl/active_filter.go @@ -35,13 +35,13 @@ type ActiveFilter struct { func (ef *ActiveFilter) Invoke(invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { logger.Infof("invoking active filter. %v,%v", invocation.MethodName(), len(invocation.Arguments())) - filter.BeginCount(invoker.GetUrl(), invocation.MethodName()) + protocol.BeginCount(invoker.GetUrl(), invocation.MethodName()) return invoker.Invoke(invocation) } func (ef *ActiveFilter) OnResponse(result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { - filter.EndCount(invoker.GetUrl(), invocation.MethodName()) + protocol.EndCount(invoker.GetUrl(), invocation.MethodName()) return result } diff --git a/filter/RpcStatus.go b/protocol/RpcStatus.go similarity index 94% rename from filter/RpcStatus.go rename to protocol/RpcStatus.go index 2148594da..89180b2dd 100644 --- a/filter/RpcStatus.go +++ b/protocol/RpcStatus.go @@ -11,16 +11,19 @@ // limitations under the License. // @author yiji@apache.org -package filter +package protocol import ( - "github.com/dubbo/go-for-apache-dubbo/common" "sync" "sync/atomic" ) +import ( + "github.com/dubbo/go-for-apache-dubbo/common" +) + var ( - methodStatistics = sync.Map{} // url -> { methodName : RpcStatus} + methodStatistics sync.Map // url -> { methodName : RpcStatus} ) type RpcStatus struct { -- GitLab