Java Reference

KosCore

Introduction

KosCore is a global object with static methods.

Overview

You can use the KosCore global object to:

  • Access the BeanContext

  • Access the PathMgr

  • Retrieve the node ID this code is running on

  • Determine which operating mode the system is running in

  • Determine if running on the Studio simulator or not

  • Determine if running on the primary node or not

  • Determine if a given profile is active or not

  • Etc.

API Components

This section describes the KosCore component.

Related classes are defined in more detail on their respective pages:

KosCore

API: KosCore class
public final class KosCore {

    // Returns true if the specified profile is active:
    public static boolean hasProfile(String profile);

    // Returns the current operational mode:
    public static Mode getMode();

    // Returns true if the current operational mode is TEST (test/development):
    public static boolean isTest();

    // Returns true if the current operational mode is PROD (production):
    public static boolean isProd();

    // Returns true if running inside the Studio simulator:
    public static boolean isSimulator();

    // Returns true if running on the system's primary node:
    public static boolean isPrimary();

    // Returns the authority value of this node:
    public static String getAuthority();

    // Returns the board type of this node:
    public static String getBoardType();

    // Returns the architecture of this node:
    public static String getArch();

    // Returns the object that gives us access to named paths:
    public static PathMgr getPathMgr();

    // Returns the context for kOS:
    public static BeanContext getCtx();

    // Returns the context for the system app:
    public static BeanContext getSystemCtx();

    // Returns the port number that kOS is running on (defaults to 8081):
    public static int getPort();

    // Returns the ID of the node this code is running on:
    public static NodeId getNodeId();
}

Example Code

In the following code, we call a number of the KosCore methods.

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

KosCoreModule

KosCoreModule class
@Slf4j
public class KosCoreModule implements Module {

    @Override
    public void init(BeanContext ctx) {
        log.info("> KosCoreModule.init()");
    }

    @Override
    public void run() {
        log.info("> KosCoreModule.run()");
        log.info("> mode:         {}", KosCore.getMode());
        log.info("> isProd:       {}", KosCore.isProd());
        log.info("> isTest:       {}", KosCore.isTest());
        log.info("> isSimulator:  {}", KosCore.isSimulator());
        log.info("> port:         {}", KosCore.getPort());
        log.info("> arch:         {}", KosCore.getArch());
        log.info("> boardType:    {}", KosCore.getBoardType());
        log.info("> authority:    {}", KosCore.getAuthority());
        log.info("> nodeId:       {}", KosCore.getNodeId());
        log.info("> isPrimary:    {}", KosCore.isPrimary());
        log.info("> pathMgr.root: {}", KosCore.getPathMgr().getPath(PathMgr.ROOT));
    }
}

Which produces the following logs:

KosCoreModule output
> ====== BEGIN =========================================
> MyKosApp.load()
> KosCoreModule.init()
> MyKosApp.start()
> KosCoreModule.run()
> mode:         TEST    (1)
> isProd:       false
> isTest:       true
> isSimulator:  true    (2)
> port:         8081    (3)
> arch:         x64
> boardType:    none
> authority:    kos
> nodeId:       nodeType-nodeName  (4)
> isPrimary:    true    (5)
> pathMgr.root: NamedPath[name=root, file=/]
> ====== END ===========================================
1 Running in TEST mode
2 Running on the Studio simulator
3 Monitoring port #8081, the default
4 The node type and node name as defined in the Studio image configuration window
5 This is the primary (or only) node in the system

Summary

In this article we examined the KosCore object and some of its methods.

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.