org.cougaar.pizza.plugin
Class SDPlaceOrderPlugin

java.lang.Object
  extended byorg.cougaar.util.GenericStateModelAdapter
      extended byorg.cougaar.core.blackboard.BlackboardClientComponent
          extended byorg.cougaar.core.plugin.ComponentPlugin
              extended byorg.cougaar.pizza.plugin.PlaceOrderPlugin
                  extended byorg.cougaar.pizza.plugin.SDPlaceOrderPlugin
All Implemented Interfaces:
org.cougaar.core.blackboard.BlackboardClient, org.cougaar.core.component.Component, org.cougaar.util.GenericStateModel, org.cougaar.core.plugin.PluginBase

public class SDPlaceOrderPlugin
extends PlaceOrderPlugin

The SDPlaceOrderPlugin extends the PlaceOrderPlugin to use Service Discovery to find pizza providers dynamically. Once the plugin receives the PizzaPreferences object, it publishes a Constants.Verbs.FIND_PROVIDERS task with a Role of Constants.Roles.PIZZAPROVIDER. This task will be handled by Service Discovery. The plugin then creates and expands the Constants.Verbs.ORDER Task as done in the super class. However, unlike the super class, this plugin waits until Service Discovery has finished finding a pizza provider and has added a Disposition on the FindProviders task before it can allocate the pizza subtasks.

ServiceDiscovery will find a provider, creating a PizzaProvider relationship. Then the plugin continues as in the PlaceOrderPlugin.

If the Expansion on the order task fails, i.e., the provider could not complete the pizza order, then the plugin will remove the Allocations on the subtasks of the Expansion and request a new provider from Service Discovery. To exclude the provider that previously failed, the plugin adds a prepositional phrase of Constants.Prepositions.NOT with the name of the provider as the indirect object on the FindProviders task. Once a new provider is found the tasks will be reallocated -- hopefully more succesfully!


Nested Class Summary
 
Nested classes inherited from class org.cougaar.core.blackboard.BlackboardClient
org.cougaar.core.blackboard.BlackboardClient.Local
 
Field Summary
 
Fields inherited from class org.cougaar.pizza.plugin.PlaceOrderPlugin
ALLOCATION_PRED, allocationSub, domainService, EXPANSION_PRED, expansionSub, logger, PIZZA_PREF_PRED, pizzaPrefSub, planningFactory, SELF_PRED, selfSub
 
Fields inherited from class org.cougaar.core.blackboard.BlackboardClientComponent
agentId, agentIdentificationService, alarmService, blackboard, blackboardClientName
 
Fields inherited from interface org.cougaar.core.plugin.PluginBase
INSERTION_POINT
 
Fields inherited from interface org.cougaar.util.GenericStateModel
ACTIVE, IDLE, LOADED, UNINITIALIZED, UNLOADED
 
Fields inherited from interface org.cougaar.core.blackboard.BlackboardClient
current
 
Constructor Summary
SDPlaceOrderPlugin()
           
 
Method Summary
protected  void execute()
          When we get the PizzaPreferences object (that subscription is changed), ask ServiceDiscovery to find a provider.
protected  org.cougaar.planning.ldm.asset.Entity getProvider(org.cougaar.planning.ldm.plan.Disposition disposition)
          Find a PizzaProvider to try using, avoiding the provider on the given Disposition if any.
protected  void setupSubscriptions()
          Overrides the super class method.
 
Methods inherited from class org.cougaar.pizza.plugin.PlaceOrderPlugin
allocateSubtasks, createOrderTask, createPizzaSubtasks, getChangedExpansion, getPizzaPreferences, getProvider, getSelfEntity, load, logExpansionResults, makeExpansion, makePizzaAsset, makeQuantityPreference, makeTask, printAllocationResults, printExpansionResults, setDomainService, updateOrderAllocationResults
 
Methods inherited from class org.cougaar.core.plugin.ComponentPlugin
getConfigFinder
 
Methods inherited from class org.cougaar.core.blackboard.BlackboardClientComponent
currentTimeMillis, cycle, getAgentIdentifier, getAlarmService, getBindingSite, getBlackboardClientName, getBlackboardService, getMessageAddress, getParameter, getParameters, getServiceBroker, halt, precycle, requestCycle, resume, setAgentIdentificationService, setAlarmService, setBindingSite, setBlackboardService, setParameter, setSchedulerService, setServiceBroker, setSuicideService, shouldExecute, start, stop, suspend, toString, unload, wasAwakened
 
Methods inherited from class org.cougaar.util.GenericStateModelAdapter
getModelState, initialize, transitState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.cougaar.util.GenericStateModel
getModelState, halt, initialize, resume, start, stop, suspend, unload
 

Constructor Detail

SDPlaceOrderPlugin

public SDPlaceOrderPlugin()
Method Detail

setupSubscriptions

protected void setupSubscriptions()
Overrides the super class method. Adds additional subscriptions to Dispositions of the FindProviders Task and our original Order Tasks.

Overrides:
setupSubscriptions in class PlaceOrderPlugin

execute

protected void execute()
When we get the PizzaPreferences object (that subscription is changed), ask ServiceDiscovery to find a provider. Meanwhile, create the root order Task and its expansions - but not yet allocated.

When the FindProviders task is Disposed (a different subscription change), we have a provider. Allocate the Order sub-tasks to that provider.

As in the base class, update the AllocationResults as they come in from our provider.

Finally, when the Expansion of the root Order Task changes, see if we got all our pizza. If not, remove the old Allocations to the old provider, and ask ServiceDiscovery to find another (different) provider. When that FindProviders is disposed, we'll try again...

Overrides:
execute in class PlaceOrderPlugin

getProvider

protected org.cougaar.planning.ldm.asset.Entity getProvider(org.cougaar.planning.ldm.plan.Disposition disposition)
Find a PizzaProvider to try using, avoiding the provider on the given Disposition if any. First, retrieve the excluded provider from the FindProviders task of the Disposition. Get all relationships that match the Role of PizzaProvider from the RelationshipSchedule. Return the first provider found that is not the excluded provider. Returns null if a provider is not found.

Note that only one failed provider can be avoided with this implementation.

Parameters:
disposition - whose previous Provider to avoid
Returns:
a pizza provider Entity to try