Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate status to Universal API #3715 #3789

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {EventJson} from './EventJson';
import {Event} from './Event';
import {UriHelper} from '../util/UriHelper';
import {NodeEventJson} from './NodeServerEvent';
import {Store} from '../store/Store';
import {ServerEventsTranslator} from './ServerEventsTranslator';
Expand All @@ -22,12 +21,12 @@ export class ServerEventsConnection extends WebSocketConnection {
this.serverEventsTranslator = new ServerEventsTranslator();
}

static get(): ServerEventsConnection {
static get(eventApiUrl: string): ServerEventsConnection {
let instance: ServerEventsConnection = Store.parentInstance().get(SERVER_EVENTS_CONNECTION_KEY);

if (instance == null) {
const builder: WebSocketConnectionBuilder = WebSocketConnection.create()
.setUrl(UriHelper.joinPath(this.getWebSocketUriPrefix(), UriHelper.getAdminUriPrefix(), 'event'))
.setUrl(eventApiUrl)
.addProtocol('text')
.setReconnectIntervalSeconds(5)
.setKeepAliveTimeSeconds(30);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export class ServerEventsListener {

private applications: Application[];

constructor(applications: Application[]) {
constructor(applications: Application[], eventApiUrl: string) {
this.applications = applications;
this.serverEventsConnection = ServerEventsConnection.get();
this.serverEventsConnection = ServerEventsConnection.get(eventApiUrl);
this.serverEventsConnection.onServerEvent((event: Event) => this.onServerEvent(event));
this.serverEventsConnection.onUnknownServerEvent((eventJson: EventJson) => this.onUnknownServerEvent(eventJson));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ export class ConnectionDetector {

private readonlyStatusChangedListeners: ((readonly: boolean) => void)[] = [];

constructor(pollIntervalMs: number = 15000) {
private statusApiUrl: string;

constructor(statusApiUrl: string, pollIntervalMs: number = 15000) {
this.statusApiUrl = statusApiUrl;
this.pollIntervalMs = pollIntervalMs;
}

static get(): ConnectionDetector {
static get(statusApiUrl: string): ConnectionDetector {
let instance: ConnectionDetector = Store.instance().get(CONNECTION_DETECTOR_KEY);

if (instance == null) {
instance = new ConnectionDetector();
instance = new ConnectionDetector(statusApiUrl);
Store.instance().set(CONNECTION_DETECTOR_KEY, instance);
}

Expand Down Expand Up @@ -151,7 +154,7 @@ export class ConnectionDetector {
}

private doPoll() {
const request: StatusRequest = new StatusRequest();
const request: StatusRequest = new StatusRequest(this.statusApiUrl);
request.setTimeout(this.pollIntervalMs);

request.sendAndParse().then((status: StatusResult) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import {StatusResult} from './StatusResult';
export class StatusRequest
extends ResourceRequest<StatusResult> {

constructor() {
private url: string;

constructor(url: string) {
super();
this.addRequestPathElements('status');
this.url = url;
}

protected getPostfixUri(): string {
return this.url;
}

protected parseResponse(response: JsonResponse<StatusJson>): StatusResult {
Expand Down
Loading