Class Nano


public class Nano extends NanoServices<Nano>
  • Constructor Details

    • Nano

      public Nano(Service... startupServices)
      Initializes Nano with a set of startup Service.
      Parameters:
      startupServices - Varargs parameter of startup Service to be initiated during the Nano creation.
    • Nano

      public Nano(String[] args, Service... startupServices)
      Initializes Nano with a function to provide startup Service based on the context.
      Parameters:
      args - Command-line arguments passed during the application start.
      startupServices - Varargs parameter of startup Service to be initiated.
    • Nano

      public Nano(Map<Object,Object> config, Service... startupServices)
      Initializes Nano with configurations and startup Service.
      Parameters:
      config - Map of configuration parameters.
      startupServices - Varargs parameter of startup Service to be initiated.
    • Nano

      public Nano(Map<Object,Object> config, berlin.yuna.typemap.model.FunctionOrNull<Context,List<Service>> startupServices)
      Initializes Nano with configurations and startup Service.
      Parameters:
      config - Map of configuration parameters.
      startupServices - Function to provide startup Service based on the given context.
    • Nano

      public Nano(String[] args, berlin.yuna.typemap.model.FunctionOrNull<Context,List<Service>> startupServices)
      Initializes Nano with a function to provide startup Service based on the context.
      Parameters:
      args - Command-line arguments passed during the application start.
      startupServices - Function to provide startup Service based on the given context.
    • Nano

      public Nano(berlin.yuna.typemap.model.FunctionOrNull<Context,List<Service>> startupServices, Map<Object,Object> config, String... args)
      Initializes Nano with a function to provide startup Service, configurations, and command-line arguments.
      Parameters:
      startupServices - Function to provide startup Service based on the given context.
      config - Map of configuration parameters.
      args - Command-line arguments passed during the application start.
  • Method Details

    • context

      public Context context()
      Returns the root Context. This context should be only used to manipulate values. context() should be used for running Lambdas, Services, Schedulers or send Events
      Returns:
      the root Context associated.
    • context

      public Context context(Class<?> clazz)
      Creates a Context with NanoLogger for the specified class.
      Parameters:
      clazz - The class for which the Context is to be created.
      Returns:
      A new Context instance associated with the given class.
    • contextEmpty

      public Context contextEmpty(Class<?> clazz)
      Creates an empty Context with NanoLogger for the specified class.
      Parameters:
      clazz - The class for which the Context is to be created.
      Returns:
      A new Context instance associated with the given class.
    • stop

      public Nano stop(Class<?> clazz)
      Initiates the shutdown process for the Nano instance.
      Specified by:
      stop in class NanoBase<Nano>
      Parameters:
      clazz - class for which the Context is to be created.
      Returns:
      The current instance of Nano for method chaining.
    • stop

      public Nano stop(Context context)
      Initiates the shutdown process for the Nano instance.
      Specified by:
      stop in class NanoBase<Nano>
      Parameters:
      context - The Context in which Nano instance shuts down.
      Returns:
      The current instance of Nano for method chaining.
    • waitForStop

      public Nano waitForStop()
      This method blocks the current thread for max 10 seconds until the Nano instance 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 Nano for method chaining.
    • printParameters

      public void printParameters()
      Prints the configurations that have been loaded into the Nano instance.
    • 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 - The Context in 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 Nano instance, 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 an Event instance 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 - The Context associated 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 Event that represents the event being processed. This object can be used for further operations or tracking.
    • sendEventSameThread

      public Nano sendEventSameThread(Event event, boolean broadcast)
      Sends an event on the same thread and determines whether to process it to the first listener. Used Context.sendEvent(int, Object) from context(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

      protected Nano shutdown(Class<?> clazz)
      Shuts down the Nano instance, ensuring all services and threads are gracefully terminated.
      Parameters:
      clazz - class for which the Context is to be created.
      Returns:
      Self for chaining
    • cleanUps

      protected void cleanUps(Event event)
    • printActiveProfiles

      protected void printActiveProfiles()
    • startServices

      protected void startServices(berlin.yuna.typemap.model.FunctionOrNull<Context,List<Service>> startupServices)
    • shutdown

      protected Nano shutdown(Context context)
      Shuts down the Nano instance, ensuring all services and threads are gracefully terminated.
      Parameters:
      context - The Context in which Nano instance shuts down.
      Returns:
      Self for chaining
    • hostname

      public String hostname()
    • printSystemInfo

      public Nano printSystemInfo()
      Prints system information for diagnostic purposes. Similar to toString()
      Returns:
      Self for chaining
    • gracefulShutdown

      protected void gracefulShutdown(NanoLogger logger)
    • exit

      protected void exit(NanoLogger logger, int exitCode)
    • toString

      public String toString()
      Overrides:
      toString in class Object