Class Components
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Implemented by classes that want a special class (scope) to be used for looking up their id or want to map to another object for getting the id (seeobjectId(Object)
).static class
An index of pooled items.static interface
Instances are added to the scheduler in order to be invoked at a given time.static class
Represents a timer as created byschedule(TimeoutHandler, Instant)
. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Wait until all generators and event queues are exhausted.static boolean
awaitExhaustion
(long timeout) Wait until all generators and event queues are exhausted or the maximum wait time has expired.static void
Utility method that checks if an assertion error has occurred while executing handlers.static String
Returns the full name or simple name of the class depending on the log level.static ExecutorService
Return the default executor service for the framework.static String
fullObjectName
(Object object) Returns the full name of the object’s class together with an id (seeobjectId(Object)
).static Manager
manager
(ComponentType component) Returns a component’s manager.static Manager
manager
(ComponentType component, Channel componentChannel) Returns a component’s manager likemanager(ComponentType)
.static <K,
V> Map <K, V> mapOf()
Deprecated.static <K,
V> Map <K, V> mapOf
(K k1, V v1) Deprecated.static <K,
V> Map <K, V> mapOf
(K k1, V v1, K k2, V v2) Deprecated.static <K,
V> Map <K, V> mapOf
(K k1, V v1, K k2, V v2, K k3, V v3) Deprecated.static <K,
V> Map <K, V> mapOf
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) Deprecated.static <K,
V> Map <K, V> mapOf
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) Deprecated.static <K,
V> Map <K, V> mapOf
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) Deprecated.static <K,
V> Map <K, V> mapOf
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) Deprecated.static <K,
V> Map <K, V> mapOf
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8) Deprecated.static <K,
V> Map <K, V> mapOf
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9) Deprecated.static <K,
V> Map <K, V> mapOf
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10) Deprecated.static String
Returns an id of the object that is unique within a specific scope.static String
objectName
(Object object) Returns the name of the object’s class together with an id (seeobjectId(Object)
).static <K,
V> Map <K, V> Puts the given key and value in the givenMap
and returns the map.static Components.Timer
schedule
(Components.TimeoutHandler timeoutHandler, Duration scheduledFor) Schedules the given timeout handler for the given offset from now.static Components.Timer
schedule
(Components.TimeoutHandler timeoutHandler, Instant scheduledFor) Schedules the given timeout handler for the given instance.static void
setDefaultExecutorService
(ExecutorService defaultExecutorService) Set the default executor service for the framework.static void
setTimerExecutorService
(ExecutorService timerExecutorService) Sets the executor service used for executing timers.static String
simpleClassName
(Class<?> clazz) Returns the simple name of a class.static String
simpleObjectName
(Object object) Returns the simple name of the object’s class together with an id (seeobjectId(Object)
).static void
start
(ComponentType application) static ExecutorService
Returns the executor service used for executing timers.static boolean
JGrapes uses virtual thread by default.
-
Method Details
-
useVirtualThreads
JGrapes uses virtual thread by default.However, as of 2024, some debuggers still have problems with virtual threads. Therefore it is possible to switch back to platform threads by starting the JVM with property
-Djgrapes.useVirtualThreads=false
.- Returns:
- true, if successful
-
defaultExecutorService
Return the default executor service for the framework.- Returns:
- the defaultExecutorService
-
setDefaultExecutorService
Set the default executor service for the framework.The default value is a cached thread pool (see @link
Executors.newCachedThreadPool()
) with daemon threads.- Parameters:
defaultExecutorService
- the executor service to set
-
manager
Returns a component’s manager.For a component that inherits from
Component
this method simply returns the component as it is its own manager.For components that implement
ComponentType
but don’t inherit fromComponent
the method returns the value of the attribute annotated as manager slot. If this attribute is still empty, this method makes the component the root of a new tree and returns its manager.- Parameters:
component
- the component- Returns:
- the component (with its manager attribute set)
-
manager
Returns a component’s manager likemanager(ComponentType)
.If the manager slot attribute is empty, the component is initialized with its component channel set to the given parameter. Invoking this method overrides any channel set in the
ComponentManager
annotation.This method is usually invoked by the constructor of a class that implements
ComponentType
.- Parameters:
component
- the componentcomponentChannel
- the channel that the component’s handlers listen on by default and thatManager.fire(Event, Channel...)
sends the event to- Returns:
- the component (with its manager attribute set)
- See Also:
-
start
Fires aStart
event with an associatedStarted
completion event on the broadcast channel of the given application and wait for the completion of theStart
event.- Parameters:
application
- the application to start- Throws:
InterruptedException
- if the execution was interrupted
-
awaitExhaustion
Wait until all generators and event queues are exhausted.When this stage is reached, nothing can happen anymore unless a new event is sent from an external thread.
- Throws:
InterruptedException
- if the current thread was interrupted while waiting
-
awaitExhaustion
Wait until all generators and event queues are exhausted or the maximum wait time has expired.- Parameters:
timeout
- the wait time in milliseconds- Returns:
- true if exhaustion state was reached
- Throws:
InterruptedException
- if the execution was interrupted- See Also:
-
checkAssertions
Utility method that checks if an assertion error has occurred while executing handlers.If so, the error is thrown and the assertion error store is reset.
This method is intended for junit tests. It enables easy propagation of assertion failures to the main thread.
- Throws:
AssertionError
- if an assertion error occurred while executing the application
-
fullObjectName
Returns the full name of the object’s class together with an id (seeobjectId(Object)
).The result can be used as a unique human readable identifier for arbitrary objects.
- Parameters:
object
- the object- Returns:
- the object’s name
-
simpleObjectName
Returns the simple name of the object’s class together with an id (seeobjectId(Object)
).Can be used to create a human readable, though not necessarily unique, label for an object.
- Parameters:
object
- the object- Returns:
- the object’s name
-
objectName
Returns the name of the object’s class together with an id (seeobjectId(Object)
).May be used to implement toString() with identifiable objects. If the log level is “finer”, the full class name will be used for the returned value, else the simple name.
- Parameters:
object
- the object- Returns:
- the object’s name
-
className
Returns the full name or simple name of the class depending on the log level.- Parameters:
clazz
- the class- Returns:
- the name
-
simpleClassName
Returns the simple name of a class.Contrary to
Class.getSimpleName()
, this method returns the last segement of the full name for anonymous classes (instead of an empty string).- Parameters:
clazz
- the class- Returns:
- the name
-
objectId
Returns an id of the object that is unique within a specific scope.Ids are generated and looked up in the scope of the object’s class unless the class implements
Components.IdInfoProvider
.- Parameters:
object
- the object- Returns:
- the object’s name
-
timerExecutorService
Returns the executor service used for executing timers.- Returns:
- the timer executor service
-
setTimerExecutorService
Sets the executor service used for executing timers.Defaults to the
defaultExecutorService()
.- Parameters:
timerExecutorService
- the timerExecutorService to set
-
schedule
public static Components.Timer schedule(Components.TimeoutHandler timeoutHandler, Instant scheduledFor) Schedules the given timeout handler for the given instance.- Parameters:
timeoutHandler
- the handlerscheduledFor
- the instance in time- Returns:
- the timer
-
schedule
public static Components.Timer schedule(Components.TimeoutHandler timeoutHandler, Duration scheduledFor) Schedules the given timeout handler for the given offset from now.- Parameters:
timeoutHandler
- the handlerscheduledFor
- the time to wait- Returns:
- the timer
-
put
Puts the given key and value in the givenMap
and returns the map.Looks ugly when nested, but comes in handy sometimes.
- Type Parameters:
K
- the key typeV
- the value type- Parameters:
map
- the mapkey
- the keyvalue
- the value- Returns:
- the map
-
mapOf
Deprecated.Provisional replacement for method available in Java 9.- Returns:
- an empty map
-
mapOf
Deprecated.Provisional replacement for method available in Java 9.- Returns:
- an immutable map filled with the given values
-
mapOf
Deprecated.Provisional replacement for method available in Java 9.- Returns:
- an immutable map filled with the given values
-
mapOf
Deprecated.Provisional replacement for method available in Java 9.- Returns:
- an immutable map filled with the given values
-
mapOf
Deprecated.Provisional replacement for method available in Java 9.- Returns:
- an immutable map filled with the given values
-
mapOf
@Deprecated public static <K,V> Map<K,V> mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) Deprecated.Provisional replacement for method available in Java 9.- Returns:
- an immutable map filled with the given values
-
mapOf
@Deprecated public static <K,V> Map<K,V> mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) Deprecated.Provisional replacement for method available in Java 9.- Returns:
- an immutable map filled with the given values
-
mapOf
@Deprecated public static <K,V> Map<K,V> mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) Deprecated.Provisional replacement for method available in Java 9.- Returns:
- an immutable map filled with the given values
-
mapOf
@Deprecated public static <K,V> Map<K,V> mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8) Deprecated.Provisional replacement for method available in Java 9.- Returns:
- an immutable map filled with the given values
-
mapOf
@Deprecated public static <K,V> Map<K,V> mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9) Deprecated.Provisional replacement for method available in Java 9.- Returns:
- an immutable map filled with the given values
-
mapOf
@Deprecated public static <K,V> Map<K,V> mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10) Deprecated.Provisional replacement for method available in Java 9.- Returns:
- an immutable map filled with the given values
-