Cleanup class
Marks a method to be invoked after a pod is destroyed.
Jetleaf automatically detects methods annotated with @Cleanup
and calls them after pod shutdown or context close.
This is typically used for:
- Releasing resources (database connections, sockets, file handles).
- Stopping background workers.
- Flushing in-memory caches.
Rules
- Must be a no-arg method.
- Return type should be
void
orFuture<void>
. - Only applied to methods (not classes or fields).
Example — Synchronous Cleanup
@Service()
class CacheManager {
final _cache = <String, String>{};
void put(String key, String value) => _cache[key] = value;
@Cleanup()
void clearCache() {
print("Clearing cache after shutdown...");
_cache.clear();
}
}
Example — Asynchronous Cleanup
@Service()
class WorkerPool {
final _workers = <Worker>[];
@Cleanup()
Future<void> shutdownWorkers() async {
for (final worker in _workers) {
await worker.stop();
}
}
}
- Annotations
-
- @Target.new({TargetKind.method})
Constructors
- Cleanup()
-
Marks a method to be invoked after a pod is destroyed.
const
Properties
- annotationType → Type
-
Returns the annotation _type of this annotation.
no setter
- hashCode → int
-
Returns a hash code consistent with equality definition.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
equals(
Object other) → bool -
Checks whether the given object is logically equivalent to this annotation.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
Returns a string representation of this annotation.
inherited
Operators
-
operator ==(
Object other) → bool -
Checks if this annotation is equal to another object.
inherited