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 void
addContextFunction(java.lang.String key, BazaarContextFunction contextFunction)
Adds aBazaarContextFunction
to thisBazaar
to exchange existing parameters to a parameter requested by aVendor
.void
addVendor(Vendor<? extends T> vendor)
Adds aVendor
to the bazaar.T
createProduct(BazaarContext bazaarContext)
Creates a product of type T, provided by theVendor
with the highestBid
and which is statisfied by the parameters in theBazaarContext
.java.util.List<T>
createProducts(BazaarContext bazaarContext)
Creates a list of products of type T, provided byVendor
s which are statisfied by the parameters in theBazaarContext
, ordered by theirBid
.void
removeVendor(Vendor<? extends T> vendor)
Removes aVendor
from the bazaar.void
setPriorityOverlapCallBack(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 benull
if not needed)contextFunctions
- optional context functions to add (may benull
if not needed)priorityOverlapCallBack
- optional overlap call-back to set (may benull
if not needed)
-
-
Method Detail
-
createProduct
public T createProduct(BazaarContext bazaarContext)
Description copied from interface:Bazaar
Creates a product of type T, provided by theVendor
with the highestBid
and which is statisfied by the parameters in theBazaarContext
. In case of tied bids, theBazaar.PriorityOverlapCallBack
if 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:
createProduct
in interfaceBazaar<T>
- Overrides:
createProduct
in 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:Bazaar
Creates a list of products of type T, provided byVendor
s 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:
createProducts
in interfaceBazaar<T>
- Overrides:
createProducts
in 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:Bazaar
Adds aVendor
to the bazaar. Will be queried if a product is requested, the best fitting will create the product. Has no effect if thevendor
is already present in this bazaar.
-
removeVendor
public void removeVendor(Vendor<? extends T> vendor)
Description copied from interface:Bazaar
Removes aVendor
from the bazaar. Has no effect if thevendor
is not present in this bazaar.- Specified by:
removeVendor
in interfaceBazaar<T>
- Overrides:
removeVendor
in classBazaarImpl<T>
- Parameters:
vendor
- theVendor
to remove
-
addContextFunction
public void addContextFunction(java.lang.String key, BazaarContextFunction contextFunction)
Description copied from interface:Bazaar
Adds aBazaarContextFunction
to thisBazaar
to exchange existing parameters to a parameter requested by aVendor
.- Specified by:
addContextFunction
in interfaceBazaar<T>
- Overrides:
addContextFunction
in classBazaarImpl<T>
- Parameters:
key
- the key of a requested parameter, which can be exchanged from other available parameters in theBazaarContext
by thisBazaarContextFunction
contextFunction
- theBazaarContextFunction
being able to exchange to the requested parameter
-
setPriorityOverlapCallBack
public void setPriorityOverlapCallBack(Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)
Description copied from interface:Bazaar
- Specified by:
setPriorityOverlapCallBack
in interfaceBazaar<T>
- Overrides:
setPriorityOverlapCallBack
in classBazaarImpl<T>
- Parameters:
priorityOverlapCallBack
- a PriorityOverlapCallBack
-
-