MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / down

Method down

samples/JGroups/src/RATE_LIMITER.java:49–94  ·  view source on GitHub ↗
(Event evt)

Source from the content-addressed store, hash-verified

47
48
49 public Object down(Event evt) {
50 if(evt.getType() == Event.MSG) {
51 Message msg=(Message)evt.getArg();
52 int len=msg.getLength();
53
54 lock.lock();
55 try {
56 if(len > max_bytes) {
57 log.error("message length (" + len + " bytes) exceeded max_bytes (" + max_bytes + "); " +
58 "adjusting max_bytes to " + len);
59 max_bytes=len;
60 }
61
62 while(true) {
63 boolean size_exceeded=num_bytes_sent + len >= max_bytes,
64 time_exceeded=System.currentTimeMillis() > end_of_current_period;
65 if(!size_exceeded && !time_exceeded)
66 break;
67
68 if(time_exceeded) {
69 reset();
70 }
71 else { // size exceeded
72 long block_time=end_of_current_period - System.currentTimeMillis();
73 if(block_time > 0) {
74 try {
75 block.await(block_time, TimeUnit.MILLISECONDS);
76 num_blockings++;
77 total_block_time+=block_time;
78 }
79 catch(InterruptedException e) {
80 }
81 }
82 }
83 }
84 }
85 finally {
86 num_bytes_sent+=len;
87 lock.unlock();
88 }
89
90 return down_prot.down(evt);
91 }
92
93 return down_prot.down(evt);
94 }
95
96
97 public void init() throws Exception {

Callers 2

runMethod · 0.45
authenticateMethod · 0.45

Calls 3

resetMethod · 0.95
getTypeMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected