Source Code Cross Referenced for ClusterOPlan.java in  » Science » Cougaar12_4 » org » cougaar » glm » plugins » 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.glm.plugins 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:         */
026:        package org.cougaar.glm.plugins;
027:
028:        import java.io.Serializable;
029:        import java.util.Enumeration;
030:        import java.util.Vector;
031:
032:        import org.cougaar.util.TimeSpan;
033:        import org.cougaar.util.MutableTimeSpan;
034:        import org.cougaar.core.blackboard.IncrementalSubscription;
035:        import org.cougaar.core.mts.MessageAddress;
036:        import org.cougaar.core.util.UID;
037:        import org.cougaar.glm.ldm.oplan.Oplan;
038:        import org.cougaar.glm.ldm.oplan.OrgActivity;
039:        import org.cougaar.glm.ldm.plan.GeolocLocation;
040:
041:        /**
042:         * Object for holding meta-data about the OPlan on the blackboard.
043:         **/
044:        public class ClusterOPlan implements  Serializable {
045:            MessageAddress clusterId_;
046:            long startTime_, endTime_;
047:            Vector orgActivities_ = null;
048:            Oplan oplan_;
049:
050:            //      IncrementalSubscription orgActivitySubscription_;
051:
052:            public ClusterOPlan(MessageAddress id, Oplan op/*, IncrementalSubscription sub*/) {
053:                //  	System.out.println("--- Creating ClusterOPlan for "+id+", oplan "+op);
054:                clusterId_ = id;
055:                oplan_ = op;
056:                startTime_ = oplan_.getCday().getTime();
057:                endTime_ = startTime_ + 1;
058:                //    endTime_ = oplan_.getEndDay().getTime();
059:                //  	orgActivitySubscription_ = sub;
060:                //  	updateOrgActivities(orgActivitySubscription_.elements());
061:                //  	updateOPlanTimes();
062:            }
063:
064:            /* If OPlan does not change but OrgActivities for the OPlan change
065:             * then get the updated OrgActivities.
066:             */
067:            public boolean updateOrgActivities(
068:                    IncrementalSubscription orgActivitySubscription_) {
069:                // Only update OrgActivities if subscription has changed
070:                if (orgActivitySubscription_.getChangedList().hasMoreElements()
071:                        || orgActivitySubscription_.getAddedList()
072:                                .hasMoreElements()
073:                        || orgActivitySubscription_.getRemovedList()
074:                                .hasMoreElements()) {
075:                    //  	    System.out.println("--- New/Changed/Removed OrgActivities for "+clusterId_);
076:                    updateOrgActivities(orgActivitySubscription_.elements());
077:                    updateOPlanTimes();
078:                    return true;
079:                }
080:                return false;
081:            }
082:
083:            // Re-calculate the overall start and end times for the OPlan
084:            protected void updateOPlanTimes() {
085:                long end_time;
086:                long newET = Long.MIN_VALUE;
087:                long start_time;
088:                long newST = Long.MAX_VALUE;
089:                OrgActivity activity;
090:                Enumeration activities = orgActivities_.elements();
091:
092:                // initialize endTime/startTime values
093:                if (activities.hasMoreElements()) {
094:                    activity = (OrgActivity) activities.nextElement();
095:                    newET = getEndTime(activity);
096:                    newST = getStartTime(activity);
097:                }
098:
099:                // search for first/last times
100:                while (activities.hasMoreElements()) {
101:                    activity = (OrgActivity) activities.nextElement();
102:                    end_time = getEndTime(activity);
103:                    if ((end_time > newET)) {
104:                        newET = end_time;
105:                    }
106:                    start_time = getStartTime(activity);
107:                    if (start_time < newST) {
108:                        newST = start_time;
109:                    }
110:                }
111:
112:                if (newET != endTime_ || newST != startTime_) {
113:                    //System.out.println("ClusterOplan at " + clusterId_ + " updating startTime from " + startTime_ + " to " + newST + ", and endTime from " + endTime_ + " to " + newET);
114:                    synchronized (this ) {
115:                        endTime_ = newET;
116:                        startTime_ = newST;
117:                    }
118:                }
119:            }
120:
121:            public void updateOrgActivities(Enumeration activities) {
122:                orgActivities_ = new Vector();
123:                OrgActivity orgact;
124:                String cluster_name = clusterId_.toString();
125:                while (activities.hasMoreElements()) {
126:                    // only deal w/ org activities for this cluster
127:                    orgact = (OrgActivity) activities.nextElement();
128:                    if (orgact.getOrgID().equals(cluster_name)) {
129:                        //  		System.out.println("--- Adding OrgActivity for "+clusterId_+", activity "+orgact.getActivityName()+
130:                        //  				   ", "+orgact.getOpTempo()+", "+orgact);
131:                        orgActivities_.add(orgact);
132:                    }
133:                }
134:            }
135:
136:            /* getOplan() returns the OPlan UID this object is handling
137:             */
138:            public UID getOplanUID() {
139:                return oplan_.getUID();
140:            }
141:
142:            public long getEndTime(OrgActivity act) {
143:                return act.getTimeSpan().getEndDate().getTime();
144:            }
145:
146:            public long getStartTime(OrgActivity act) {
147:                return act.getTimeSpan().getStartDate().getTime();
148:            }
149:
150:            /* Latest end time of the OrgActivities
151:             * If no orgActivities are received, end time is not set
152:             * <b>WARN</b>: This is not safe, particularly if you will be comparing to StartTime. Use #getOplanSpan()
153:             */
154:            public long getEndTime() {
155:                return endTime_;
156:            }
157:
158:            /* Earliest start time of the OrgActivities
159:             * If no orgActivities are received, start time is not set
160:             * <b>WARN</b>: This is not safe, particularly if you will be comparing to EndTime. Use #getOplanSpan()
161:             */
162:            public long getStartTime() {
163:                return startTime_;
164:            }
165:
166:            /**
167:             * Return the current start and end times (longs) of the OPlan
168:             **/
169:            public synchronized TimeSpan getOplanSpan() {
170:                MutableTimeSpan ts = new MutableTimeSpan();
171:                try {
172:                    ts.setTimeSpan(startTime_, endTime_);
173:                } catch (IllegalArgumentException iae) {
174:                    System.err
175:                            .println(clusterId_
176:                                    + " ClusterOPlan has invalid oplan start/end times. Start: "
177:                                    + startTime_ + ", End: " + endTime_);
178:                }
179:                return ts;
180:            }
181:
182:            public GeolocLocation getGeoLoc(long time) {
183:                OrgActivity oa = getOrgActivity(time);
184:                if (oa != null) {
185:                    return oa.getGeoLoc();
186:                }
187:                return null;
188:            }
189:
190:            public String getOpTempo(long time) {
191:                OrgActivity oa = getOrgActivity(time);
192:                if (oa != null) {
193:                    return oa.getOpTempo();
194:                }
195:                return null;
196:            }
197:
198:            public long getOplanCday() {
199:                return oplan_.getCday().getTime();
200:            }
201:
202:            public OrgActivity getOrgActivity(long t) {
203:                long end_time, start_time;
204:                Enumeration en = orgActivities_.elements();
205:                OrgActivity oa;
206:                while (en.hasMoreElements()) {
207:                    oa = (OrgActivity) en.nextElement();
208:                    start_time = getStartTime(oa);
209:                    end_time = getEndTime(oa);
210:                    if ((t >= start_time) && (t < end_time)) {
211:                        return oa;
212:                    }
213:                }
214:                return null;
215:            }
216:
217:            //      /* When disposing of a ClusterOPlan object, need to get the
218:            //       * OrgActivity subscription to do an 'unsubscribe'
219:            //       */
220:            //      public IncrementalSubscription getOrgActivitySubscription() {
221:            //  	return orgActivitySubscription_;
222:            //      }
223:
224:            public String toString() {
225:                return oplan_.toString();
226:            }
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.