|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.ourgrid.peer.community.nof.AccountingManager
public class AccountingManager
Stores the reputation of all known peers. It coordinates the peer's strategies for calculating and maintaining his knowledge about the other peer's reputations. Each peer maintains a map with a balance for each other known peer calculated as a function of the past bilateral interactions between this and each other known peer.
Each peer accounts both for each favor that it makes and each favor that is made to him.
Field Summary | |
---|---|
static double |
DEFAULT_UNKNOWN_PEER_BALANCE
The default value of the reputation of an unknown peer. |
static double |
FACTOR
This factor is a timer scale. |
Method Summary | |
---|---|
protected double |
calculateNewBalance(ObjectID peerID,
double usedTime,
boolean isProviding)
Calculates the new balance based on the use of a given GuM . |
double |
consumerAccount(double usedTime,
double currentProviderBalance)
Calculates the new balance given the used time of a GridMachine and the current balance of a provider peer. |
double |
finishAccounting(GumID gumID,
long requestID,
boolean isProviding)
|
double |
finishAccounting(GumID gumID,
ObjectID peerID,
boolean isProviding)
|
static AccountingManager |
getInstance()
Recover the unique instance of this entity. |
java.util.Map<ObjectID,java.lang.Double> |
getKnownPeerBalances()
Gets a Map containing all the known peer balances. |
java.util.List<java.util.Map.Entry<ObjectID,java.lang.Double>> |
getKnownPeers()
|
double |
getPeerBalance(ObjectID peerID)
Gets the balance of a peer represented by its ID. |
ObjectID |
getPeerIdForRequest(long requestID)
Gets the peer's id of the peer that make the request identified by the given requestID |
protected boolean |
isAKnownPeer(ObjectID peerID)
Verifies if the peer is a known one. |
void |
loadRankingFromFile(java.lang.String fileName)
Loads the ranking from a file. |
double |
providerAccount(double usedTime,
double currentConsumerBalance)
Calculates the new balance given the grid machine used time and the current balance of a consumer peer. |
void |
registerPeerIdForRequest(long requestID,
ObjectID peerID)
Associates an requestID with the peer's id of the peer that has made that request. |
void |
removeRequest(long requestID)
Removed a request from the |
static void |
reset()
Reseting the know instance of AccountManager. |
void |
saveRankingInFile(java.lang.String fileName)
Saves the current ranking to a file. |
void |
startAccounting(GumID gumID,
long requestID)
|
void |
startAccounting(GumID gumID,
ObjectID peerID)
Informs, with accounting purpose, that the usage of a gum has started. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final double DEFAULT_UNKNOWN_PEER_BALANCE
public static final double FACTOR
Method Detail |
---|
public void startAccounting(GumID gumID, long requestID)
public void startAccounting(GumID gumID, ObjectID peerID)
Informs, with accounting purpose, that the usage of a gum has started. Note that it is used both when providing or receiving a machine.
gumID
- The internet name of GridMachine just being used.peerID
- The peer's ID that is receiving or providing the machine.public double finishAccounting(GumID gumID, long requestID, boolean isProviding)
public double finishAccounting(GumID gumID, ObjectID peerID, boolean isProviding)
protected double calculateNewBalance(ObjectID peerID, double usedTime, boolean isProviding)
GuM
.
usedTime
- The used time of this GuM
.peerID
- The peer that is using or providind this GuM
.isProviding
- If the peer is providing the GuM
.
GuM
.public double getPeerBalance(ObjectID peerID)
Gets the balance of a peer represented by its ID.
peerID
- The ID of peer whose balance is wished.
public java.util.List<java.util.Map.Entry<ObjectID,java.lang.Double>> getKnownPeers()
protected boolean isAKnownPeer(ObjectID peerID)
Verifies if the peer is a known one.
peerID
- The peer is
public java.util.Map<ObjectID,java.lang.Double> getKnownPeerBalances()
Gets a Map containing all the known peer balances.
public void saveRankingInFile(java.lang.String fileName) throws java.io.IOException
Saves the current ranking to a file. Currently, this file is written as a Properties file.
fileName
- The name of the file to write into.
java.io.IOException
- If any problem happens while writing the file.public void loadRankingFromFile(java.lang.String fileName)
Loads the ranking from a file.
fileName
- The name of the file to read from.public ObjectID getPeerIdForRequest(long requestID)
requestID
- The request ID.
public void registerPeerIdForRequest(long requestID, ObjectID peerID)
requestID
- The unique identifier for the request.peerID
- the unique identifier for the peer that makes the request.public void removeRequest(long requestID)
requestID
- public static AccountingManager getInstance()
public double providerAccount(double usedTime, double currentConsumerBalance) throws java.lang.IllegalArgumentException
Calculates the new balance given the grid machine used time and the current balance of a consumer peer. Only positives balance are allowed. That is, if the new consumer balance will not be lower than 0 (zero). The new balance is obtained from currentConsumerBalance - usedTime / SimpleAccontant.FACTOR.
usedTime
- The time a GridMachine was used.currentConsumerBalance
- The current balance of a peer
java.lang.IllegalArgumentException
- Thrown when the given used time is
negative.public double consumerAccount(double usedTime, double currentProviderBalance) throws java.lang.IllegalArgumentException
Calculates the new balance given the used time of a GridMachine and the current balance of a provider peer. The new balance is obtained from currentConsumerBalance + usedTime / SimpleAccontant.FACTOR.
usedTime
- The time a GridMachine was used.currentProviderBalance
- The current balance of a peer
java.lang.IllegalArgumentException
- Thrown when the given used time is not
positive.public static void reset()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |