///
import { EventEmitter } from "events";
import { NamingServicePlugin, LocalRegistryPlugin, ServiceRules, DataWithRevision, RegistryCategory, StatReporterPlugin, RatelimitServicePlugin, ServiceDataSet } from "./plugins";
import { Instance } from "./instance";
import { PartialSubset } from "./utils";
import { Location } from "./location";
import { RatelimitRule } from "./rules";
import { Logger } from "./logging";
/**
* 事件类型
*/
export declare const enum RegistryEventType {
/** 同步实例状态事件 */
SyncInstanceStatus = "SyncInstanceStatus"
}
declare const kDefaultOptions: {
/**
* 过期时间
* 超过此时间,会 __异步__ 请求新数据
* _也就是说,返回值可能为旧数据_
*/
expireTime: {
/** 实例过期时间 */
Instance: number;
/** 规则过期时间 */
Rule: number;
/** 限流规则过期时间 */
Ratelimit: number;
};
/**
* 脏数据时间
* 超过此时间,会 __同步__ 请求新数据
* _也就是说,返回值一定为新数据_
*/
dirtyTime: {
/** 实例脏数据时间 */
Instance: number;
/** 规则脏数据时间 */
Rule: number;
/** 限流规则脏数据时间 */
Ratelimit: number;
};
/**
* 资源回收时间
* 回收条件为:_至少_经历指定的间隔都没被访问
* 小于或等于 0 则为不启用此特性
*/
recycleTime: number;
/**
* 服务状态上报间隔
*/
reportInterval: number;
/**
* 服务状态上报阈值
*/
reportThreshold: number;
};
declare type LocalRegistryAssembleOptions = typeof kDefaultOptions & {
/**
* 基础位置信息
* 如果 `Naming` 返回的位置信息为空,则使用此配置
*/
baseLocation?: Location;
};
export declare type LocalRegistryOptions = PartialSubset;
/**
* 版本号变更记录
*/
export interface RevisionLog {
/**
* 变更时间 (ms)
*/
time: number;
/**
* 变更后版本号
*/
revision: string;
}
/** 服务变更历史 */
export declare type ServiceChangelog = Record;
/**
* 服务状态
*/
export declare type CacheStat = Record;
export declare class LocalRegistry extends EventEmitter {
private readonly logger;
private readonly naming;
private readonly registry;
private readonly reporters;
private readonly ratelimit?;
private lifeCycle;
private readonly activeRequests;
private history;
private countOfHistory;
private cacheRecycle;
private timer;
private readonly needReport;
private readonly options;
private disposed;
constructor(logger: Logger, naming: NamingServicePlugin, registry: LocalRegistryPlugin, reporters: StatReporterPlugin[], ratelimit?: RatelimitServicePlugin | undefined, options?: Partial);
get location(): Location | undefined;
fetch(type: RegistryCategory.Instance, namespace: string, service: string): Promise;
fetch(type: RegistryCategory.Rule, namespace: string, service: string): Promise;
fetch(type: RegistryCategory.Ratelimit, namespace: string, service: string): Promise;
fetch(type: RegistryCategory, namespace: string, service: string): Promise;
local(type: RegistryCategory.Instance, namespace: string, service: string): DataWithRevision | null;
local(type: RegistryCategory.Rule, namespace: string, service: string): DataWithRevision | null;
local(type: RegistryCategory.Ratelimit, namespace: string, service: string): DataWithRevision | null;
local(type: RegistryCategory, namespace: string, service: string): DataWithRevision | null;
local(type: RegistryCategory.Instance): ServiceDataSet>;
local(type: RegistryCategory.Rule): ServiceDataSet>;
local(type: RegistryCategory.Ratelimit): ServiceDataSet>;
local(type: RegistryCategory): ServiceDataSet> | ServiceDataSet> | ServiceDataSet>;
dispose(): void;
get isDisposed(): boolean;
/** for external use only */
update(type: RegistryCategory, namespace: string, service: string): Promise;
/** for internal use only */
private performUpdate;
private updateInstance;
private updateRule;
private updateRatelimit;
/**
* @note
* 将相同的查询请求做合并(以最早发出为准)
* 以减少本地名字服务无缓存情况下,对于 `Naming` 的调用压力。
*/
private request;
private report;
private changelog;
private stink;
private recycle;
private pull;
private extraData;
}
export {};