All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nstream.reflect.model.SystemStats Maven / Gradle / Ivy

There is a newer version: 4.13.21
Show newest version
// Copyright 2015-2024 Nstream, inc.
//
// Licensed under the Redis Source Available License 2.0 (RSALv2) Agreement;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://redis.com/legal/rsalv2-agreement/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package nstream.reflect.model;

import swim.structure.Form;
import swim.structure.Item;
import swim.structure.Kind;
import swim.structure.Record;
import swim.structure.Value;

@SuppressWarnings("checkstyle:VisibilityModifier")
public class SystemStats {
  public int cpuUsage;
  public int cpuTotal;
  public long memUsage;
  public long memTotal;
  public long diskUsage;
  public long diskTotal;
  public long startTime;

  public SystemStats() {
    // nop
  }

  public Value toValue() {
    return form().mold(this).toValue();
  }

  private static Form form;

  @Kind
  public static Form form() {
    if (form == null) {
      form = new SystemStatsForm();
    }
    return form;
  }
}

final class SystemStatsForm extends Form {
  @Override
  public String tag() {
    return "system";
  }

  @Override
  public Class type() {
    return SystemStats.class;
  }

  @Override
  public Item mold(SystemStats system) {
    if (system != null) {
      return Record.create(7).attr(tag())
          .slot("cpuUsage", system.cpuUsage)
          .slot("cpuTotal", system.cpuTotal)
          .slot("memUsage", system.memUsage)
          .slot("memTotal", system.memTotal)
          .slot("diskUsage", system.diskUsage)
          .slot("diskTotal", system.diskTotal)
          .slot("startTime", system.startTime);
    } else {
      return Item.extant();
    }
  }

  @Override
  public SystemStats cast(Item item) {
    final Value value = item.toValue();
    final Value header = value.header(tag());
    if (header.isDefined()) {
      final SystemStats system = new SystemStats();
      system.cpuUsage = value.get("cpuUsage").intValue(0);
      system.cpuTotal = value.get("cpuUsage").intValue(0);
      system.memUsage = value.get("memUsage").longValue(0L);
      system.memTotal = value.get("memTotal").longValue(0L);
      system.diskUsage = value.get("diskUsage").longValue(0L);
      system.diskTotal = value.get("diskTotal").longValue(0L);
      system.startTime = value.get("startTime").longValue(0L);
      return system;
    }
    return null;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy