This commit is contained in:
crusader 2018-05-31 21:04:52 +09:00
parent 7d9fd23271
commit 4ff5eead18
4 changed files with 1838 additions and 1772 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 DiscoverySubject extends Subject<DiscoveryNotify> {
}

View File

@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { RPCService } from '@loafer/ng-rpc';
import { RPCService, RPCSubscribeService } from '@loafer/ng-rpc';
import {
DiscoverZone as MDDiscoverZone,
DiscoverHost as MDDiscoverHost,
@ -12,25 +13,50 @@ import {
Service,
} from '@overflow/commons-typescript/model/discovery';
import { DiscoverySubject, DiscoveryNotify } from '../core/discovery-subject';
import * as DiscoverStore from '../store/discover';
import { DiscoverySubscriber } from '../subscriber/discovery.subscriber';
@Injectable()
export class DiscoveryService {
public constructor(
private discoverySubscriber: DiscoverySubscriber,
private rpcService: RPCService,
) {
}
public discoverZone(probeID: string, discoverZone: MDDiscoverZone): void {
public discoverZone(probeID: string, discoverZone: MDDiscoverZone): Observable<DiscoveryNotify> {
const discoverySubject: DiscoverySubject = new DiscoverySubject();
this.discoverySubscriber.setDiscoverySubject(discoverySubject);
this.rpcService.send('DiscoveryService.discoverZone', probeID, discoverZone);
return discoverySubject;
}
public discoverHost(probeID: string, zone: Zone, discoverHost: MDDiscoverHost): void {
public discoverHost(probeID: string, zone: Zone, discoverHost: MDDiscoverHost): Observable<DiscoveryNotify> {
const discoverySubject: DiscoverySubject = new DiscoverySubject();
this.discoverySubscriber.setDiscoverySubject(discoverySubject);
this.rpcService.send('DiscoveryService.discoverHost', probeID, zone, discoverHost);
return discoverySubject;
}
public discoverPort(probeID: string, host: Host, discoverPort: MDDiscoverPort): void {
public discoverPort(probeID: string, host: Host, discoverPort: MDDiscoverPort): Observable<DiscoveryNotify> {
const discoverySubject: DiscoverySubject = new DiscoverySubject();
this.discoverySubscriber.setDiscoverySubject(discoverySubject);
this.rpcService.send('DiscoveryService.discoverPort', probeID, host, discoverPort);
return discoverySubject;
}
public discoverService(probeID: string, port: Port, discoverService: MDDiscoverService): void {
public discoverService(probeID: string, port: Port, discoverService: MDDiscoverService): Observable<DiscoveryNotify> {
const discoverySubject: DiscoverySubject = new DiscoverySubject();
this.discoverySubscriber.setDiscoverySubject(discoverySubject);
this.rpcService.send('DiscoveryService.discoverService', probeID, port, discoverService);
return discoverySubject;
}
}

View File

@ -1,9 +1,10 @@
import { Injectable } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
import { RPCSubscriber } from '@loafer/ng-rpc';
import { LoggerService } from '@loafer/ng-logger';
import { DiscoverSelector } from '../store';
import * as DiscoverStore from '../store/discover';
import {
@ -12,28 +13,43 @@ import {
Port,
Service,
} from '@overflow/commons-typescript/model/discovery';
import { DiscoverySubject } from '../core/discovery-subject';
@Injectable()
export class DiscoverySubscriber {
discoverySubject: DiscoverySubject | null;
public constructor(
private store: Store<DiscoverStore.State>,
private loggerService: LoggerService,
) {
}
/**
* 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});
}
}
@RPCSubscriber({method: 'DiscoveryService.discoveryStart'})
public discoveryStart(startDate: Date): void {
this.loggerService.debug('DiscoverySubscriber.discoveryStart startDate:', startDate);
this.store.dispatch(new DiscoverStore.DiscoveryStart(startDate));
this.publish('DiscoveryService.discoveryStart', startDate);
}
@RPCSubscriber({method: 'DiscoveryService.discoveryStop'})
public discoveryStop(stopDate: Date): void {
this.loggerService.debug('DiscoverySubscriber.discoveryStop stopDate:', stopDate);
this.store.dispatch(new DiscoverStore.DiscoveryStop(stopDate));
this.publish('DiscoveryService.discoveryStop', stopDate);
this.setDiscoverySubject(null);
}
@ -41,21 +57,21 @@ export class DiscoverySubscriber {
public discoveredZone(zone: Zone): void {
this.loggerService.debug('DiscoverySubscriber.discoveredZone zone:', zone);
this.store.dispatch(new DiscoverStore.DiscoveredZone(zone));
this.publish('DiscoveryService.discoveredZone', zone);
}
@RPCSubscriber({method: 'DiscoveryService.discoveredHost'})
public discoveredHost(host: Host): void {
this.loggerService.debug('DiscoverySubscriber.discoveredHost host:', host);
this.store.dispatch(new DiscoverStore.DiscoveredHost(host));
this.publish('DiscoveryService.discoveredHost', host);
}
@RPCSubscriber({method: 'DiscoveryService.discoveredPort'})
public discoveredPort(port: Port): void {
this.store.dispatch(new DiscoverStore.DiscoveredPort(port));
this.publish('DiscoveryService.discoveredPort', port);
}
@RPCSubscriber({method: 'DiscoveryService.discoveredService'})
public discoveredService(service: Service): void {
this.loggerService.debug('DiscoverySubscriber.discoveredService service:', service);
this.store.dispatch(new DiscoverStore.DiscoveredService(service));
this.publish('DiscoveryService.discoveredService', service);
}
}

3525
package-lock.json generated

File diff suppressed because it is too large Load Diff