const mixinafIoc::ThreadLocalManager

afIoc::ThreadLocalManager

(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

LocalXXX Injection

IoC defines a DependencyProvider that injects LocalXXX instances directly into your class. Where possible, the field name is used as the local name.

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.

@since 1.6.0

addCleanUpHandler

Source

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

Source

abstract Void cleanUpThread()

Removes all values in the current thread associated / used with this manager.

createList

Source

abstract LocalList createList(Str name)

Creates a afConcurrent::LocalList with the given name.

createMap

Source

abstract LocalMap createMap(Str name)

Creates a afConcurrent::LocalMap with the given name.

createName

Source

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

Source

abstract LocalRef createRef(Str name, |->Obj?? defFunc := null)

Creates a afConcurrent::LocalRef with the given default function.

keys

Source

abstract Str[] keys()

Returns all (fully qualified) keys in the current thread associated / used with this manager.