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

78 lines
2.4 KiB
TypeScript
Raw Permalink Normal View History

2018-04-06 11:02:18 +00:00
import { Injectable } from '@angular/core';
2018-05-31 12:44:11 +00:00
import { Observable, Subject } from 'rxjs';
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
import {
Zone,
Host,
Port,
Service,
2018-05-02 07:23:35 +00:00
} from '@overflow/commons-typescript/model/discovery';
2018-05-31 13:11:23 +00:00
export interface DiscoveryNotify {
method: string;
params: Date | Zone | Host | Port | Service;
}
export class DiscoverySubscriberSubject extends Subject<DiscoveryNotify> {
}
2018-04-06 11:02:18 +00:00
@Injectable()
export class DiscoverySubscriber {
2018-05-31 12:44:11 +00:00
discoverySubscriberSubject: DiscoverySubscriberSubject;
2018-04-06 11:02:18 +00:00
public constructor(
private loggerService: LoggerService,
) {
2018-06-20 07:00:24 +00:00
this.discoverySubscriberSubject = new DiscoverySubscriberSubject();
2018-04-06 11:02:18 +00:00
}
2018-05-31 13:11:23 +00:00
public observable(): Observable<DiscoveryNotify> {
2018-05-31 12:44:11 +00:00
return this.discoverySubscriberSubject.asObservable();
2018-05-31 12:04:52 +00:00
}
private publish(method: string, params: any): void {
2018-05-31 12:44:11 +00:00
this.discoverySubscriberSubject.next({ method: method, params: params });
2018-05-31 12:04:52 +00:00
}
2018-05-31 12:44:11 +00:00
@RPCSubscriber({ method: 'DiscoveryService.discoveryStart' })
2018-04-19 15:15:20 +00:00
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
}
2018-05-31 12:44:11 +00:00
@RPCSubscriber({ method: 'DiscoveryService.discoveryStop' })
2018-04-19 15:15:20 +00:00
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);
2018-04-19 15:15:20 +00:00
}
2018-05-31 12:44:11 +00:00
@RPCSubscriber({ method: 'DiscoveryService.discoveredZone' })
2018-04-06 11:02:18 +00:00
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
}
2018-05-31 12:44:11 +00:00
@RPCSubscriber({ method: 'DiscoveryService.discoveredHost' })
2018-04-06 11:02:18 +00:00
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
}
2018-05-31 12:44:11 +00:00
@RPCSubscriber({ method: 'DiscoveryService.discoveredPort' })
2018-04-06 11:02:18 +00:00
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
}
2018-05-31 12:44:11 +00:00
@RPCSubscriber({ method: 'DiscoveryService.discoveredService' })
2018-04-06 11:02:18 +00:00
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
}
}