Java Reference

Modes

Introduction

KOS operates in one of two distinct modes: production (PROD) or development/testing (TEST).

Production mode is used for deploying and running the system in a live environment, where reliability and performance are critical.

Test mode is used for developing and debugging the system in a simulated environment, where errors and failures can be detected and fixed without affecting the real users.

Depending on the mode, KOS may have different configurations, behaviors and outputs.

Overview

KOS always runs in one of the following modes:

  • PROD (production)

  • TEST (development and testing)

The mode is encoded in certificates and KAB files, and therefore allows KOS to determine when to trust artifacts and when not to.

  • The TEST mode trusts both TEST and PROD components

  • The PROD mode only trusts PROD components

API Components

This section gives the API for modes of operation, which is simply a Mode enum.

Mode

Here’s the definition of the Mode enum:

API: Mode enum
public enum Mode {
    TEST,
    PROD;

    // Returns true if this mode trusts the specified node:
    public boolean trust(Mode mode);
}

Here’s the unit tests that should make it clear:

Mode unit tests
class UT_Mode {

    @Test
    void verify_all() {
        // There are exactly two possible modes:
        assertThat(Mode.values().length, equalTo(2));

        // TEST mode trusts TEST and PROD:
        assertThat(Mode.TEST.trust(Mode.TEST), equalTo(true));
        assertThat(Mode.TEST.trust(Mode.PROD), equalTo(true));

        // PROD mode only trusts PROD:
        assertThat(Mode.PROD.trust(Mode.TEST), equalTo(false));
        assertThat(Mode.PROD.trust(Mode.PROD), equalTo(true));

        // Null is never trusted:
        assertThat(Mode.PROD.trust(null), equalTo(false));
        assertThat(Mode.TEST.trust(null), equalTo(false));
    }
}

Example Code

Here’s a little example code to demonstrate the mode of operation.

Source code for this and most other Java reference pages is available on GitHub.

ModesModule

The system mode is easily obtained using the built-in global KosCore object:

ModesModule class
package com.example.modes;

import com.example.Module;
import com.tccc.kos.commons.core.context.BeanContext;
import com.tccc.kos.core.app.KosCore;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ModesModule implements Module {

    @Override
    public void init(BeanContext ctx) {
        log.info("> ModesModule.init()");
        log.info("> Mode = {}", KosCore.getMode());
        log.info("> Mode.isProd() = {}", KosCore.isProd());
        log.info("> Mode.isTest() = {}", KosCore.isTest());
    }

    @Override
    public void run() {
        log.info("> ModesModule.run()");
    }
}

MyKosApp

Be sure to make the following change to the MyKosApp class:

MyKosApp class modification
public class MyKosApp extends SystemApplication<BaseAppConfig> {

    public void initModule() {
        module = new ModesModule();
    }

    // . . .
}

Debug code

Running the above code produces the following output logs:

ModesModule output
> ====== BEGIN =========================================
> MyKosApp.load()
> ModesModule.init()
> KosCore.getMode() = TEST
> KosCore.isProd()  = false
> KosCore.isTest()  = true
> MyKosApp.start()
> ModesModule.run()
> ====== END ===========================================
Note

When running your KOS application in the Studio simulator, it always runs in TEST mode.

Summary

In this article, we learned that KOS has two modes of operation: PROD and TEST, and that those are used to determine which related KAB components can be trusted.

Previous
Next
On this page
Java Development
Seamlessly transition from Legacy+ systems to Freestyle microdosing and advanced distributed dispense systems.
UI Development
Using KOS SDKs, integrating Consumer and Non-consumer facing UIs becomes seamless, giving you less hassle and more time to create.
Video Library
Meet some of our development team, as they lead you through the tools, features, and tips and tricks of various KOS tools.
Resources
Familiarize yourself with KOS terminology, our reference materials, and explore additional resources that complement your KOS journey.
Copyright © 2024 TCCC. All rights reserved.