84 lines
2.7 KiB
Dart
84 lines
2.7 KiB
Dart
import 'dart:io';
|
|
import 'dart:async';
|
|
import 'package:sweepstore/header.dart';
|
|
|
|
|
|
void main() async {
|
|
int refreshCount = 0;
|
|
int? previousMasterHeartbeat;
|
|
Map<int, int> previousWorkerHeartbeats = {};
|
|
|
|
while (true) {
|
|
// Clear console
|
|
if (Platform.isWindows) {
|
|
print(Process.runSync("cls", [], runInShell: true).stdout);
|
|
} else {
|
|
print(Process.runSync("clear", [], runInShell: true).stdout);
|
|
}
|
|
|
|
refreshCount++;
|
|
|
|
// Read example.bin
|
|
final file = File('example.bin');
|
|
|
|
if (await file.exists()) {
|
|
final raf = await file.open(mode: FileMode.read);
|
|
|
|
|
|
try {
|
|
final header = SweepstoreHeader(raf);
|
|
final concurrency = header.concurrency;
|
|
|
|
int now32 = (DateTime.now().millisecondsSinceEpoch ~/ 1000) & 0xFFFFFFFF;
|
|
|
|
print('Sweepstore Tickets - Refresh #$refreshCount');
|
|
print('Current Time (now32): $now32');
|
|
print('Master ID: ${concurrency.masterIdentifier}');
|
|
|
|
int masterAge = now32 - concurrency.masterHeartbeat;
|
|
String masterStatus = masterAge > 5 ? "(stale)" : "(active)";
|
|
String masterPrevious = previousMasterHeartbeat != null ? "(previously $previousMasterHeartbeat)" : "";
|
|
print('Master Heartbeat: ${concurrency.masterHeartbeat} $masterStatus $masterPrevious');
|
|
|
|
print('Workers: ${concurrency.numberOfWorkers}');
|
|
print('Read Allowed: ${concurrency.isReadAllowed}');
|
|
print('');
|
|
|
|
// display each ticket
|
|
for (int i = 0; i < concurrency.numberOfWorkers; i++) {
|
|
final ticket = concurrency[i];
|
|
|
|
print('--- Ticket #$i ---');
|
|
print(' Identifier: ${ticket.identifier}');
|
|
|
|
int workerAge = now32 - ticket.workerHeartbeat;
|
|
String workerStatus = workerAge > 5 ? "(stale)" : "(active)";
|
|
String workerPrevious = previousWorkerHeartbeats.containsKey(i) ? "(previously ${previousWorkerHeartbeats[i]})" : "";
|
|
print(' Heartbeat: ${ticket.workerHeartbeat} $workerStatus $workerPrevious');
|
|
|
|
print(' State: ${ticket.ticketState.name}');
|
|
print(' Operation: ${ticket.ticketOperation.name}');
|
|
print(' Key Hash: ${ticket.keyHash}');
|
|
print(' Write Ptr: ${ticket.writePointer}');
|
|
print(' Write Size: ${ticket.writeSize} bytes');
|
|
print('');
|
|
|
|
// update previous heartbeat
|
|
previousWorkerHeartbeats[i] = ticket.workerHeartbeat;
|
|
|
|
}
|
|
|
|
// updat previous master heartbeat
|
|
previousMasterHeartbeat = concurrency.masterHeartbeat;
|
|
|
|
print('--- Refreshing in 1 seconds ---');
|
|
} finally {
|
|
await raf.close();
|
|
}
|
|
} else {
|
|
print('Error: example.bin not found - Refresh #$refreshCount');
|
|
}
|
|
|
|
await Future.delayed(Duration(milliseconds: 1));
|
|
}
|
|
} |