import { RPCMessage } from '../../constants'; import { SimpleSocketWrapper, DeepstreamConfig, DeepstreamServices, SocketWrapper, SubscriptionRegistry, Handler } from '@deepstream/types'; export default class RpcHandler extends Handler { private config; private services; private metaData?; private subscriptionRegistry; private rpcs; /** * Handles incoming messages for the RPC Topic. */ constructor(config: DeepstreamConfig, services: DeepstreamServices, subscriptionRegistry?: SubscriptionRegistry, metaData?: any | undefined); /** * Main interface. Handles incoming messages * from the message distributor */ handle(socketWrapper: SocketWrapper, message: RPCMessage, originServerName: string): void; /** * This method is called by Rpc to reroute its request * * If a provider is temporarily unable to service a request, it can reject it. Deepstream * will then try to reroute it to an alternative provider. Finding an alternative provider * happens in this method. * * Initially, deepstream will look for a local provider that hasn't been used by the RPC yet. * If non can be found, it will go through the currently avaiblable remote providers and try * find one that hasn't been used yet. * * If a remote provider couldn't be found or all remote-providers have been tried already * this method will return null - which in turn will prompt the RPC to send a NO_RPC_PROVIDER * error to the client */ getAlternativeProvider(rpcName: string, correlationId: string): SimpleSocketWrapper | null; /** * Executes a RPC. If there are clients connected to * this deepstream instance that can provide the rpc, it * will be routed to a random one of them, otherwise it will be routed * to the message connector */ private makeRpc; /** * Callback to remoteProviderRegistry.getProviderProxy() * * If a remote provider is available this method will route the rpc to it. * * If no remote provider could be found this class will return a * NO_RPC_PROVIDER error to the requestor. The RPC won't continue from * thereon */ makeRemoteRpc(requestor: SimpleSocketWrapper, message: RPCMessage): void; /** * Callback for messages that are send directly to * this deepstream instance. * * Please note: Private messages are generic, so the RPC * specific ones need to be filtered out. */ private onRemoteRPCMessage; /** * Called by the RPC with correlationId to destroy itself * when lifecycle is over. */ onRPCDestroyed(correlationId: string): void; }