001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: * THIS SOFTWARE IS MODIFIED FOR TESTING QUO_ULTRALLOG INTEGRATION
026: */
027: package org.cougaar.lib.quo.performance;
028:
029: import java.util.Enumeration;
030: import java.util.Vector;
031:
032: import org.cougaar.core.blackboard.IncrementalSubscription;
033: import org.cougaar.glm.ldm.asset.Organization;
034: import org.cougaar.glm.ldm.asset.OrganizationPG;
035: import org.cougaar.planning.ldm.asset.Asset;
036: import org.cougaar.planning.ldm.plan.Allocation;
037: import org.cougaar.planning.ldm.plan.AllocationResult;
038: import org.cougaar.planning.ldm.plan.Role;
039: import org.cougaar.planning.ldm.plan.Task;
040: import org.cougaar.planning.ldm.plan.Verb;
041: import org.cougaar.util.UnaryPredicate;
042:
043: /**
044: * This COUGAAR Plugin allocates tasks of verb "CODE"
045: * to Organizations that have the "SoftwareDevelopment" role.
046: *
047: **/
048: public class ManagerAllocatorPlugin extends CommonUtilPlugin {
049:
050: private IncrementalSubscription tasks; // "CODE" tasks
051: private IncrementalSubscription programmers; // SoftwareDevelopment orgs
052: private IncrementalSubscription allocations; // My allocations
053: protected String VERB;//= getParameterValue(getParameters(), "VERB");
054: protected String DEPARTMENT = "SoftwareDevelopment"; //defaults
055:
056: // protected Verb verb = Verb.get(VERB);
057: /**
058: * parsing the plugIn arguments and setting the values for CPUCONSUME and MESSAGESIZE
059: */
060: protected void parseParameter() {
061: Vector p = getParameters();
062: VERB = getParameterValue(p, "VERB");
063: DEPARTMENT = getParameterValue(p, "DEPARTMENT");
064: //System.out.println("ManagerAllocator ===" + DEPARTMENT);
065: }
066:
067: public UnaryPredicate myAllocationPredicate = new UnaryPredicate() {
068: public boolean execute(Object o) {
069: if (o instanceof Allocation) {
070: Task task = ((Allocation) o).getTask();
071:
072: return (task != null)
073: && (task.getVerb().equals(Verb.get(VERB)));
074: }
075: return false;
076: }
077: };
078:
079: /**
080: * Predicate that matches VERB"
081: */
082: private UnaryPredicate myTaskPredicate = new UnaryPredicate() {
083: public boolean execute(Object o) {
084: if (o instanceof Task) {
085: Task task = (Task) o;
086: return task.getVerb().equals(Verb.get(VERB));
087: }
088: return false;
089: }
090: };
091:
092: protected UnaryPredicate myProgrammersPredicate = new UnaryPredicate() {
093: public boolean execute(Object o) {
094: boolean ret = false;
095: if (o instanceof Organization) {
096: Organization org = (Organization) o;
097: OrganizationPG orgPG = org.getOrganizationPG();
098: //ret = orgPG.inRoles(Role.getRole("SoftwareDevelopment"));
099: ret = orgPG.inRoles(Role.getRole(DEPARTMENT));
100: }
101: return ret;
102: }
103: };
104:
105: /**
106: * subscribe to tasks and programming organizations
107: */
108: protected void setupSubscriptions() {
109: parseParameter();
110: tasks = (IncrementalSubscription) subscribe(myTaskPredicate);
111: programmers = (IncrementalSubscription) subscribe(myProgrammersPredicate);
112: allocations = (IncrementalSubscription) subscribe(myAllocationPredicate);
113: }
114:
115: /**
116: * Top level plugin execute loop. Allocate CODE tasks to organizations
117: */
118: protected void execute() {
119: allocateUnallocatedTasks();
120: }
121:
122: /**
123: * Allocate the task to the asset
124: */
125: private void allocateTo(Asset asset, Task task) {
126: AllocationResult estAR = null;
127: Allocation allocation = theLDMF.createAllocation(
128: task.getPlan(), task, asset, estAR, Role.ASSIGNED);
129: publishAdd(allocation);
130: }
131:
132: protected void allocateUnallocatedTasks() {
133: Enumeration task_enum = tasks.elements(); // process unallocated tasks
134: while (task_enum.hasMoreElements()) {
135: Task t = (Task) task_enum.nextElement();
136: if (t.getPlanElement() != null)
137: continue; //already allocated
138: Asset organization = (Asset) programmers.first();
139: if (organization != null) //if no organization yet, give up for now
140: allocateTo(organization, t);
141: }
142: }
143: }
|