UNPKG

hazelcast-client

Version:

Hazelcast - open source In-Memory Data Grid - client for NodeJS

119 lines (118 loc) 4.14 kB
/// <reference types="bluebird" /> /// <reference types="node" /> import ClientMessage = require('../ClientMessage'); import Address = require('../Address'); import * as Promise from 'bluebird'; import HazelcastClient from '../HazelcastClient'; import { ClientConnection } from './ClientConnection'; /** * A request to be sent to a hazelcast node. */ export declare class Invocation { constructor(client: HazelcastClient, request: ClientMessage); client: HazelcastClient; invocationService: InvocationService; /** * Representatiton of the request in binary form. */ request: ClientMessage; /** * Partition id of the request. If request is not bound to a specific partition, should be set to -1. */ partitionId: number; /** * Address of the request. If request is not bound to any specific address, should be set to null. */ address: Address; /** * Deadline of validity. Client will not try to send this request to server after the deadline passes. */ deadline: Date; /** * Connection of the request. If request is not bound to any specific address, should be set to null. */ connection: ClientConnection; /** * Promise managing object. */ deferred: Promise.Resolver<ClientMessage>; invokeCount: number; /** * If this is an event listener registration, handler should be set to the function to be called on events. * Otherwise, should be set to null. */ handler: (...args: any[]) => any; /** * @returns {boolean} */ hasPartitionId(): boolean; } /** * Sends requests to appropriate nodes. Resolves waiting promises with responses. */ export declare class InvocationService { private correlationCounter; private eventHandlers; private pending; private client; private smartRoutingEnabled; private readonly invocationRetryPauseMillis; private readonly invocationTimeoutMillis; private logger; private isShutdown; doInvoke: (invocation: Invocation) => void; constructor(hazelcastClient: HazelcastClient); shutdown(): void; invoke(invocation: Invocation): Promise<ClientMessage>; /** * Invokes given invocation on specified connection. * @param connection * @param request * @param handler called with values returned from server for this invocation. * @returns */ invokeOnConnection(connection: ClientConnection, request: ClientMessage, handler?: (...args: any[]) => any): Promise<ClientMessage>; /** * Invokes given invocation on the node that owns given partition. * @param request * @param partitionId * @returns */ invokeOnPartition(request: ClientMessage, partitionId: number): Promise<ClientMessage>; /** * Invokes given invocation on the host with given address. * @param request * @param target * @returns */ invokeOnTarget(request: ClientMessage, target: Address): Promise<ClientMessage>; /** * Invokes given invocation on any host. * Useful when an operation is not bound to any host but a generic operation. * @param request * @returns */ invokeOnRandomTarget(request: ClientMessage): Promise<ClientMessage>; getInvocationTimeoutMillis(): number; getInvocationRetryPauseMillis(): number; private invokeSmart(invocation); private invokeNonSmart(invocation); private invokeOnOwner(invocation); private invokeOnAddress(invocation, address); private invokeOnPartitionOwner(invocation, partitionId); private send(invocation, connection); private write(invocation, connection); private notifyError(invocation, error); private isRetryable(invocation); private registerInvocation(invocation); /** * Removes the handler for all event handlers with a specific correlation id. * @param id correlation id */ removeEventHandler(id: number): void; /** * Extract codec specific properties in a protocol message and resolves waiting promise. * @param buffer */ processResponse(buffer: Buffer): void; }