const mixinafConcurrent::LocalRefManager
afConcurrent::LocalRefManager
(Service) - Use to create LocalRef
/ LocalList
/ LocalMap
instances whose contents can be cleaned up. Erm, I mean deleted!
This is particularly important in the context of web applications where resources need to be cleaned up at the end of a web request / thread.
Then when cleanUpThread()
is called, all thread local data created by this manager will be deleted from Actor.locals
LocalRefManager
is automatically made available in IoC enabled applications.
LocalXXX Injection
The Concurrent library also defines an IoC DependencyProvider
that injects LocalXXX
instances directly into your class. Where possible, the field name is used as the local name. Example:
const class Example { @Inject const LocalMap localMap new make(|This|in) { in(this) } }
@Inject.type
may be used to declare the underlying parameters of the LocalList / LocalMap
:
const class Example { @Inject { type=Str[]# } const LocalList localList @Inject { type=[Str:Slot?]# } const LocalMap localMap new make(|This|in) { in(this) } }
If @Inject.type
is used with a LocalMap
, then if the key is a Str
the map will be case-insensitive, otherwise it will be ordered.
- addCleanUpHandler
abstract Void addCleanUpHandler(|->Void handler)
Add a handler to be called on thread clean up. New handlers have to be added for each thread.
- cleanUpThread
abstract Void cleanUpThread()
Removes all values in the current thread associated / used with this manager.
- createList
abstract LocalList createList(Str name)
Creates a afConcurrent::LocalList with the given name.
- createMap
abstract LocalMap createMap(Str name)
Creates a afConcurrent::LocalMap with the given name.
- createName
abstract Str createName(Str name)
Creates a qualified name unique to this
ThreadLocalManager
that when used to create a Local Refs, List or Map, ensures it is cleanup up with all the others.- createRef
abstract LocalRef createRef(Str name, |->Obj?? defFunc := null)
Creates a afConcurrent::LocalRef with the given default function.
- keys
abstract Str[] keys()
Returns all (fully qualified) keys in the current thread associated / used with this manager.