Skip to content

Commit

Permalink
changing stopping and starting of subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Dec 23, 2023
1 parent c0320d7 commit 8f573d0
Show file tree
Hide file tree
Showing 24 changed files with 190 additions and 480 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
~ @authors Christof Strack
-->

<c8y-title>Dynamic Mapping</c8y-title>
<c8y-title>Broker Configuration</c8y-title>
<c8y-action-bar-item [placement]="'right'">
<button
class="btn btn-link"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class BrokerConfigurationComponent implements OnInit {
await this.loadData();
this.statusLogs$ = this.brokerConfigurationService.getStatusLogs();
this.feature = await this.sharedService.getFeatures();
this.brokerConfigurationService.startConnectorStatusSubscriptions();
}

public async refresh() {
Expand Down Expand Up @@ -271,6 +272,6 @@ export class BrokerConfigurationComponent implements OnInit {
}

ngOnDestroy(): void {
console.log("Stop subscriptions");
this.brokerConfigurationService.stopConnectorStatusSubscriptions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ import { Injectable } from "@angular/core";
import {
EventService,
FetchClient,
IdentityService,
IEvent,
IExternalIdentity,
IFetchResponse,
Realtime,
} from "@c8y/client";
import {
AGENT_ID,
BASE_URL,
CONNECTOR_FRAGMENT,
Extension,
Expand All @@ -38,35 +35,36 @@ import {
PATH_EXTENSION_ENDPOINT,
PATH_OPERATION_ENDPOINT,
PATH_STATUS_CONNECTORS_ENDPOINT,
SharedService,
} from "../../shared";

import { BehaviorSubject, merge, Observable, Subject } from "rxjs";
import { filter, map, scan, switchMap, withLatestFrom } from "rxjs/operators";
import {
filter,
map,
scan,
switchMap,
withLatestFrom,
} from "rxjs/operators";
import { ConnectorConfiguration, ConnectorSpecification, ConnectorStatusEvent, Feature, Operation, ServiceConfiguration, ConnectorStatus, StatusEventTypes } from "./configuration.model";
ConnectorConfiguration,
ConnectorSpecification,
ConnectorStatus,
ConnectorStatusEvent,
Operation,
ServiceConfiguration,
StatusEventTypes,
} from "./configuration.model";

@Injectable({ providedIn: "root" })
export class BrokerConfigurationService {
constructor(
private client: FetchClient,
private identity: IdentityService,
private eventService: EventService
private eventService: EventService,
private sharedService: SharedService
) {
this.realtime = new Realtime(this.client);
this.startConnectorStatusSubscriptions();
this.initializeConnectorLogsRealtime();
//console.log("Constructor:BrokerConfigurationService");
}

private _agentId: Promise<string>;
private _connectorConfigurations: ConnectorConfiguration[];
private _serviceConfiguration: ServiceConfiguration;
private _connectorSpecifications: ConnectorSpecification[];
private _feature: Promise<Feature>;
private realtime: Realtime;
private statusLogs$: Observable<any[]>;
private subscriptionEvents: any;
Expand All @@ -84,27 +82,11 @@ export class BrokerConfigurationService {

public resetCache() {
console.log("resetCache() :BrokerConfigurationService");
this._feature = undefined;
this._connectorConfigurations = undefined;
this._connectorSpecifications = undefined;
this._serviceConfiguration = undefined;
}

async getDynamicMappingServiceAgent(): Promise<string> {
if (!this._agentId) {
const identity: IExternalIdentity = {
type: "c8y_Serial",
externalId: AGENT_ID,
};
const { data, res } = await this.identity.detail(identity);
if (res.status < 300) {
const agentId = data.managedObject.id.toString();
this._agentId = Promise.resolve(agentId);
}
}
return this._agentId;
}

async updateConnectorConfiguration(
configuration: ConnectorConfiguration
): Promise<IFetchResponse> {
Expand Down Expand Up @@ -249,8 +231,8 @@ export class BrokerConfigurationService {
}

async startConnectorStatusCheck(): Promise<void> {
const agentId = await this.getDynamicMappingServiceAgent();
console.log("Started subscription:", agentId);
const agentId = await this.sharedService.getDynamicMappingServiceAgent();
console.log("Started subscriptions:", agentId);

// subscribe to event stream
this.subscriptionEvents = this.realtime.subscribe(
Expand Down Expand Up @@ -282,8 +264,8 @@ export class BrokerConfigurationService {
this.statusLogEventType = eventType;
}

async startConnectorLogsRealtime(): Promise<void> {
const agentId = await this.getDynamicMappingServiceAgent();
async initializeConnectorLogsRealtime(): Promise<void> {
const agentId = await this.sharedService.getDynamicMappingServiceAgent();
console.log("Agent Id", agentId);

const sourceList$ = this.filterTrigger$.pipe(
Expand Down Expand Up @@ -332,11 +314,15 @@ export class BrokerConfigurationService {
}

public startConnectorStatusSubscriptions() {
this.startConnectorLogsRealtime();
this.startConnectorStatusCheck();
}
public stopConnectorStatusSubscriptions() {

public async stopConnectorStatusSubscriptions() {
const agentId = await this.sharedService.getDynamicMappingServiceAgent();
console.log("Stop subscriptions:", agentId);
this.realtime.unsubscribe(this.subscriptionEvents);
// this.mergeFilterTrigger$.complete();
// this.incomingRealtime$.complete();
}

public runOperation(op: Operation, parameter?: any): Promise<IFetchResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
*
* @authors Christof Strack
*/
import { Component, ViewChild, ViewEncapsulation } from "@angular/core";
import { ApplicationService, IApplication, IManagedObject, IManagedObjectBinary } from "@c8y/client";
import { Component, OnInit, ViewChild, ViewEncapsulation } from "@angular/core";
import {
ApplicationService,
IApplication,
IManagedObject,
IManagedObjectBinary,
} from "@c8y/client";
import {
AlertService,
DropAreaComponent,
Expand All @@ -35,8 +40,7 @@ import { ExtensionService } from "../share/extension.service";
styleUrls: ["./add-extension.component.style.css"],
encapsulation: ViewEncapsulation.None,
})
export class AddExtensionComponent {

export class AddExtensionComponent implements OnInit {
@ViewChild(DropAreaComponent) dropAreaComponent;

isLoading: boolean;
Expand All @@ -53,6 +57,12 @@ export class AddExtensionComponent {
private applicationService: ApplicationService
) {}

ngOnInit(): void {}

ngOnDestroy(): void {
this.closeSubject.complete();
}

get progress(): BehaviorSubject<number> {
return this.extensionService.progress;
}
Expand Down
4 changes: 4 additions & 0 deletions dynamic-mapping-ui/src/extension/grid/extension.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@ export class ExtensionComponent implements OnInit {
modalRef.hide();
});
}

ngOnDestroy(): void {
this.reload$.complete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,20 +267,8 @@ export class EditSubstitutionComponent implements OnInit {
//console.log("Evaluation", d0,d1,d2,d3, this.templateModel.currentSubstitution)
return r;
}
}

// Showing modal:

// import { BsModalService } from "ngx-bootstrap/modal";
// import { ModalLabels } from "@c8y/ngx-components";

// constructor(
// public bsModalService: BsModalService,
// ) {}

// showModal() {
// const modalRef = this.bsModalService.show(MyModalComponent);
// modalRef.content.closeSubject.subscribe(result => {
// console.log('results:', result);
// });
// }
ngOnDestroy(): void {
this.disabled$.complete();
}
}
2 changes: 1 addition & 1 deletion dynamic-mapping-ui/src/mapping/grid/mapping.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
~ @authors Christof Strack
-->

<c8y-title translate>Dynamic Mapping</c8y-title>
<c8y-title translate>Mapping {{stepperConfiguration.direction | capitalCase}}</c8y-title>
<!-- <mapping-help src="../../shared/help/help-mapping.html"></mapping-help> -->
<!-- <mapping-help src="/apps/mqtt-mapping/assets/help/help-mapping.html"></mapping-help> -->
<!-- <mapping-help src="."></mapping-help> -->
Expand Down
2 changes: 1 addition & 1 deletion dynamic-mapping-ui/src/mapping/grid/mapping.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
SAMPLE_TEMPLATES_C8Y,
SnoopStatus,
getExternalTemplate,
uuidCustom
uuidCustom, CamelCasePipe
} from "../../shared";

import { Router } from "@angular/router";
Expand Down
10 changes: 8 additions & 2 deletions dynamic-mapping-ui/src/mapping/import-modal/import.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @authors Christof Strack
*/
import { Component, ViewChild, ViewEncapsulation } from "@angular/core";
import { Component, OnInit, ViewChild, ViewEncapsulation } from "@angular/core";
import {
AlertService,
DropAreaComponent,
Expand All @@ -34,7 +34,7 @@ import { uuidCustom, Mapping } from "../../shared";
styleUrls: ["./import.component.style.css"],
encapsulation: ViewEncapsulation.None,
})
export class ImportMappingsComponent {
export class ImportMappingsComponent implements OnInit {
@ViewChild(DropAreaComponent) dropAreaComponent;
private importCanceled: boolean = false;
progress$: BehaviorSubject<number> = new BehaviorSubject<number>(null);
Expand All @@ -49,6 +49,8 @@ export class ImportMappingsComponent {
private alertService: AlertService
) {}

ngOnInit(): void {}

onFileDroppedEvent(event) {
if (event && event.length > 0) {
const file = event[0].file;
Expand Down Expand Up @@ -96,4 +98,8 @@ export class ImportMappingsComponent {
private cancelFileUpload() {
this.importCanceled = true;
}

ngOnDestroy() {
this.progress$.unsubscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,8 @@ export class MappingTypeComponent implements OnInit {
this.closeSubject.next(this.mappingType);
this.closeSubject.complete();
}

ngOnDestroy() {
this.closeSubject.complete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@ export class OverwriteSubstitutionModalComponent implements OnInit {
this.closeSubject.next(false);
this.closeSubject.complete();
}

ngOnDestroy() {
this.closeSubject.complete();
}
}
Loading

0 comments on commit 8f573d0

Please sign in to comment.