Class NanoBase<T extends NanoBase<T>>

java.lang.Object
org.nanonative.nano.core.NanoBase<T>
Type Parameters:
T - The type of the NanoBase implementation, used for method chaining.
Direct Known Subclasses:
NanoThreads

public abstract class NanoBase<T extends NanoBase<T>> extends Object
The abstract base class for Nano framework providing the core functionalities.
  • Field Details

  • Constructor Details

    • NanoBase

      protected NanoBase(Map<Object,Object> configs, String... args)
      Initializes the NanoBase with provided configurations and arguments.
      Parameters:
      configs - Configuration settings in a key-value map.
      args - Command line arguments.
  • Method Details

    • putAll

      public NanoBase<T> putAll(berlin.yuna.typemap.model.TypeMap map)
    • stop

      public abstract T stop(Class<?> clazz)
      Initiates the shutdown process for the Nano instance.
      Parameters:
      clazz - class for which the Context is to be created.
      Returns:
      Self for chaining
    • stop

      public abstract T stop(Context context)
      Initiates the shutdown process for the Nano instance.
      Parameters:
      context - The Context in which Nano instance shuts down.
      Returns:
      The current instance of Nano for method chaining.
    • logger

      public NanoLogger logger()
      Retrieves the logger associated with this instance.
      Returns:
      The NanoLogger for this instance.
    • listeners

      public Map<Integer,Set<Consumer<Event>>> listeners()
      Retrieves the registered event listeners.
      Returns:
      A map of event types to their respective listeners.
    • subscribeEvent

      public T subscribeEvent(int channelId, Consumer<Event> listener)
      Registers an event listener for a specific event type.
      Parameters:
      channelId - The integer identifier of the event type.
      listener - The consumer function that processes the Event.
      Returns:
      Self for chaining
    • unsubscribeEvent

      public T unsubscribeEvent(int channelId, Consumer<Event> listener)
      Removes a registered event listener for a specific event type.
      Parameters:
      channelId - The integer identifier of the event type.
      listener - The consumer function to be removed.
      Returns:
      Self for chaining
    • pid

      public long pid()
      Retrieves the process ID of the current instance.
      Returns:
      The process ID.
    • usedMemoryMB

      public double usedMemoryMB()
      Calculates the memory usage of the application in megabytes.
      Returns:
      Memory usage in megabytes, rounded to two decimal places.
    • heapMemoryUsage

      public double heapMemoryUsage()
      Calculates the memory usage of the application in percentage.
      Returns:
      Memory usage in percentage, rounded to two decimal places.
    • createdAtMs

      public long createdAtMs()
      Retrieves the creation timestamp of the instance.
      Returns:
      The timestamp of creation in milliseconds.
    • isReady

      public boolean isReady()
      Checks whether the instance is ready for operations.
      Returns:
      readiness state.
    • eventCount

      public int eventCount()
    • displayHelpMenu

      protected void displayHelpMenu()
      Displays a help menu with available configuration keys and their descriptions and exits.
    • readConfigs

      protected Context readConfigs(String... args)
      Reads and initializes Context based on provided arguments.
      Parameters:
      args - Command-line arguments.
      Returns:
      The Context initialized with the configurations.
    • setLogLevel

      protected T setLogLevel(LogLevel level)
      Sets the logging level for the NanoBase instance.
      Parameters:
      level - The logging level to be set.
      Returns:
      True if the level was successfully set.
    • standardiseKey

      public static String standardiseKey(Object key)
      Standardizes a config key.
      Parameters:
      key - The config key to be standardized.