Skip to content
Snippets Groups Projects
Commit 0c19b529 authored by flycash's avatar flycash
Browse files

Using default context.Context.

parent e07ca040
No related branches found
No related tags found
No related merge requests found
......@@ -106,6 +106,7 @@ func (ef *GenericServiceFilter) Invoke(invoker protocol.Invoker, invocation prot
newParams[i] = newParam
}
newInvocation := invocation2.NewRPCInvocation(methodName, newParams, invocation.Attachments())
newInvocation.SetContext(invocation.Context())
newInvocation.SetReply(invocation.Reply())
return invoker.Invoke(newInvocation)
}
......
......@@ -56,7 +56,7 @@ func (tf *tracingFilter) Invoke(invoker protocol.Invoker, invocation protocol.In
// withTimeout after we support the timeout between different ends.
invCtx, cancel := context.WithCancel(invocation.Context())
span, spanCtx := opentracing.StartSpanFromContext(invCtx, operationName)
invocation.SetContext(protocol.NewContextWith(spanCtx))
invocation.SetContext(spanCtx)
defer func() {
span.Finish()
cancel()
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package protocol
import (
"context"
)
type Context struct {
context.Context
}
func NewContext() Context {
return NewContextWith(context.Background())
}
func NewContextWith(ctx context.Context) Context {
return Context{Context: ctx}
}
......@@ -18,6 +18,7 @@
package protocol
import (
"context"
"reflect"
)
......@@ -29,6 +30,6 @@ type Invocation interface {
Attachments() map[string]string
AttachmentsByKey(string, string) string
Invoker() Invoker
Context() Context
SetContext(ctx Context)
Context() context.Context
SetContext(ctx context.Context)
}
......@@ -18,6 +18,7 @@
package invocation
import (
"context"
"reflect"
"sync"
)
......@@ -39,7 +40,7 @@ type RPCInvocation struct {
attachments map[string]string
invoker protocol.Invoker
lock sync.RWMutex
ctx protocol.Context
ctx context.Context
}
func NewRPCInvocation(methodName string, arguments []interface{}, attachments map[string]string) *RPCInvocation {
......@@ -47,11 +48,14 @@ func NewRPCInvocation(methodName string, arguments []interface{}, attachments ma
methodName: methodName,
arguments: arguments,
attachments: attachments,
ctx: context.Background(),
}
}
func NewRPCInvocationWithOptions(opts ...option) *RPCInvocation {
invo := &RPCInvocation{}
invo := &RPCInvocation{
ctx: context.Background(),
}
for _, opt := range opts {
opt(invo)
}
......@@ -120,11 +124,11 @@ func (r *RPCInvocation) SetCallBack(c interface{}) {
r.callBack = c
}
func (r *RPCInvocation) Context() protocol.Context {
func (r *RPCInvocation) Context() context.Context {
return r.ctx
}
func (r *RPCInvocation) SetContext(ctx protocol.Context) {
func (r *RPCInvocation) SetContext(ctx context.Context) {
r.ctx = ctx
}
......
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