T
- the type of product produced by this Bazaar
public final class ThreadSafeBazaar<T> extends BazaarImpl<T>
Bazaar
.
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).Bazaar.Builder<T>, Bazaar.PriorityOverlapCallBack<T>
Constructor and Description |
---|
ThreadSafeBazaar()
Initializes me.
|
ThreadSafeBazaar(Collection<? extends Vendor<? extends T>> vendors,
Map<String,? extends BazaarContextFunction> contextFunctions,
Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)
Initializes me with an initial configuration.
|
Modifier and Type | Method and Description |
---|---|
void |
addContextFunction(String key,
BazaarContextFunction contextFunction)
Adds a
BazaarContextFunction to this Bazaar to exchange existing parameters to a parameter
requested by a Vendor . |
void |
addVendor(Vendor<? extends T> vendor)
Adds a
Vendor to the bazaar. |
T |
createProduct(BazaarContext bazaarContext)
Creates a product of type T, provided by the
Vendor with the highest Bid and which is statisfied
by the parameters in the BazaarContext . |
List<T> |
createProducts(BazaarContext bazaarContext)
Creates a list of products of type T, provided by
Vendor s which are statisfied by the parameters in the
BazaarContext , ordered by their Bid . |
void |
removeVendor(Vendor<? extends T> vendor)
Removes a
Vendor from the bazaar. |
void |
setPriorityOverlapCallBack(Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)
|
addContextFunctions, checkPreConditions, createEclipseContext, createProduct, getBestVendor
public ThreadSafeBazaar()
public ThreadSafeBazaar(Collection<? extends Vendor<? extends T>> vendors, Map<String,? extends BazaarContextFunction> contextFunctions, Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)
vendors
- optional vendors to add (may be null
if not needed)contextFunctions
- optional context functions to add (may be null
if not needed)priorityOverlapCallBack
- optional overlap call-back to set (may be null
if not needed)public T createProduct(BazaarContext bazaarContext)
Bazaar
Vendor
with the highest Bid
and which is statisfied
by the parameters in the BazaarContext
. In case of tied bids, the Bazaar.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.createProduct
in interface Bazaar<T>
createProduct
in class BazaarImpl<T>
bazaarContext
- the BazaarContext
, which is used to provide requested parameters for Vendor
Vendor
Bazaar.createProduct(org.eclipse.emfforms.bazaar.BazaarContext)
public List<T> createProducts(BazaarContext bazaarContext)
Bazaar
Vendor
s which are statisfied by the parameters in the
BazaarContext
, ordered by their Bid
. Ties are not broken as all bids are successful
and are used only for ordering.createProducts
in interface Bazaar<T>
createProducts
in class BazaarImpl<T>
bazaarContext
- the BazaarContext
, which is used to provide requested parameters for Vendor
Bid
Bazaar.createProducts(org.eclipse.emfforms.bazaar.BazaarContext)
public void addVendor(Vendor<? extends T> vendor)
Bazaar
Vendor
to the bazaar. Will be queried if a product is requested, the best fitting will create the
product. Has no effect if the vendor
is already present in this bazaar.public void removeVendor(Vendor<? extends T> vendor)
Bazaar
Vendor
from the bazaar. Has no effect if the vendor
is not present in this bazaar.removeVendor
in interface Bazaar<T>
removeVendor
in class BazaarImpl<T>
vendor
- the Vendor
to removepublic void addContextFunction(String key, BazaarContextFunction contextFunction)
Bazaar
BazaarContextFunction
to this Bazaar
to exchange existing parameters to a parameter
requested by a Vendor
.addContextFunction
in interface Bazaar<T>
addContextFunction
in class BazaarImpl<T>
key
- the key of a requested parameter, which can be exchanged from other available parameters in the
BazaarContext
by this BazaarContextFunction
contextFunction
- the BazaarContextFunction
being able to exchange to the requested parameterpublic void setPriorityOverlapCallBack(Bazaar.PriorityOverlapCallBack<? super T> priorityOverlapCallBack)
Bazaar
setPriorityOverlapCallBack
in interface Bazaar<T>
setPriorityOverlapCallBack
in class BazaarImpl<T>
priorityOverlapCallBack
- a PriorityOverlapCallBackCopyright © 2018. All rights reserved.