member_webapp/@overflow/discovery/subscriber/discovery.subscriber.ts

78 lines
2.4 KiB
TypeScript
Raw Normal View History

2018-04-06 11:02:18 +00:00
import { Injectable } from '@angular/core';
2018-05-31 12:04:52 +00:00
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
2018-04-06 11:02:18 +00:00
2018-05-24 06:44:13 +00:00
import { RPCSubscriber } from '@loafer/ng-rpc';
import { LoggerService } from '@loafer/ng-logger';
2018-04-06 11:02:18 +00:00
2018-05-31 12:04:52 +00:00
import { DiscoverSelector } from '../store';
2018-04-06 11:02:18 +00:00
import * as DiscoverStore from '../store/discover';
import {
Zone,
Host,
Port,
Service,
2018-05-02 07:23:35 +00:00
} from '@overflow/commons-typescript/model/discovery';
2018-05-31 12:04:52 +00:00
import { DiscoverySubject } from '../core/discovery-subject';
2018-04-06 11:02:18 +00:00
@Injectable()
export class DiscoverySubscriber {
2018-05-31 12:04:52 +00:00
discoverySubject: DiscoverySubject | null;
2018-04-06 11:02:18 +00:00
public constructor(
private loggerService: LoggerService,
) {
}
2018-05-31 12:04:52 +00:00
/**
* name
*/
public setDiscoverySubject(discoverySubject: DiscoverySubject) {
this.discoverySubject = discoverySubject;
}
private publish(method: string, params: any): void {
if (null !== this.discoverySubject) {
this.discoverySubject.next({method: method, params: params});
}
}
2018-04-19 15:15:20 +00:00
@RPCSubscriber({method: 'DiscoveryService.discoveryStart'})
public discoveryStart(startDate: Date): void {
this.loggerService.debug('DiscoverySubscriber.discoveryStart startDate:', startDate);
2018-05-31 12:04:52 +00:00
this.publish('DiscoveryService.discoveryStart', startDate);
2018-04-19 15:15:20 +00:00
}
@RPCSubscriber({method: 'DiscoveryService.discoveryStop'})
public discoveryStop(stopDate: Date): void {
this.loggerService.debug('DiscoverySubscriber.discoveryStop stopDate:', stopDate);
2018-05-31 12:04:52 +00:00
this.publish('DiscoveryService.discoveryStop', stopDate);
this.setDiscoverySubject(null);
2018-04-19 15:15:20 +00:00
}
2018-04-06 11:02:18 +00:00
@RPCSubscriber({method: 'DiscoveryService.discoveredZone'})
public discoveredZone(zone: Zone): void {
this.loggerService.debug('DiscoverySubscriber.discoveredZone zone:', zone);
2018-05-31 12:04:52 +00:00
this.publish('DiscoveryService.discoveredZone', zone);
2018-04-06 11:02:18 +00:00
}
@RPCSubscriber({method: 'DiscoveryService.discoveredHost'})
public discoveredHost(host: Host): void {
2018-04-19 15:15:20 +00:00
this.loggerService.debug('DiscoverySubscriber.discoveredHost host:', host);
2018-04-06 11:02:18 +00:00
2018-05-31 12:04:52 +00:00
this.publish('DiscoveryService.discoveredHost', host);
2018-04-06 11:02:18 +00:00
}
@RPCSubscriber({method: 'DiscoveryService.discoveredPort'})
public discoveredPort(port: Port): void {
2018-05-31 12:04:52 +00:00
this.publish('DiscoveryService.discoveredPort', port);
2018-04-06 11:02:18 +00:00
}
@RPCSubscriber({method: 'DiscoveryService.discoveredService'})
public discoveredService(service: Service): void {
this.loggerService.debug('DiscoverySubscriber.discoveredService service:', service);
2018-05-31 12:04:52 +00:00
this.publish('DiscoveryService.discoveredService', service);
2018-04-06 11:02:18 +00:00
}
}