| org.cougaar.core.plugin.ComponentPlugin org.cougaar.pizza.plugin.PlaceOrderPlugin
All known Subclasses: org.cougaar.pizza.plugin.SDPlaceOrderPlugin,
PlaceOrderPlugin | public class PlaceOrderPlugin extends ComponentPlugin (Code) | | This plugin orders the pizza for a pizza party. It subscribes to a
PizzaPreferences object
published by the
InvitePlugin when it knows how much of what kind of pizza to order.
On receiving the PizzaPreferences, it creates and publishes a Task with the Verb
"Order" and a Direct Object of type Pizza (Asset). Next, it expands the Order Task
into a workflow of two subtasks, one subtask per type of pizza with a quantity
Preference for the number of servings needed. To place the order, it allocates the subtasks
to its pizza provider, Joes Local Pizza Shack. This customer/provider relationship is
defined in the XML configuration files and is established when the agents start up. See
PizzaNode1.xml and PizzaNode2.xml for details.
In this example, the plugin cannot successfully complete the pizza order because Joe's
Local Pizza Shack doesn't make veggie pizzas. The final result is a failed Expansion
on the parent order Task due to the failed Allocation of the veggie pizza subtask.
|
Method Summary | |
protected void | allocateSubtasks(Collection subtasks, Entity provider) Creates and publishes Allocations for each subtask in the collection. | protected Task | createOrderTask() Returns a Task for ordering pizza. | protected Collection | createPizzaSubtasks(PizzaPreferences pizzaPrefs, Task parentTask) Returns a Collection of subtasks for ordering meat and veggie pizzas. | protected void | execute() When there are changes to the plugins's subscriptions, we:
1) When the PizzaPreferences arrives, create the root Order Task, and expand
it by the types of pizza. | protected Expansion | getChangedExpansion() Returns the Expansion that was changed (the one and only typically). | protected PizzaPreferences | getPizzaPreferences() Returns any added PizzaPreferences object from the PizzaPreferences Subscription. | protected Entity | getProvider() Returns a pizza provider for this agent. | protected Entity | getSelfEntity() Returns the Entity representing the agent. | public void | load() Loads services used by the plugin. | protected void | logExpansionResults(Expansion exp) Log (at SHOUT) the results of the given Expansion, showing
what was ordered, how much, from whom, and with what success. | protected void | makeExpansion(Task parentTask, Collection subtasks) Creates and adds an Expansion on a Task and publishes it to the blackboard. | protected PizzaAsset | makePizzaAsset(String assetType) Creates an instance of a PizzaAsset of the
specified asset type. | protected Preference | makeQuantityPreference(int value) Returns a quantity Preference, representing the number of servings of pizza to order.
Creates a Preference with a Strictly-at ScoringFunction and a
quantity AspectType from the specified value. | protected NewTask | makeTask(Verb verb, Asset directObject) Returns a NewTask. | protected String | printAllocationResults(PlanElement pe) | protected String | printExpansionResults(Expansion exp) | public void | setDomainService(DomainService aDomainService) Services that are absolutely required by the plugin can be loaded via introspection
by the binding utility instead of explicitly getting each service from the
ServiceBroker in load(). | protected void | setupSubscriptions() Initialize the subcriptions the plugin is interested in: self Entity, the PizzaPreferences,
and existing Allocations or Expansions or Order Tasks. | protected void | updateOrderAllocationResults() Updates the estimated AllocationResults with reported AllocationResults. |
ALLOCATION_PRED | final protected static UnaryPredicate ALLOCATION_PRED(Code) | | This predicate matches Allocations on "Order" tasks.
|
EXPANSION_PRED | final protected static UnaryPredicate EXPANSION_PRED(Code) | | This predicate matches Expansions on "Order" tasks.
|
PIZZA_PREF_PRED | final protected static UnaryPredicate PIZZA_PREF_PRED(Code) | | This predicate matches PizzaPreferences objects.
|
SELF_PRED | final protected static UnaryPredicate SELF_PRED(Code) | | This predicate matches the Entity object of the agent.
|
allocateSubtasks | protected void allocateSubtasks(Collection subtasks, Entity provider)(Code) | | Creates and publishes Allocations for each subtask in the collection. The Allocation
includes: the provider assigned to compelete the task, an estimated AllocationResult,
and the Role of PizzaProvider. The estimated AllocationResult includes: an
estimated confidence rating of 0.25 and success is true. Valid range for the
confidence rating is between 0 and 1. The assumption is, as the subtasks are
completed, the allocation results will become closer to 1. The Allocations are then
published to the blackboard.
Parameters: subtasks - a collection of subtasks to be allocated Parameters: provider - the provider to which the subtasks are allocated |
createOrderTask | protected Task createOrderTask()(Code) | | Returns a Task for ordering pizza. Creates a Task with Verb "Order", makes a Pizza
asset and sets it as the direct object of the task. Next, it publishes the task to
the blackboard.
a task for ordering pizza |
createPizzaSubtasks | protected Collection createPizzaSubtasks(PizzaPreferences pizzaPrefs, Task parentTask)(Code) | | Returns a Collection of subtasks for ordering meat and veggie pizzas. Creates a meat
pizza subtask and a veggie pizza subtask. The number of individuals requesting meat
and veggie pizzas are obtained from the PizzaPreferences object. A quantity
Preference is created to represent the number of servings needed and is added to the
appropriate subtask. The parentTask is set as the parent of the subtasks.
Parameters: pizzaPrefs - contains the number of people requesting meat or veggie pizzas Parameters: parentTask - the parent of the subtasks a Collection of pizza subtasks |
execute | protected void execute()(Code) | | When there are changes to the plugins's subscriptions, we:
1) When the PizzaPreferences arrives, create the root Order Task, and expand
it by the types of pizza. Then allocate these to the available provider.
2) Propagate up any changed Allocation Results
3) See if the root Expansion changed. If so, we may be done.
|
getChangedExpansion | protected Expansion getChangedExpansion()(Code) | | Returns the Expansion that was changed (the one and only typically).
Checks the changed collection on the
Subscription. If the collection is not empty, it returns the first element. If empty
it returns null.
the Expansion that was changed if any |
getPizzaPreferences | protected PizzaPreferences getPizzaPreferences()(Code) | | Returns any added PizzaPreferences object from the PizzaPreferences Subscription. Checks the
added collection on the subscription and returns the first element in the
collection. Will return null if the added collection is empty.
Note that since we only check the Added list, this method will only return an object
once in our application. This keeps the plugin from publishing
the Order Tasks each time the plugin runs.
first PizzaPrefereneces object from the subscription |
getProvider | protected Entity getProvider()(Code) | | Returns a pizza provider for this agent. Get all relationships that match the Role
of PizzaProvider from the RelationshipSchedule. Return the provider Entity from
the first Relationship found. If there are no pizza provider relationships, null
will be returned.
a pizza provider Entity |
getSelfEntity | protected Entity getSelfEntity()(Code) | | Returns the Entity representing the agent. Checks the self entity subscription and
returns the first element. In this example, there should be only one self entity.
Will return null if the subscription is empty.
the Entity representing the agent. |
load | public void load()(Code) | | Loads services used by the plugin.
|
logExpansionResults | protected void logExpansionResults(Expansion exp)(Code) | | Log (at SHOUT) the results of the given Expansion, showing
what was ordered, how much, from whom, and with what success.
Parameters: exp - The Expansion of the root Order task, whose details we print |
makeExpansion | protected void makeExpansion(Task parentTask, Collection subtasks)(Code) | | Creates and adds an Expansion on a Task and publishes it to the blackboard. An
Expansion is created containing a Workflow of the specified subtasks. This Expansion
is set to the parent task. The subtasks are published to the blackboard first, then
the Expansion is published.
Parameters: parentTask - the parent task to be expanded Parameters: subtasks - the collection of subtasks to be added to the Workflow of Expansion |
makePizzaAsset | protected PizzaAsset makePizzaAsset(String assetType)(Code) | | Creates an instance of a PizzaAsset of the
specified asset type. Adds an ItemIdentification property group to the pizzaAsset
instance marking the pizza type.
Parameters: assetType - the name of the type of asset (veg/meat) a PizzaAsset |
makeQuantityPreference | protected Preference makeQuantityPreference(int value)(Code) | | Returns a quantity Preference, representing the number of servings of pizza to order.
Creates a Preference with a Strictly-at ScoringFunction and a
quantity AspectType from the specified value. In other words,
says I want this many, and you get 0 credit for any more or less.
Parameters: value - the number required a Preference requesting that number of items exactly |
makeTask | protected NewTask makeTask(Verb verb, Asset directObject)(Code) | | Returns a NewTask. Creates a task with the specified verb and sets the Asset as the
direct object.
Parameters: verb - the verb of the newtask Parameters: directObject - asset that this Task is acting on a NewTask |
setDomainService | public void setDomainService(DomainService aDomainService)(Code) | | Services that are absolutely required by the plugin can be loaded via introspection
by the binding utility instead of explicitly getting each service from the
ServiceBroker in load(). The setter methods are called after the component is
constructed but before the state methods such as initialize, load,
setupSubscriptions, etc. If the service is not available at that time, the component
will be unloaded.
|
setupSubscriptions | protected void setupSubscriptions()(Code) | | Initialize the subcriptions the plugin is interested in: self Entity, the PizzaPreferences,
and existing Allocations or Expansions or Order Tasks.
|
updateOrderAllocationResults | protected void updateOrderAllocationResults()(Code) | | Updates the estimated AllocationResults with reported AllocationResults.
Remember that the infrastructure sets the ReportedResult for you (in this case,
by copying it from the provider agent when the provider settles the Task), but
you must copy that up typically.
Checks the
changed collection on the Allocation subscription. If the collection is not empty,
it retrieves the Allocation PlanElement from the subscription. If the reported
AllocationResults have changed, the results are udpated and a publish change is
called on the PlanElement. The reported AllocationResults are changed by the
provider assigned to the task.
|
|
|