Source Code Cross Referenced for TransportAllocatorPlugin.java in  » Science » Cougaar12_4 » org » cougaar » logistics » plugin » trans » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.logistics.plugin.trans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 2001-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:         */
026:        package org.cougaar.logistics.plugin.trans;
027:
028:        import org.cougaar.planning.ldm.asset.Asset;
029:
030:        import org.cougaar.planning.ldm.plan.Allocation;
031:        import org.cougaar.planning.ldm.plan.MPTask;
032:        import org.cougaar.planning.ldm.plan.PlanElement;
033:        import org.cougaar.planning.ldm.plan.Task;
034:
035:        import org.cougaar.planning.ldm.plan.AspectType;
036:        import org.cougaar.planning.ldm.plan.AspectValue;
037:
038:        import org.cougaar.lib.filter.UTILSingleTaskAllocatorPlugin;
039:
040:        import java.util.Date;
041:        import java.util.Iterator;
042:        import java.util.List;
043:
044:        import org.cougaar.logistics.ldm.Constants;
045:        import org.cougaar.glm.ldm.asset.Organization;
046:        import org.cougaar.glm.ldm.asset.GLMAsset;
047:
048:        import org.cougaar.lib.callback.UTILExpandableTaskCallback;
049:        import org.cougaar.lib.callback.UTILFilterCallback;
050:        import org.cougaar.lib.callback.UTILGenericListener;
051:
052:        /**
053:         * <pre>
054:         * Plugin that looks for TRANSIT or TRANSPORT tasks.
055:         *
056:         * Will just allocate the task to whatever asset
057:         * is hanging off the WITH prep, since this plugin is meant to paired 
058:         * with and fire after a VishnuAggregatorPlugin.  That plugin 
059:         * indicates the assignment of task to asset by attaching the WITH prep.
060:         * 
061:         * </pre>
062:         */
063:        public class TransportAllocatorPlugin extends
064:                UTILSingleTaskAllocatorPlugin {
065:            /** 
066:             * <pre>
067:             * This plugin is interested in tasks with verb TRANSIT or TRANSPORT 
068:             * The task must also have the VISHNU prep attached, indicating that the Vishnu
069:             * plugin upstream has created the task.
070:             * </pre>
071:             * @param t task to check to see if it is an input task to this plugin
072:             */
073:            public boolean interestingTask(Task t) {
074:                boolean hasTransitVerb = t.getVerb().equals(
075:                        Constants.Verb.TRANSIT);
076:                boolean hasTransportVerb = t.getVerb().equals(
077:                        Constants.Verb.TRANSPORT);
078:                boolean hasVishnu = prepHelper.hasPrepNamed(t, "VISHNU");
079:
080:                if (hasTransitVerb && hasVishnu) {
081:                    if (isDebugEnabled())
082:                        debug(getName()
083:                                + ".interestingTask - interested in TRANSIT task "
084:                                + t.getUID());
085:                    return true;
086:                }
087:
088:                if (hasTransportVerb && hasVishnu) {
089:                    if (isDebugEnabled())
090:                        debug(getName()
091:                                + ".interestingTask - interested in TRANSPORT task "
092:                                + t.getUID());
093:                    return true;
094:                }
095:
096:                if (isDebugEnabled())
097:                    debug(getName() + ".interestingTask - NOT interested in "
098:                            + t.getUID());
099:
100:                return false;
101:            }
102:
103:            /** determines the asset that is allocated to */
104:            public Asset findAsset(Task t) {
105:                Asset found = getAssetFromTask(t);
106:                return found;
107:            }
108:
109:            /** looks at the task's WITH prep to get the asset -- was attached by the aggregator */
110:            protected Asset getAssetFromTask(Task combinedTask) {
111:                Object returnedObj = prepHelper.getIndirectObject(combinedTask,
112:                        Constants.Preposition.WITH);
113:
114:                return (Asset) returnedObj;
115:            }
116:
117:            /**
118:             * Deal with the tasks that we have accumulated.
119:             * Find the asset that is attached to the task 
120:             * (in agents with this plugin the vishnu aggregator makes 
121:             * the task->asset assignment, encoded as a WITH preposition),
122:             * make an allocation, and publish the allocation.
123:             *
124:             * @param List of tasks to handle
125:             * @see #getAssetFromTask
126:             */
127:            public void processTasks(List tasks) {
128:                for (Iterator iter = tasks.iterator(); iter.hasNext();) {
129:                    Task t = (Task) iter.next();
130:                    if (t.getPlanElement() == null) {
131:                        Asset a = findAsset(t);
132:                        PlanElement alloc = createAllocation(t, a);
133:                        publishAddingOfAllocation(alloc);
134:                    } else {
135:                        Object uid = ((Allocation) t.getPlanElement())
136:                                .getAsset().getUID();
137:
138:                        // this will happen when we become aware of changed tasks
139:                        if (isInfoEnabled()) {
140:                            info(getName() + " task " + t.getUID()
141:                                    + " was already allocated to " + uid);
142:                        }
143:
144:                        if (!uid.equals(findAsset(t).getUID())) {
145:                            if (isWarnEnabled()) {
146:                                warn(getName()
147:                                        + " task "
148:                                        + t.getUID()
149:                                        + " was already allocated to "
150:                                        + uid
151:                                        + " but trying to allocate to different asset "
152:                                        + findAsset(t).getUID());
153:                            }
154:                        }
155:                    }
156:                }
157:
158:                tasks.clear();
159:            }
160:
161:            /** 
162:             * <pre>
163:             * Do the actual allocation here
164:             *
165:             * If the asset is an organization, allocate with a MEDIUM confidence, otherwise,
166:             * use a HIGH confidence.
167:             *
168:             * Uses two aspects : START and END time.
169:             *
170:             * </pre>
171:             * @param t the task to allocate 
172:             * @param a the asset to allocate to
173:             * @return the allocation
174:             */
175:            public PlanElement createAllocation(Task t, Asset a) {
176:                Date from = prefHelper.getReadyAt(t);
177:                Date to = prefHelper.getBestDate(t);
178:
179:                double confidence = (((GLMAsset) a).hasOrganizationPG()) ? allocHelper.MEDIUM_CONFIDENCE
180:                        : allocHelper.HIGHEST_CONFIDENCE;
181:
182:                if (isDebugEnabled())
183:                    debug(getName() + ".createAllocation - ready at " + from
184:                            + " - best " + to + " confidence " + confidence);
185:
186:                AspectValue[] values = new AspectValue[2];
187:                values[0] = AspectValue.newAspectValue(AspectType.START_TIME,
188:                        from.getTime());
189:                values[1] = AspectValue.newAspectValue(AspectType.END_TIME, to
190:                        .getTime());
191:
192:                PlanElement pe = allocHelper.makeAllocation(this, ldmf,
193:                        realityPlan, t, a, values, confidence,
194:                        Constants.Role.TRANSPORTER);
195:                return pe;
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.