hamok
Version:
Lightweight Distributed Object Storage on RAFT consensus algorithm
139 lines • 8.5 kB
TypeScript
import { EventEmitter } from 'events';
import { HamokMessage, HamokMessage_MessageType as HamokMessageType } from '../messages/HamokMessage';
import { GetEntriesRequest, GetEntriesResponse } from '../messages/messagetypes/GetEntries';
import { StorageCodec } from '../messages/StorageCodec';
import { OngoingRequestsNotification } from '../messages/messagetypes/OngoingRequests';
import { ClearEntriesRequest, ClearEntriesNotification, ClearEntriesResponse } from '../messages/messagetypes/ClearEntries';
import { DeleteEntriesRequest, DeleteEntriesNotification, DeleteEntriesResponse } from '../messages/messagetypes/DeleteEntries';
import { GetKeysRequest, GetKeysResponse } from '../messages/messagetypes/GetKeys';
import { GetSizeRequest } from '../messages/messagetypes/GetSize';
import { InsertEntriesRequest, InsertEntriesNotification, InsertEntriesResponse, EntriesInsertedNotification } from '../messages/messagetypes/InsertEntries';
import { RemoveEntriesRequest, RemoveEntriesNotification, RemoveEntriesResponse, EntriesRemovedNotification } from '../messages/messagetypes/RemoveEntries';
import { UpdateEntriesRequest, UpdateEntriesNotification, UpdateEntriesResponse, EntryUpdatedNotification } from '../messages/messagetypes/UpdateEntries';
import { HamokGrid } from '../HamokGrid';
import { StorageAppliedCommitNotification } from '../messages/messagetypes/StorageAppliedCommit';
import { StorageHelloNotification } from '../messages/messagetypes/StorageHelloNotification';
import { StorageStateNotification } from '../messages/messagetypes/StorageStateNotification';
export type HamokConnectionConfig = {
/**
* The identifier of the storage the comlink belongs to.
* In case of a storage builder this infromation is automatically fetched
* from the given storage.
*/
storageId: string;
/**
* Determining the timeout for a request generated by this comlink.
* in case of a storage builder belongs to a hamok grid, the default value is
* the grid request timeout config setting
*/
requestTimeoutInMs: number;
/**
* Determine how many response is necessary to resolve the request.
*/
neededResponse: number;
submitting?: ReadonlySet<HamokMessageType>;
/**
* The maximum number of keys a response can contain.
*/
maxOutboundKeys?: number;
/**
* The maximum number of values a response can contain.
*/
maxOutboundValues?: number;
/**
* The maximum time in milliseconds to wait for storage state notification from a remote peer.
*
* DEFAULT: 1000
*/
remoteStorageStateWaitingTimeoutInMs: number;
};
export type HamokConnectionEventMap<K, V> = {
'message': [message: HamokMessage, submit: boolean];
'leader-changed': [newLeaderId: string | undefined];
'remote-peer-removed': [remotePeerId: string];
connected: [];
disconnected: [];
close: [];
OngoingRequestsNotification: [OngoingRequestsNotification];
ClearEntriesRequest: [ClearEntriesRequest, commitIndex?: number];
ClearEntriesNotification: [ClearEntriesNotification];
GetEntriesRequest: [GetEntriesRequest<K>];
GetKeysRequest: [GetKeysRequest];
GetSizeRequest: [GetSizeRequest];
DeleteEntriesRequest: [DeleteEntriesRequest<K>, commitIndex?: number];
DeleteEntriesNotification: [DeleteEntriesNotification<K>];
RemoveEntriesRequest: [RemoveEntriesRequest<K>, commitIndex?: number];
RemoveEntriesNotification: [RemoveEntriesNotification<K>];
EntriesRemovedNotification: [EntriesRemovedNotification<K, V>];
InsertEntriesRequest: [InsertEntriesRequest<K, V>, commitIndex?: number];
InsertEntriesNotification: [InsertEntriesNotification<K, V>];
EntriesInsertedNotification: [EntriesInsertedNotification<K, V>];
UpdateEntriesRequest: [UpdateEntriesRequest<K, V>, commitIndex?: number];
UpdateEntriesNotification: [UpdateEntriesNotification<K, V>];
EntryUpdatedNotification: [EntryUpdatedNotification<K, V>];
StorageAppliedCommitNotification: [StorageAppliedCommitNotification];
StorageHelloNotification: [StorageHelloNotification];
StorageStateNotification: [StorageStateNotification];
'remote-snapshot': [serializedSnapshot: string, done: () => void];
};
export type HamokConnectionResponseMap<K, V> = {
GetEntriesResponse: GetEntriesResponse<K, V>;
GetKeysResponse: GetKeysResponse<K>;
ClearEntriesResponse: ClearEntriesResponse;
DeleteEntriesResponse: DeleteEntriesResponse<K>;
RemoveEntriesResponse: RemoveEntriesResponse<K, V>;
InsertEntriesResponse: InsertEntriesResponse<K, V>;
UpdateEntriesResponse: UpdateEntriesResponse<K, V>;
};
export declare interface HamokConnection<K, V> {
on<U extends keyof HamokConnectionEventMap<K, V>>(event: U, listener: (...args: HamokConnectionEventMap<K, V>[U]) => void): this;
once<U extends keyof HamokConnectionEventMap<K, V>>(event: U, listener: (...args: HamokConnectionEventMap<K, V>[U]) => void): this;
off<U extends keyof HamokConnectionEventMap<K, V>>(event: U, listener: (...args: HamokConnectionEventMap<K, V>[U]) => void): this;
emit<U extends keyof HamokConnectionEventMap<K, V>>(event: U, ...args: HamokConnectionEventMap<K, V>[U]): boolean;
}
export declare class HamokConnection<K, V> extends EventEmitter {
readonly config: HamokConnectionConfig;
readonly codec: StorageCodec<K, V>;
readonly grid: HamokGrid;
readonly waitUntilCommitHead: () => Promise<void>;
private readonly _responseChunker;
private _closed;
private _connected;
private _joined;
private _appliedCommitIndex;
private _joining?;
private _bufferedMessages;
constructor(config: HamokConnectionConfig, codec: StorageCodec<K, V>, grid: HamokGrid, waitUntilCommitHead: () => Promise<void>);
get closed(): boolean;
get localPeerId(): string;
get connected(): boolean;
get highestSeenCommitIndex(): number;
close(): void;
join(): Promise<void>;
accept(message: HamokMessage, commitIndex?: number): void;
notifyStorageHello(targetPeerIds?: ReadonlySet<string> | string[] | string): void;
notifyStorageState(serializedStorageSnapshot: string, appliedCommitIndex: number, targetPeerIds?: ReadonlySet<string> | string[] | string): void;
requestGetEntries(keys: ReadonlySet<K>, targetPeerIds?: ReadonlySet<string> | string[]): Promise<ReadonlyMap<K, V>>;
requestGetKeys(targetPeerIds?: ReadonlySet<string> | string[]): Promise<ReadonlySet<K>>;
requestClearEntries(targetPeerIds?: ReadonlySet<string> | string[]): Promise<void>;
notifyClearEntries(targetPeerIds?: ReadonlySet<string> | string[] | string): void;
requestDeleteEntries(keys: ReadonlySet<K>, targetPeerIds?: ReadonlySet<string> | string[]): Promise<ReadonlySet<K>>;
notifyDeleteEntries(keys: ReadonlySet<K>, targetPeerIds?: ReadonlySet<string> | string[] | string): void;
requestRemoveEntries(keys: ReadonlySet<K>, targetPeerIds?: ReadonlySet<string> | string[], prevValue?: V): Promise<ReadonlyMap<K, V>>;
notifyRemoveEntries(keys: ReadonlySet<K>, targetPeerIds?: ReadonlySet<string> | string[] | string): void;
notifyEntriesRemoved(entries: ReadonlyMap<K, V>, targetPeerIds?: ReadonlySet<string> | string[] | string): void;
requestInsertEntries(entries: ReadonlyMap<K, V>, targetPeerIds?: ReadonlySet<string> | string[]): Promise<ReadonlyMap<K, V>>;
notifyInsertEntries(entries: ReadonlyMap<K, V>, targetPeerIds?: ReadonlySet<string> | string[] | string): void;
notifyEntriesInserted(entries: ReadonlyMap<K, V>, targetPeerIds?: ReadonlySet<string> | string[] | string): void;
requestUpdateEntries(entries: ReadonlyMap<K, V>, targetPeerIds?: ReadonlySet<string> | string[] | string, prevValue?: V): Promise<ReadonlyMap<K, V>>;
notifyUpdateEntries(entries: ReadonlyMap<K, V>, targetPeerIds?: ReadonlySet<string> | string[] | string): void;
notifyEntryUpdated(key: K, oldValue: V, newValue: V, targetPeerIds?: ReadonlySet<string> | string[] | string): void;
notifyStorageAppliedCommit(commitIndex: number, targetPeerIds?: ReadonlySet<string> | string[] | string): void;
respond<U extends keyof HamokConnectionResponseMap<K, V>>(type: U, response: HamokConnectionResponseMap<K, V>[U], targetPeerIds?: string | string[]): void;
private _request;
private _sendMessage;
private _join;
private _fetchStorageState;
private _leaderChangedListener;
}
//# sourceMappingURL=HamokConnection.d.ts.map