UNPKG

raas-client

Version:
290 lines (288 loc) 13 kB
import { Protocol } from './protocol/protocol'; /** * Runtime Server Protocol client implementation using JSON RPC */ export declare class RSPClient { private host; private port; private socket; private connection; private discoveryUtil; private serverUtil; private launcherUtil; private emitter; /** * Constructs a new RSP client * @param host hostname/address to connect to * @param port port of the running RSP service */ constructor(host: string, port: number); /** * Initiates connection to the RSP server * * @param timeout operation timeout in milliseconds, default 2000 ms */ connect(timeout?: number): Promise<void>; /** * Terminates an existing connection * * @throws {@link rpc.ConnectionError} if connection is not initialized or already disposed */ disconnect(): void; /** * Terminates the currently running RSP server instance and disconnects itself */ shutdownServer(): void; /** * Finds suitable servers in a directory * * @param path path to the desired directory * @param timeout timeout in milliseconds */ findServerBeans(path: string, timeout?: number): Promise<Protocol.ServerBean[]>; /** * Synchronously adds discovery path to RSP by sending a notification and then waiting for * 'discoveryPathAdded' event to be fired * * @param path path to the desired directory * @param timeout timeout in milliseconds */ addDiscoveryPathSync(path: string, timeout?: number): Promise<Protocol.DiscoveryPath>; /** * Sends notification to the RSP to add a directory to its discovery paths. * 'discoveryPathAdded' event will be fired when a response notification is received * * @param path path to the desired directory * @param timeout timeout in milliseconds */ addDiscoveryPathAsync(path: string, timeout?: number): Promise<Protocol.Status>; /** * Synchronously removes discovery path from RSP by sending a notification and then waiting for * 'discoveryPathRemoved' event to be fired * * @param path path to the desired directory or a DiscoveryPath object containing the given filepath * @param timeout timeout in milliseconds */ removeDiscoveryPathSync(path: string | Protocol.DiscoveryPath, timeout?: number): Promise<Protocol.DiscoveryPath>; /** * Sends notification to the RSP to remove a directory from its discovery paths. * 'discoveryPathRemoved' event will be fired when a response notification is received * * @param path path to the desired directory or a DiscoveryPath object containing the given filepath * @param timeout timeout in milliseconds */ removeDiscoveryPathAsync(path: string | Protocol.DiscoveryPath, timeout?: number): Promise<Protocol.Status>; /** * Retrieves all discovery paths from the server * * @param timeout timeout in milliseconds */ getDiscoveryPaths(timeout?: number): Promise<Protocol.DiscoveryPath[]>; /** * Sends a request to create a server from a given directory, then waits for the 'serverAdded' * event with the given id * * @param path path to the server's root directory, or a ServerBean object representing the server * @param id unique identifier for the newly created server * @param timeout timeout in milliseconds */ createServerSync(pathOrBean: string | Protocol.ServerBean, id?: string, timeout?: number): Promise<Protocol.ServerHandle>; /** * Sends a request to create a server from a given directory, subscribe to the 'serverAdded' * event to see when the server creation is finished * * @param path path to the server's root directory, or a ServerBean object representing the server * @param id unique identifier for the newly created server * @param timeout timeout in milliseconds */ createServerAsync(pathOrBean: string | Protocol.ServerBean, id?: string, timeout?: number): Promise<Protocol.Status>; /** * Sends notification to remove a server from RSP, then waits for the appropriate 'serverRemoved' event * * @param serverHandle server handle containing the server id and type, see {@link Protocol.ServerHandle} * @param timeout timeout in milliseconds */ deleteServerSync(serverHandle: Protocol.ServerHandle, timeout?: number): Promise<Protocol.ServerHandle>; /** * Sends notification to remove a server from RSP. Subscribe to the 'serverRemoved' event to see * when the removal finishes * * @param serverHandle server handle containing the server id and type, see {@link Protocol.ServerHandle} * @param timeout timeout in milliseconds */ deleteServerAsync(serverHandle: Protocol.ServerHandle, timeout?: number): Promise<Protocol.Status>; /** * Retrieves handles for all servers created within the RSP instance * * @param timeout timeout in milliseconds */ getServerHandles(timeout?: number): Promise<Protocol.ServerHandle[]>; /** * Retreives all supported server types * * @param timeout timeout in milliseconds */ getServerTypes(timeout?: number): Promise<Protocol.ServerType[]>; /** * Retrieves attributes required for a specific server type * * @param serverType {@link Protocol.ServerType} object representing the chosen type of server * @param timeout timeout in milliseconds */ getServerTypeRequiredAttributes(serverType: Protocol.ServerType, timeout?: number): Promise<Protocol.Attributes>; /** * Retrieves optional attributes for a specific server type * * @param serverType {@link Protocol.ServerType} object representing the chosen type of server * @param timeout timeout in milliseconds */ getServerTypeOptionalAttributes(serverType: Protocol.ServerType, timeout?: number): Promise<Protocol.Attributes>; /** * Retrieves launch modes available for a given server type * * @param serverType {@link Protocol.ServerType} object representing the chosen type of server * @param timeout timeout in milliseconds */ getServerLaunchModes(serverType: Protocol.ServerType, timeout?: number): Promise<Protocol.ServerLaunchMode[]>; /** * Retrieves required launch attributes for a given server using a given mode * * @param launchAttrRequest object specifying the server id and launch mode, see {@link Protocol.LaunchAttributesRequest} * @param timeout timeout in milliseconds */ getServerRequiredLaunchAttributes(launchAttrRequest: Protocol.LaunchAttributesRequest, timeout?: number): Promise<Protocol.Attributes>; /** * Retrieves optional launch attributes for a given server using a given mode * * @param launchAttrRequest object specifying the server id and launch mode, see {@link Protocol.LaunchAttributesRequest} * @param timeout timeout in milliseconds */ getServerOptionalLaunchAttributes(launchAttrRequest: Protocol.LaunchAttributesRequest, timeout?: number): Promise<Protocol.Attributes>; /** * Retrieves launch command for a given server, usable to manually launch the server from CLI * * @param launchParameters object representing the given attributes required to launch a given server, see {@link Protocol.LaunchParameters} * @param timeout timeout in milliseconds */ getServerLaunchCommand(launchParameters: Protocol.LaunchParameters, timeout?: number): Promise<Protocol.CommandLineDetails>; /** * Notifies the RSP that the client is launching one of the servers manually to update its state * * @param startingAttributes object representing the server being launched, set the 'initiatePolling' attribute to true to let RSP * track the server's launch state to notify when it finished launching, see {@link Protocol.ServerStartingAttributes} * @param timeout timeout in milliseconds */ serverStartingByClient(startingAttributes: Protocol.ServerStartingAttributes, timeout?: number): Promise<Protocol.Status>; /** * Notifies the RSP that the client has launched one of the servers manually to update its state * * @param startingAttributes object representing the server launched, see {@link Protocol.ServerStartingAttributes} * @param timeout timeout in milliseconds */ serverStartedByClient(launchParameters: Protocol.LaunchParameters, timeout?: number): Promise<Protocol.Status>; /** * Requests the RSP to start a server. In order to then get the server state changes, subscribe to the * 'serverStateChanged' event * * @param launchParameters parameters to start the server with, see {@link Protocol.LaunchParameters} * @param timeout timeout in milliseconds */ startServerAsync(launchParameters: Protocol.LaunchParameters, timeout?: number): Promise<Protocol.StartServerResponse>; /** * Requests the RSP to stop a server. In order to then get the server state changes, subscribe to the * 'serverStateChanged' event * * @param stopAttributes server stopping parameters, set force to 'true' to force shutdown, see {@link Protocol.StopServerAttributes} * @param timeout timeout in milliseconds */ stopServerAsync(stopAttributes: Protocol.StopServerAttributes, timeout?: number): Promise<Protocol.Status>; /** * Requests the RSP to start a server and waits until it receives a notification that the server changed * its state to STARTED * * @param launchParameters parameters to start the server with, see {@link Protocol.LaunchParameters} * @param timeout timeout in milliseconds */ startServerSync(launchParameters: Protocol.LaunchParameters, timeout?: number): Promise<Protocol.ServerStateChange>; /** * Requests the RSP to stop a server and waits until it receives a notification that the server changed * its state to STOPPED * * @param stopAttributes server stopping parameters, set force to 'true' to force shutdown, see {@link Protocol.StopServerAttributes} * @param timeout timeout in milliseconds */ stopServerSync(stopAttributes: Protocol.StopServerAttributes, timeout?: number): Promise<Protocol.ServerStateChange>; /** * Attaches a listener to discovery path added event * * @param listener callback to handle the event */ onDiscoveryPathAdded(listener: (arg: Protocol.DiscoveryPath) => void): void; /** * Attaches a listener to discovery path removed event * * @param listener callback to handle the event */ onDiscoveryPathRemoved(listener: (arg: Protocol.DiscoveryPath) => void): void; /** * Attaches a listener to server creation event * * @param listener callback to handle the event */ onServerAdded(listener: (arg: Protocol.ServerHandle) => void): void; /** * Attaches a listener to server deleteion event * * @param listener callback to handle the event */ onServerRemoved(listener: (arg: Protocol.ServerHandle) => void): void; /** * Attaches a listener to server state change * * @param listener callback to handle the event */ onServerStateChange(listener: (arg: Protocol.ServerStateChange) => void): void; /** * Attaches a listener to the server displaying new output * * @param listener callback to handle the event */ onServerOutputAppended(listener: (arg: Protocol.ServerProcessOutput) => void): void; /** * Attaches a listener to server attribute change * * @param listener callback to handle the event */ onServerAttributeChange(listener: (arg: Protocol.ServerHandle) => void): void; /** * Attaches a listener to the server process being created * * @param listener callback to handle the event */ onServerProcessCreated(listener: (arg: Protocol.ServerProcess) => void): void; /** * Attaches a listener to the server process being terminated * * @param listener callback to handle the event */ onServerProcessTerminated(listener: (arg: Protocol.ServerProcess) => void): void; /** * Retrieves all listeners bound to an event * * @param eventName name of the event to get listeners for */ getListeners(eventName: string): Function[]; /** * Removes a listener from an event * * @param eventName name of the event the listener is bound to * @param listener the listener to remove */ removeListener(eventName: string, listener: (...args: any[]) => void): void; /** * Removes all listeners from an event * * @param eventName name of the event to remove listeners from */ removeAllListeners(eventName: string): void; }