Source Code Cross Referenced for LogisticsManagerPlugin.java in  » Science » Cougaar12_4 » org » cougaar » logistics » plugin » manager » 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.manager 
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.logistics.plugin.manager;
027:
028:        import java.util.*;
029:
030:        import org.cougaar.core.blackboard.IncrementalSubscription;
031:        import org.cougaar.core.component.ServiceBroker;
032:        import org.cougaar.core.component.ServiceRevokedListener;
033:        import org.cougaar.core.component.ServiceRevokedEvent;
034:        import org.cougaar.planning.plugin.legacy.SimplePlugin;
035:        import org.cougaar.core.service.LoggingService;
036:        import org.cougaar.core.service.UIDService;
037:        import org.cougaar.core.service.community.CommunityService;
038:
039:        import org.cougaar.multicast.AttributeBasedAddress;
040:
041:        import org.cougaar.util.UnaryPredicate;
042:
043:        /**
044:         * Test implementation to verify that ABAMessages are reaching the
045:         * Manager agent. Logs all added/modified/removed LoadIndicators
046:         */
047:        public class LogisticsManagerPlugin extends SimplePlugin {
048:            private IncrementalSubscription myLoadIndicators;
049:            private IncrementalSubscription myFallingBehindPolicies;
050:
051:            private UIDService myUIDService;
052:            private LoggingService myLoggingService;
053:
054:            private double myFallingBehindValue = UNINITIALIZED;
055:
056:            Collection myCommunitiesToManage;
057:
058:            private static double UNINITIALIZED = -1.0;
059:
060:            // From FallingBehind values in the playbook
061:            private static double NORMAL = .5;
062:            private static double MODERATE = 1.0;
063:            private static double SEVERE = 2.0;
064:            private static double MAX_FALLING_BEHIND_VALUE = SEVERE;
065:            private static double DEFAULT_FALLING_BEHIND_VALUE = NORMAL;
066:
067:            private static UnaryPredicate myLoadIndicatorsPred = new UnaryPredicate() {
068:                public boolean execute(Object o) {
069:                    if (o instanceof  LoadIndicator) {
070:                        return true;
071:                    } else {
072:                        return false;
073:                    }
074:                }
075:            };
076:
077:            private static UnaryPredicate myFallingBehindPoliciesPred = new UnaryPredicate() {
078:                public boolean execute(Object o) {
079:                    if (o instanceof  FallingBehindPolicy) {
080:                        return true;
081:                    } else {
082:                        return false;
083:                    }
084:                }
085:            };
086:
087:            protected void setupSubscriptions() {
088:                myUIDService = (UIDService) getBindingSite().getServiceBroker()
089:                        .getService(this , UIDService.class, null);
090:
091:                myLoggingService = (LoggingService) getBindingSite()
092:                        .getServiceBroker().getService(this ,
093:                                LoggingService.class, null);
094:
095:                myLoadIndicators = (IncrementalSubscription) subscribe(myLoadIndicatorsPred);
096:                myFallingBehindPolicies = (IncrementalSubscription) subscribe(myFallingBehindPoliciesPred);
097:
098:                // Find name of community to monitor
099:                String filter = "(CommunityManager="
100:                        + getAgentIdentifier().toString() + ")";
101:                myCommunitiesToManage = getCommunityService()
102:                        .listParentCommunities(null, filter, null);
103:
104:                if (myCommunitiesToManage.isEmpty()) {
105:                    myLoggingService.warn(getAgentIdentifier()
106:                            + " is not a CommunityManager."
107:                            + " Plugin will not be receiving LoadIndicators.");
108:                }
109:
110:                if (didRehydrate()) {
111:                    myFallingBehindValue = communityFallingBehindValue();
112:                }
113:
114:                if (myFallingBehindValue == UNINITIALIZED) {
115:                    myFallingBehindValue = DEFAULT_FALLING_BEHIND_VALUE;
116:                }
117:
118:                if (myFallingBehindPolicies.size() == 0) {
119:                    createFallingBehindPolicies();
120:                }
121:
122:            }
123:
124:            public void execute() {
125:
126:                if (myLoggingService.isDebugEnabled()) {
127:                    for (Iterator iterator = myLoadIndicators
128:                            .getAddedCollection().iterator(); iterator
129:                            .hasNext();) {
130:                        myLoggingService.debug("New LoadIndicator: "
131:                                + ((LoadIndicator) iterator.next()).toString());
132:                    }
133:
134:                    for (Iterator iterator = myLoadIndicators
135:                            .getChangedCollection().iterator(); iterator
136:                            .hasNext();) {
137:                        myLoggingService.debug("Modified LoadIndicator: "
138:                                + ((LoadIndicator) iterator.next()).toString());
139:                    }
140:
141:                    for (Iterator iterator = myLoadIndicators
142:                            .getRemovedCollection().iterator(); iterator
143:                            .hasNext();) {
144:                        myLoggingService.debug("Removed LoadIndicator: "
145:                                + ((LoadIndicator) iterator.next()).toString());
146:                    }
147:                }
148:
149:                if (myLoadIndicators.hasChanged()) {
150:                    double currentFallingBehindValue = communityFallingBehindValue();
151:
152:                    if (myFallingBehindValue != currentFallingBehindValue) {
153:                        myFallingBehindValue = currentFallingBehindValue;
154:                        adjustFallingBehindPolicy();
155:
156:                    }
157:                }
158:            }
159:
160:            protected double getFallingBehindValue() {
161:                return myFallingBehindValue;
162:            }
163:
164:            private double communityFallingBehindValue() {
165:                double FallingBehindValue = -1;
166:
167:                for (Iterator iterator = myLoadIndicators.getCollection()
168:                        .iterator(); iterator.hasNext();) {
169:                    double nextFallingBehindValue = loadStatusToFallingBehindValue(((LoadIndicator) iterator
170:                            .next()));
171:
172:                    FallingBehindValue = Math.max(FallingBehindValue,
173:                            nextFallingBehindValue);
174:
175:                    if (FallingBehindValue == MAX_FALLING_BEHIND_VALUE) {
176:                        // Exit loop because we can't get any worse
177:                        break;
178:                    }
179:                }
180:
181:                return FallingBehindValue;
182:            }
183:
184:            private double loadStatusToFallingBehindValue(
185:                    LoadIndicator loadIndicator) {
186:                String loadStatus = loadIndicator.getLoadStatus();
187:
188:                if (loadStatus.equals(LoadIndicator.NORMAL_LOAD)) {
189:                    return NORMAL;
190:                } else if (loadStatus.equals(LoadIndicator.MODERATE_LOAD)) {
191:                    return MODERATE;
192:                } else if (loadStatus.equals(LoadIndicator.SEVERE_LOAD)) {
193:                    return SEVERE;
194:                } else {
195:                    myLoggingService.warn("Unrecognized load status: "
196:                            + loadStatus);
197:                    return UNINITIALIZED;
198:                }
199:            }
200:
201:            private void adjustFallingBehindPolicy() {
202:                if (myLoggingService.isDebugEnabled()) {
203:                    myLoggingService
204:                            .debug("Modifying FallingBehindPolicy: new falling behind =  "
205:                                    + getFallingBehindValue());
206:                }
207:
208:                FallingBehindPolicy fallingBehindPolicy;
209:
210:                for (Iterator iterator = myFallingBehindPolicies.iterator(); iterator
211:                        .hasNext();) {
212:                    fallingBehindPolicy = (FallingBehindPolicy) iterator.next();
213:                    fallingBehindPolicy
214:                            .setFallingBehindValue(getFallingBehindValue());
215:                    publishChange(fallingBehindPolicy);
216:                }
217:
218:            }
219:
220:            /**
221:             * Gets reference to CommunityService.
222:             */
223:            private CommunityService getCommunityService() {
224:                ServiceBroker sb = getBindingSite().getServiceBroker();
225:                if (sb.hasService(CommunityService.class)) {
226:                    return (CommunityService) sb.getService(this ,
227:                            CommunityService.class,
228:                            new ServiceRevokedListener() {
229:                                public void serviceRevoked(
230:                                        ServiceRevokedEvent re) {
231:                                }
232:                            });
233:                } else {
234:                    myLoggingService.error("CommunityService not available");
235:                    return null;
236:                }
237:            }
238:
239:            private void createFallingBehindPolicies() {
240:                // Publish default falling behind policy
241:                for (Iterator iterator = myCommunitiesToManage.iterator(); iterator
242:                        .hasNext();) {
243:                    FallingBehindPolicy fallingBehindPolicy = new FallingBehindPolicy(
244:                            getFallingBehindValue());
245:                    fallingBehindPolicy.setUID(myUIDService.nextUID());
246:                    String community = (String) iterator.next();
247:                    fallingBehindPolicy.setTarget(AttributeBasedAddress
248:                            .getAttributeBasedAddress(community, "Role",
249:                                    "Member"));
250:                    publishAdd(fallingBehindPolicy);
251:                }
252:            }
253:
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.