Skip to content

Commit ff579fa

Browse files
committed
Fixing CheckStyle issues.
1 parent 5393c96 commit ff579fa

File tree

5 files changed

+81
-82
lines changed

5 files changed

+81
-82
lines changed

ambassador/src/main/java/com/iluwatar/ambassador/App.java

+9-10
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,13 @@
4141
*/
4242
public class App {
4343

44-
/**
45-
* Entry point
46-
*/
47-
public static void main(String[] args) {
48-
49-
Client host1 = new Client();
50-
Client host2 = new Client();
51-
host1.useService(12);
52-
host2.useService(73);
53-
}
44+
/**
45+
* Entry point
46+
*/
47+
public static void main(String[] args) {
48+
Client host1 = new Client();
49+
Client host2 = new Client();
50+
host1.useService(12);
51+
host2.useService(73);
52+
}
5453
}

ambassador/src/main/java/com/iluwatar/ambassador/Client.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
*/
2828
public class Client {
2929

30-
private ServiceAmbassador serviceAmbassador;
30+
private ServiceAmbassador serviceAmbassador;
3131

32-
Client() {
33-
serviceAmbassador = new ServiceAmbassador();
34-
}
32+
Client() {
33+
serviceAmbassador = new ServiceAmbassador();
34+
}
3535

36-
long useService(int value) {
37-
long result = serviceAmbassador.doRemoteFunction(value);
38-
System.out.println(result);
39-
return result;
40-
}
36+
long useService(int value) {
37+
long result = serviceAmbassador.doRemoteFunction(value);
38+
System.out.println(result);
39+
return result;
40+
}
4141
}

ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java

+25-25
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,35 @@
2929
*/
3030
public class RemoteService implements RemoteServiceInterface {
3131

32-
private static RemoteService service = null;
32+
private static RemoteService service = null;
3333

34-
static synchronized RemoteService getRemoteService() {
35-
if (service == null) {
36-
service = new RemoteService();
37-
}
38-
return service;
34+
static synchronized RemoteService getRemoteService() {
35+
if (service == null) {
36+
service = new RemoteService();
3937
}
38+
return service;
39+
}
4040

41-
private RemoteService() {
41+
private RemoteService() {
4242

43-
}
43+
}
44+
45+
/**
46+
* Remote function takes a value and multiplies it by 10 taking a random amount of time.
47+
* Will sometimes return -1. This immitates connectivity issues a client might have to account for.
48+
* @param value integer value to be multiplied.
49+
* @return if waitTime is more than 200ms, it returns value * 10, otherwise -1.
50+
*/
51+
@Override
52+
public long doRemoteFunction(int value) {
53+
54+
long waitTime = (long) Math.floor(Math.random() * 1000);
4455

45-
/**
46-
* Remote function takes a value and multiplies it by 10 taking a random amount of time.
47-
* Will sometimes return -1. This immitates connectivity issues a client might have to account for.
48-
* @param value integer value to be multiplied.
49-
* @return if waitTime is more than 200ms, it returns value * 10, otherwise -1.
50-
*/
51-
@Override
52-
public long doRemoteFunction(int value) {
53-
54-
long waitTime = (long) Math.floor(Math.random() * 1000);
55-
56-
try {
57-
sleep(waitTime);
58-
} catch (InterruptedException e) {
59-
e.printStackTrace();
60-
}
61-
return waitTime >= 200 ? value * 10 : -1;
56+
try {
57+
sleep(waitTime);
58+
} catch (InterruptedException e) {
59+
e.printStackTrace();
6260
}
61+
return waitTime >= 200 ? value * 10 : -1;
62+
}
6363
}

ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceInterface.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
* Interface shared by ({@link RemoteService}) and ({@link ServiceAmbassador}).
2727
*/
2828
interface RemoteServiceInterface {
29-
30-
long doRemoteFunction(int value) throws Exception;
29+
30+
long doRemoteFunction(int value) throws Exception;
3131
}

ambassador/src/main/java/com/iluwatar/ambassador/ServiceAmbassador.java

+36-36
Original file line numberDiff line numberDiff line change
@@ -36,53 +36,53 @@
3636
*/
3737
public class ServiceAmbassador implements RemoteServiceInterface {
3838

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;
4242

43-
ServiceAmbassador() {
43+
ServiceAmbassador() {
4444

45-
}
45+
}
4646

47-
@Override
48-
public long doRemoteFunction(int value) {
47+
@Override
48+
public long doRemoteFunction(int value) {
4949

50-
return safeCall(value);
51-
}
50+
return safeCall(value);
51+
}
5252

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;
5858

59-
LOGGER.info("Time taken (ms): " + timeTaken);
60-
return result;
61-
}
59+
LOGGER.info("Time taken (ms): " + timeTaken);
60+
return result;
61+
}
6262

63-
private long safeCall(int value) {
63+
private long safeCall(int value) {
6464

65-
int retries = 0;
66-
long result = -1;
65+
int retries = 0;
66+
long result = -1;
6767

68-
for (int i = 0; i < RETRIES; i++) {
68+
for (int i = 0; i < RETRIES; i++) {
6969

70-
if (retries >= RETRIES) {
71-
return -1;
72-
}
70+
if (retries >= RETRIES) {
71+
return -1;
72+
}
7373

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();
8581
}
86-
return result;
82+
} else {
83+
break;
84+
}
8785
}
86+
return result;
87+
}
8888
}

0 commit comments

Comments
 (0)