Skip to content

Ambassador Pattern #722 - #755

Merged
iluwatar merged 10 commits into
iluwatar:masterfrom
okinskas:ambassador
Jul 8, 2018
Merged

iluwatar merged 10 commits into
iluwatar:masterfrom
okinskas:ambassador

Conversation

@okinskas

@okinskas okinskas commented Jun 4, 2018

Copy link
Copy Markdown
Contributor

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

okinskas commented Jun 5, 2018

Copy link
Copy Markdown
Contributor Author

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

@iluwatar iluwatar left a comment

Copy link
Copy Markdown
Owner

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.

Comment thread ambassador/README.md Outdated
---

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

Copy link
Copy Markdown
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?

Comment thread ambassador/README.md Outdated

private RemoteService() {

}

Copy link
Copy Markdown
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.

Comment thread ambassador/README.md Outdated
try {
sleep(DELAY_MS);
} catch (InterruptedException e) {
e.printStackTrace();

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@iluwatar iluwatar left a comment

Copy link
Copy Markdown
Owner

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