Commit 8899b0c0 authored by AlexStocks's avatar AlexStocks

Mod: add pool's watcher filter

parent 9ba61f3f
......@@ -14,6 +14,10 @@
## develop history ##
---
- 2018/08/16
> Feature
* Add gxpool.watcher filter
- 2018/08/13
> Feature
* Add Micro
......
......@@ -7,7 +7,7 @@ import (
)
import (
"github.com/AlexStocks/getty/rpc"
"github.com/AlexStocks/goext/context"
"github.com/AlexStocks/goext/database/filter"
"github.com/AlexStocks/goext/database/filter/pool"
"github.com/AlexStocks/goext/database/registry"
......@@ -18,6 +18,10 @@ import (
jerrors "github.com/juju/errors"
)
import (
"github.com/AlexStocks/getty/rpc"
)
type ClientOption func(*ClientOptions)
type ClientOptions struct {
......@@ -78,8 +82,16 @@ func NewClient(conf *rpc.ClientConfig, regConf *RegistryConfig, opts ...ClientOp
return nil, jerrors.Trace(err)
}
serviceAttrFilter := gxregistry.ServiceAttr{
Group: regConf.IDC,
Role: gxregistry.SRT_Provider,
}
gxctx := gxcontext.NewValuesContext(nil)
gxctx.Set(gxpool.GxfilterServiceAttrKey, serviceAttrFilter)
if filter, err = gxpool.NewFilter(
gxfilter.WithRegistry(registry),
gxfilter.WithContext(gxctx),
gxpool.WithTTL(time.Duration(1e9*regConf.KeepaliveTimeout)),
); err != nil {
return nil, jerrors.Trace(err)
......@@ -106,7 +118,11 @@ func NewClient(conf *rpc.ClientConfig, regConf *RegistryConfig, opts ...ClientOp
clt := &Client{
Client: rpcClient,
registry: registry,
filter: filter,
attr: gxregistry.ServiceAttr{
Group: regConf.IDC,
},
filter: filter,
svcMap: make(map[gxregistry.ServiceAttr]*gxfilter.ServiceArray),
}
for _, o := range opts {
......@@ -117,11 +133,13 @@ func NewClient(conf *rpc.ClientConfig, regConf *RegistryConfig, opts ...ClientOp
}
func (c *Client) Call(ctx context.Context, typ rpc.CodecType,
service, method string, args interface{}, reply interface{}) error {
service, version, method string, args interface{}, reply interface{}) error {
attr := c.attr
attr.Service = service
attr.Protocol = typ.String()
attr.Role = gxregistry.SRT_Provider
attr.Version = version
flag := false
svcArray, ok := c.svcMap[attr]
......
Markdown is supported
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