Skip to content

Ambassador Pattern #722 #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 8, 2018
Merged

Ambassador Pattern #722 #755

merged 10 commits into from
Jul 8, 2018

Conversation

okinskas
Copy link
Contributor

@okinskas okinskas commented Jun 4, 2018

Ambassador Pattern

  • Implementing the ambassador pattern suggested in this issue.

Pull request description:

  • Added a new module 'ambassador' and its implementation
  • PR includes implementation, tests for each class and README.md with detailed description.

@okinskas
Copy link
Contributor Author

okinskas commented Jun 5, 2018

Requesting a review - please let me know if any changes or improvements should be made.

Copy link
Owner

@iluwatar iluwatar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well written pattern example. Please let me know when you've done the changes so we can merge it.

---

## Intent
Provide a helper service that sends network requests on behalf of a client and offload common additional connectivity tasks.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't networking just one example of Ambassador usages? Could the description be more general?


private RemoteService() {

}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be written on one line private RemoteService() {}. Please check whitespace usage elsewhere too.

try {
sleep(DELAY_MS);
} catch (InterruptedException e) {
e.printStackTrace();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use logger for output. Check this elsewhere too.

*/
public class Client {

private ServiceAmbassador serviceAmbassador;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be private final ServiceAmbassador serviceAmbassador = new ServiceAmbassador();


long useService(int value) {
long result = serviceAmbassador.doRemoteFunction(value);
System.out.println(result);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use logger

private long checkLatency(int value) {
RemoteService service = RemoteService.getRemoteService();
long startTime = System.currentTimeMillis();
long result = service.doRemoteFunction(value);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be written on one line RemoteService.getRemoteService().doRemoteFunction(value)

RemoteService remoteService = RemoteService.getRemoteService();
long result = remoteService.doRemoteFunction(10);

assert result == 100 || result == -1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where this assertion comes from

@Test
public void test() {
ServiceAmbassador ambassador = new ServiceAmbassador();
long result = ambassador.doRemoteFunction(10);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be written on one line

@okinskas
Copy link
Contributor Author

@iluwatar Changes have now been made.

Only bit not changed was: assert result == 100 || result == -1; in ClientTest and RemoteServiceTest as I'm not sure how else to assert that the output acted correctly. I am happy to change if you could advise how I should do so. Otherwise I believe it is ready for a merge as you mentioned.

Copy link
Owner

@iluwatar iluwatar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for the explanation.

@iluwatar iluwatar merged commit d915b66 into iluwatar:master Jul 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants