Finished readme

This commit is contained in:
Tomáš Musil 2021-01-05 14:37:26 +01:00
parent d247c0a7ce
commit ca6d4ca71e
5 changed files with 45 additions and 20 deletions

View File

@ -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 - Facade - FactoryManager
- Object pool - Skupina tříd v package pool - Object pool - Skupina tříd v package pool
- Simple factory - Skupina tříd v package factory - 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 - Visitor - Skupina tříd použitá v reportingu
- Singleton - Využit u poolů a factory - Singleton - Využit u poolů a factory
- Builder - Report builder - 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.
*** ***

View File

@ -85,7 +85,7 @@ public class FoodChain
* @param rootElementTag tag to be parsed * @param rootElementTag tag to be parsed
* @return parser result * @return parser result
*/ */
public static ParserResult parseDocument(String path, String rootElementTag) private static ParserResult parseDocument(String path, String rootElementTag)
{ {
try try
{ {
@ -104,7 +104,7 @@ public class FoodChain
* Parses channels. * Parses channels.
* @param path file path * @param path file path
*/ */
public static void parseChannels(String path) private static void parseChannels(String path)
{ {
ParserResult parserResult = parseDocument(path, "channel"); ParserResult parserResult = parseDocument(path, "channel");
List<ParserResultElement> elements = parserResult.getElements(); List<ParserResultElement> elements = parserResult.getElements();
@ -119,7 +119,7 @@ public class FoodChain
* Parses nodes. * Parses nodes.
* @param path file path * @param path file path
*/ */
public static void parseNodes(String path) private static void parseNodes(String path)
{ {
ParserResult parserResult = parseDocument(path, "node"); ParserResult parserResult = parseDocument(path, "node");
List<ParserResultElement> elements = parserResult.getElements(); List<ParserResultElement> elements = parserResult.getElements();
@ -134,7 +134,7 @@ public class FoodChain
* Parses products. * Parses products.
* @param path file path * @param path file path
*/ */
public static void parseProducts(String path) private static void parseProducts(String path)
{ {
ParserResult parserResult = parseDocument(path, "product"); ParserResult parserResult = parseDocument(path, "product");
List<ParserResultElement> elements = parserResult.getElements(); List<ParserResultElement> elements = parserResult.getElements();
@ -149,7 +149,7 @@ public class FoodChain
* Parses scenarios. * Parses scenarios.
* @param path file path * @param path file path
*/ */
public static void parseScenarios(String path) private static void parseScenarios(String path)
{ {
ParserResult parserResult = parseDocument(path, "scenario"); ParserResult parserResult = parseDocument(path, "scenario");
List<ParserResultElement> elements = parserResult.getElements(); List<ParserResultElement> elements = parserResult.getElements();

View File

@ -57,7 +57,7 @@ public class NodeBase implements ChannelObserver {
* @param product product to be sent * @param product product to be sent
* @param node receiver node * @param node receiver node
*/ */
public void sendTransaction(Product product, NodeBase node) { private void sendTransaction(Product product, NodeBase node) {
try { try {
Transaction transaction = new ProductTransaction(this, node, TransactionType.SALE, product); Transaction transaction = new ProductTransaction(this, node, TransactionType.SALE, product);
subscribedChannels.keySet().stream() subscribedChannels.keySet().stream()
@ -76,7 +76,7 @@ public class NodeBase implements ChannelObserver {
* @param node receiver node * @param node receiver node
* @param prevTransaction previous product transaction * @param prevTransaction previous product transaction
*/ */
public void sendTransaction(MonetaryAmount amount, NodeBase node, ProductTransaction prevTransaction) { private void sendTransaction(MonetaryAmount amount, NodeBase node, ProductTransaction prevTransaction) {
try { try {
Transaction transaction = new FinancialTransaction(this, node, TransactionType.PURCHASE, amount, prevTransaction); Transaction transaction = new FinancialTransaction(this, node, TransactionType.PURCHASE, amount, prevTransaction);
subscribedChannels.keySet().stream() subscribedChannels.keySet().stream()
@ -92,7 +92,7 @@ public class NodeBase implements ChannelObserver {
* *
* @param transaction transaction to be received * @param transaction transaction to be received
*/ */
public void receiveTransaction(Transaction transaction) { private void receiveTransaction(Transaction transaction) {
try { try {
receiveTransaction((ProductTransaction) transaction); receiveTransaction((ProductTransaction) transaction);
} catch (Exception e) { } catch (Exception e) {
@ -109,7 +109,7 @@ public class NodeBase implements ChannelObserver {
* *
* @param transaction transaction to be received * @param transaction transaction to be received
*/ */
public void receiveTransaction(ProductTransaction transaction) { private void receiveTransaction(ProductTransaction transaction) {
if (validateSignature(transaction)) { if (validateSignature(transaction)) {
transaction.getProduct().setStateToReadyForReception(); transaction.getProduct().setStateToReadyForReception();
transaction.endTransaction(); transaction.endTransaction();
@ -123,7 +123,7 @@ public class NodeBase implements ChannelObserver {
* *
* @param transaction transaction to be received * @param transaction transaction to be received
*/ */
public void receiveTransaction(FinancialTransaction transaction) { private void receiveTransaction(FinancialTransaction transaction) {
if (validateSignature(transaction)) transaction.endTransaction(); if (validateSignature(transaction)) transaction.endTransaction();
else refuseTransaction(transaction); else refuseTransaction(transaction);
} }
@ -134,7 +134,7 @@ public class NodeBase implements ChannelObserver {
* *
* @param transaction * @param transaction
*/ */
public void refuseTransaction(Transaction transaction) { private void refuseTransaction(Transaction transaction) {
transaction.endTransaction(); transaction.endTransaction();
refusedTransactions.add(transaction); refusedTransactions.add(transaction);
} }
@ -142,7 +142,7 @@ public class NodeBase implements ChannelObserver {
/** /**
* Receives all transactions for this node. * Receives all transactions for this node.
*/ */
public void receiveTransactions() { private void receiveTransactions() {
subscribedChannels.keySet().forEach(ch -> ch.getTransactions(this).forEach(t -> { subscribedChannels.keySet().forEach(ch -> ch.getTransactions(this).forEach(t -> {
receiveTransaction(t); receiveTransaction(t);
ch.disposeOf(t); ch.disposeOf(t);
@ -187,7 +187,7 @@ public class NodeBase implements ChannelObserver {
* @param req requirement to be accepted * @param req requirement to be accepted
* @throws InsufficientResourcesException if product is unavailable * @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()); LOGGER.log(Level.INFO, this.nodeType.toString() + " accepted " + req.toString());
if (req.getTransactionType() == TransactionType.SALE) { if (req.getTransactionType() == TransactionType.SALE) {
createRequirement(TransactionType.PURCHASE, req.getProductType(), req.getProductName(), req.getPrice()); createRequirement(TransactionType.PURCHASE, req.getProductType(), req.getProductName(), req.getPrice());
@ -296,7 +296,7 @@ public class NodeBase implements ChannelObserver {
* @param transaction transaction to be validated * @param transaction transaction to be validated
* @return signature is valid * @return signature is valid
*/ */
public boolean validateSignature(Transaction transaction) { private boolean validateSignature(Transaction transaction) {
return SignatureManager.validateSignature(transaction); return SignatureManager.validateSignature(transaction);
} }
@ -306,7 +306,7 @@ public class NodeBase implements ChannelObserver {
* @param req requirement * @param req requirement
* @return creator is valid * @return creator is valid
*/ */
boolean senderPurchaserCheck(Requirement req) { private boolean senderPurchaserCheck(Requirement req) {
NodeType creatorType = req.getCreator().nodeType; NodeType creatorType = req.getCreator().nodeType;
return !req.getCreator().equals(this) && return !req.getCreator().equals(this) &&
@ -321,7 +321,7 @@ public class NodeBase implements ChannelObserver {
* @param channel channel * @param channel channel
* @return requirement type corresponds with channel subscription type * @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)) { switch (subscribedChannels.get(channel)) {
case SALE: case SALE:
return requirement.getTransactionType() == TransactionType.SALE; return requirement.getTransactionType() == TransactionType.SALE;
@ -340,7 +340,7 @@ public class NodeBase implements ChannelObserver {
* @param req requirement * @param req requirement
* @return product is available or node has enough money * @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()); Product product = storage.getProduct(req.getProductName(), req.getProductType());
return (req.getTransactionType() == TransactionType.SALE && money.isGreaterThanOrEqualTo(req.getPrice())) || return (req.getTransactionType() == TransactionType.SALE && money.isGreaterThanOrEqualTo(req.getPrice())) ||
(req.getTransactionType() == TransactionType.PURCHASE && product != null && (req.getTransactionType() == TransactionType.PURCHASE && product != null &&

View File

@ -8,7 +8,7 @@ import java.util.List;
* @param <T> pool type * @param <T> pool type
*/ */
public abstract class PoolListBase<T> { public abstract class PoolListBase<T> {
List<T> pool; protected List<T> pool;
public PoolListBase() { public PoolListBase() {
pool = new LinkedList<T>(); pool = new LinkedList<T>();