55'use strict' ;
66
77import { TPromise } from 'vs/base/common/winjs.base' ;
8- import { IManyHandler } from 'vs/workbench/services/extensions/node/ipcRemoteCom ' ;
8+ import { IDispatcher , RPCProtocol } from 'vs/workbench/services/extensions/node/rpcProtocol ' ;
99import { ProxyIdentifier } from 'vs/workbench/services/thread/common/threadService' ;
1010
1111// declare var Proxy:any; // TODO@TypeScript
1212
13- export abstract class AbstractThreadService implements IManyHandler {
13+ export abstract class AbstractThreadService implements IDispatcher {
1414
15- private _isMain : boolean ;
16- protected _locals : { [ id : string ] : any ; } ;
17- private _proxies : { [ id : string ] : any ; } = Object . create ( null ) ;
15+ private readonly _rpcProtocol : RPCProtocol ;
16+ private readonly _isMain : boolean ;
17+ protected readonly _locals : { [ id : string ] : any ; } ;
18+ private readonly _proxies : { [ id : string ] : any ; } = Object . create ( null ) ;
1819
19- constructor ( isMain : boolean ) {
20+ constructor ( rpcProtocol : RPCProtocol , isMain : boolean ) {
21+ this . _rpcProtocol = rpcProtocol ;
2022 this . _isMain = isMain ;
2123 this . _locals = Object . create ( null ) ;
2224 this . _proxies = Object . create ( null ) ;
25+ this . _rpcProtocol . setDispatcher ( this ) ;
2326 }
2427
25- public handle ( rpcId : string , methodName : string , args : any [ ] ) : any {
26- if ( ! this . _locals [ rpcId ] ) {
27- throw new Error ( 'Unknown actor ' + rpcId ) ;
28+ public invoke ( proxyId : string , methodName : string , args : any [ ] ) : any {
29+ if ( ! this . _locals [ proxyId ] ) {
30+ throw new Error ( 'Unknown actor ' + proxyId ) ;
2831 }
29- let actor = this . _locals [ rpcId ] ;
32+ let actor = this . _locals [ proxyId ] ;
3033 let method = actor [ methodName ] ;
3134 if ( typeof method !== 'function' ) {
32- throw new Error ( 'Unknown method ' + methodName + ' on actor ' + rpcId ) ;
35+ throw new Error ( 'Unknown method ' + methodName + ' on actor ' + proxyId ) ;
3336 }
3437 return method . apply ( actor , args ) ;
3538 }
@@ -41,12 +44,12 @@ export abstract class AbstractThreadService implements IManyHandler {
4144 return this . _proxies [ identifier . id ] ;
4245 }
4346
44- private _createProxy < T > ( id : string , methodNames : string [ ] ) : T {
47+ private _createProxy < T > ( proxyId : string , methodNames : string [ ] ) : T {
4548 // Check below how to switch to native proxies
4649 let result : any = { } ;
4750 for ( let i = 0 ; i < methodNames . length ; i ++ ) {
4851 let methodName = methodNames [ i ] ;
49- result [ methodName ] = this . createMethodProxy ( id , methodName ) ;
52+ result [ methodName ] = this . _createMethodProxy ( proxyId , methodName ) ;
5053 }
5154 return result ;
5255
@@ -60,9 +63,9 @@ export abstract class AbstractThreadService implements IManyHandler {
6063 // return new Proxy({}, handler);
6164 }
6265
63- private createMethodProxy ( id : string , methodName : string ) : ( ...myArgs : any [ ] ) => TPromise < any > {
66+ private _createMethodProxy ( proxyId : string , methodName : string ) : ( ...myArgs : any [ ] ) => TPromise < any > {
6467 return ( ...myArgs : any [ ] ) => {
65- return this . _callOnRemote ( id , methodName , myArgs ) ;
68+ return this . _callOnRemote ( proxyId , methodName , myArgs ) ;
6669 } ;
6770 }
6871
@@ -73,5 +76,7 @@ export abstract class AbstractThreadService implements IManyHandler {
7376 this . _locals [ identifier . id ] = value ;
7477 }
7578
76- protected abstract _callOnRemote ( proxyId : string , path : string , args : any [ ] ) : TPromise < any > ;
79+ private _callOnRemote ( proxyId : string , methodName : string , args : any [ ] ) : TPromise < any > {
80+ return this . _rpcProtocol . callOnRemote ( proxyId , methodName , args ) ;
81+ }
7782}
0 commit comments