This commit is contained in:
crusader
2018-05-31 21:44:11 +09:00
parent e46aa26170
commit 87f68ca3f3
4 changed files with 28 additions and 47 deletions

View File

@@ -0,0 +1,17 @@
import { Subject } from 'rxjs';
import {
Zone,
Host,
Port,
Service,
} from '@overflow/commons-typescript/model/discovery';
export interface DiscoveryNotify {
method: string;
params: Date | Zone | Host | Port | Service;
}
export class DiscoverySubscriberSubject extends Subject<DiscoveryNotify> {
}

View File

@@ -1,4 +1,5 @@
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
import { RPCSubscriber } from '@loafer/ng-rpc';
@@ -13,63 +14,61 @@ import {
Port,
Service,
} from '@overflow/commons-typescript/model/discovery';
import { DiscoverySubject } from '../core/discovery-subject';
import { DiscoverySubscriberSubject, DiscoveryNotify } from './discovery.subscriber.subject';
@Injectable()
export class DiscoverySubscriber {
discoverySubject: DiscoverySubject | null;
discoverySubscriberSubject: DiscoverySubscriberSubject;
public constructor(
private loggerService: LoggerService,
) {
this.discoverySubscriberSubject = new DiscoverySubscriberSubject();
}
/**
* name
*/
public setDiscoverySubject(discoverySubject: DiscoverySubject) {
this.discoverySubject = discoverySubject;
public subscribe(): Observable<DiscoveryNotify> {
return this.discoverySubscriberSubject.asObservable();
}
private publish(method: string, params: any): void {
if (null !== this.discoverySubject) {
this.discoverySubject.next({method: method, params: params});
}
this.discoverySubscriberSubject.next({ method: method, params: params });
}
@RPCSubscriber({method: 'DiscoveryService.discoveryStart'})
@RPCSubscriber({ method: 'DiscoveryService.discoveryStart' })
public discoveryStart(startDate: Date): void {
this.loggerService.debug('DiscoverySubscriber.discoveryStart startDate:', startDate);
this.publish('DiscoveryService.discoveryStart', startDate);
}
@RPCSubscriber({method: 'DiscoveryService.discoveryStop'})
@RPCSubscriber({ method: 'DiscoveryService.discoveryStop' })
public discoveryStop(stopDate: Date): void {
this.loggerService.debug('DiscoverySubscriber.discoveryStop stopDate:', stopDate);
this.publish('DiscoveryService.discoveryStop', stopDate);
this.setDiscoverySubject(null);
}
@RPCSubscriber({method: 'DiscoveryService.discoveredZone'})
@RPCSubscriber({ method: 'DiscoveryService.discoveredZone' })
public discoveredZone(zone: Zone): void {
this.loggerService.debug('DiscoverySubscriber.discoveredZone zone:', zone);
this.publish('DiscoveryService.discoveredZone', zone);
}
@RPCSubscriber({method: 'DiscoveryService.discoveredHost'})
@RPCSubscriber({ method: 'DiscoveryService.discoveredHost' })
public discoveredHost(host: Host): void {
this.loggerService.debug('DiscoverySubscriber.discoveredHost host:', host);
this.publish('DiscoveryService.discoveredHost', host);
}
@RPCSubscriber({method: 'DiscoveryService.discoveredPort'})
@RPCSubscriber({ method: 'DiscoveryService.discoveredPort' })
public discoveredPort(port: Port): void {
this.publish('DiscoveryService.discoveredPort', port);
}
@RPCSubscriber({method: 'DiscoveryService.discoveredService'})
@RPCSubscriber({ method: 'DiscoveryService.discoveredService' })
public discoveredService(service: Service): void {
this.loggerService.debug('DiscoverySubscriber.discoveredService service:', service);
this.publish('DiscoveryService.discoveredService', service);