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.
Modifier and Type | Class and Description |
---|---|
static class |
Scope.Safe |
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 innermost Scope, remove all Keys created since the matching
enter call except for the listed Keys.
|
static boolean |
isActive() |
static int |
nLevel()
for testing purpose
|
static Frame |
protect(Frame... frames)
Protects the listed frames and their vecs inside this scope and inner scopes so that they can't be removed,
for example if an unprotected frame shares some Vecs.
|
static void |
reset()
for testing purpose
|
static Scope.Safe |
safe(Frame... protectedFrames)
Enters a new scope and protects the passed frames in that scope.
|
static <T extends Keyed<T>> |
track_generic(T keyed) |
static Frame |
track(Frame... frames)
Track one or more
Frame s, as well as all their Vecs independently. |
static Vec |
track(Vec vec)
Track a single Vec.
|
static Frame |
untrack(Frame... frames) |
static <K extends Key> |
untrack(java.lang.Iterable<K> keys)
Untrack the specified keys.
|
static <K extends Key> |
untrack(K... keys)
Untrack the specified keys.
|
public static Scope current()
public static int nLevel()
public static void reset()
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, as well as all their Vecs independently.
The tracked frames and vecs will be removed from DKV when exit(Key[])
is called,
but for Frame
s, they will be removed without their Vecs as those are tracked independently,
and we want to be able to untrack(Key[])
them (or spare them at exit(Key[])
without them being removed together with the Frame
to which they're attached.frames
- public static <K extends Key> void untrack(K... keys)
untrack(Frame...)
is you need a behaviour symmetrical to track(Frame...)
.keys
- public static <K extends Key> void untrack(java.lang.Iterable<K> keys)
untrack(Frame...)
is you need a behaviour symmetrical to track(Frame...)
.keys
- public static Frame untrack(Frame... frames)
frames
- public static Frame protect(Frame... frames)
frames
- public static Scope.Safe safe(Frame... protectedFrames)