Last active
April 4, 2018 05:53
-
-
Save adamw/24b2c234a7b20c2c0c3bb707c91cf669 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package test; | |
| public class Compare4Synchronous { | |
| // data structures | |
| public class ProfileData { | |
| public long getUserId() { return 42; } | |
| } | |
| public class User { | |
| public String getEmail() { return null; } | |
| boolean getNotificationsEnabled() { return false; } | |
| } | |
| // I/O operations: blocking, synchronous | |
| <T> T fetchFromDb(Class<T> entityClass, long id) { return null; } | |
| void sendEmail(String to, String content) { } | |
| void sendHttpPost(String url, Object payload) { } | |
| // the business logic: synchronous, sequence of statements | |
| String runBusinessProcess(ProfileData profileData) { | |
| User user = fetchFromDb(User.class, profileData.getUserId()); | |
| if (user != null) { | |
| sendHttpPost("http://profile_service/post/" + profileData.getUserId(), | |
| profileData); | |
| if (user.getNotificationsEnabled()) { | |
| sendEmail(user.getEmail(), "profile updated"); | |
| } | |
| return "ok"; | |
| } else { | |
| return "user not found"; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment