Package org.nanonative.nano.core
Class Nano
-
Field Summary
Fields inherited from class org.nanonative.nano.core.NanoServices
servicesFields inherited from class org.nanonative.nano.core.NanoThreads
schedulers, threadPoolFields inherited from class org.nanonative.nano.core.NanoBase
CONFIG_KEYS, context, createdAtMs, EVENT_ID_COUNTER, EVENT_TYPES, eventCount, isReady, listeners, logger -
Constructor Summary
ConstructorsConstructorDescriptionNano(berlin.yuna.typemap.model.FunctionOrNull<Context, List<Service>> startupServices, Map<Object, Object> config, String... args) Nano(String[] args, berlin.yuna.typemap.model.FunctionOrNull<Context, List<Service>> startupServices) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcontext()Returns the rootContext.Creates aContextwithNanoLoggerfor the specified class.contextEmpty(Class<?> clazz) Creates an emptyContextwithNanoLoggerfor the specified class.protected voidexit(NanoLogger logger, int exitCode) protected voidgracefulShutdown(NanoLogger logger) hostname()protected voidvoidPrints the configurations that have been loaded into theNanoinstance.Prints system information for diagnostic purposes.sendEvent(int channelId, Context context, Object payload, Consumer<Object> responseListener, boolean broadcast) Sends an event with the specified parameters, either broadcasting it to all listeners or sending it to a targeted listener asynchronously if a response listener is provided.sendEventReturn(int channelId, Context context, Object payload, Consumer<Object> responseListener, boolean broadCast) Processes an event with the given parameters and decides on the execution path based on the presence of a response listener and the broadcast flag.sendEventSameThread(Event event, boolean broadcast) Sends an event on the same thread and determines whether to process it to the first listener.protected NanoShuts down theNanoinstance, ensuring all services and threads are gracefully terminated.protected NanoShuts down theNanoinstance, ensuring all services and threads are gracefully terminated.protected voidstartServices(berlin.yuna.typemap.model.FunctionOrNull<Context, List<Service>> startupServices) Initiates the shutdown process for theNanoinstance.Initiates the shutdown process for theNanoinstance.toString()This method blocks the current thread for max 10 seconds until theNanoinstance is no longer ready.Methods inherited from class org.nanonative.nano.core.NanoServices
registerService, service, services, services, shutdownServices, unregisterServiceMethods inherited from class org.nanonative.nano.core.NanoThreads
asyncFromPool, executeScheduler, kill, removeScheduler, run, run, run, schedulers, shutdownExecutors, shutdownThreads, threadPoolMethods inherited from class org.nanonative.nano.core.NanoBase
createdAtMs, displayHelpMenu, eventCount, heapMemoryUsage, isReady, listeners, logger, pid, putAll, readConfigs, setLogLevel, standardiseKey, subscribeEvent, unsubscribeEvent, usedMemoryMB
-
Constructor Details
-
Nano
-
Nano
- Parameters:
args- Command-line arguments passed during the application start.startupServices- Varargs parameter of startupServiceto be initiated.
-
Nano
- Parameters:
config- Map of configuration parameters.startupServices- Varargs parameter of startupServiceto be initiated.
-
Nano
public Nano(Map<Object, Object> config, berlin.yuna.typemap.model.FunctionOrNull<Context, List<Service>> startupServices) - Parameters:
config- Map of configuration parameters.startupServices- Function to provide startupServicebased on the given context.
-
Nano
public Nano(String[] args, berlin.yuna.typemap.model.FunctionOrNull<Context, List<Service>> startupServices) - Parameters:
args- Command-line arguments passed during the application start.startupServices- Function to provide startupServicebased on the given context.
-
Nano
public Nano(berlin.yuna.typemap.model.FunctionOrNull<Context, List<Service>> startupServices, Map<Object, Object> config, String... args) InitializesNanowith a function to provide startupService, configurations, and command-line arguments.- Parameters:
startupServices- Function to provide startupServicebased on the given context.config- Map of configuration parameters.args- Command-line arguments passed during the application start.
-
-
Method Details
-
context
Returns the rootContext. This context should be only used to manipulate values.context()should be used for running Lambdas,Services,Schedulers or sendEvents- Returns:
- the root
Contextassociated.
-
context
Creates aContextwithNanoLoggerfor the specified class. -
contextEmpty
Creates an emptyContextwithNanoLoggerfor the specified class. -
stop
Initiates the shutdown process for theNanoinstance. -
stop
Initiates the shutdown process for theNanoinstance. -
waitForStop
This method blocks the current thread for max 10 seconds until theNanoinstance is no longer ready. This is useful in tests for ensuring that the application has fully stopped before proceeding with further operations.- Returns:
- The current instance of
Nanofor method chaining.
-
printParameters
public void printParameters()Prints the configurations that have been loaded into theNanoinstance. -
sendEvent
public Nano sendEvent(int channelId, Context context, Object payload, Consumer<Object> responseListener, boolean broadcast) Sends an event with the specified parameters, either broadcasting it to all listeners or sending it to a targeted listener asynchronously if a response listener is provided.- Parameters:
channelId- The integer representing the channelId of the event. This typically corresponds to a specific action or state change.context- TheContextin which the event is being sent, providing environmental data and configurations.payload- The data or object associated with this event. This could be any relevant information that needs to be communicated through the event.responseListener- A consumer that handles the response of the event processing. If null, the event is processed in the same thread; otherwise, it's processed asynchronously.broadcast- A boolean flag indicating whether the event should be broadcast to all listeners. If true, the event is broadcast; if false, it is sent to a targeted listener.- Returns:
- The
Nanoinstance, allowing for method chaining.
-
sendEventReturn
public Event sendEventReturn(int channelId, Context context, Object payload, Consumer<Object> responseListener, boolean broadCast) Processes an event with the given parameters and decides on the execution path based on the presence of a response listener and the broadcast flag. If a response listener is provided, the event is processed asynchronously; otherwise, it is processed in the current thread. This method creates anEventinstance and triggers the appropriate event handling logic.- Parameters:
channelId- The integer representing the channelId of the event, identifying the nature or action of the event.context- TheContextassociated with the event, encapsulating environment and configuration details.payload- The payload of the event, containing data relevant to the event's context and purpose.responseListener- A consumer for handling the event's response. If provided, the event is handled asynchronously; if null, the handling is synchronous.broadCast- Determines the event's distribution: if true, the event is made available to all listeners; if false, it targets specific listeners based on the implementation logic.- Returns:
- An instance of
Eventthat represents the event being processed. This object can be used for further operations or tracking.
-
sendEventSameThread
Sends an event on the same thread and determines whether to process it to the first listener. UsedContext.sendEvent(int, Object)fromcontext(Class)instead of the core method.- Parameters:
event- The event to be processed.broadcast- Whether to send the event only to the first matching listener or to all.- Returns:
- self for chaining
-
shutdown
Shuts down theNanoinstance, ensuring all services and threads are gracefully terminated.- Parameters:
clazz- class for which theContextis to be created.- Returns:
- Self for chaining
-
cleanUps
-
printActiveProfiles
protected void printActiveProfiles() -
startServices
-
shutdown
Shuts down theNanoinstance, ensuring all services and threads are gracefully terminated. -
hostname
-
printSystemInfo
Prints system information for diagnostic purposes. Similar totoString()- Returns:
- Self for chaining
-
gracefulShutdown
-
exit
-
toString
-