|
36 | 36 | */
|
37 | 37 | public class ServiceAmbassador implements RemoteServiceInterface {
|
38 | 38 |
|
39 |
| - private static final Logger LOGGER = LoggerFactory.getLogger(ServiceAmbassador.class); |
40 |
| - private static final int RETRIES = 3; |
41 |
| - private static final int DELAY_MS = 3000; |
| 39 | + private static final Logger LOGGER = LoggerFactory.getLogger(ServiceAmbassador.class); |
| 40 | + private static final int RETRIES = 3; |
| 41 | + private static final int DELAY_MS = 3000; |
42 | 42 |
|
43 |
| - ServiceAmbassador() { |
| 43 | + ServiceAmbassador() { |
44 | 44 |
|
45 |
| - } |
| 45 | + } |
46 | 46 |
|
47 |
| - @Override |
48 |
| - public long doRemoteFunction(int value) { |
| 47 | + @Override |
| 48 | + public long doRemoteFunction(int value) { |
49 | 49 |
|
50 |
| - return safeCall(value); |
51 |
| - } |
| 50 | + return safeCall(value); |
| 51 | + } |
52 | 52 |
|
53 |
| - private long checkLatency(int value) { |
54 |
| - RemoteService service = RemoteService.getRemoteService(); |
55 |
| - long startTime = System.currentTimeMillis(); |
56 |
| - long result = service.doRemoteFunction(value); |
57 |
| - long timeTaken = System.currentTimeMillis() - startTime; |
| 53 | + private long checkLatency(int value) { |
| 54 | + RemoteService service = RemoteService.getRemoteService(); |
| 55 | + long startTime = System.currentTimeMillis(); |
| 56 | + long result = service.doRemoteFunction(value); |
| 57 | + long timeTaken = System.currentTimeMillis() - startTime; |
58 | 58 |
|
59 |
| - LOGGER.info("Time taken (ms): " + timeTaken); |
60 |
| - return result; |
61 |
| - } |
| 59 | + LOGGER.info("Time taken (ms): " + timeTaken); |
| 60 | + return result; |
| 61 | + } |
62 | 62 |
|
63 |
| - private long safeCall(int value) { |
| 63 | + private long safeCall(int value) { |
64 | 64 |
|
65 |
| - int retries = 0; |
66 |
| - long result = -1; |
| 65 | + int retries = 0; |
| 66 | + long result = -1; |
67 | 67 |
|
68 |
| - for (int i = 0; i < RETRIES; i++) { |
| 68 | + for (int i = 0; i < RETRIES; i++) { |
69 | 69 |
|
70 |
| - if (retries >= RETRIES) { |
71 |
| - return -1; |
72 |
| - } |
| 70 | + if (retries >= RETRIES) { |
| 71 | + return -1; |
| 72 | + } |
73 | 73 |
|
74 |
| - if ((result = checkLatency(value)) == -1) { |
75 |
| - LOGGER.info("Failed to reach remote: (" + (i + 1) + ")"); |
76 |
| - retries++; |
77 |
| - try { |
78 |
| - sleep(DELAY_MS); |
79 |
| - } catch (InterruptedException e) { |
80 |
| - e.printStackTrace(); |
81 |
| - } |
82 |
| - } else { |
83 |
| - break; |
84 |
| - } |
| 74 | + if ((result = checkLatency(value)) == -1) { |
| 75 | + LOGGER.info("Failed to reach remote: (" + (i + 1) + ")"); |
| 76 | + retries++; |
| 77 | + try { |
| 78 | + sleep(DELAY_MS); |
| 79 | + } catch (InterruptedException e) { |
| 80 | + e.printStackTrace(); |
85 | 81 | }
|
86 |
| - return result; |
| 82 | + } else { |
| 83 | + break; |
| 84 | + } |
87 | 85 | }
|
| 86 | + return result; |
| 87 | + } |
88 | 88 | }
|
0 commit comments