Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FUCoin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DistributedSystems4Students
FUCoin
Commits
555a1eb0
Unverified
Commit
555a1eb0
authored
8 years ago
by
Luca Keidel
Browse files
Options
Downloads
Patches
Plain Diff
Implemented a basic version of a random transaction
parent
8da179f4
No related branches found
No related tags found
1 merge request
!5
Configuration system
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/fucoin/configurations/DefaultConfiguration.java
+42
-3
42 additions, 3 deletions
...main/java/fucoin/configurations/DefaultConfiguration.java
with
42 additions
and
3 deletions
src/main/java/fucoin/configurations/DefaultConfiguration.java
+
42
−
3
View file @
555a1eb0
package
fucoin.configurations
;
import
akka.actor.ActorRef
;
import
akka.pattern.Patterns
;
import
akka.util.Timeout
;
import
fucoin.actions.control.ActionWalletSendMoney
;
import
fucoin.actions.transaction.ActionGetAmount
;
import
fucoin.actions.transaction.ActionGetAmountAnswer
;
import
fucoin.actions.transaction.ActionNotifyObserver
;
import
fucoin.configurations.internal.ConfigurationName
;
import
scala.concurrent.Await
;
import
scala.concurrent.Future
;
import
scala.concurrent.duration.Duration
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Random
;
/**
* This configuration is the previous default of 2 wallets with GUI and a supervisor.
...
...
@@ -11,6 +22,12 @@ import fucoin.configurations.internal.ConfigurationName;
@ConfigurationName
(
"Default Configuration"
)
public
class
DefaultConfiguration
extends
AbstractConfiguration
{
private
Random
rand
;
public
DefaultConfiguration
(){
rand
=
new
Random
();
}
@Override
public
void
run
()
{
initSupervisor
();
...
...
@@ -18,19 +35,41 @@ public class DefaultConfiguration extends AbstractConfiguration {
ActorRef
wallet1
=
null
;
ActorRef
wallet2
=
null
;
try
{
wallet1
=
spawnWallet
(
"Wallet0"
,
fals
e
);
wallet1
=
spawnWallet
(
"Wallet0"
,
tru
e
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Wallet0 spawning timed out"
);
}
try
{
wallet2
=
spawnWallet
(
"Wallet1"
,
fals
e
);
wallet2
=
spawnWallet
(
"Wallet1"
,
tru
e
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Wallet1 spawning timed out"
);
}
/*
if (wallet1 != null && wallet2 != null) {
wallet1.tell(new ActionWalletSendMoney(wallet2.path().name(), 50, getSelf()), wallet1);
}
*/
try
{
randomTransaction
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
private
void
randomTransaction
()
throws
Exception
{
List
<
ActorRef
>
wallets
=
wallets
();
Collections
.
shuffle
(
wallets
);
ActorRef
sender
=
wallets
.
get
(
0
);
ActorRef
recipient
=
wallets
.
get
(
1
);
Timeout
timeout
=
new
Timeout
(
Duration
.
create
(
10
,
"seconds"
));
Future
<
Object
>
future
=
Patterns
.
ask
(
sender
,
new
ActionGetAmount
(),
timeout
);
ActionGetAmountAnswer
answer
=
(
ActionGetAmountAnswer
)
Await
.
result
(
future
,
timeout
.
duration
());
int
transferAmount
=
rand
.
nextInt
(
answer
.
amount
);
sender
.
tell
(
new
ActionWalletSendMoney
(
recipient
.
path
().
name
(),
transferAmount
,
self
()),
self
());
}
@Override
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment