/**
 * A proxy (or called accessor) of the ProcessContext, to provide a grace interface to use
 */ import { ProcessContext } from './ProcessContext' ; import { Environment } from 'pandora-env' ; import { Service } from '../domain' ; import { Facade as HubFacade } from 'pandora-hub' ; import { DefaultObjectProxy , ObjectDescription , ConsumerExtInfo } from 'pandora-hub' ; import { TraceManager } from 'pandora-metrics' ; /**
 * Class ProcessContextAccessor
 * A easy way to access ProcessContext
 */ export class ProcessContextAccessor { /**
     * Original context object
     */ context : ProcessContext ; param context constructor ( context ) { this . context = context ; } returns { string } get appName ( ) : string { return this . context . processRepresentation . appName ; } returns { string } get appDir ( ) : string { return this . context . processRepresentation . appDir ; } returns { string } get processName ( ) : string { return this . context . processRepresentation . processName ; } returns { string } get env ( ) : string { return this . context . getEnvironment ( ) . get ( 'env' ) ; } returns { Environment } get environment ( ) : Environment { return this . context . getEnvironment ( ) ; } param { string } name returns { Service } getService < T extends Service > ( name ) { return this . context . serviceReconciler . get ( name ) ; } param { string } name returns { class } getServiceClass ( name ) { return this . context . serviceReconciler . getServiceClass ( name ) ; } getHub ( ) { return this . context . getIPCHub ( ) ; } async getProxy < T extends any > ( name , extInfo ? ) ; async getProxy < T extends any > ( objectDescription , extInfo ? ) ; async getProxy ( target , extInfo ? ) { let objDesc = null ; if ( typeof target === 'string' ) { objDesc = { name : target } ; } else { objDesc = target ; } const hub = this . context . getIPCHub ( ) ; return hub . getProxy ( objDesc , extInfo ) ; } async publishObject ( name , obj ) ; async publishObject ( objectDescription , obj ) ; async publishObject ( target , obj ) { let objDesc = null ; if ( typeof target === 'string' ) { objDesc = { name : target } ; } else { objDesc = target ; } const hub = this . context . getIPCHub ( ) ; return hub . publish ( obj , objDesc ) ; } get traceManager ( ) : TraceManager { return TraceManager . getInstance ( ) ; } }