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
c4478ffd
Commit
c4478ffd
authored
9 years ago
by
rimesime
Browse files
Options
Downloads
Patches
Plain Diff
adding common interface
parent
4cbe7478
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Interface/AbstractWallet.java
+109
-0
109 additions, 0 deletions
Interface/AbstractWallet.java
Interface/Wallet.java
+55
-0
55 additions, 0 deletions
Interface/Wallet.java
with
164 additions
and
0 deletions
Interface/AbstractWallet.java
0 → 100644
+
109
−
0
View file @
c4478ffd
import
java.util.HashMap
;
import
akka.actor.ActorRef
;
import
akka.actor.UntypedActor
;
import
java.io.Serializable
;
public
abstract
class
AbstractWallet
extends
UntypedActor
implements
Serializable
{
// Returns some neighbors that might be used as local
// and/or local neighborsUntypedActor
public
static
class
ActionJoin
implements
Serializable
{}
public
class
ActionJoinAnswer
implements
Serializable
{
public
final
HashMap
<
String
,
ActorRef
>
someNeighbors
=
new
HashMap
<>();
}
// Used to push the state of my/a wallet to another participant
public
static
class
ActionStoreOrUpdate
implements
Serializable
{
public
final
AbstractWallet
w
;
public
ActionStoreOrUpdate
(
AbstractWallet
w
)
{
this
.
w
=
w
;
}
}
// May be used to delete a stored Wallet on another participant
public
static
class
ActionInvalidate
implements
Serializable
{
final
String
name
;
public
ActionInvalidate
(
String
name
)
{
this
.
name
=
name
;
}
}
// Used to send (positive amount) or retreive money (negative amount)
public
static
class
ActionReceiveTransaction
implements
Serializable
{
final
public
int
amount
;
public
ActionReceiveTransaction
(
int
amount
)
{
this
.
amount
=
amount
;
}
}
// Used to search a Wallet by name, i.e. when we want to
// perform a transaction on it
public
static
class
ActionSearchWalletReference
implements
Serializable
{
final
String
name
;
public
ActionSearchWalletReference
(
String
name
)
{
this
.
name
=
name
;
}
}
// Used to return a Wallet
public
static
class
ActionSearchWalletReferenceAnswer
implements
Serializable
{
final
AbstractWallet
w
;
public
ActionSearchWalletReferenceAnswer
(
AbstractWallet
w
)
{
this
.
w
=
w
;
}
}
// Used to search a Wallet by name, i.e. the own wallet if we just
// joined the network
public
static
class
ActionSearchMyWallet
implements
Serializable
{
final
String
name
;
public
ActionSearchMyWallet
(
String
name
)
{
this
.
name
=
name
;
}
}
// Constructor
public
AbstractWallet
(
String
name
)
{
this
.
name
=
name
;
}
// Returns the name of this wallet, e.g. "Lieschen Müller"
public
String
getName
()
{
return
this
.
name
;
}
// Returns the akka-style address as String, which
// could be converted to an ActorRef object later
public
abstract
String
getAddress
();
// Performs housekeeping operations, e.g. pushes
// backedUpNeighbor-entries to other neighbors
public
abstract
void
leave
();
// The which receives Action objects
public
abstract
void
onReceive
(
Object
message
);
// Holds references to neighbors that were in
// contact with this wallet during runtime;
// The key corresponds to the Wallet's name
public
transient
HashMap
<
String
,
ActorRef
>
knownNeighbors
;
// Holds references to neighbors this wallet
// synchronizes itself to (the Wallet object);
// The key corresponds to the Wallet's name
public
transient
HashMap
<
String
,
ActorRef
>
localNeighbors
;
// Holds all Wallets from network participants
// which synchronize their state (Wallet object)
// with us;
// The key corresponds to the Wallet's name
public
transient
HashMap
<
String
,
AbstractWallet
>
backedUpNeighbors
;
// The name of this wallet (does never change, no
// duplicates in network assumed)
public
final
String
name
;
// The amount this wallet currently holds
public
int
amount
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Interface/Wallet.java
0 → 100644
+
55
−
0
View file @
c4478ffd
import
akka.actor.ActorRef
;
import
akka.actor.UntypedActor
;
import
akka.actor.ActorSystem
;
import
akka.actor.Props
;
import
akka.actor.Inbox
;
import
java.io.Serializable
;
public
class
Wallet
extends
AbstractWallet
{
public
static
void
main
(
String
[]
args
)
{
// Create the 'helloakka' actor system
final
ActorSystem
system
=
ActorSystem
.
create
(
"FuCoin"
);
// Create the 'greeter' actor
final
ActorRef
greeter
=
system
.
actorOf
(
Props
.
create
(
Wallet
.
class
),
"wallet"
);
// Create the "actor-in-a-box"
final
Inbox
inbox
=
Inbox
.
create
(
system
);
}
public
Wallet
(
String
name
)
{
super
(
name
);
}
public
void
onReceive
(
Object
message
)
{
// TODO implement
/*
if (message instanceof ActionReceiveTransaction)
{
System.out.println("hello, " + ((ActionReceiveTransaction) message).amount;
}
else if (message instanceof ActionReceiveTransaction) {
// Send the current greeting back to the sender
getSender().tell(new ActionReceiveTransaction(0.01), getSelf());
}
else {
unhandled(message);
}
*/
}
public
String
getAddress
()
{
// TODO implement
return
""
;
}
public
void
leave
()
{
// TODO implement
}
}
\ No newline at end of file
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