Finished readme
This commit is contained in:
parent
d247c0a7ce
commit
ca6d4ca71e
29
README.MD
29
README.MD
@ -1,5 +1,17 @@
|
||||
***
|
||||
Použité návrhové vzory:
|
||||
**Funkční požadavky:**
|
||||
- F1: package node
|
||||
- F2: package operation
|
||||
- F3: OperationBase / lastOperation
|
||||
- F4: FoodChainReportVisitor
|
||||
- F5: package channel
|
||||
- F6: scénář double-spending-scenario.xml + kontrola při změně productState (konkr. změna na stav IN_REQUIREMENT)
|
||||
- F7: lastOperation se nastavuje pouze v konstruktoru a není možné ji ji přepsat zpětně => nelze odsimulovat
|
||||
- F8: Product => setStateTo...()
|
||||
- F9: Requirement + NodeBase / update()
|
||||
- F10: package reporting
|
||||
***
|
||||
**Použité návrhové vzory:**
|
||||
- Facade - FactoryManager
|
||||
- Object pool - Skupina tříd v package pool
|
||||
- Simple factory - Skupina tříd v package factory
|
||||
@ -9,5 +21,18 @@ Použité návrhové vzory:
|
||||
- Visitor - Skupina tříd použitá v reportingu
|
||||
- Singleton - Využit u poolů a factory
|
||||
- Builder - Report builder
|
||||
|
||||
***
|
||||
**Nefunkční požadavky:**
|
||||
- Aplikace nepožaduje autentizaci ani autorizaci.
|
||||
- Do konzole se při každém ticku vypisují provedené úkony. Z toho pak vzniká PartiesReport.
|
||||
- V systému není centrální autorita, jednotlivé nody na sebe nevidí a jediná třída přes kterou procházejí všechny transakce je SignatureManager, který je v tomto směru naprosto neutrální. Aplikace běží pouze v jednom threadu.
|
||||
- Všechny proměnné jsou private nebo protected. Většina proměnných je final, abychom se vyhnuli např. změtným úpravám transakcí.
|
||||
- SignatureManager přidává na transakce Signature, které následně i validuje. Node zahazuje (ukládá jako neplatné) všechny nevalidní transakce.
|
||||
- Reporty se generují do stejnojmenných textových souborů.
|
||||
- Konfigurace probíhá pomocí XML souborů (defaultně ve složce conf).
|
||||
***
|
||||
**Požadované výstupy:**
|
||||
- Diskrétní kroky jsou realizovány pomocí třídy Ticker resp. metody tick() na jednotlivých třídách.
|
||||
- Diagramy jsou ve složce resources v souboru FoodChain.eap. BahavioralDiagram byl náš prvotní návrh a není aktuální. Ostatní reporty odpovídají realitě.
|
||||
- Javadoc je ve složce resources v souboru FoodChain.html.
|
||||
***
|
||||
@ -85,7 +85,7 @@ public class FoodChain
|
||||
* @param rootElementTag tag to be parsed
|
||||
* @return parser result
|
||||
*/
|
||||
public static ParserResult parseDocument(String path, String rootElementTag)
|
||||
private static ParserResult parseDocument(String path, String rootElementTag)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -104,7 +104,7 @@ public class FoodChain
|
||||
* Parses channels.
|
||||
* @param path file path
|
||||
*/
|
||||
public static void parseChannels(String path)
|
||||
private static void parseChannels(String path)
|
||||
{
|
||||
ParserResult parserResult = parseDocument(path, "channel");
|
||||
List<ParserResultElement> elements = parserResult.getElements();
|
||||
@ -119,7 +119,7 @@ public class FoodChain
|
||||
* Parses nodes.
|
||||
* @param path file path
|
||||
*/
|
||||
public static void parseNodes(String path)
|
||||
private static void parseNodes(String path)
|
||||
{
|
||||
ParserResult parserResult = parseDocument(path, "node");
|
||||
List<ParserResultElement> elements = parserResult.getElements();
|
||||
@ -134,7 +134,7 @@ public class FoodChain
|
||||
* Parses products.
|
||||
* @param path file path
|
||||
*/
|
||||
public static void parseProducts(String path)
|
||||
private static void parseProducts(String path)
|
||||
{
|
||||
ParserResult parserResult = parseDocument(path, "product");
|
||||
List<ParserResultElement> elements = parserResult.getElements();
|
||||
@ -149,7 +149,7 @@ public class FoodChain
|
||||
* Parses scenarios.
|
||||
* @param path file path
|
||||
*/
|
||||
public static void parseScenarios(String path)
|
||||
private static void parseScenarios(String path)
|
||||
{
|
||||
ParserResult parserResult = parseDocument(path, "scenario");
|
||||
List<ParserResultElement> elements = parserResult.getElements();
|
||||
|
||||
@ -57,7 +57,7 @@ public class NodeBase implements ChannelObserver {
|
||||
* @param product product to be sent
|
||||
* @param node receiver node
|
||||
*/
|
||||
public void sendTransaction(Product product, NodeBase node) {
|
||||
private void sendTransaction(Product product, NodeBase node) {
|
||||
try {
|
||||
Transaction transaction = new ProductTransaction(this, node, TransactionType.SALE, product);
|
||||
subscribedChannels.keySet().stream()
|
||||
@ -76,7 +76,7 @@ public class NodeBase implements ChannelObserver {
|
||||
* @param node receiver node
|
||||
* @param prevTransaction previous product transaction
|
||||
*/
|
||||
public void sendTransaction(MonetaryAmount amount, NodeBase node, ProductTransaction prevTransaction) {
|
||||
private void sendTransaction(MonetaryAmount amount, NodeBase node, ProductTransaction prevTransaction) {
|
||||
try {
|
||||
Transaction transaction = new FinancialTransaction(this, node, TransactionType.PURCHASE, amount, prevTransaction);
|
||||
subscribedChannels.keySet().stream()
|
||||
@ -92,7 +92,7 @@ public class NodeBase implements ChannelObserver {
|
||||
*
|
||||
* @param transaction transaction to be received
|
||||
*/
|
||||
public void receiveTransaction(Transaction transaction) {
|
||||
private void receiveTransaction(Transaction transaction) {
|
||||
try {
|
||||
receiveTransaction((ProductTransaction) transaction);
|
||||
} catch (Exception e) {
|
||||
@ -109,7 +109,7 @@ public class NodeBase implements ChannelObserver {
|
||||
*
|
||||
* @param transaction transaction to be received
|
||||
*/
|
||||
public void receiveTransaction(ProductTransaction transaction) {
|
||||
private void receiveTransaction(ProductTransaction transaction) {
|
||||
if (validateSignature(transaction)) {
|
||||
transaction.getProduct().setStateToReadyForReception();
|
||||
transaction.endTransaction();
|
||||
@ -123,7 +123,7 @@ public class NodeBase implements ChannelObserver {
|
||||
*
|
||||
* @param transaction transaction to be received
|
||||
*/
|
||||
public void receiveTransaction(FinancialTransaction transaction) {
|
||||
private void receiveTransaction(FinancialTransaction transaction) {
|
||||
if (validateSignature(transaction)) transaction.endTransaction();
|
||||
else refuseTransaction(transaction);
|
||||
}
|
||||
@ -134,7 +134,7 @@ public class NodeBase implements ChannelObserver {
|
||||
*
|
||||
* @param transaction
|
||||
*/
|
||||
public void refuseTransaction(Transaction transaction) {
|
||||
private void refuseTransaction(Transaction transaction) {
|
||||
transaction.endTransaction();
|
||||
refusedTransactions.add(transaction);
|
||||
}
|
||||
@ -142,7 +142,7 @@ public class NodeBase implements ChannelObserver {
|
||||
/**
|
||||
* Receives all transactions for this node.
|
||||
*/
|
||||
public void receiveTransactions() {
|
||||
private void receiveTransactions() {
|
||||
subscribedChannels.keySet().forEach(ch -> ch.getTransactions(this).forEach(t -> {
|
||||
receiveTransaction(t);
|
||||
ch.disposeOf(t);
|
||||
@ -187,7 +187,7 @@ public class NodeBase implements ChannelObserver {
|
||||
* @param req requirement to be accepted
|
||||
* @throws InsufficientResourcesException if product is unavailable
|
||||
*/
|
||||
public void acceptRequirement(Requirement req) throws InsufficientResourcesException {
|
||||
private void acceptRequirement(Requirement req) throws InsufficientResourcesException {
|
||||
LOGGER.log(Level.INFO, this.nodeType.toString() + " accepted " + req.toString());
|
||||
if (req.getTransactionType() == TransactionType.SALE) {
|
||||
createRequirement(TransactionType.PURCHASE, req.getProductType(), req.getProductName(), req.getPrice());
|
||||
@ -296,7 +296,7 @@ public class NodeBase implements ChannelObserver {
|
||||
* @param transaction transaction to be validated
|
||||
* @return signature is valid
|
||||
*/
|
||||
public boolean validateSignature(Transaction transaction) {
|
||||
private boolean validateSignature(Transaction transaction) {
|
||||
return SignatureManager.validateSignature(transaction);
|
||||
}
|
||||
|
||||
@ -306,7 +306,7 @@ public class NodeBase implements ChannelObserver {
|
||||
* @param req requirement
|
||||
* @return creator is valid
|
||||
*/
|
||||
boolean senderPurchaserCheck(Requirement req) {
|
||||
private boolean senderPurchaserCheck(Requirement req) {
|
||||
NodeType creatorType = req.getCreator().nodeType;
|
||||
|
||||
return !req.getCreator().equals(this) &&
|
||||
@ -321,7 +321,7 @@ public class NodeBase implements ChannelObserver {
|
||||
* @param channel channel
|
||||
* @return requirement type corresponds with channel subscription type
|
||||
*/
|
||||
boolean transactionSubscriptionCheck(Requirement requirement, ChannelBase channel) {
|
||||
private boolean transactionSubscriptionCheck(Requirement requirement, ChannelBase channel) {
|
||||
switch (subscribedChannels.get(channel)) {
|
||||
case SALE:
|
||||
return requirement.getTransactionType() == TransactionType.SALE;
|
||||
@ -340,7 +340,7 @@ public class NodeBase implements ChannelObserver {
|
||||
* @param req requirement
|
||||
* @return product is available or node has enough money
|
||||
*/
|
||||
boolean requirementCheck(Requirement req) {
|
||||
private boolean requirementCheck(Requirement req) {
|
||||
Product product = storage.getProduct(req.getProductName(), req.getProductType());
|
||||
return (req.getTransactionType() == TransactionType.SALE && money.isGreaterThanOrEqualTo(req.getPrice())) ||
|
||||
(req.getTransactionType() == TransactionType.PURCHASE && product != null &&
|
||||
|
||||
@ -8,7 +8,7 @@ import java.util.List;
|
||||
* @param <T> pool type
|
||||
*/
|
||||
public abstract class PoolListBase<T> {
|
||||
List<T> pool;
|
||||
protected List<T> pool;
|
||||
|
||||
public PoolListBase() {
|
||||
pool = new LinkedList<T>();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user