Class NodeBase

    • Field Detail

      • LOGGER

        protected static final java.util.logging.Logger LOGGER
      • refusedTransactions

        private final java.util.List<Transaction> refusedTransactions
      • refusedRequirements

        private final java.util.List<RefusedRequirement> refusedRequirements
      • money

        private javax.money.MonetaryAmount money
      • margin

        private final double margin
      • acceptableDiscount

        private final double acceptableDiscount
      • storage

        protected final Storage storage
      • allowedSeller

        protected NodeType allowedSeller
      • allowedPurchaser

        protected NodeType allowedPurchaser
    • Constructor Detail

      • NodeBase

        public NodeBase()
      • NodeBase

        public NodeBase​(double m,
                        double margin,
                        double acceptableDiscount)
    • Method Detail

      • sendTransaction

        private void sendTransaction​(Product product,
                                     NodeBase node)
        Sends product transaction to node through a channel based on its type.
        Parameters:
        product - product to be sent
        node - receiver node
      • sendTransaction

        private void sendTransaction​(javax.money.MonetaryAmount amount,
                                     NodeBase node,
                                     ProductTransaction prevTransaction)
        Sends financial transaction to node through a channel based on previous transaction type.
        Parameters:
        amount - amount to be sent
        node - receiver node
        prevTransaction - previous product transaction
      • receiveTransaction

        private void receiveTransaction​(Transaction transaction)
        Receives (processes) transaction.
        Parameters:
        transaction - transaction to be received
      • receiveTransaction

        private void receiveTransaction​(ProductTransaction transaction)
        Receives (validates) product transaction and sends financial transaction as response.
        Parameters:
        transaction - transaction to be received
      • receiveTransaction

        private void receiveTransaction​(FinancialTransaction transaction)
        Receives (validates) financial transaction.
        Parameters:
        transaction - transaction to be received
      • refuseTransaction

        private void refuseTransaction​(Transaction transaction)
        Adds transaction to refused transactions.
        Parameters:
        transaction -
      • receiveTransactions

        private void receiveTransactions()
        Receives all transactions for this node.
      • createRequirement

        public void createRequirement​(TransactionType tType,
                                      ProductType pType,
                                      java.lang.String pName,
                                      javax.money.MonetaryAmount price)
                               throws javax.naming.InsufficientResourcesException
        Creates requirement based on data provided.
        Parameters:
        tType - transaction type
        pType - product type
        pName - product name
        price - product price
        Throws:
        javax.naming.InsufficientResourcesException - if product is unavailable
      • acceptRequirement

        private void acceptRequirement​(Requirement req)
                                throws javax.naming.InsufficientResourcesException
        Accepts requirement and creates response.
        Parameters:
        req - requirement to be accepted
        Throws:
        javax.naming.InsufficientResourcesException - if product is unavailable
      • subscribeToChannel

        public void subscribeToChannel​(ChannelBase channel,
                                       ChannelSubscriptionType type)
        Adds channel to subscribed channels with correct type.
        Parameters:
        channel - channel to be subscribed
        type - type of subscription
      • unsubscribeFromChannel

        public void unsubscribeFromChannel​(ChannelBase channel)
        Removes channel from subscribed channels.
        Parameters:
        channel -
      • doAction

        public void doAction​(ProductOperationType action,
                             java.lang.String name)
                      throws java.lang.IllegalCallerException,
                             javax.naming.InsufficientResourcesException
        Proceed specific type of action on provided product if its possible. (Propagated to its storage).
        Parameters:
        action - type of product operation to do
        name - product to proceed
        Throws:
        java.lang.IllegalCallerException
        javax.naming.InsufficientResourcesException
      • doAction

        public void doAction​(ProductOperationType action)
        Calls specific ProductOperation on each product in stock (Propagated to its storage).
        Parameters:
        action - ProductOperationType
      • getStorage

        public Storage getStorage()
      • getNodeType

        public NodeType getNodeType()
      • getMoney

        public javax.money.MonetaryAmount getMoney()
      • getRefusedTransactions

        public java.util.List<Transaction> getRefusedTransactions()
      • getRefusedRequirements

        public java.util.List<RefusedRequirement> getRefusedRequirements()
      • getAllowedSeller

        public NodeType getAllowedSeller()
      • getAllowedPurchaser

        public NodeType getAllowedPurchaser()
      • getMargin

        public double getMargin()
      • getAcceptableDiscount

        public double getAcceptableDiscount()
      • addMoney

        public void addMoney​(javax.money.MonetaryAmount m)
        Adds amount to current assets
        Parameters:
        m - amount to be added
      • subtractMoney

        public void subtractMoney​(javax.money.MonetaryAmount m)
        Subtracts amount from current assets.
        Parameters:
        m - amount to be subtracted
      • validateSignature

        private boolean validateSignature​(Transaction transaction)
        Validates signature on transaction.
        Parameters:
        transaction - transaction to be validated
        Returns:
        signature is valid
      • senderPurchaserCheck

        private boolean senderPurchaserCheck​(Requirement req)
        Checks if requirement creator is an allowed purchaser or allowed seller.
        Parameters:
        req - requirement
        Returns:
        creator is valid
      • transactionSubscriptionCheck

        private boolean transactionSubscriptionCheck​(Requirement requirement,
                                                     ChannelBase channel)
        Checks if requirement type corresponds with channel subscription type.
        Parameters:
        requirement - requirement
        channel - channel
        Returns:
        requirement type corresponds with channel subscription type
      • requirementCheck

        private boolean requirementCheck​(Requirement req)
        Chacks if product is available or if node has enough money
        Parameters:
        req - requirement
        Returns:
        product is available or node has enough money
      • update

        public void update​(Requirement requirement,
                           ChannelBase channel)
        Chacks incomming requirement.
        Specified by:
        update in interface ChannelObserver
        Parameters:
        requirement - requirement
        channel - channel
      • tick

        public void tick()
        Receives transactions and passes tick to storage.