1
1
package io .scalecube .cluster .utils ;
2
2
3
3
import io .scalecube .cluster .transport .api .Message ;
4
+ import java .lang .System .Logger ;
5
+ import java .lang .System .Logger .Level ;
4
6
import java .time .Duration ;
5
7
import java .util .Arrays ;
6
8
import java .util .Collection ;
9
11
import java .util .concurrent .ConcurrentHashMap ;
10
12
import java .util .concurrent .ThreadLocalRandom ;
11
13
import java .util .concurrent .atomic .AtomicLong ;
12
- import org .slf4j .Logger ;
13
- import org .slf4j .LoggerFactory ;
14
14
import reactor .core .publisher .Mono ;
15
15
16
16
/**
24
24
*/
25
25
public final class NetworkEmulator {
26
26
27
- private static final Logger LOGGER = LoggerFactory .getLogger (NetworkEmulator .class );
27
+ private static final Logger LOGGER = System .getLogger (NetworkEmulator .class . getName () );
28
28
29
29
private volatile OutboundSettings defaultOutboundSettings = new OutboundSettings (0 , 0 );
30
30
private volatile InboundSettings defaultInboundSettings = new InboundSettings (true );
@@ -69,7 +69,8 @@ public OutboundSettings outboundSettings(String destination) {
69
69
public void outboundSettings (String destination , int lossPercent , int meanDelay ) {
70
70
OutboundSettings settings = new OutboundSettings (lossPercent , meanDelay );
71
71
outboundSettings .put (destination , settings );
72
- LOGGER .debug ("[{}] Set outbound settings {} to {}" , address , settings , destination );
72
+ LOGGER .log (
73
+ Level .DEBUG , "[{0}] Set outbound settings {1} to {2}" , address , settings , destination );
73
74
}
74
75
75
76
/**
@@ -80,21 +81,22 @@ public void outboundSettings(String destination, int lossPercent, int meanDelay)
80
81
*/
81
82
public void setDefaultOutboundSettings (int lossPercent , int meanDelay ) {
82
83
defaultOutboundSettings = new OutboundSettings (lossPercent , meanDelay );
83
- LOGGER .debug ("[{}] Set default outbound settings {}" , address , defaultOutboundSettings );
84
+ LOGGER .log (
85
+ Level .DEBUG , "[{0}] Set default outbound settings {1}" , address , defaultOutboundSettings );
84
86
}
85
87
86
88
/** Blocks outbound messages to all destinations. */
87
89
public void blockAllOutbound () {
88
90
outboundSettings .clear ();
89
91
setDefaultOutboundSettings (100 , 0 );
90
- LOGGER .debug ( "[{}] Blocked outbound to all destinations" , address );
92
+ LOGGER .log ( Level . DEBUG , "[{0 }] Blocked outbound to all destinations" , address );
91
93
}
92
94
93
95
/** Unblocks outbound messages to all destinations. */
94
96
public void unblockAllOutbound () {
95
97
outboundSettings .clear ();
96
98
setDefaultOutboundSettings (0 , 0 );
97
- LOGGER .debug ( "[{}] Unblocked outbound to all destinations" , address );
99
+ LOGGER .log ( Level . DEBUG , "[{0 }] Unblocked outbound to all destinations" , address );
98
100
}
99
101
100
102
/**
@@ -115,7 +117,7 @@ public void blockOutbound(Collection<String> destinations) {
115
117
for (String destination : destinations ) {
116
118
outboundSettings .put (destination , new OutboundSettings (100 , 0 ));
117
119
}
118
- LOGGER .debug ( "[{}] Blocked outbound to {}" , address , destinations );
120
+ LOGGER .log ( Level . DEBUG , "[{0 }] Blocked outbound to {1 }" , address , destinations );
119
121
}
120
122
121
123
/**
@@ -134,7 +136,7 @@ public void unblockOutbound(String... destinations) {
134
136
*/
135
137
public void unblockOutbound (Collection <String > destinations ) {
136
138
destinations .forEach (outboundSettings ::remove );
137
- LOGGER .debug ( "[{}] Unblocked outbound {}" , address , destinations );
139
+ LOGGER .log ( Level . DEBUG , "[{0 }] Unblocked outbound {1 }" , address , destinations );
138
140
}
139
141
140
142
/**
@@ -220,7 +222,8 @@ public InboundSettings inboundSettings(String destination) {
220
222
public void inboundSettings (String destination , boolean shallPass ) {
221
223
InboundSettings settings = new InboundSettings (shallPass );
222
224
inboundSettings .put (destination , settings );
223
- LOGGER .debug ("[{}] Set inbound settings {} to {}" , address , settings , destination );
225
+ LOGGER .log (
226
+ Level .DEBUG , "[{0}] Set inbound settings {1} to {2}" , address , settings , destination );
224
227
}
225
228
226
229
/**
@@ -230,21 +233,22 @@ public void inboundSettings(String destination, boolean shallPass) {
230
233
*/
231
234
public void setDefaultInboundSettings (boolean shallPass ) {
232
235
defaultInboundSettings = new InboundSettings (shallPass );
233
- LOGGER .debug ("[{}] Set default inbound settings {}" , address , defaultInboundSettings );
236
+ LOGGER .log (
237
+ Level .DEBUG , "[{0}] Set default inbound settings {1}" , address , defaultInboundSettings );
234
238
}
235
239
236
240
/** Blocks inbound messages from all destinations. */
237
241
public void blockAllInbound () {
238
242
inboundSettings .clear ();
239
243
setDefaultInboundSettings (false );
240
- LOGGER .debug ( "[{}] Blocked inbound from all destinations" , address );
244
+ LOGGER .log ( Level . DEBUG , "[{0 }] Blocked inbound from all destinations" , address );
241
245
}
242
246
243
247
/** Unblocks inbound messages to all destinations. */
244
248
public void unblockAllInbound () {
245
249
inboundSettings .clear ();
246
250
setDefaultInboundSettings (true );
247
- LOGGER .debug ( "[{}] Unblocked inbound from all destinations" , address );
251
+ LOGGER .log ( Level . DEBUG , "[{0 }] Unblocked inbound from all destinations" , address );
248
252
}
249
253
250
254
/**
@@ -265,7 +269,7 @@ public void blockInbound(Collection<String> destinations) {
265
269
for (String destination : destinations ) {
266
270
inboundSettings .put (destination , new InboundSettings (false ));
267
271
}
268
- LOGGER .debug ( "[{}] Blocked inbound from {}" , address , destinations );
272
+ LOGGER .log ( Level . DEBUG , "[{0 }] Blocked inbound from {1 }" , address , destinations );
269
273
}
270
274
271
275
/**
@@ -284,7 +288,7 @@ public void unblockInbound(String... destinations) {
284
288
*/
285
289
public void unblockInbound (Collection <String > destinations ) {
286
290
destinations .forEach (inboundSettings ::remove );
287
- LOGGER .debug ( "[{}] Unblocked inbound from {}" , address , destinations );
291
+ LOGGER .log ( Level . DEBUG , "[{0 }] Unblocked inbound from {1 }" , address , destinations );
288
292
}
289
293
290
294
/**
0 commit comments