health.dart 1.17 KB
Newer Older
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'enum_util.dart';
6 7 8 9 10 11
import 'message.dart';

/// Requests an application health check.
class GetHealth implements Command {
  final String kind = 'get_health';

12
  static GetHealth deserialize(Map<String, String> json) => new GetHealth();
13

14
  Map<String, String> serialize() => const {};
15 16 17 18 19 20 21 22 23 24 25
}

/// Application health status.
enum HealthStatus {
  /// Application is known to be in a good shape and should be able to respond.
  ok,

  /// Application is not known to be in a good shape and may be unresponsive.
  bad,
}

26 27 28
final EnumIndex<HealthStatus> _healthStatusIndex =
    new EnumIndex<HealthStatus>(HealthStatus.values);

29 30 31 32 33 34 35
/// Application health status.
class Health extends Result {
  Health(this.status) {
    assert(status != null);
  }

  static Health fromJson(Map<String, dynamic> json) {
36
    return new Health(_healthStatusIndex.lookupBySimpleName(json['status']));
37 38 39 40 41 42
  }

  /// Health status
  final HealthStatus status;

  Map<String, dynamic> toJson() => {
43
    'status': _healthStatusIndex.toSimpleName(status)
44 45
  };
}