General cleanup. Simplifying code. Replacing all prints with appropriate Logger.

This commit is contained in:
Ovidijus Okinskas
2018-06-23 13:24:07 +01:00
committed by O.Okinskas
parent 868e4561b5
commit 0453bf9063
6 changed files with 27 additions and 35 deletions

View File

@ -10,7 +10,7 @@ tags:
---
## Intent
Provide a helper service that sends network requests on behalf of a client and offload common additional connectivity tasks.
Provide a helper service instance on a client and offload common functionality away from a shared resource.
## Explanation
Real world example
@ -42,7 +42,8 @@ A remote services represented as a singleton.
```java
public class RemoteService implements RemoteServiceInterface {
private static RemoteService service = null;
private static final Logger LOGGER = LoggerFactory.getLogger(RemoteService.class);
private static RemoteService service = null;2
static synchronized RemoteService getRemoteService() {
if (service == null) {
@ -51,9 +52,7 @@ public class RemoteService implements RemoteServiceInterface {
return service;
}
private RemoteService() {
}
private RemoteService() {}
@Override
public long doRemoteFunction(int value) {
@ -63,7 +62,7 @@ public class RemoteService implements RemoteServiceInterface {
try {
sleep(waitTime);
} catch (InterruptedException e) {
e.printStackTrace();
LOGGER.error("Thread sleep interrupted", e)
}
return waitTime >= 200 ? value * 10 : -1;
}
@ -79,9 +78,7 @@ public class ServiceAmbassador implements RemoteServiceInterface {
private static final int RETRIES = 3;
private static final int DELAY_MS = 3000;
ServiceAmbassador() {
}
ServiceAmbassador() {}
@Override
public long doRemoteFunction(int value) {
@ -116,7 +113,7 @@ public class ServiceAmbassador implements RemoteServiceInterface {
try {
sleep(DELAY_MS);
} catch (InterruptedException e) {
e.printStackTrace();
LOGGER.error("Thread sleep state interrupted", e);
}
} else {
break;
@ -140,7 +137,7 @@ public class Client {
long useService(int value) {
long result = serviceAmbassador.doRemoteFunction(value);
System.out.println(result);
LOGGER.info("Service result: " + result)
return result;
}
}