Skip to content
Snippets Groups Projects
Commit dd97fccd authored by Xin.Zh's avatar Xin.Zh Committed by GitHub
Browse files

Merge pull request #537 from cvictory/attribute_into_invocation

Add attribute method into Invocation and RpcInvocation
parents c1c8a7e6 43de2dae
No related branches found
No related tags found
No related merge requests found
......@@ -30,5 +30,8 @@ type Invocation interface {
Reply() interface{}
Attachments() map[string]string
AttachmentsByKey(string, string) string
// Refer to dubbo 2.7.6. It is different from attachment. It is used in internal process.
Attributes() map[string]interface{}
AttributeByKey(string, interface{}) interface{}
Invoker() Invoker
}
......@@ -40,8 +40,10 @@ type RPCInvocation struct {
reply interface{}
callBack interface{}
attachments map[string]string
invoker protocol.Invoker
lock sync.RWMutex
// Refer to dubbo 2.7.6. It is different from attachment. It is used in internal process.
attributes map[string]interface{}
invoker protocol.Invoker
lock sync.RWMutex
}
// NewRPCInvocation ...
......@@ -50,6 +52,7 @@ func NewRPCInvocation(methodName string, arguments []interface{}, attachments ma
methodName: methodName,
arguments: arguments,
attachments: attachments,
attributes: make(map[string]interface{}, 8),
}
}
......@@ -59,6 +62,9 @@ func NewRPCInvocationWithOptions(opts ...option) *RPCInvocation {
for _, opt := range opts {
opt(invo)
}
if invo.attributes == nil {
invo.attributes = make(map[string]interface{})
}
return invo
}
......@@ -111,6 +117,22 @@ func (r *RPCInvocation) AttachmentsByKey(key string, defaultValue string) string
return defaultValue
}
// get attributes
func (r *RPCInvocation) Attributes() map[string]interface{} {
return r.attributes
}
// get attribute by key. If it is not exist, it will return default value
func (r *RPCInvocation) AttributeByKey(key string, defaultValue interface{}) interface{} {
r.lock.RLock()
defer r.lock.RUnlock()
value, ok := r.attributes[key]
if ok {
return value
}
return defaultValue
}
// SetAttachments ...
func (r *RPCInvocation) SetAttachments(key string, value string) {
r.lock.Lock()
......@@ -121,6 +143,13 @@ func (r *RPCInvocation) SetAttachments(key string, value string) {
r.attachments[key] = value
}
// SetAttribute. If Attributes is nil, it will be inited.
func (r *RPCInvocation) SetAttribute(key string, value interface{}) {
r.lock.Lock()
defer r.lock.Unlock()
r.attributes[key] = value
}
// Invoker ...
func (r *RPCInvocation) Invoker() protocol.Invoker {
return r.invoker
......
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