Skip to content
Snippets Groups Projects
Commit e226771b authored by cvictory's avatar cvictory
Browse files

add attribute into Invocation

parent fbba79fd
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 ...
......@@ -111,6 +113,25 @@ 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()
if r.attributes == nil {
return defaultValue
}
value, ok := r.attributes[key]
if ok {
return value
}
return defaultValue
}
// SetAttachments ...
func (r *RPCInvocation) SetAttachments(key string, value string) {
r.lock.Lock()
......
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