public class Scope
extends java.lang.Object
A Scope defines a SINGLE THREADED local lifetime management context,
stored in Thread Local Storage. Scopes can be explicitly entered or exited.
User keys created by this thread are tracked, and deleted when the scope is
exited. Since enter & exit are explicit, failure to exit means the Keys
leak (there is no reliable thread-on-exit cleanup action). You must call
Scope.exit()
at some point. Only user keys & Vec keys are tracked.
Scopes support nesting. Scopes support partial cleanup: you can list Keys you'd like to keep in the exit() call. These will be "bumped up" to the higher nested scope - or escaped and become untracked at the top-level.
Constructor and Description |
---|
Scope() |
Modifier and Type | Method and Description |
---|---|
static Scope |
current()
debugging purpose
|
static void |
enter()
Enter a new Scope
|
static Key[] |
exit(Key... keep)
Exit the inner-most Scope, remove all Keys created since the matching
enter call except for the listed Keys.
|
static boolean |
isActive()
Pop-scope (same as exit-scope) but return all keys that are tracked (and
would have been deleted).
|
static <T extends Keyed<T>> |
track_generic(T keyed) |
static Frame |
track(Frame... frames)
Track one or more
Frame s, and return the first one. |
static Vec |
track(Vec vec) |
static void |
untrack(Frame... frames) |
static <K extends Keyed> |
untrack(java.lang.Iterable<Key<K>> keys) |
static <K extends Keyed> |
untrack(Key<K>... keys) |
public static Scope current()
public static void enter()
public static Key[] exit(Key... keep)
public static boolean isActive()
public static <T extends Keyed<T>> T track_generic(T keyed)
public static Frame track(Frame... frames)
Frame
s, and return the first one. The tracked
frames will be removed from DKV when exit(Key[])
is called.public static void untrack(Frame... frames)