Class ChannelBase
- java.lang.Object
-
- cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase
-
- All Implemented Interfaces:
Observable
- Direct Known Subclasses:
FruitChannel,MeatChannel,OtherChannel,VegetableChannel
public abstract class ChannelBase extends java.lang.Object implements Observable
Base class for all channels
-
-
Field Summary
Fields Modifier and Type Field Description protected ProductTypeproductTypeprotected java.util.Queue<Requirement>requirementsprivate java.util.Set<ChannelObserver>subscribersprotected java.util.Queue<Transaction>transactions
-
Constructor Summary
Constructors Constructor Description ChannelBase()ChannelBase(ProductType type)
-
Method Summary
Modifier and Type Method Description voidaddRequirement(Requirement requirement)Adds new requirement to the requirement Queue.voidaddTransaction(Transaction transaction)Adds new transaction to the transaction Queue.voidattach(ChannelObserver observer)Adds observer to list of subscribed nodes.voidclearRequirements()Clears all active requirements from this channel.voiddetach(ChannelObserver observer)Removes observer from list of subscribed nodes.voiddisposeOf(Transaction transaction)Removes transaction from list of unprocessed transactions.voiddisposeOf(Requirement requirement)Removes requirement from list of active requirements.java.util.Queue<Requirement>getCurrentRequirements()ProductTypegetProductType()java.util.Queue<Transaction>getTransactions(NodeBase node)voidnotifyAllObservers()Notifies all nodes apart from creator about a requirement.booleantick()Passes tick onto every requirement in channel, if requirement has TTL= 0 deletes it, notifies all nodes with current requirements.
-
-
-
Field Detail
-
productType
protected ProductType productType
-
requirements
protected java.util.Queue<Requirement> requirements
-
transactions
protected java.util.Queue<Transaction> transactions
-
subscribers
private java.util.Set<ChannelObserver> subscribers
-
-
Constructor Detail
-
ChannelBase
public ChannelBase(ProductType type)
-
ChannelBase
public ChannelBase()
-
-
Method Detail
-
getTransactions
public java.util.Queue<Transaction> getTransactions(NodeBase node)
-
getCurrentRequirements
public java.util.Queue<Requirement> getCurrentRequirements()
-
addRequirement
public void addRequirement(Requirement requirement)
Adds new requirement to the requirement Queue.- Parameters:
requirement- requirement
-
tick
public boolean tick()
Passes tick onto every requirement in channel, if requirement has TTL= 0 deletes it, notifies all nodes with current requirements.- Returns:
- if there are any requirements
-
notifyAllObservers
public void notifyAllObservers()
Notifies all nodes apart from creator about a requirement.- Specified by:
notifyAllObserversin interfaceObservable
-
attach
public void attach(ChannelObserver observer)
Adds observer to list of subscribed nodes.- Specified by:
attachin interfaceObservable- Parameters:
observer- channelobserver
-
detach
public void detach(ChannelObserver observer)
Removes observer from list of subscribed nodes.- Specified by:
detachin interfaceObservable- Parameters:
observer- channelobserver
-
addTransaction
public void addTransaction(Transaction transaction)
Adds new transaction to the transaction Queue.- Parameters:
transaction- transaction
-
disposeOf
public void disposeOf(Requirement requirement)
Removes requirement from list of active requirements.- Parameters:
requirement- requirement
-
disposeOf
public void disposeOf(Transaction transaction)
Removes transaction from list of unprocessed transactions.- Parameters:
transaction- transaction
-
clearRequirements
public void clearRequirements()
Clears all active requirements from this channel.
-
getProductType
public ProductType getProductType()
-
-