-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsumerGroup.java
More file actions
58 lines (44 loc) · 1.32 KB
/
Copy pathConsumerGroup.java
File metadata and controls
58 lines (44 loc) · 1.32 KB
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
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
public class ConsumerGroup {
private int groupId;
private int offset;
private final ReentrantLock lock = new ReentrantLock();
private List<ConsumerConnection> consumers;
public ConsumerGroup(int groupId, int offset) {
this.groupId = groupId;
this.offset = offset;
this.consumers = new ArrayList<>();
}
public int getGroupId() {
return groupId;
}
public void setOffset(int offset) {
this.offset = offset;
}
public int getOffset() {
return offset;
}
public void incOffset(){
offset++;
}
public ReentrantLock getLock() {
return lock;
}
public List<ConsumerConnection> getConsumers() {
return consumers;
}
public void addConsumer(Socket socket) {
consumers.add(new ConsumerConnection(false, socket));
}
public static class ConsumerConnection {
public boolean isAvailable;
public Socket connection;
public ConsumerConnection(boolean isAvailable, Socket connection) {
this.isAvailable = isAvailable;
this.connection = connection;
}
}
}