@eclipse-ditto/ditto-javascript-client-dom
Version:
DOM implementation of Eclipse Ditto JavaScript API to be used in browsers.
130 lines • 4.16 kB
TypeScript
/*!
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
import { WebSocketImplementation } from './websocket-resilience-interfaces';
/**
* A class to buffer Messages.
*/
export declare class ResilienceMessageBuffer {
private readonly maxBufferSize?;
private readonly messages;
constructor(maxBufferSize?: number | undefined);
/**
* Adds a message to the buffer.
*
* @param message - The message to buffer.
* @returns A Promise that resolves once the message was sent
*/
addMessage(message: string): Promise<void>;
/**
* Sends the messages from the buffer and resolves their promises.
*
* @param webSocket - The web socket to send the messages on.
* @returns Whether all messages were successfully sent or not
*/
sendMessages(webSocket: WebSocketImplementation): boolean;
/**
* Rejects the Promises for all messages in the buffer and clears it.
*
* @param reason - The reason to reject the Promises with.
*/
rejectMessages(reason: any): void;
/**
* Calculates whether the buffer is full.
*
* @returns Whether the buffer is full
*/
full(): boolean;
/**
* Calculates the number of messages in the buffer.
*
* @returns The number of messages in the buffer
*/
get size(): number;
/**
* Calculates whether the buffer is empty.
*
* @returns Whether the buffer is empty
*/
empty(): boolean;
}
/**
* A class to buffer requests that expect a response.
*/
export declare class ResilienceRequestBuffer {
private readonly maxBufferSize?;
private readonly requests;
private readonly outstanding;
private readonly polling;
constructor(maxBufferSize?: number | undefined);
/**
* Stores a request that is waiting for a response.
*
* @param id - The correlation-id of the request.
* @param request - The request to be stored.
*/
addRequest(id: string, request: string): void;
/**
* Adds a request to the buffer.
*
* @param id - The id of the request to buffer.
* @param rejectionHandler - The method to use if the request needs to be rejected.
* @returns Whether the request was successfully buffered or not
*/
addOutstanding(id: string, rejectionHandler: (reason: object) => void): boolean;
/**
* Sends the first element of the buffer that is not currently waiting for a response.
*
* @param webSocket - The web socket to send the requests on.
* @returns Whether a request was successfully sent or not
*/
sendNextOutstanding(webSocket: WebSocketImplementation): boolean;
/**
* Rejects all requests in the buffer.
*
* @param rejectionHandler - The method to use to reject the requests.
*/
rejectAllOngoing(rejectionHandler: (id: string) => void): void;
/**
* Deletes a request from the buffer.
*
* @param id - The id of the request to delete.
*/
deleteRequest(id: string): void;
/**
* Removes a request from an array.
*
* @param id - The id of the request to delete.
* @param array - The array to delete the request from.
*/
private removeFromArray;
/**
* Checks whether a buffered request is currently waiting for response.
*
* @param id - The id of the message.
* @returns Whether the request is polling or not
*/
isPolling(id: string): boolean;
/**
* Checks whether the buffer is empty.
*
* @returns Whether the buffer is empty or not
*/
empty(): boolean;
/**
* Checks whether the buffer is full.
*
* @returns Whether the buffer is full or not
*/
full(): boolean;
}
//# sourceMappingURL=websocket-resilience-buffer.d.ts.map