src/sockets/events/odm/odm-listener.service.ts
The OdmListenerService is similar to the ODMListener in the REDHAWK sandbox.
Properties |
|
Methods |
|
Accessors |
constructor(eventChannel: EventChannelService)
|
||||||||
Constructor
Parameters :
|
Public connect | ||||||||
connect(domainId: string)
|
||||||||
Connect to a Domain's ODM Event Channel
Parameters :
Returns :
void
|
Public disconnect | ||||||||
disconnect(domainId: string)
|
||||||||
Disconnect from a Domain's ODM Event Channel
Parameters :
Returns :
void
|
Private handleAdd | ||||||||
handleAdd(event: DomainManagementObjectAddedEvent)
|
||||||||
Uses the event's source category to determine the subject to update.
Parameters :
Returns :
void
|
Private handleRemove | ||||||||
handleRemove(event: DomainManagementObjectRemovedEvent)
|
||||||||
Uses the event's source category to determine the subject to update.
Parameters :
Returns :
void
|
Private allEvents |
allEvents:
|
Type : Subject<OdmEvent>
|
All events |
Private applicationAdded |
applicationAdded:
|
Type : Subject<DomainManagementObjectAddedEvent>
|
application added |
Private applicationFactoryAdded |
applicationFactoryAdded:
|
Type : Subject<DomainManagementObjectAddedEvent>
|
application factory added |
Private applicationFactoryRemoved |
applicationFactoryRemoved:
|
Type : Subject<DomainManagementObjectRemovedEvent>
|
application factory removed |
Private applicationRemoved |
applicationRemoved:
|
Type : Subject<DomainManagementObjectRemovedEvent>
|
application removed |
Private deviceAdded |
deviceAdded:
|
Type : Subject<DomainManagementObjectAddedEvent>
|
device added |
Private deviceManagerAdded |
deviceManagerAdded:
|
Type : Subject<DomainManagementObjectAddedEvent>
|
device manager added |
Private deviceManagerRemoved |
deviceManagerRemoved:
|
Type : Subject<DomainManagementObjectRemovedEvent>
|
device manager removed |
Private deviceRemoved |
deviceRemoved:
|
Type : Subject<DomainManagementObjectRemovedEvent>
|
device removed |
Private serviceAdded |
serviceAdded:
|
Type : Subject<DomainManagementObjectAddedEvent>
|
servce added |
Private serviceRemoved |
serviceRemoved:
|
Type : Subject<DomainManagementObjectRemovedEvent>
|
service removed |
allEvents$ |
getallEvents$()
|
Obsevable for all possible events on the ODM Event Channel
Returns :
Observable<OdmEvent>
|
deviceManagerAdded$ |
getdeviceManagerAdded$()
|
Observable for specifically Device Manager Added events. |
deviceManagerRemoved$ |
getdeviceManagerRemoved$()
|
Observable for specifically DeviceManager Removed events. |
deviceAdded$ |
getdeviceAdded$()
|
Observable for specifically Device Added events. |
deviceRemoved$ |
getdeviceRemoved$()
|
Observable for specifically Device Removed events. |
applicationFactoryAdded$ |
getapplicationFactoryAdded$()
|
Observable for specifically Application Factory Added events. |
applicationFactoryRemoved$ |
getapplicationFactoryRemoved$()
|
Observable for specifically Application Factory Removed events. |
applicationAdded$ |
getapplicationAdded$()
|
Observable for specifically Application Added events. |
applicationRemoved$ |
getapplicationRemoved$()
|
Observable for specifically Application Removed events. |
serviceAdded$ |
getserviceAdded$()
|
Observable for specifically Service Added events. |
serviceRemoved$ |
getserviceRemoved$()
|
Observable for specifically Service Removed events. |
import { Injectable, Provider } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import 'rxjs/add/operator/map';
import {
OdmEvent,
DomainManagementObjectAddedEvent,
DomainManagementObjectRemovedEvent,
SourceCategory
} from '../../../models/index';
import { EventChannelService } from '../generic/index';
/**
* The ODM Event Channel name
*/
export const ODM_CHANNEL_NAME: string = 'ODM_Channel';
/**
* Provides an instantiation of the ODM Listener Service
* @param ecs An EventChannelService instance to utilize
*/
export function configureOdmListenerService(ecs: EventChannelService): OdmListenerService {
const s = new OdmListenerService(ecs);
return s;
}
/**
* Returns providers for a pre-configured ODM Listener Service
*/
export function odmListenerServiceProvider(): Provider[] {
return [
EventChannelService,
{
provide: OdmListenerService,
useFactory: configureOdmListenerService,
deps: [ EventChannelService ]
}
];
}
/**
* The OdmListenerService is similar to the ODMListener in the REDHAWK sandbox.
*/
@Injectable()
export class OdmListenerService {
/**
* Obsevable for all possible events on the ODM Event Channel
*/
public get allEvents$(): Observable<OdmEvent> {
return this.allEvents.asObservable();
}
/**
* Observable for specifically Device Manager Added events.
*/
public get deviceManagerAdded$(): Observable<DomainManagementObjectAddedEvent> {
return this.deviceManagerAdded.asObservable();
}
/**
* Observable for specifically DeviceManager Removed events.
*/
public get deviceManagerRemoved$(): Observable<DomainManagementObjectRemovedEvent> {
return this.deviceManagerRemoved.asObservable();
}
/**
* Observable for specifically Device Added events.
*/
public get deviceAdded$(): Observable<DomainManagementObjectAddedEvent> {
return this.deviceAdded.asObservable();
}
/**
* Observable for specifically Device Removed events.
*/
public get deviceRemoved$(): Observable<DomainManagementObjectRemovedEvent> {
return this.deviceRemoved.asObservable();
}
/**
* Observable for specifically Application Factory Added events.
*/
public get applicationFactoryAdded$(): Observable<DomainManagementObjectAddedEvent> {
return this.applicationFactoryAdded.asObservable();
}
/**
* Observable for specifically Application Factory Removed events.
*/
public get applicationFactoryRemoved$(): Observable<DomainManagementObjectRemovedEvent> {
return this.applicationFactoryRemoved.asObservable();
}
/**
* Observable for specifically Application Added events.
*/
public get applicationAdded$(): Observable<DomainManagementObjectAddedEvent> {
return this.applicationAdded.asObservable();
}
/**
* Observable for specifically Application Removed events.
*/
public get applicationRemoved$(): Observable<DomainManagementObjectRemovedEvent> {
return this.applicationRemoved.asObservable();
}
/**
* Observable for specifically Service Added events.
*/
public get serviceAdded$(): Observable<DomainManagementObjectAddedEvent> {
return this.serviceAdded.asObservable();
}
/**
* Observable for specifically Service Removed events.
*/
public get serviceRemoved$(): Observable<DomainManagementObjectRemovedEvent> {
return this.serviceRemoved.asObservable();
}
/** All events */
private allEvents: Subject<OdmEvent>;
/** device manager added */
private deviceManagerAdded: Subject<DomainManagementObjectAddedEvent>;
/** device manager removed */
private deviceManagerRemoved: Subject<DomainManagementObjectRemovedEvent>;
/** device added */
private deviceAdded: Subject<DomainManagementObjectAddedEvent>;
/** device removed */
private deviceRemoved: Subject<DomainManagementObjectRemovedEvent>;
/** application factory added */
private applicationFactoryAdded: Subject<DomainManagementObjectAddedEvent>;
/** application factory removed */
private applicationFactoryRemoved: Subject<DomainManagementObjectRemovedEvent>;
/** application added */
private applicationAdded: Subject<DomainManagementObjectAddedEvent>;
/** application removed */
private applicationRemoved: Subject<DomainManagementObjectRemovedEvent>;
/** servce added */
private serviceAdded: Subject<DomainManagementObjectAddedEvent>;
/** service removed */
private serviceRemoved: Subject<DomainManagementObjectRemovedEvent>;
/**
* Connect to a Domain's ODM Event Channel
* @param domainId The Domain ID (Name)
*/
public connect(domainId: string) {
this.eventChannel.connect(domainId, ODM_CHANNEL_NAME);
}
/**
* Disconnect from a Domain's ODM Event Channel
* @param domainId The Domain ID (Name)
*/
public disconnect(domainId: string) {
this.eventChannel.disconnect(domainId, ODM_CHANNEL_NAME);
}
/**
* Constructor
* @param eventChannel The Event Channel (Service) to use for connections
*/
constructor(private eventChannel: EventChannelService) {
this.allEvents = new Subject<OdmEvent>();
this.deviceManagerAdded = new Subject<DomainManagementObjectAddedEvent>();
this.deviceManagerRemoved = new Subject<DomainManagementObjectRemovedEvent>();
this.deviceAdded = new Subject<DomainManagementObjectAddedEvent>();
this.deviceRemoved = new Subject<DomainManagementObjectRemovedEvent>();
this.applicationFactoryAdded = new Subject<DomainManagementObjectAddedEvent>();
this.applicationFactoryRemoved = new Subject<DomainManagementObjectRemovedEvent>();
this.applicationAdded = new Subject<DomainManagementObjectAddedEvent>();
this.applicationRemoved = new Subject<DomainManagementObjectRemovedEvent>();
this.serviceAdded = new Subject<DomainManagementObjectAddedEvent>();
this.serviceRemoved = new Subject<DomainManagementObjectRemovedEvent>();
this.eventChannel
.events$
.subscribe((data: any) => {
if (data instanceof OdmEvent) {
this.allEvents.next(data);
if (data instanceof DomainManagementObjectAddedEvent) {
this.handleAdd(data);
} else if (data instanceof DomainManagementObjectRemovedEvent) {
this.handleRemove(data);
}
}
});
}
/**
* Uses the event's source category to determine the subject to update.
* @param event The Event to handle
*/
private handleAdd(event: DomainManagementObjectAddedEvent) {
switch (event.sourceCategory) {
case SourceCategory.DEVICE_MANAGER:
this.deviceManagerAdded.next(event);
break;
case SourceCategory.DEVICE:
this.deviceAdded.next(event);
break;
case SourceCategory.APPLICATION_FACTORY:
this.applicationFactoryAdded.next(event);
break;
case SourceCategory.APPLICATION:
this.applicationAdded.next(event);
break;
case SourceCategory.SERVICE:
this.serviceAdded.next(event);
break;
default:
break;
}
}
/**
* Uses the event's source category to determine the subject to update.
* @param event The Event to handle
*/
private handleRemove(event: DomainManagementObjectRemovedEvent) {
switch (event.sourceCategory) {
case SourceCategory.DEVICE_MANAGER:
this.deviceManagerRemoved.next(event);
break;
case SourceCategory.DEVICE:
this.deviceRemoved.next(event);
break;
case SourceCategory.APPLICATION_FACTORY:
this.applicationFactoryRemoved.next(event);
break;
case SourceCategory.APPLICATION:
this.applicationRemoved.next(event);
break;
case SourceCategory.SERVICE:
this.serviceRemoved.next(event);
break;
default:
break;
}
}
}