Skip to content

Commit 8cfed46

Browse files
committed
1 parent 25394fd commit 8cfed46

File tree

1 file changed

+79
-8
lines changed

1 file changed

+79
-8
lines changed
Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,93 @@
11
package org.jgroups.protocols;
22

33
import org.jgroups.Message;
4-
import org.jgroups.annotations.Property;
4+
import org.jgroups.annotations.MBean;
5+
import org.jgroups.annotations.ManagedAttribute;
6+
import org.jgroups.annotations.ManagedOperation;
57
import org.jgroups.stack.Protocol;
8+
import org.jgroups.util.MessageBatch;
9+
10+
import java.util.Set;
11+
import java.util.concurrent.ConcurrentSkipListSet;
12+
import java.util.stream.Collectors;
613

714
/**
8-
* Protocol which clears the given flags in the down direction for all messages
15+
* Protocol which clears a set of flags in the down or up direction for all messages
916
* @author Bela Ban
1017
* @since 4.0.4
1118
*/
19+
@MBean(description="Clears a given set of flags from up or down messages")
1220
public class CLEAR_FLAGS extends Protocol {
13-
@Property(description="clear OOB flags")
14-
protected boolean oob=true;
21+
protected final Set<Message.Flag> down_flags=new ConcurrentSkipListSet<>();
22+
protected final Set<Message.Flag> up_flags=new ConcurrentSkipListSet<>();
1523

16-
@Override
17-
public Object down(Message msg) {
18-
if(oob)
19-
msg.clearFlag(Message.Flag.OOB);
24+
@ManagedAttribute(description="Shows up and down flags")
25+
public String flags() {
26+
return String.format("down flags: %s\nup_flags: %s", downFlags(), upFlags());
27+
}
28+
29+
@ManagedOperation(description="Adds a flag to the up or down set")
30+
public CLEAR_FLAGS addFlag(boolean down, String flag) {
31+
Message.Flag fl=Message.Flag.valueOf(flag);
32+
return fl != null? addFlag(down, fl) : this;
33+
}
34+
35+
public CLEAR_FLAGS addFlag(boolean down, Message.Flag flag) {
36+
Set<Message.Flag> s=down? down_flags : up_flags;
37+
s.add(flag);
38+
return this;
39+
}
40+
41+
@ManagedOperation(description="Removes a flag from the up or down set")
42+
public CLEAR_FLAGS removeFlag(boolean down, String flag) {
43+
Message.Flag fl=Message.Flag.valueOf(flag);
44+
return fl != null? removeFlag(down, fl) : this;
45+
}
46+
47+
public CLEAR_FLAGS removeFlag(boolean down, Message.Flag flag) {
48+
Set<Message.Flag> s=down? down_flags : up_flags;
49+
s.remove(flag);
50+
return this;
51+
}
52+
53+
@ManagedOperation(description="Removes all up or down flags")
54+
public CLEAR_FLAGS removeAllFlags() {
55+
down_flags.clear();
56+
up_flags.clear();
57+
return this;
58+
}
59+
60+
@Override public Object down(Message msg) {
61+
if(!down_flags.isEmpty()) {
62+
for(Message.Flag flag: down_flags)
63+
msg.clearFlag(flag);
64+
}
2065
return down_prot.down(msg);
2166
}
67+
68+
@Override public Object up(Message msg) {
69+
if(!up_flags.isEmpty()) {
70+
for(Message.Flag fl: up_flags)
71+
msg.clearFlag(fl);
72+
}
73+
return up_prot.up(msg);
74+
}
75+
76+
@Override
77+
public void up(MessageBatch batch) {
78+
if(!up_flags.isEmpty()) {
79+
for(Message.Flag fl: up_flags)
80+
for(Message msg: batch)
81+
msg.clearFlag(fl);
82+
}
83+
up_prot.up(batch);
84+
}
85+
86+
public String downFlags() {
87+
return down_flags.stream().map(Enum::toString).collect(Collectors.joining(", "));
88+
}
89+
90+
public String upFlags() {
91+
return up_flags.stream().map(Enum::toString).collect(Collectors.joining(", "));
92+
}
2293
}

0 commit comments

Comments
 (0)