Class ThreadSafeBazaar<T>
- java.lang.Object
-
- org.eclipse.emfforms.bazaar.internal.BazaarImpl<T>
-
- org.eclipse.emfforms.bazaar.internal.ThreadSafeBazaar<T>
-
- Type Parameters:
T- the type of product produced by thisBazaar
- All Implemented Interfaces:
Bazaar<T>
public final class ThreadSafeBazaar<T> extends BazaarImpl<T>
A thread-safe implementation of theBazaar. It supports any number of threads concurrently creating products, to the exclusion of at most one thread changing the bazaar's configuration (adding/removing vendors, context functions, and so on).- Author:
- Christian W. Damus
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.emfforms.bazaar.Bazaar
Bazaar.Builder<T>, Bazaar.PriorityOverlapCallBack<T>
-
-
Constructor Summary
Constructors Constructor Description ThreadSafeBazaar()Initializes me.ThreadSafeBazaar(java.util.Collection<? extends Vendor<? extends T>> vendors, java.util.Map<java.lang.String,? extends BazaarContextFunction> contextFunctions, Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)Initializes me with an initial configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddContextFunction(java.lang.String key, BazaarContextFunction contextFunction)Adds aBazaarContextFunctionto thisBazaarto exchange existing parameters to a parameter requested by aVendor.voidaddVendor(Vendor<? extends T> vendor)Adds aVendorto the bazaar.TcreateProduct(BazaarContext bazaarContext)Creates a product of type T, provided by theVendorwith the highestBidand which is statisfied by the parameters in theBazaarContext.java.util.List<T>createProducts(BazaarContext bazaarContext)Creates a list of products of type T, provided byVendors which are statisfied by the parameters in theBazaarContext, ordered by theirBid.voidremoveVendor(Vendor<? extends T> vendor)Removes aVendorfrom the bazaar.voidsetPriorityOverlapCallBack(Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)-
Methods inherited from class org.eclipse.emfforms.bazaar.internal.BazaarImpl
addContextFunctions, checkPreConditions, createEclipseContext, createProduct, getBestVendor
-
-
-
-
Constructor Detail
-
ThreadSafeBazaar
public ThreadSafeBazaar()
Initializes me.
-
ThreadSafeBazaar
public ThreadSafeBazaar(java.util.Collection<? extends Vendor<? extends T>> vendors, java.util.Map<java.lang.String,? extends BazaarContextFunction> contextFunctions, Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)
Initializes me with an initial configuration.- Parameters:
vendors- optional vendors to add (may benullif not needed)contextFunctions- optional context functions to add (may benullif not needed)priorityOverlapCallBack- optional overlap call-back to set (may benullif not needed)
-
-
Method Detail
-
createProduct
public T createProduct(BazaarContext bazaarContext)
Description copied from interface:BazaarCreates a product of type T, provided by theVendorwith the highestBidand which is statisfied by the parameters in theBazaarContext. In case of tied bids, theBazaar.PriorityOverlapCallBackif one is set will be notified of which vendor is chosen to break the tie. Note that during the bidding process, ties may have to be broken in this way that are later defeated by a higher bid.- Specified by:
createProductin interfaceBazaar<T>- Overrides:
createProductin classBazaarImpl<T>- Parameters:
bazaarContext- theBazaarContext, which is used to provide requested parameters forVendor- Returns:
- the product provided by the best
Vendor - See Also:
Bazaar.createProduct(org.eclipse.emfforms.bazaar.BazaarContext)
-
createProducts
public java.util.List<T> createProducts(BazaarContext bazaarContext)
Description copied from interface:BazaarCreates a list of products of type T, provided byVendors which are statisfied by the parameters in theBazaarContext, ordered by theirBid. Ties are not broken as all bids are successful and are used only for ordering.- Specified by:
createProductsin interfaceBazaar<T>- Overrides:
createProductsin classBazaarImpl<T>- Parameters:
bazaarContext- theBazaarContext, which is used to provide requested parameters forVendor- Returns:
- a list of products ordered by the highest
Bid - See Also:
Bazaar.createProducts(org.eclipse.emfforms.bazaar.BazaarContext)
-
addVendor
public void addVendor(Vendor<? extends T> vendor)
Description copied from interface:BazaarAdds aVendorto the bazaar. Will be queried if a product is requested, the best fitting will create the product. Has no effect if thevendoris already present in this bazaar.
-
removeVendor
public void removeVendor(Vendor<? extends T> vendor)
Description copied from interface:BazaarRemoves aVendorfrom the bazaar. Has no effect if thevendoris not present in this bazaar.- Specified by:
removeVendorin interfaceBazaar<T>- Overrides:
removeVendorin classBazaarImpl<T>- Parameters:
vendor- theVendorto remove
-
addContextFunction
public void addContextFunction(java.lang.String key, BazaarContextFunction contextFunction)Description copied from interface:BazaarAdds aBazaarContextFunctionto thisBazaarto exchange existing parameters to a parameter requested by aVendor.- Specified by:
addContextFunctionin interfaceBazaar<T>- Overrides:
addContextFunctionin classBazaarImpl<T>- Parameters:
key- the key of a requested parameter, which can be exchanged from other available parameters in theBazaarContextby thisBazaarContextFunctioncontextFunction- theBazaarContextFunctionbeing able to exchange to the requested parameter
-
setPriorityOverlapCallBack
public void setPriorityOverlapCallBack(Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)
Description copied from interface:Bazaar- Specified by:
setPriorityOverlapCallBackin interfaceBazaar<T>- Overrides:
setPriorityOverlapCallBackin classBazaarImpl<T>- Parameters:
priorityOverlapCallBack- a PriorityOverlapCallBack
-
-