Skip to content

Commit

Permalink
chore(process-explorer-frontend): Add back mock processes (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
kruplm authored Aug 8, 2023
1 parent dae08a1 commit f95fee4
Show file tree
Hide file tree
Showing 4 changed files with 1,200 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<igx-grid-pinning-actions></igx-grid-pinning-actions>

<!-- custom controls -->
<button title="Stop" igxButton="icon" igxRipple (click)='KillProcessById(actionstrip.context._rowData.PID)'>
<button title="Stop" igxButton="icon" igxRipple>
<igx-icon>stop</igx-icon>
</button>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,7 @@ export class ProcessesComponent implements OnInit {
}

ngOnInit() {
this.mockProcessesData = this.mockProcessesService.getProcessServiceObjectsProcesses();
//depending on implementation, data subscriptions might need to be unsubbed later
const throttlingProcesses = this.mockProcessesService.getProcessServiceObject()
.subjectAddProcesses.pipe(throttleTime(1000));
const subscribingToProcesses = throttlingProcesses.subscribe((data) => {
this.mockProcessesData = data;
this.TreeGrid.markForCheck();
});
}

KillProcessById(pid: number){
this.mockProcessesService.KillProcessByID(pid);
this.mockProcessesService.getData('Processes').subscribe(data => this.mockProcessesData = data);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,13 @@
/* Morgan Stanley makes this available to you under the Apache License, Version 2.0 (the "License"). You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */
import { Injectable } from '@angular/core';
import { SuperRPC } from 'super-rpc';
import { IProcessInfoAggregator } from '../DTOs/IProcessInfoAggregator';
import { ProcessInfo } from '../DTOs/ProcessInfo';
import { ServiceProcessObject } from '../main-view/processes/ServiceProcessObject';
import { Observable, of } from 'rxjs';
import { MockProcesses } from './mock-processes';

@Injectable({
providedIn: 'root'
})
export class MockProcessesService {

private ws: WebSocket = new WebSocket('ws://localhost:5056/processes');
private rpc : SuperRPC;
private process : ServiceProcessObject;
private connected: any;
private processController: IProcessInfoAggregator;

constructor(){
this.process = new ServiceProcessObject();
this.connected = new Promise( (resolve, reject) =>
{
try{
this.ws.addEventListener('open', async() => {
this.rpc = new SuperRPC( () => (Math.random()*1e17).toString(36));
this.rpc.connect({
sendAsync: (message) => this.ws.send(JSON.stringify(message)),
receive: (callback) => { this.ws.addEventListener('message', (msg) => callback(JSON.parse(msg.data)))}
});
this.rpc.registerHostObject('ServiceProcessObject', this.process, {functions:['AddProcesses', 'AddProcess', 'UpdateProcess', 'TerminateProcess',
'AddRuntimeInfo', 'AddConnections', 'AddConnection', 'UpdateConnection', 'UpdateEnvironmentVariables','UpdateRegistrations', 'UpdateModules', 'AddRuntimeInfos']});
await this.rpc.requestRemoteDescriptors();
this.processController = this.rpc.getProxyObject('processController');
resolve(undefined);
})}catch(ex){
reject(ex);}
});
}

public getProcessServiceObject() : ServiceProcessObject{
return this.process;
}

public getProcessServiceObjectsProcesses() : ProcessInfo[]{
return this.process.getProcesses();
}

public KillProcessByID(pid: number) : void{
this.processController.RemoveProcessById(pid);
public getData(tableName: string): Observable<any[]> {
return of(MockProcesses[tableName]);
}
}

}
Loading

0 comments on commit f95fee4

Please sign in to comment.