11package io .scalecube .cluster .utils ;
22
33import io .scalecube .cluster .transport .api .Message ;
4- import io .scalecube .net .Address ;
54import java .time .Duration ;
65import java .util .Arrays ;
76import java .util .Collection ;
@@ -30,21 +29,21 @@ public final class NetworkEmulator {
3029 private volatile OutboundSettings defaultOutboundSettings = new OutboundSettings (0 , 0 );
3130 private volatile InboundSettings defaultInboundSettings = new InboundSettings (true );
3231
33- private final Map <Address , OutboundSettings > outboundSettings = new ConcurrentHashMap <>();
34- private final Map <Address , InboundSettings > inboundSettings = new ConcurrentHashMap <>();
32+ private final Map <String , OutboundSettings > outboundSettings = new ConcurrentHashMap <>();
33+ private final Map <String , InboundSettings > inboundSettings = new ConcurrentHashMap <>();
3534
3635 private final AtomicLong totalMessageSentCount = new AtomicLong ();
3736 private final AtomicLong totalOutboundMessageLostCount = new AtomicLong ();
3837 private final AtomicLong totalInboundMessageLostCount = new AtomicLong ();
3938
40- private final Address address ;
39+ private final String address ;
4140
4241 /**
4342 * Creates new instance of network emulator.
4443 *
4544 * @param address local address
4645 */
47- NetworkEmulator (Address address ) {
46+ NetworkEmulator (String address ) {
4847 this .address = address ;
4948 }
5049
@@ -56,7 +55,7 @@ public final class NetworkEmulator {
5655 * @param destination address of target endpoint
5756 * @return network outbound settings
5857 */
59- public OutboundSettings outboundSettings (Address destination ) {
58+ public OutboundSettings outboundSettings (String destination ) {
6059 return outboundSettings .getOrDefault (destination , defaultOutboundSettings );
6160 }
6261
@@ -67,7 +66,7 @@ public OutboundSettings outboundSettings(Address destination) {
6766 * @param lossPercent loss in percents
6867 * @param meanDelay mean delay
6968 */
70- public void outboundSettings (Address destination , int lossPercent , int meanDelay ) {
69+ public void outboundSettings (String destination , int lossPercent , int meanDelay ) {
7170 OutboundSettings settings = new OutboundSettings (lossPercent , meanDelay );
7271 outboundSettings .put (destination , settings );
7372 LOGGER .debug ("[{}] Set outbound settings {} to {}" , address , settings , destination );
@@ -103,7 +102,7 @@ public void unblockAllOutbound() {
103102 *
104103 * @param destinations collection of target endpoints where to apply
105104 */
106- public void blockOutbound (Address ... destinations ) {
105+ public void blockOutbound (String ... destinations ) {
107106 blockOutbound (Arrays .asList (destinations ));
108107 }
109108
@@ -112,8 +111,8 @@ public void blockOutbound(Address... destinations) {
112111 *
113112 * @param destinations collection of target endpoints where to apply
114113 */
115- public void blockOutbound (Collection <Address > destinations ) {
116- for (Address destination : destinations ) {
114+ public void blockOutbound (Collection <String > destinations ) {
115+ for (String destination : destinations ) {
117116 outboundSettings .put (destination , new OutboundSettings (100 , 0 ));
118117 }
119118 LOGGER .debug ("[{}] Blocked outbound to {}" , address , destinations );
@@ -124,7 +123,7 @@ public void blockOutbound(Collection<Address> destinations) {
124123 *
125124 * @param destinations collection of target endpoints where to apply
126125 */
127- public void unblockOutbound (Address ... destinations ) {
126+ public void unblockOutbound (String ... destinations ) {
128127 unblockOutbound (Arrays .asList (destinations ));
129128 }
130129
@@ -133,7 +132,7 @@ public void unblockOutbound(Address... destinations) {
133132 *
134133 * @param destinations collection of target endpoints where to apply
135134 */
136- public void unblockOutbound (Collection <Address > destinations ) {
135+ public void unblockOutbound (Collection <String > destinations ) {
137136 destinations .forEach (outboundSettings ::remove );
138137 LOGGER .debug ("[{}] Unblocked outbound {}" , address , destinations );
139138 }
@@ -164,7 +163,7 @@ public long totalOutboundMessageLostCount() {
164163 * @param address target address
165164 * @return mono message
166165 */
167- public Mono <Message > tryFailOutbound (Message msg , Address address ) {
166+ public Mono <Message > tryFailOutbound (Message msg , String address ) {
168167 return Mono .defer (
169168 () -> {
170169 totalMessageSentCount .incrementAndGet ();
@@ -187,7 +186,7 @@ public Mono<Message> tryFailOutbound(Message msg, Address address) {
187186 * @param address target address
188187 * @return mono message
189188 */
190- public Mono <Message > tryDelayOutbound (Message msg , Address address ) {
189+ public Mono <Message > tryDelayOutbound (Message msg , String address ) {
191190 return Mono .defer (
192191 () -> {
193192 totalMessageSentCount .incrementAndGet ();
@@ -209,7 +208,7 @@ public Mono<Message> tryDelayOutbound(Message msg, Address address) {
209208 * @param destination address of target endpoint
210209 * @return network inbound settings
211210 */
212- public InboundSettings inboundSettings (Address destination ) {
211+ public InboundSettings inboundSettings (String destination ) {
213212 return inboundSettings .getOrDefault (destination , defaultInboundSettings );
214213 }
215214
@@ -218,7 +217,7 @@ public InboundSettings inboundSettings(Address destination) {
218217 *
219218 * @param shallPass shallPass inbound flag
220219 */
221- public void inboundSettings (Address destination , boolean shallPass ) {
220+ public void inboundSettings (String destination , boolean shallPass ) {
222221 InboundSettings settings = new InboundSettings (shallPass );
223222 inboundSettings .put (destination , settings );
224223 LOGGER .debug ("[{}] Set inbound settings {} to {}" , address , settings , destination );
@@ -253,7 +252,7 @@ public void unblockAllInbound() {
253252 *
254253 * @param destinations collection of target endpoints where to apply
255254 */
256- public void blockInbound (Address ... destinations ) {
255+ public void blockInbound (String ... destinations ) {
257256 blockInbound (Arrays .asList (destinations ));
258257 }
259258
@@ -262,8 +261,8 @@ public void blockInbound(Address... destinations) {
262261 *
263262 * @param destinations collection of target endpoints where to apply
264263 */
265- public void blockInbound (Collection <Address > destinations ) {
266- for (Address destination : destinations ) {
264+ public void blockInbound (Collection <String > destinations ) {
265+ for (String destination : destinations ) {
267266 inboundSettings .put (destination , new InboundSettings (false ));
268267 }
269268 LOGGER .debug ("[{}] Blocked inbound from {}" , address , destinations );
@@ -274,7 +273,7 @@ public void blockInbound(Collection<Address> destinations) {
274273 *
275274 * @param destinations collection of target endpoints where to apply
276275 */
277- public void unblockInbound (Address ... destinations ) {
276+ public void unblockInbound (String ... destinations ) {
278277 unblockInbound (Arrays .asList (destinations ));
279278 }
280279
@@ -283,7 +282,7 @@ public void unblockInbound(Address... destinations) {
283282 *
284283 * @param destinations collection of target endpoints where to apply
285284 */
286- public void unblockInbound (Collection <Address > destinations ) {
285+ public void unblockInbound (Collection <String > destinations ) {
287286 destinations .forEach (inboundSettings ::remove );
288287 LOGGER .debug ("[{}] Unblocked inbound from {}" , address , destinations );
289288 }
0 commit comments