This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class LongRunningTaskService { | |
| public <T> CompletableFuture<T> executeCompletableFuture(Supplier<T> task) { | |
| CompletableFuture<T> completableFuture = new CompletableFuture<>(); | |
| new Thread(() -> { | |
| try { | |
| System.out.println("Do something before task execution ..."); | |
| completableFuture.complete(task.get()); | |
| System.out.println("Do something after task execution ..."); | |
| } catch (Exception exception) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Future<void> _requestTrackPositions( | |
| String correlationId, String deviceId, String station, String trackNumber) async { | |
| _messagingService.request( | |
| topicRetrieveTrackPositionsQuery, | |
| jsonEncode(RetrieveTrackPositionsQuery( | |
| mobileDeviceId: deviceId, | |
| correlationId: correlationId, | |
| station: station, | |
| trackNumber: trackNumber))); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final RequestReplyService requestReplyService = RequestReplyService(); | |
| // request track positions and wait for received response | |
| final TrackPositionsRetrievedResponse response = await requestReplyService.execute( | |
| request: () => _requestTrackPositions(correlationId, mobileDeviceId, station, trackNumber), | |
| response: () => _trackPositionRetrieved$(correlationId, mobileDeviceId)); | |
| // do something with response ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:mqtt_client/mqtt_client.dart'; | |
| import 'package:rxdart/rxdart.dart'; | |
| class MessagingService { | |
| /// Subscribes to the given topic and produces a stream of received updates from the message | |
| /// broker matching this topic. You can also pass [MqttQos] which defaults to atLeastOnce. | |
| /// | |
| /// This method returns a stream of [MqttMessage] instances. | |
| Stream<MqttMessage> updatesFor(String topic, [MqttQos qos = MqttQos.atLeastOnce]) { | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:async'; | |
| import 'package:flutter/foundation.dart'; | |
| /// This class allows request-reply communication over messaging. | |
| class RequestReplyService { | |
| StreamSubscription _subscription; | |
| /// release resources | |
| void dispose() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| selector: 'app-identify-device', | |
| template: ` | |
| ... | |
| <form (submit)="identifyDevice()" [formGroup]="formGroup"> | |
| <ion-item> | |
| <ion-label color="dark" [position]="'stacked'">Track Number</ion-label> | |
| <ion-input clearInput type="text" formControlName="trackNumber"></ion-input> | |
| </ion-item> | |
| </form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Injectable({ | |
| providedIn: 'root' | |
| }) | |
| export class LoggedInGuard implements CanActivate { | |
| protected constructor(private _router: Router, _store: CoreStore) { } | |
| public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> { | |
| return this._store.ready$.then(() => this.toResult(), () => this.toResult()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Injectable({ | |
| providedIn: 'root' | |
| }) | |
| export class CoreFacade { | |
| public isLoggedIn$ = this._store.select((state: CoreState) => !!state.authToken); | |
| constructor(private _store: CoreStore, private _loginService: LoginService) { } | |
| public getTrackNumber(): string { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Injectable } from '@angular/core'; | |
| import { Storage } from '@ionic/storage'; | |
| @Injectable({ | |
| providedIn: 'root' | |
| }) | |
| export class StoreService { | |
| private readonly _prefix: string; | |
| private readonly AUTH_TOKEN = 'authToken'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { BehaviorSubject, Observable } from 'rxjs'; | |
| import { distinctUntilChanged, map } from 'rxjs/operators'; | |
| export abstract class Store<T> { | |
| private _state$: BehaviorSubject<T>; | |
| protected constructor(initialState: T) { | |
| this._state$ = new BehaviorSubject(initialState); | |
| } |