Package org.nanonative.nano.core
Class NanoBase<T extends NanoBase<T>>
java.lang.Object
org.nanonative.nano.core.NanoBase<T>
- Type Parameters:
T- The type of theNanoBaseimplementation, used for method chaining.
- Direct Known Subclasses:
NanoThreads
The abstract base class for
Nano framework providing the core functionalities.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Contextprotected final longstatic final AtomicIntegerprotected final AtomicIntegerprotected final LockedBooleanprotected final NanoLogger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongRetrieves the creation timestamp of the instance.protected voidDisplays a help menu with available configuration keys and their descriptions and exits.intdoubleCalculates the memory usage of the application in percentage.booleanisReady()Checks whether the instance is ready for operations.Retrieves the registered event listeners.logger()Retrieves the logger associated with this instance.longpid()Retrieves the process ID of the current instance.putAll(berlin.yuna.typemap.model.TypeMap map) protected ContextreadConfigs(String... args) Reads and initializesContextbased on provided arguments.protected TsetLogLevel(LogLevel level) Sets the logging level for the NanoBase instance.static StringstandardiseKey(Object key) Standardizes a config key.abstract TInitiates the shutdown process for theNanoinstance.abstract TInitiates the shutdown process for theNanoinstance.subscribeEvent(int channelId, Consumer<Event> listener) Registers an event listener for a specific event type.unsubscribeEvent(int channelId, Consumer<Event> listener) Removes a registered event listener for a specific event type.doubleCalculates the memory usage of the application in megabytes.
-
Field Details
-
context
-
createdAtMs
protected final long createdAtMs -
logger
-
listeners
-
isReady
-
eventCount
-
EVENT_TYPES
-
CONFIG_KEYS
-
EVENT_ID_COUNTER
-
-
Constructor Details
-
NanoBase
Initializes the NanoBase with provided configurations and arguments.- Parameters:
configs- Configuration settings in a key-value map.args- Command line arguments.
-
-
Method Details
-
putAll
-
stop
Initiates the shutdown process for theNanoinstance.- Parameters:
clazz- class for which theContextis to be created.- Returns:
- Self for chaining
-
stop
Initiates the shutdown process for theNanoinstance. -
logger
Retrieves the logger associated with this instance.- Returns:
- The
NanoLoggerfor this instance.
-
listeners
Retrieves the registered event listeners.- Returns:
- A map of event types to their respective listeners.
-
subscribeEvent
Registers an event listener for a specific event type.- Parameters:
channelId- The integer identifier of the event type.listener- The consumer function that processes theEvent.- Returns:
- Self for chaining
-
unsubscribeEvent
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
Reads and initializesContextbased on provided arguments.- Parameters:
args- Command-line arguments.- Returns:
- The
Contextinitialized with the configurations.
-
setLogLevel
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
Standardizes a config key.- Parameters:
key- The config key to be standardized.
-