public abstract class Hooklet extends Object implements Comparable<Hooklet>
| Constructor and Description |
|---|
Hooklet() |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(@NotNull Hooklet other) |
boolean |
equals(Object obj) |
int |
hashCode() |
protected Object |
identity()
Hooks are only called once but may be registered multiple times.
|
static Hooklet |
of(int priority,
Runnable hook)
Accepts callback and priority to produce shutdown hook object.
|
abstract void |
onShutdown()
The callback which will be invoked on shutdown.
|
abstract int |
priority()
Hooks with lesser priority will be called before hooks with greater priority.
|
String |
toString() |
public abstract void onShutdown()
public abstract int priority()
It is advised to allocate an unique priority in the range of 0-100. In general, more high level code needs to do its shutdown routines before lower level code. An example priority layout is given below:
0: Run before all hooks. For test/example use. 1-49: Release of network resources and stopping distributed activity. 50-89: Release of local resources and stopping data structures. 90-99 Cleanup of file system resources such as temporary directories. 100: Run after all hooks. For test/example use.
protected Object identity()
The default implementation returns this instance's class and should usually be sufficient.
public static Hooklet of(int priority, Runnable hook)
Hook callback class is used to check for identity, see identity().
priority - See priority()hook - See onShutdown()PriorityHook.addAndGet(Hooklet)public int compareTo(@NotNull
@NotNull Hooklet other)
compareTo in interface Comparable<Hooklet>Copyright © 2024. All rights reserved.