/
ThreadLifecycleListener.java
67 lines (60 loc) · 2.26 KB
/
ThreadLifecycleListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package ru.yoomoney.tech.dbqueue.config;
import ru.yoomoney.tech.dbqueue.settings.QueueLocation;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* Listener for task processing thread in the queue.
*
* @author Oleg Kandaurov
* @since 16.07.2017
*/
public interface ThreadLifecycleListener {
/**
* Start of the task processing in the queue.
* <p>
* Always called.
* <p>
* Might be useful for setting values in the logging context or change thread name.
*
* @param shardId Shard identifier, which processes the queue.
* @param location Queue location.
*/
void started(@Nonnull QueueShardId shardId, @Nonnull QueueLocation location);
/**
* Thread was executed and finished processing.
* <p>
* Called when normal end of task processing.
* <p>
* Might be useful for measuring performance of the queue.
*
* @param shardId Shard identifier, which processes the queue.
* @param location Queue location.
* @param taskProcessed Attribute that task was taken and processed, no tasks for processing otherwise.
* @param threadBusyTime Time in millis of the thread was running active before sleep.
*/
void executed(QueueShardId shardId, QueueLocation location, boolean taskProcessed, long threadBusyTime);
/**
* End of the task processing lifecycle and start of the new one.
* <p>
* Always called, even after {@link #crashed}.
* <p>
* Might be useful for logging context return or move the thread to the initial state.
*
* @param shardId Shard identifier, which processes the queue.
* @param location Queue location.
*/
void finished(@Nonnull QueueShardId shardId, @Nonnull QueueLocation location);
/**
* Queue failed with fatal error.
* <p>
* Client code cannot trigger that method call,
* this method is called when task picking crashed.
* <p>
* Might be useful for logging and monitoring.
*
* @param shardId Shard identifier, which processes the queue.
* @param location Queue location.
* @param exc An error caused the crash.
*/
void crashed(@Nonnull QueueShardId shardId, @Nonnull QueueLocation location, @Nullable Throwable exc);
}