-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EDU-2293: Update source code for "Run your first app in Java"
* Change amount from double to int * Added toggles to control the success of the deposit and refund * Add compensation mechanism to refund failed deposit JIRA: https://temporalio.atlassian.net/browse/EDU-2293
- Loading branch information
1 parent
e276c21
commit 80c4add
Showing
7 changed files
with
85 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
// @@@SNIPSTART money-transfer-java-activity-implementation | ||
package moneytransferapp; | ||
|
||
import io.temporal.activity.*; | ||
|
||
public class AccountActivityImpl implements AccountActivity { | ||
// Mock up the withdrawal of an amount of money from the source account | ||
@Override | ||
public void withdraw(String accountId, String referenceId, double amount) { | ||
public void withdraw(String accountId, String referenceId, int amount) { | ||
System.out.printf( | ||
"\nWithdrawing $%.2f from account %s.\n[ReferenceId: %s]\n", | ||
"\nWithdrawing $%d from account %s.\n[ReferenceId: %s]\n", | ||
amount, accountId, referenceId | ||
); | ||
} | ||
|
||
// Mock up the deposit of an amount of money from the destination account | ||
@Override | ||
public void deposit(String accountId, String referenceId, double amount) { | ||
public void deposit(String accountId, String referenceId, int amount, boolean activityShouldSucceed) { | ||
System.out.printf( | ||
"\nDepositing $%.2f into account %s.\n[ReferenceId: %s]\n", | ||
"\nDepositing $%d into account %s.\n[ReferenceId: %s]\n", | ||
amount, accountId, referenceId | ||
); | ||
|
||
// TO SIMULATE AN ACTIVITY ERROR: Uncomment the following line | ||
// throw Activity.wrap(new RuntimeException("Simulated Activity error")); | ||
if (!activityShouldSucceed) { | ||
System.out.println("Deposit failed"); | ||
throw Activity.wrap(new RuntimeException("Simulated Activity error during deposit of funds")); | ||
} | ||
} | ||
} | ||
// @@@SNIPEND |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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