File

src/sockets/events/idm/idm-listener.service.ts

Description

The IdmListenerService is similar to the IDMListener in the REDHAWK sandbox.

Index

Properties
Methods
Accessors

Constructor

constructor(eventChannel: EventChannelService)

Constructor

Parameters :
Name Type Optional Description
eventChannel EventChannelService

The Event Channel (Service) to use for connections

Methods

Public connect
connect(domainId: string)

Connect to a Domain's IDM Event Channel

Parameters :
Name Type Optional Description
domainId string

The Domain ID (Name)

Returns : void
Public disconnect
disconnect(domainId: string)

Disconnect from a Domain's IDM Event Channel

Parameters :
Name Type Optional Description
domainId string

The Domain ID (Name)

Returns : void

Properties

Private abnormalComponentTerminationChanged
abnormalComponentTerminationChanged: Subject<AbnormalComponentTerminationEvent>
Type : Subject<AbnormalComponentTerminationEvent>

Abnormal termination events

Private administrativeStateChanged
administrativeStateChanged: Subject<AdministrativeStateEvent>
Type : Subject<AdministrativeStateEvent>

Administrative state events

Private allEvents
allEvents: Subject<IdmEvent>
Type : Subject<IdmEvent>

All events

Private operationalStateChanged
operationalStateChanged: Subject<OperationalStateEvent>
Type : Subject<OperationalStateEvent>

Operational state events

Private usageStateChanged
usageStateChanged: Subject<UsageStateEvent>
Type : Subject<UsageStateEvent>

Usage State events

Accessors

allEvents$
getallEvents$()

Observable for all possible events on the IDM Channel

administrativeStateChanged$
getadministrativeStateChanged$()

Observable for specifically Administrative State Changed events.

operationalStateChanged$
getoperationalStateChanged$()

Observable for specifically Operational State Changed events.

usageStateChanged$
getusageStateChanged$()

Observable for specifically Usage State Changed events.

abnormalComponentTerminationChanged$
getabnormalComponentTerminationChanged$()

Observable for specifically Abnormal Component Termination Changed events.

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import 'rxjs/add/operator/map';

import {
    IdmEvent,
    UsageStateEvent,
    AdministrativeStateEvent,
    OperationalStateEvent,
    AbnormalComponentTerminationEvent
} from '../../../models/index';

import { EventChannelService } from '../generic/index';

/**
 * Provides an instantiation of the IDM Listener Service
 * @param ecs An EventChannelService instance to utilize
 */
export function configureIdmListenerService(ecs: EventChannelService): IdmListenerService {
    const s = new IdmListenerService(ecs);
    return s;
}

/**
 * Returns providers for a pre-configured ODM Listener Service
 */
export function idmListenerServiceProvider(): any {
    return [
        EventChannelService,
        {
            provide: IdmListenerService,
            useFactory: configureIdmListenerService,
            deps: [ EventChannelService ]
        }
    ];
}

/**
 * The IdmListenerService is similar to the IDMListener in the REDHAWK sandbox.
 */
@Injectable()
export class IdmListenerService {

    /**
     * Observable for all possible events on the IDM Channel
     */
    public get allEvents$(): Observable<IdmEvent> {
        return this.allEvents.asObservable();
    }

    /**
     * Observable for specifically Administrative State Changed events.
     */
    public get administrativeStateChanged$(): Observable<AdministrativeStateEvent> {
        return this.administrativeStateChanged.asObservable();
    }

    /**
     * Observable for specifically Operational State Changed events.
     */
    public get operationalStateChanged$(): Observable<OperationalStateEvent> {
        return this.operationalStateChanged.asObservable();
    }

    /**
     * Observable for specifically Usage State Changed events.
     */
    public get usageStateChanged$(): Observable<UsageStateEvent> {
        return this.usageStateChanged.asObservable();
    }

    /**
     * Observable for specifically Abnormal Component Termination Changed events.
     */
    public get abnormalComponentTerminationChanged$(): Observable<AbnormalComponentTerminationEvent> {
        return this.abnormalComponentTerminationChanged.asObservable();
    }

    /** All events */
    private allEvents: Subject<IdmEvent>;

    /** Administrative state events */
    private administrativeStateChanged: Subject<AdministrativeStateEvent>;
    /** Operational state events */
    private operationalStateChanged: Subject<OperationalStateEvent>;
    /** Usage State events */
    private usageStateChanged: Subject<UsageStateEvent>;
    /** Abnormal termination events */
    private abnormalComponentTerminationChanged: Subject<AbnormalComponentTerminationEvent>;

    /**
     * Connect to a Domain's IDM Event Channel
     * @param domainId The Domain ID (Name)
     */
    public connect(domainId: string) {
        this.eventChannel.connect(domainId, 'IDM_Channel');
    }

    /**
     * Disconnect from a Domain's IDM Event Channel
     * @param domainId The Domain ID (Name)
     */
    public disconnect(domainId: string) {
        this.eventChannel.disconnect(domainId, 'IDM_Channel');
    }

    /**
     * Constructor
     * @param eventChannel The Event Channel (Service) to use for connections
     */
    constructor(private eventChannel: EventChannelService) {

        this.allEvents = new Subject<IdmEvent>();
        this.administrativeStateChanged = new Subject<AdministrativeStateEvent>();
        this.operationalStateChanged = new Subject<OperationalStateEvent>();
        this.usageStateChanged = new Subject<UsageStateEvent>();
        this.abnormalComponentTerminationChanged = new Subject<AbnormalComponentTerminationEvent>();

        this.eventChannel
            .events$
            .subscribe((data: any) => {
                if (data instanceof IdmEvent) {
                    this.allEvents.next(data);
                    if (data instanceof AdministrativeStateEvent) {
                        this.administrativeStateChanged.next(data);
                    } else if (data instanceof OperationalStateEvent) {
                        this.operationalStateChanged.next(data);
                    } else if (data instanceof UsageStateEvent) {
                        this.usageStateChanged.next(data);
                    } else if (data instanceof AbnormalComponentTerminationEvent) {
                        this.abnormalComponentTerminationChanged.next(data);
                    }
                }
            });
    }
}

results matching ""

    No results matching ""