Documentation ¶
Overview ¶
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
Index ¶
- Constants
- Variables
- func AddEventHandleFunc(t Type, f KvEventFunc)
- func AddEventHandler(h KvEventHandler)
- func ReportProcessEventCompleted(prefix string, evts []KvEvent)
- type Adaptor
- type AdaptorRepository
- type Cache
- type CacheIndexer
- type CacheReader
- type Cacher
- type CommonCacher
- type Config
- func (cfg *Config) AppendEventFunc(f KvEventFunc) *Config
- func (cfg *Config) String() string
- func (cfg *Config) WithDeferHandler(h DeferHandler) *Config
- func (cfg *Config) WithEventFunc(f KvEventFunc) *Config
- func (cfg *Config) WithInitSize(size int) *Config
- func (cfg *Config) WithParser(parser proto.Parser) *Config
- func (cfg *Config) WithPeriod(ot time.Duration) *Config
- func (cfg *Config) WithPrefix(key string) *Config
- func (cfg *Config) WithTimeout(ot time.Duration) *Config
- type DeferHandler
- type Indexer
- type KeyValue
- type KvCache
- func (c *KvCache) Clear()
- func (c *KvCache) Dirty() bool
- func (c *KvCache) ForEach(iter func(k string, v *KeyValue) (next bool))
- func (c *KvCache) Get(key string) (v *KeyValue)
- func (c *KvCache) GetAll(arr *[]*KeyValue) (count int)
- func (c *KvCache) GetPrefix(prefix string, arr *[]*KeyValue) (count int)
- func (c *KvCache) MarkDirty()
- func (c *KvCache) Name() string
- func (c *KvCache) Put(key string, v *KeyValue)
- func (c *KvCache) Remove(key string)
- func (c *KvCache) Size() (l int)
- type KvEvent
- type KvEventFunc
- type KvEventHandler
- type KvEventProxy
- type Response
- type Runnable
- type Type
Constants ¶
const ( DefaultTimeout = 30 * time.Second DefaultCacheInitSize = 100 )
const (
TypeError = Type(-1)
)
Variables ¶
var ( NullCache = &nullCache{} NullCacher = &nullCacher{} )
var (
Types []Type
)
Functions ¶
func AddEventHandleFunc ¶
func AddEventHandleFunc(t Type, f KvEventFunc)
the event handler/func must be good performance, or will block the event bus.
func AddEventHandler ¶
func AddEventHandler(h KvEventHandler)
Types ¶
type Adaptor ¶
type Adaptor interface { Runnable // Indexer is used to search data from the registry. Indexer // Cacher is used to manage the registry's cache. Cacher }
Adaptor is used to do service discovery. To improve the performance, Adaptor may use cache firstly in service discovery.
type AdaptorRepository ¶
type AdaptorRepository interface { // New news an instance of specify Type adaptor New(t Type, cfg *Config) Adaptor }
AdaptorRepository creates Adaptors
type Cache ¶
type Cache interface { CacheReader // Put puts a k-v Put(k string, v *KeyValue) // Remove removes a k-v data Remove(k string) // MarkDirty mark k-v data dirty MarkDirty() // Dirty k-v data is dirty or not Dirty() bool // Clear clear all k-v data Clear() }
Cache stores k-v data.
type CacheIndexer ¶
type CacheIndexer struct {
Cache CacheReader
}
CacheIndexer implements discovery.Indexer. CacheIndexer searches data from cache.
func NewCacheIndexer ¶
func NewCacheIndexer(cache CacheReader) *CacheIndexer
func (*CacheIndexer) Creditable ¶
func (i *CacheIndexer) Creditable() bool
Creditable implements discovery.Indexer.Creditable.
func (*CacheIndexer) Search ¶
func (i *CacheIndexer) Search(ctx context.Context, opts ...registry.PluginOpOption) (resp *Response, _ error)
type CacheReader ¶
type CacheReader interface { Name() string // The name of implementation Size() int // the bytes size of the cache // Get gets a value by input key Get(k string) *KeyValue // GetAll gets all the data stored in Cache GetAll(arr *[]*KeyValue) int // GetPrefix gets values by the key prefix GetPrefix(prefix string, arr *[]*KeyValue) int // ForEach executes the given function for each of the k-v ForEach(iter func(k string, v *KeyValue) (next bool)) }
CacheReader reads k-v data.
type Cacher ¶
type Cacher interface { // Cache gets the cache that Cacher manages. Cache() CacheReader }
Cacher manages cache of some data source, e.g. etcd, kubernetes. An user can do nothing but read the managed cache.
type CommonCacher ¶
type CommonCacher struct { Cfg *Config // contains filtered or unexported fields }
CommonCacher implements discovery.Cacher. CommonCacher is universal to manage cache of any registry. Use Cfg to set it's behavior.
func NewCommonCacher ¶
func NewCommonCacher(cfg *Config, cache Cache) *CommonCacher
func (*CommonCacher) Cache ¶
func (c *CommonCacher) Cache() CacheReader
func (*CommonCacher) Notify ¶
func (c *CommonCacher) Notify(action types.EventType, key string, kv *KeyValue)
func (*CommonCacher) OnEvent ¶
func (c *CommonCacher) OnEvent(evt KvEvent)
func (*CommonCacher) Ready ¶
func (c *CommonCacher) Ready() <-chan struct{}
func (*CommonCacher) Run ¶
func (c *CommonCacher) Run()
func (*CommonCacher) Stop ¶
func (c *CommonCacher) Stop()
type Config ¶
type Config struct { // Key is the prefix to unique specify resource type Key string InitSize int Timeout time.Duration Period time.Duration DeferHandler DeferHandler OnEvent KvEventFunc Parser proto.Parser }
func (*Config) AppendEventFunc ¶
func (cfg *Config) AppendEventFunc(f KvEventFunc) *Config
func (*Config) WithDeferHandler ¶
func (cfg *Config) WithDeferHandler(h DeferHandler) *Config
func (*Config) WithEventFunc ¶
func (cfg *Config) WithEventFunc(f KvEventFunc) *Config
func (*Config) WithInitSize ¶
func (*Config) WithPrefix ¶
type DeferHandler ¶
type DeferHandler interface { OnCondition(CacheReader, []KvEvent) bool HandleChan() <-chan KvEvent Reset() bool }
type Indexer ¶
type Indexer interface { // Search searches k-v data based on the input options Search(ctx context.Context, opts ...registry.PluginOpOption) (*Response, error) // Creditable judges whether Indexer's search results are creditable // It is recommended to use cache only and not to call the backend // directly, If Indexer is not creditable. Creditable() bool }
Indexer searches k-v data. An indexer may search k-v data from many data sources, e.g. cache, registry, file, other Indexers...
type KeyValue ¶
type KeyValue struct { Key []byte Value interface{} Version int64 CreateRevision int64 ModRevision int64 ClusterName string }
func NewKeyValue ¶
func NewKeyValue() *KeyValue
type KvCache ¶
type KvCache struct { Cfg *Config // contains filtered or unexported fields }
KvCache implements Cache. KvCache is dedicated to stores service discovery data, e.g. service, instance, lease.
func NewKvCache ¶
type KvEventFunc ¶
type KvEventFunc func(evt KvEvent)
type KvEventHandler ¶
type KvEventProxy ¶
type KvEventProxy struct {
// contains filtered or unexported fields
}
func (*KvEventProxy) AddHandleFunc ¶
func (h *KvEventProxy) AddHandleFunc(f KvEventFunc)
func (*KvEventProxy) InjectConfig ¶
func (h *KvEventProxy) InjectConfig(cfg *Config) *Config
InjectConfig will inject a resource changed event callback function in Config
func (*KvEventProxy) OnEvent ¶
func (h *KvEventProxy) OnEvent(evt KvEvent)