This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/develop by this push:
     new 4b6c00cf2 Optimize: remove deplicate judge available (#2908)
4b6c00cf2 is described below

commit 4b6c00cf238c6c4f33b4bcec4d4773c693598a81
Author: marsevilspirit <[email protected]>
AuthorDate: Sat Jun 14 22:54:08 2025 +0800

    Optimize: remove deplicate judge available (#2908)
    
    * remove depliate judge available
    
    * use SetError to set result error
    
    * optimize result usage
    
    * fix typo
    
    * fix comments
---
 protocol/dubbo/dubbo_invoker.go   | 35 ++++++++++++++---------------------
 protocol/grpc/grpc_invoker.go     | 26 ++++++++------------------
 protocol/triple/dubbo3_invoker.go | 30 ++++++++++--------------------
 3 files changed, 32 insertions(+), 59 deletions(-)

diff --git a/protocol/dubbo/dubbo_invoker.go b/protocol/dubbo/dubbo_invoker.go
index 7c2eac811..4a080d785 100644
--- a/protocol/dubbo/dubbo_invoker.go
+++ b/protocol/dubbo/dubbo_invoker.go
@@ -100,24 +100,14 @@ func (di *DubboInvoker) Invoke(ctx context.Context, ivc 
base.Invocation) result.
                // Generally, the case will not happen, because the invoker has 
been removed
                // from the invoker list before destroy,so no new request will 
enter the destroyed invoker
                logger.Warnf("this dubboInvoker is destroyed")
-               res.Err = base.ErrDestroyedInvoker
+               res.SetError(base.ErrDestroyedInvoker)
                return &res
        }
 
-       di.clientGuard.RLock()
-       defer di.clientGuard.RUnlock()
-
-       if di.client == nil {
-               res.Err = base.ErrClientClosed
-               logger.Debugf("result.Err: %v", res.Err)
-               return &res
-       }
-
-       if !di.BaseInvoker.IsAvailable() {
-               // Generally, the case will not happen, because the invoker has 
been removed
-               // from the invoker list before destroy,so no new request will 
enter the destroyed invoker
-               logger.Warnf("this dubboInvoker is destroying")
-               res.Err = base.ErrDestroyedInvoker
+       client := di.getClient()
+       if client == nil {
+               res.SetError(base.ErrClientClosed)
+               logger.Debugf("result.Err: %v", res.Error())
                return &res
        }
 
@@ -149,20 +139,23 @@ func (di *DubboInvoker) Invoke(ctx context.Context, ivc 
base.Invocation) result.
        timeout := di.getTimeout(inv)
        if async {
                if callBack, ok := inv.CallBack().(func(response 
common.CallbackResponse)); ok {
-                       res.Err = di.client.AsyncRequest(&ivc, url, timeout, 
callBack, rest)
+                       err = client.AsyncRequest(&ivc, url, timeout, callBack, 
rest)
+                       res.SetError(err)
                } else {
-                       res.Err = di.client.Send(&ivc, url, timeout)
+                       err = client.Send(&ivc, url, timeout)
+                       res.SetError(err)
                }
        } else {
                if inv.Reply() == nil {
-                       res.Err = base.ErrNoReply
+                       res.SetError(base.ErrNoReply)
                } else {
-                       res.Err = di.client.Request(&ivc, url, timeout, rest)
+                       err = client.Request(&ivc, url, timeout, rest)
+                       res.SetError(err)
                }
        }
        if res.Err == nil {
-               res.Rest = inv.Reply()
-               res.Attrs = rest.Attrs
+               res.SetResult(inv.Reply())
+               res.SetAttachments(rest.Attachments())
        }
 
        return &res
diff --git a/protocol/grpc/grpc_invoker.go b/protocol/grpc/grpc_invoker.go
index 04121da05..4039ea1c7 100644
--- a/protocol/grpc/grpc_invoker.go
+++ b/protocol/grpc/grpc_invoker.go
@@ -80,28 +80,18 @@ func (gi *GrpcInvoker) Invoke(ctx context.Context, 
invocation base.Invocation) r
                // Generally, the case will not happen, because the invoker has 
been removed
                // from the invoker list before destroy,so no new request will 
enter the destroyed invoker
                logger.Warnf("this grpcInvoker is destroyed")
-               result.Err = base.ErrDestroyedInvoker
+               result.SetError(base.ErrDestroyedInvoker)
                return &result
        }
 
-       gi.clientGuard.RLock()
-       defer gi.clientGuard.RUnlock()
-
-       if gi.client == nil {
-               result.Err = base.ErrClientClosed
-               return &result
-       }
-
-       if !gi.BaseInvoker.IsAvailable() {
-               // Generally, the case will not happen, because the invoker has 
been removed
-               // from the invoker list before destroy,so no new request will 
enter the destroyed invoker
-               logger.Warnf("this grpcInvoker is destroying")
-               result.Err = base.ErrDestroyedInvoker
+       client := gi.getClient()
+       if client == nil {
+               result.SetError(base.ErrClientClosed)
                return &result
        }
 
        if invocation.Reply() == nil {
-               result.Err = errNoReply
+               result.SetError(errNoReply)
        }
 
        var in []reflect.Value
@@ -109,13 +99,13 @@ func (gi *GrpcInvoker) Invoke(ctx context.Context, 
invocation base.Invocation) r
        in = append(in, invocation.ParameterValues()...)
 
        methodName := invocation.MethodName()
-       method := gi.client.invoker.MethodByName(methodName)
+       method := client.invoker.MethodByName(methodName)
        res := method.Call(in)
 
-       result.Rest = res[0]
+       result.SetResult(res[0])
        // check err
        if !res[1].IsNil() {
-               result.Err = res[1].Interface().(error)
+               result.SetError(res[1].Interface().(error))
        } else {
                _ = hessian2.ReflectResponse(res[0], invocation.Reply())
        }
diff --git a/protocol/triple/dubbo3_invoker.go 
b/protocol/triple/dubbo3_invoker.go
index 888997eac..48be3cd8e 100644
--- a/protocol/triple/dubbo3_invoker.go
+++ b/protocol/triple/dubbo3_invoker.go
@@ -207,23 +207,13 @@ func (di *DubboInvoker) Invoke(ctx context.Context, 
invocation base.Invocation)
                // Generally, the case will not happen, because the invoker has 
been removed
                // from the invoker list before destroy,so no new request will 
enter the destroyed invoker
                logger.Warnf("this dubboInvoker is destroyed")
-               result.Err = base.ErrDestroyedInvoker
+               result.SetError(base.ErrDestroyedInvoker)
                return &result
        }
 
-       di.clientGuard.RLock()
-       defer di.clientGuard.RUnlock()
-
-       if di.client == nil {
-               result.Err = base.ErrClientClosed
-               return &result
-       }
-
-       if !di.BaseInvoker.IsAvailable() {
-               // Generally, the case will not happen, because the invoker has 
been removed
-               // from the invoker list before destroy,so no new request will 
enter the destroyed invoker
-               logger.Warnf("this grpcInvoker is destroying")
-               result.Err = base.ErrDestroyedInvoker
+       client := di.getClient()
+       if client == nil {
+               result.SetError(base.ErrClientClosed)
                return &result
        }
 
@@ -267,13 +257,13 @@ func (di *DubboInvoker) Invoke(ctx context.Context, 
invocation base.Invocation)
        }
 
        methodName := invocation.MethodName()
-       triAttachmentWithErr := di.client.Invoke(methodName, in, 
invocation.Reply())
-       result.Err = triAttachmentWithErr.GetError()
-       result.Attrs = make(map[string]any)
+       triAttachmentWithErr := client.Invoke(methodName, in, 
invocation.Reply())
+       result.SetError(triAttachmentWithErr.GetError())
+       result.SetAttachments(make(map[string]any))
        for k, v := range triAttachmentWithErr.GetAttachments() {
-               result.Attrs[k] = v
+               result.AddAttachment(k, v)
        }
-       result.Rest = invocation.Reply()
+       result.SetResult(invocation.Reply())
        return &result
 }
 
@@ -296,7 +286,7 @@ func (di *DubboInvoker) getTimeout(inv 
*invocation.RPCInvocation) time.Duration
 func (di *DubboInvoker) IsAvailable() bool {
        client := di.getClient()
        if client != nil {
-               // FIXME here can't check if tcp server is started now!!!
+               // FIXME: here can't check if tcp server is started now!!!
                return client.IsAvailable()
        }
        return false

Reply via email to