Package org.nanonative.nano.core.model
Class Context
java.lang.Object
java.util.AbstractMap<Object,Object>
java.util.concurrent.ConcurrentHashMap<Object,Object>
berlin.yuna.typemap.model.ConcurrentTypeMap
org.nanonative.nano.core.model.Context
- All Implemented Interfaces:
berlin.yuna.typemap.model.TypeInfo<berlin.yuna.typemap.model.ConcurrentTypeMap>,berlin.yuna.typemap.model.TypeMapI<berlin.yuna.typemap.model.ConcurrentTypeMap>,Serializable,ConcurrentMap<Object,,Object> Map<Object,Object>
public class Context
extends berlin.yuna.typemap.model.ConcurrentTypeMap
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.ConcurrentHashMap
ConcurrentHashMap.KeySetView<K,V> Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intprotected Nano -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbroadcastEvent(int channelId, Supplier<Object> payload) Broadcasts an event of the specified type with the provided payload to all listeners within this context without expecting a response.broadcastEvent(int channelId, Supplier<Object> payload, Consumer<Object> responseListener) Broadcasts an event of the specified type with the provided payload to all listeners within this context, expecting a response that is handled by the provided responseListener.broadcastEventR(int channelId, Supplier<Object> payload) Broadcasts an event of the specified type with the provided payload to all listeners within this context without expecting a response.broadcastEventR(int channelId, Supplier<Object> payload, Consumer<Object> responseListener) Broadcasts an event of the specified type with the provided payload to all listeners within this context, expecting a response that is handled by the provided responseListener.static ContextcreateRootContext(Class<?> clazz) Creates a new root context with a unique trace ID.Logs a message with the specified log level.Logs a message with the specified log level.Logs a message with the specified log level.Logs a message with the specified log level.Logs a message with the specified log level.Logs a message with the specified log level.Logs a message with the specified log level.Logs a message with the specified log level.Logs a message with the specified log level.Logs a message with the specified log level.nano()Retrieves theNanoinstance associated with this context.newContext(Class<?> clazz) Creates new Context with a new logger and trace ID.newEmptyContext(Class<?> clazz) Creates new empty Context with a new logger and trace ID.newEvent(int channelId) Creates a newEventinstance with the specified event type.parent()Retrieves theContextparent associated with this context.Puts a key-value pair into the context.Associates the specified value with the specified key in this map.intregisterChannelId(String channelName) Registers a new event type with a given name if it does not already exist.Executes one or multipleServiceasynchronously.final Contextrun(ExRunnable... runnable) Executes one or multiple runnable asynchronously.run(ExRunnable task, long delay, long period, TimeUnit unit) Executes a task periodically, starting after an initial delay.run(ExRunnable task, long delay, long period, TimeUnit unit, BooleanSupplier until) Executes a task periodically, starting after an initial delay.run(ExRunnable task, long delay, TimeUnit timeUnit) Executes a task asynchronously after a specified delay.run(ExRunnable task, LocalTime atTime) Executes a task periodically, starting after an initial delay.run(ExRunnable task, LocalTime atTime, DayOfWeek dow, BooleanSupplier until) Executes a task periodically, starting after an initial delay.run(ExRunnable task, LocalTime atTime, BooleanSupplier until) Executes a task periodically, starting after an initial delay.Executes asynchronously and waits for allServiceto be readyfinal ContextrunAwait(ExRunnable... runnable) Executes asynchronously and waits for all runnable to be readyfinal ContextrunAwaitHandled(Consumer<Unhandled> onFailure, ExRunnable... runnable) Executes asynchronously and waits for all runnable to be readyExecutes and waits for allServiceto be readyfinal NanoThread[]runAwaitR(ExRunnable... runnable) Executes asynchronously and waits for allServiceto be readyfinal NanoThread[]runAwaitRHandled(Consumer<Unhandled> onFailure, ExRunnable... runnable) Executes and waits for allServiceto be readyfinal ContextrunHandled(Consumer<Unhandled> onFailure, ExRunnable... runnable) Executes one or multiple runnable asynchronously.Executes one or multipleServiceasynchronously.final NanoThread[]runR(ExRunnable... runnable) Executes one or multiple runnable asynchronously.final NanoThread[]runReturnHandled(Consumer<Unhandled> onFailure, ExRunnable... runnable) Executes one or multiple runnable asynchronously.Sends an event of the specified type with the provided payload within this context without expecting a response.Sends an event of the specified type with the provided payload within this context, expecting a response that is handled by the provided responseListener.sendEventError(Object payload, Throwable throwable) Sends an unhandled event with the provided, nullable payload and exception.sendEventError(Event event, Service service, Throwable throwable) Sends an unhandled event with the provided, nullable payload and exception.sendEventR(int channelId, Supplier<Object> payload) Sends an event of the specified type with the provided payload within this context without expecting a response.sendEventR(int channelId, Supplier<Object> payload, Consumer<Object> responseListener) Sends an event of the specified type with the provided payload within this context, expecting a response that is handled by the provided responseListener.<S extends Service>
SRetrieves aServiceof a specified type.services()Provides an unmodifiable list of all registeredService.Retrieves a list of services of a specified type.subscribeEvent(int channelId, Consumer<Event> listener) Registers an event listener for a specific event type.toString()Logs a message with the specified log level.Logs a message with the specified log level.traceId()Retrieves the last created trace ID of the context.traceId(int index) Retrieves the trace ID at the specified index.traceIds()Retrieves all trace IDs associated with this context.voidtryExecute(ExRunnable operation) voidtryExecute(ExRunnable operation, Consumer<Throwable> consumer) unsubscribeEvent(int channelId, Consumer<Event> listener) Removes a registered event listener for a specific event type.Logs a message with the specified log level.Logs a message with the specified log level.Methods inherited from class berlin.yuna.typemap.model.ConcurrentTypeMap
addR, concurrentMapOfMethods inherited from class java.util.concurrent.ConcurrentHashMap
clear, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, forEach, forEach, forEachEntry, forEachEntry, forEachKey, forEachKey, forEachValue, forEachValue, get, getOrDefault, hashCode, isEmpty, keys, keySet, keySet, mappingCount, merge, newKeySet, newKeySet, putAll, putIfAbsent, reduce, reduceEntries, reduceEntries, reduceEntriesToDouble, reduceEntriesToInt, reduceEntriesToLong, reduceKeys, reduceKeys, reduceKeysToDouble, reduceKeysToInt, reduceKeysToLong, reduceToDouble, reduceToInt, reduceToLong, reduceValues, reduceValues, reduceValuesToDouble, reduceValuesToInt, reduceValuesToLong, remove, remove, replace, replace, replaceAll, search, searchEntries, searchKeys, searchValues, size, valuesMethods inherited from class java.util.AbstractMap
cloneMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, valuesMethods inherited from interface berlin.yuna.typemap.model.TypeInfo
addPath, addPathR, as, asArray, asArray, asAtomicBoolean, asAtomicBooleanOpt, asAtomicInteger, asAtomicIntegerOpt, asAtomicLong, asAtomicLongOpt, asBigDecimal, asBigDecimalOpt, asBigInteger, asBigIntegerOpt, asBoolean, asBooleanOpt, asBooleans, asByte, asByteOpt, asBytes, asCalendar, asCalendarOpt, asCalendars, asCharacter, asCharacterOpt, asCharacters, asCharset, asCharsetOpt, asCharsets, asDate, asDateOpt, asDates, asDouble, asDoubleOpt, asDoubles, asFile, asFileOpt, asFiles, asFloat, asFloatOpt, asFloats, asInet4Address, asInet4Addresses, asInet4AddressOpt, asInet6Address, asInet6Addresses, asInet6AddressOpt, asInetAddress, asInetAddresses, asInetAddressOpt, asInstant, asInstantOpt, asInstants, asInt, asIntOpt, asInts, asList, asList, asList, asLocalDate, asLocalDateOpt, asLocalDates, asLocalDateTime, asLocalDateTimeOpt, asLocalDateTimes, asLocalTime, asLocalTimeOpt, asLocalTimes, asLong, asLongOpt, asLongs, asMap, asMap, asMap, asMap, asMap, asMap, asNumber, asNumberOpt, asNumbers, asOffsetDateTime, asOffsetDateTimeOpt, asOffsetDateTimes, asOpt, asOpt, asPath, asPathOpt, asPaths, asShort, asShortOpt, asShorts, asSqlDate, asSqlDateOpt, asSqlDates, asString, asStringOpt, asStrings, asThrowable, asThrowableOpt, asThrowables, asTime, asTimeOpt, asTimes, asTimestamp, asTimestampOpt, asTimestamps, asURI, asURIOpt, asURIs, asURL, asURLOpt, asURLs, asUUID, asUUIDOpt, asUUIDs, asZonedDateTime, asZonedDateTimeOpt, asZonedDateTimes, containsPath, filter, flatMap, flatOpt, get, ifPresent, ifPresentOrElse, isEmpty, isPresent, map, or, orElse, orElseGet, orElseThrow, orElseThrow, putPath, putPathR, setPath, setPathR, stream, toJson, toJsonMethods inherited from interface berlin.yuna.typemap.model.TypeMapI
typeListOpt, typeMapOpt
-
Field Details
-
CONTEXT_TRACE_ID_KEY
- See Also:
-
CONTEXT_PARENT_KEY
- See Also:
-
CONTEXT_CLASS_KEY
- See Also:
-
CONTEXT_NANO_KEY
- See Also:
-
CONTEXT_LOG_QUEUE_KEY
- See Also:
-
APP_HELP
-
APP_PARAMS
-
CONFIG_PROFILES
-
CONFIG_THREAD_POOL_TIMEOUT_MS
-
CONFIG_PARALLEL_SHUTDOWN
-
CONFIG_OOM_SHUTDOWN_THRESHOLD
-
CONFIG_ENV_PROD
-
EVENT_APP_START
public static final int EVENT_APP_START -
EVENT_APP_SHUTDOWN
public static final int EVENT_APP_SHUTDOWN -
EVENT_APP_SERVICE_REGISTER
public static final int EVENT_APP_SERVICE_REGISTER -
EVENT_APP_SERVICE_UNREGISTER
public static final int EVENT_APP_SERVICE_UNREGISTER -
EVENT_APP_SCHEDULER_REGISTER
public static final int EVENT_APP_SCHEDULER_REGISTER -
EVENT_APP_SCHEDULER_UNREGISTER
public static final int EVENT_APP_SCHEDULER_UNREGISTER -
EVENT_APP_UNHANDLED
public static final int EVENT_APP_UNHANDLED -
EVENT_APP_ERROR
public static final int EVENT_APP_ERROR -
EVENT_APP_OOM
public static final int EVENT_APP_OOM -
EVENT_APP_HEARTBEAT
public static final int EVENT_APP_HEARTBEAT -
EVENT_CONFIG_CHANGE
public static final int EVENT_CONFIG_CHANGE -
nano
-
-
Constructor Details
-
Context
-
Context
-
Context
-
-
Method Details
-
createRootContext
Creates a new root context with a unique trace ID.- Returns:
- The newly created root context.
-
nano
Retrieves theNanoinstance associated with this context.- Returns:
- The
Nanoinstance associated with this context.
-
parent
Retrieves theContextparent associated with this context.- Returns:
- Parent
Contextor null
-
traceId
Retrieves the last created trace ID of the context.- Returns:
- The last created trace ID of the context.
-
traceId
Retrieves the trace ID at the specified index.- Parameters:
index- The index of the trace ID to retrieve.- Returns:
- The trace ID at the specified index, or the last trace ID if the index is out of bounds.
-
traceIds
Retrieves all trace IDs associated with this context.- Returns:
- A list of all trace IDs associated with this context.
-
fatal
Logs a message with the specified log level.- Parameters:
message- The message to log.params- The parameters to replace in the message.- Returns:
- self for chaining
-
fatal
Logs a message with the specified log level.- Parameters:
thrown- The exception to log.message- The message to log.params- The parameters to replace in the message.- Returns:
- self for chaining
-
error
Logs a message with the specified log level.- Parameters:
message- The message to log.params- The parameters to replace in the message.- Returns:
- self for chaining
-
error
Logs a message with the specified log level.- Parameters:
thrown- The exception to log.message- The message to log.params- The parameters to replace in the message.- Returns:
- self for chaining
-
warn
Logs a message with the specified log level.- Parameters:
message- The message to log.params- The parameters to replace in the message.- Returns:
- self for chaining
-
warn
Logs a message with the specified log level.- Parameters:
thrown- The exception to log.message- The message to log.params- The parameters to replace in the message.- Returns:
- self for chaining
-
info
Logs a message with the specified log level.- Parameters:
message- The message to log.params- The parameters to replace in the message.- Returns:
- self for chaining
-
info
Logs a message with the specified log level.- Parameters:
thrown- The exception to log.message- The message to log.params- The parameters to replace in the message.- Returns:
- self for chaining
-
debug
Logs a message with the specified log level.- Parameters:
message- The message to log.params- The parameters to replace in the message.- Returns:
- self for chaining
-
debug
Logs a message with the specified log level.- Parameters:
thrown- The exception to log.message- The message to log.params- The parameters to replace in the message.- Returns:
- self for chaining
-
trace
Logs a message with the specified log level.- Parameters:
message- The message to log.params- The parameters to replace in the message.- Returns:
- self for chaining
-
trace
Logs a message with the specified log level.- Parameters:
thrown- The exception to log.message- The message to log.params- The parameters to replace in the message.- Returns:
- self for chaining
-
log
Logs a message with the specified log level.- Parameters:
level- The log level to use.message- The message to log.params- The parameters to replace in the message.- Returns:
- self for chaining
-
log
Logs a message with the specified log level.- Parameters:
level- The log level to use.thrown- The exception to log.message- The message to log.params- The parameters to replace in the message.- Returns:
- self for chaining
-
newContext
Creates new Context with a new logger and trace ID.- Parameters:
clazz- The class to use for the logger name. If null, the logger name will be the class of the context.- Returns:
- The newly created context.
-
newEmptyContext
Creates new empty Context with a new logger and trace ID.- Parameters:
clazz- The class to use for the logger name. If null, the logger name will be the class of the context.- Returns:
- The newly created context.
-
put
Puts a key-value pair into the context.- Specified by:
putin interfaceMap<Object,Object> - Overrides:
putin classConcurrentHashMap<Object,Object> - Parameters:
key- The key to put into the context. Null keys are interpreted as empty strings.value- The value to associate with the key.- Returns:
- The current
Contextinstance, allowing for method chaining and further configuration.
-
putR
Associates the specified value with the specified key in this map.- Parameters:
key- the key with which the specified value is to be associated.value- the value to be associated with the specified key.- Returns:
- the updated
ConcurrentTypeMapinstance for chaining.
-
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
-
run
Executes a task asynchronously after a specified delay.- Parameters:
task- The task to execute.delay- The delay before executing the task.timeUnit- The time unit of the delay parameter.- Returns:
- Self for chaining
-
run
Executes a task periodically, starting after an initial delay.- Parameters:
task- The task to execute.delay- The initial delay before executing the task.period- The period between successive task executions.unit- The time unit of the initialDelay and period parameters.- Returns:
- Self for chaining
-
run
Executes a task periodically, starting after an initial delay.- Parameters:
task- The task to execute.delay- The initial delay before executing the task.period- The period between successive task executions.unit- The time unit of the initialDelay and period parameters.until- A BooleanSupplier indicating the termination condition.truestops the next execution.- Returns:
- Self for chaining
-
run
Executes a task periodically, starting after an initial delay.nano.run(() -> myMethod(), LocalTime.of(7, 0, 0))- Parameters:
task- The task to execute.atTime- The time of hour/minute/second to start the task.- Returns:
- Self for chaining
-
run
Executes a task periodically, starting after an initial delay.nano.run(() -> myMethod(), LocalTime.of(7, 0, 0))- Parameters:
task- The task to execute.atTime- The time of hour/minute/second to start the task.until- A BooleanSupplier indicating the termination condition.truestops the next execution.- Returns:
- Self for chaining
-
run
Executes a task periodically, starting after an initial delay.nano.run(() -> myMethod(), LocalTime.of(7, 0, 0))- Parameters:
task- The task to execute.atTime- The time of hour/minute/second to start the task.until- A BooleanSupplier indicating the termination condition.truestops the next execution.- Returns:
- Self for chaining
-
run
Executes one or multiple runnable asynchronously.- Parameters:
runnable- function to execute.- Returns:
- The
Contextobject for chaining further operations.
-
runHandled
Executes one or multiple runnable asynchronously.- Parameters:
onFailure- function to execute on failurerunnable- function to execute.- Returns:
- The
Contextobject for chaining further operations.
-
run
Executes one or multipleServiceasynchronously. -
runR
Executes one or multiple runnable asynchronously.- Parameters:
runnable- function to execute.- Returns:
NanoThreads
-
runReturnHandled
Executes one or multiple runnable asynchronously.- Parameters:
onFailure- function to execute on failurerunnable- function to execute.- Returns:
NanoThreads
-
runR
Executes one or multipleServiceasynchronously.- Parameters:
services- TheServiceto be appended.- Returns:
NanoThreads
-
runAwait
Executes asynchronously and waits for all runnable to be ready- Parameters:
runnable- function to execute.- Returns:
- The
Contextobject for chaining further operations.
-
runAwaitHandled
Executes asynchronously and waits for all runnable to be ready- Parameters:
onFailure- function to execute on failurerunnable- function to execute.- Returns:
- The
Contextobject for chaining further operations.
-
runAwait
Executes asynchronously and waits for allServiceto be ready- Returns:
- The
Contextobject for chaining further operations.
-
runAwaitR
Executes asynchronously and waits for allServiceto be ready- Parameters:
runnable- function to execute.- Returns:
NanoThreads
-
runAwaitRHandled
Executes and waits for allServiceto be ready- Parameters:
onFailure- function to execute on failurerunnable- function to execute.- Returns:
NanoThreads
-
runAwaitR
Executes and waits for allServiceto be ready- Returns:
NanoThreads
-
sendEventError
Sends an unhandled event with the provided, nullable payload and exception. If the event is not acknowledged, the error message is logged.- Parameters:
payload- The payload of the unhandled event, containing data relevant to the event's context and purpose.throwable- The exception that occurred during the event processing.- Returns:
- self for chaining
-
sendEventError
Sends an unhandled event with the provided, nullable payload and exception. If the event is not acknowledged, the error message is logged.- Parameters:
event- The unhandled event, containing data relevant to the event's context and purpose.service- The service which failed to handle the event.throwable- The exception that occurred during the event processing.- Returns:
- self for chaining
-
sendEvent
Sends an event of the specified type with the provided payload within this context without expecting a response. This method is used for sending targeted events that do not require asynchronous processing or response handling.- Parameters:
channelId- The integer representing the type of the event, identifying the nature or action of the event.payload- The payload of the event, containing data relevant to the event's context and purpose.- Returns:
- The current
Contextinstance, allowing for method chaining and further configuration.
-
sendEvent
public Context sendEvent(int channelId, Supplier<Object> payload, Consumer<Object> responseListener) Sends an event of the specified type with the provided payload within this context, expecting a response that is handled by the provided responseListener. This method allows for asynchronous event processing and response handling through the specified consumer.- Parameters:
channelId- The integer representing the type of the event.payload- The payload of the event, containing the data to be communicated.responseListener- A consumer that processes the response of the event. This allows for asynchronous event handling and response processing.- Returns:
- The current
Contextinstance, facilitating method chaining and further actions.
-
broadcastEvent
Broadcasts an event of the specified type with the provided payload to all listeners within this context without expecting a response. This method is ideal for notifying all interested parties of a particular event where no direct response is required.- Parameters:
channelId- The integer representing the type of the event, used to notify all listeners interested in this type of event.payload- The payload of the event, containing information relevant to the broadcast.- Returns:
- The current
Contextinstance, enabling method chaining and additional configurations.
-
broadcastEvent
public Context broadcastEvent(int channelId, Supplier<Object> payload, Consumer<Object> responseListener) Broadcasts an event of the specified type with the provided payload to all listeners within this context, expecting a response that is handled by the provided responseListener. This method allows for the broad dissemination of an event while also facilitating asynchronous response processing.- Parameters:
channelId- The integer representing the type of the event.payload- The payload associated with the event, intended for widespread distribution.responseListener- A consumer that handles the response of the event, enabling asynchronous processing and response handling across multiple listeners.- Returns:
- The current
Contextinstance, allowing for method chaining and further actions.
-
sendEventR
Sends an event of the specified type with the provided payload within this context without expecting a response. This method is used for sending targeted events that do not require asynchronous processing or response handling.- Parameters:
channelId- The integer representing the type of the event, identifying the nature or action of the event.payload- The payload of the event, containing data relevant to the event's context and purpose.- Returns:
- An instance of
Eventthat represents the event being processed. This object can be used for further operations or tracking.
-
sendEventR
Sends an event of the specified type with the provided payload within this context, expecting a response that is handled by the provided responseListener. This method allows for asynchronous event processing and response handling through the specified consumer.- Parameters:
channelId- The integer representing the type of the event.payload- The payload of the event, containing the data to be communicated.responseListener- A consumer that processes the response of the event. This allows for asynchronous event handling and response processing.- Returns:
- An instance of
Eventthat represents the event being processed. This object can be used for further operations or tracking.
-
broadcastEventR
Broadcasts an event of the specified type with the provided payload to all listeners within this context without expecting a response. This method is ideal for notifying all interested parties of a particular event where no direct response is required.- Parameters:
channelId- The integer representing the type of the event, used to notify all listeners interested in this type of event.payload- The payload of the event, containing information relevant to the broadcast.- Returns:
- An instance of
Eventthat represents the event being processed. This object can be used for further operations or tracking.
-
broadcastEventR
public Event broadcastEventR(int channelId, Supplier<Object> payload, Consumer<Object> responseListener) Broadcasts an event of the specified type with the provided payload to all listeners within this context, expecting a response that is handled by the provided responseListener. This method allows for the broad dissemination of an event while also facilitating asynchronous response processing.- Parameters:
channelId- The integer representing the type of the event.payload- The payload associated with the event, intended for widespread distribution.responseListener- A consumer that handles the response of the event, enabling asynchronous processing and response handling across multiple listeners.- Returns:
- An instance of
Eventthat represents the event being processed. This object can be used for further operations or tracking.
-
newEvent
Creates a newEventinstance with the specified event type.- Parameters:
channelId- The integer representing the type of the event.- Returns:
- An instance of
Eventthat represents the event being processed. This object can be used for further operations or tracking.
-
registerChannelId
Registers a new event type with a given name if it does not already exist. If the event type already exists, it returns the existing event type's ID.- Parameters:
channelName- The name of the event type to register.- Returns:
- The ID of the newly registered event type, or the ID of the existing event type if it already exists. Returns -1 if the input is null or empty.
-
service
Retrieves aServiceof a specified type. -
services
Retrieves a list of services of a specified type.- Type Parameters:
S- The type of the service to retrieve, which extendsService.- Parameters:
serviceClass- The class of the service to retrieve.- Returns:
- A list of services of the specified type. If no services of this type are found, an empty list is returned.
-
services
Provides an unmodifiable list of all registeredService.- Returns:
- An unmodifiable list of
Serviceinstances.
-
tryExecute
-
tryExecute
-
toString
- Overrides:
toStringin classConcurrentHashMap<Object,Object>
-