Skip to content

Issue #469: Event-based Asynchronous pattern#483

Merged
iluwatar merged 16 commits into
iluwatar:masterfrom
waisuan:master
Oct 18, 2016
Merged

Issue #469: Event-based Asynchronous pattern#483
iluwatar merged 16 commits into
iluwatar:masterfrom
waisuan:master

Conversation

@waisuan
Copy link
Copy Markdown
Contributor

@waisuan waisuan commented Aug 8, 2016

Hey @iluwatar . Let me know if there are any issues with the implementation of the new pattern. Thanks.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.1%) to 88.924% when pulling ca30b2e on waisuan:master into d50139e on iluwatar:master.

@waisuan
Copy link
Copy Markdown
Contributor Author

waisuan commented Aug 8, 2016

Failed at Checkstyle. Working on it.

@waisuan
Copy link
Copy Markdown
Contributor Author

waisuan commented Aug 9, 2016

Issue seems to be stemming from PMD check. I believe that it is due to the unnecessary "public" scope in IEvent. Will submit a fix before the end of today.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.1%) to 87.928% when pulling d9bfb6d on waisuan:master into d50139e on iluwatar:master.

@waisuan
Copy link
Copy Markdown
Contributor Author

waisuan commented Aug 9, 2016

Coverage decreased by ~1%. Is it still OK to merge?

@waisuan
Copy link
Copy Markdown
Contributor Author

waisuan commented Aug 16, 2016

Hey, @iluwatar . Any thoughts on this so far? :)

@iluwatar
Copy link
Copy Markdown
Owner

iluwatar commented Sep 3, 2016

@waisuan My apologies for taking this long to review the pull request. Here are my comments:

  • Can we add some spice to the example? I mean now it starts and stops some generic events which is technically ok, but I would like to add some human elements also. How about using a microwave oven, boiling eggs or operating a time machine?
  • I like the interactive mode. However, if there are events running the application does not seem to exit. Is this a bug or feature? Maybe it should output some info like "cannot exit while events are running"?
  • In interactive mode it is fun to play with events. However, the event ids are quite long and hard to type. Could we use shorter event ids?
  • The description of the pattern gives quite strict rules for naming the methods such as Load, LoadAsync and LoadCompleted. Should we use this naming pattern also?
  • There are no assertions in the unit tests, they just test that exceptions are not thrown. Could we add some assertions?

@iluwatar iluwatar self-assigned this Sep 3, 2016
permalink: /patterns/event-asynchronous/
categories: Other
tags:
- Java
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.

Can you think proper categories and tags for the pattern? For reference see http://java-design-patterns.com/patterns/

@iluwatar
Copy link
Copy Markdown
Owner

iluwatar commented Sep 3, 2016

@waisuan You have my review comments. Please comment on this thread once you're ready for another review.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.9%) to 88.058% when pulling 233f1e6 on waisuan:master into ff23e90 on iluwatar:master.

@waisuan
Copy link
Copy Markdown
Contributor Author

waisuan commented Sep 5, 2016

Thanks for getting back to me, @iluwatar . Your comments have been noted. I'll try to get to them sometime this week. Cheers.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.3%) to 84.692% when pulling f215951 on waisuan:master into 59e6a0a on iluwatar:master.

@waisuan
Copy link
Copy Markdown
Contributor Author

waisuan commented Sep 11, 2016

Hey, @iluwatar . I've made the necessary changes based on your feedback. Do take another look and let me know if there is anything else. Thanks!

@iluwatar
Copy link
Copy Markdown
Owner

@waisuan here are my comments:

  • I could not trigger the interactive mode using the properties file.
  • The interactive mode menu is confusing. Especially 3 and 4 seem to do the same thing. Can we combine these into one?
  • The interactive mode application is somewhat unstable. See the following console log:
Hello. Would you like to boil some eggs?
(1) BOIL AN EGG 
(2) STOP BOILING THIS EGG 
(3) HOW IS MY EGG? 
(4) HOW ARE MY EGGS? 
(5) EXIT
Choose [1,2,3,4,5]: 1
Boil multiple eggs at once (A) or boil them one-by-one (S)?: S
How long should this egg be boiled for (in seconds)?: 5
Egg [986] is being boiled.
Hello. Would you like to boil some eggs?
(1) BOIL AN EGG 
(2) STOP BOILING THIS EGG 
(3) HOW IS MY EGG? 
(4) HOW ARE MY EGGS? 
(5) EXIT
Choose [1,2,3,4,5]: 1
Boil multiple eggs at once (A) or boil them one-by-one (S)?: S
How long should this egg be boiled for (in seconds)?: [986] is done.
5
Event [986] is still running. Please wait until it finishes and try again.
Hello. Would you like to boil some eggs?
(1) BOIL AN EGG 
(2) STOP BOILING THIS EGG 
(3) HOW IS MY EGG? 
(4) HOW ARE MY EGGS? 
(5) EXIT
Choose [1,2,3,4,5]: 5
Exception in thread "main" java.lang.NullPointerException
    at com.iluwatar.event.asynchronous.Event.stop(Event.java:45)
    at com.iluwatar.event.asynchronous.EventManager.shutdown(EventManager.java:172)
    at com.iluwatar.event.asynchronous.App.runInteractiveMode(App.java:194)
    at com.iluwatar.event.asynchronous.App.run(App.java:94)
    at com.iluwatar.event.asynchronous.App.main(App.java:64)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Process finished with exit code 1
  • I suggest you add more unit tests to catch errors. Try for example running different combinations of events, starting & stopping & restarting etc.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.6%) to 82.756% when pulling 69cab15 on waisuan:master into 6026eed on iluwatar:master.

@waisuan
Copy link
Copy Markdown
Contributor Author

waisuan commented Sep 19, 2016

Hey, @iluwatar . Kindly take another look at my changes. The properties file accept "YES" or "NO" as its input. I've toggled the settings. They seem to work just fine. I've fine-tuned the interactive mode as well. It was meant to be a "fun" way of displaying the design pattern at hand; not take focus away from it. I can remove it if you like. I prefer not to complicate the interactive mode any further so that the focus on this design pattern can be the pattern itself. :)

Comment thread event-asynchronous/README.md Outdated
title: Event-based Asynchronous
folder: event-asynchronous
permalink: /patterns/event-asynchronous/
categories: Other
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.

We should use Concurrency category

System.out.println("Event [" + aEventId + "] has been stopped.");
eventManager.cancel(sEventId);
System.out.println("Event [" + sEventId + "] has been stopped.");

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.

Can we change the output so that it tells whether we are talking about sync or async event. For example "Async event [xxx] has been created" and "Sync event [xxx] has been created"?

} catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException e) {
System.out.println(e.getMessage());
}
}
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.

We should add tests to run operations from start to finish also. Create and start event and wait for it to finish. For async operations we could create multiple events and wait for all of them to finish.

long endTime = currentTime + (eventTime * 1000);
while (System.currentTimeMillis() < endTime) {
try {
Thread.sleep(5000); // Sleep for 5 seconds.
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.

I think the granularity should be 1 seconds instead of 5 seconds here.

@waisuan
Copy link
Copy Markdown
Contributor Author

waisuan commented Sep 27, 2016

Hey, @iluwatar . Your feedback has been noted. I'll get to them sometime this week.

@waisuan
Copy link
Copy Markdown
Contributor Author

waisuan commented Oct 3, 2016

Gonna work on this today. :)

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.02%) to 83.273% when pulling 8f1758c on waisuan:master into 4ca205c on iluwatar:master.

@waisuan
Copy link
Copy Markdown
Contributor Author

waisuan commented Oct 3, 2016

Done, @iluwatar

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

@waisuan the interactive mode cannot be triggered with a change to config.properties file. I changed the property to INTERACTIVEMODE=YES and ran the program in IntelliJ Idea. I also tried placing the config.properties file to the same folder as the produced event-asynchronous-1.14.0-SNAPSHOT.jar and running the jar with java -cp event-asynchronous-1.14.0-SNAPSHOT.jar com.iluwatar.event.asynchronous.App. The app still runs in non-interactive mode. Am I missing something or how does it work for you?

I propose you put the config.properties in src/main/resources to fix this issue.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.8%) to 83.531% when pulling 7031812 on waisuan:master into 4ca205c on iluwatar:master.

@waisuan
Copy link
Copy Markdown
Contributor Author

waisuan commented Oct 17, 2016

Not sure what happened there, @iluwatar . It works on Eclipse. Regardless, I've moved the config file into a separate directory as suggested.

@iluwatar iluwatar merged commit 0f7b44c into iluwatar:master Oct 18, 2016
@iluwatar
Copy link
Copy Markdown
Owner

@waisuan work well done! Thank you for the new pattern contribution 👍

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.

3 participants