Source Code Cross Referenced for TPT.java in  » Workflow-Engines » pegasus-2.1.0 » org » griphyn » cPlanner » common » 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 » Workflow Engines » pegasus 2.1.0 » org.griphyn.cPlanner.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file or a portion of this file is licensed under the terms of
003:         * the Globus Toolkit Public License, found in file GTPL, or at
004:         * http://www.globus.org/toolkit/download/license.html. This notice must
005:         * appear in redistributions of this file, with or without modification.
006:         *
007:         * Redistributions of this Software, with or without modification, must
008:         * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009:         * some other similar material which is provided with the Software (if
010:         * any).
011:         *
012:         * Copyright 1999-2004 University of Chicago and The University of
013:         * Southern California. All rights reserved.
014:         */
015:
016:        package org.griphyn.cPlanner.common;
017:
018:        import java.util.Iterator;
019:        import java.util.Collection;
020:        import java.util.TreeMap;
021:        import java.util.Map;
022:        import java.util.Set;
023:        import java.util.HashSet;
024:        import java.util.StringTokenizer;
025:
026:        /**
027:         * A common class, that builds up the third party state for the sites from
028:         * the properties file.
029:         *
030:         *
031:         * @author Karan Vahi
032:         * @version $Revision: 50 $
033:         */
034:
035:        public class TPT {
036:
037:            /**
038:             * The constant to apply to all sites.
039:             */
040:            public static final String ALL_SITES = "*";
041:
042:            /**
043:             * The property name to get the sites for which all transfers need to
044:             * be TPT.
045:             */
046:            public static final String ALL_TPT_PROPERTY = "pegasus.transfer.*.thirdparty.sites";
047:
048:            /**
049:             * The property name to get the sites for which stage-in transfers need to
050:             * be TPT.
051:             */
052:            public static final String STAGE_IN_TPT_PROPERTY = "pegasus.transfer.stagein.thirdparty.sites";
053:
054:            /**
055:             * The property name to get the sites for which inter site transfers need
056:             * to be TPT.
057:             */
058:            public static final String INTER_TPT_PROPERTY = "pegasus.transfer.inter.thirdparty.sites";
059:
060:            /**
061:             * The property name to get the sites for which stage-out transfers need to
062:             * be TPT.
063:             */
064:            public static final String STAGE_OUT_TPT_PROPERTY = "pegasus.transfer.stageout.thirdparty.sites";
065:
066:            /**
067:             * The property name to get the sites for which all TPT transfers need to
068:             * be executed on the remote site.
069:             */
070:            public static final String ALL_TPT_REMOTE_PROPERTY = "pegasus.transfer.*.thirdparty.remote";
071:
072:            /**
073:             * The property name to get the sites for which stage-in TPT transfers need to
074:             * be executed on the remote site.
075:             */
076:            public static final String STAGE_IN_TPT_REMOTE_PROPERTY = "pegasus.transfer.stagein.thirdparty.remote";
077:
078:            /**
079:             * The property name to get the sites for which inter site TPT transfers need to
080:             * be executed on the remote site.
081:             */
082:            public static final String INTER_TPT_REMOTE_PROPERTY = "pegasus.transfer.inter.thirdparty.remote";
083:
084:            /**
085:             * The property name to get the sites for which stage-out TPT transfers need to
086:             * be executed on the remote site.
087:             */
088:            public static final String STAGE_OUT_TPT_REMOTE_PROPERTY = "pegasus.transfer.stageout.thirdparty.remote";
089:
090:            /**
091:             * An internal table that maps third party transfer type to the corresponding
092:             * property.
093:             */
094:            private static Map mPropertyTable;
095:
096:            /**
097:             * The handle to the properties object holding the properties relevant to
098:             * Pegasus.
099:             */
100:            private PegasusProperties mProps;
101:
102:            /**
103:             * The handle to the logging object.
104:             */
105:            private LogManager mLogger;
106:
107:            /**
108:             * The map indexed by site name, that contains the state for all the sites.
109:             */
110:            private Map mStateMap;
111:
112:            /**
113:             * Singleton access to the type table
114:             * Contains the mapping of a property to the third party transfer type
115:             *
116:             * @return map
117:             */
118:            private static Map propertyTable() {
119:                //singleton access
120:                if (mPropertyTable == null) {
121:                    mPropertyTable = new TreeMap();
122:                    mPropertyTable.put(new Integer(TPTState.STAGE_IN_TPT_TYPE),
123:                            STAGE_IN_TPT_PROPERTY);
124:                    mPropertyTable.put(new Integer(TPTState.INTER_TPT_TYPE),
125:                            INTER_TPT_PROPERTY);
126:                    mPropertyTable.put(
127:                            new Integer(TPTState.STAGE_OUT_TPT_TYPE),
128:                            STAGE_OUT_TPT_PROPERTY);
129:                    mPropertyTable.put(new Integer(TPTState.ALL_TPT_TYPE),
130:                            ALL_TPT_PROPERTY);
131:                    mPropertyTable.put(
132:                            new Integer(TPTState.STAGE_IN_TPT_REMOTE),
133:                            STAGE_IN_TPT_REMOTE_PROPERTY);
134:                    mPropertyTable.put(new Integer(TPTState.INTER_TPT_REMOTE),
135:                            INTER_TPT_REMOTE_PROPERTY);
136:                    mPropertyTable.put(new Integer(
137:                            TPTState.STAGE_OUT_TPT_REMOTE),
138:                            STAGE_OUT_TPT_REMOTE_PROPERTY);
139:                    mPropertyTable.put(new Integer(TPTState.ALL_TPT_REMOTE),
140:                            ALL_TPT_REMOTE_PROPERTY);
141:
142:                }
143:                return mPropertyTable;
144:            }
145:
146:            /**
147:             * The default constructor.
148:             */
149:            public TPT() {
150:                mProps = PegasusProperties.getInstance();
151:                mLogger = LogManager.getInstance();
152:                mStateMap = new TreeMap();
153:            }
154:
155:            /**
156:             * The overloaded constructor.
157:             *
158:             * @param properties   handle to the properties required.
159:             */
160:            public TPT(PegasusProperties properties) {
161:                mProps = properties;
162:                mLogger = LogManager.getInstance();
163:                mStateMap = new TreeMap();
164:            }
165:
166:            /**
167:             * Builds up the third party state for all the sites. This reflects what is
168:             * set in the properties file.
169:             */
170:            public void buildState() {
171:                String site;
172:                Set sites;
173:                //build for stagein transfers
174:                buildState(TPTState.STAGE_IN_TPT_TYPE);
175:                buildState(TPTState.STAGE_IN_TPT_REMOTE);
176:
177:                //build for inter site transfers
178:                buildState(TPTState.INTER_TPT_TYPE);
179:                buildState(TPTState.INTER_TPT_REMOTE);
180:
181:                //build for stage out transfers
182:                buildState(TPTState.STAGE_OUT_TPT_TYPE);
183:                buildState(TPTState.STAGE_OUT_TPT_REMOTE);
184:
185:                //build for all transfers
186:                buildState(TPTState.ALL_TPT_TYPE);
187:                buildState(TPTState.ALL_TPT_REMOTE);
188:
189:                //put the all sites (site = *) entry
190:                TPTState allState;
191:                if (containsKey(ALL_SITES)) {
192:                    allState = get(ALL_SITES);
193:                } else {
194:                    allState = new TPTState();
195:                    put(ALL_SITES, allState);
196:                }
197:                if (allState.getState() != 0x0) {
198:                    //apply the state to all sites
199:                    for (Iterator it = mStateMap.values().iterator(); it
200:                            .hasNext();) {
201:                        TPTState state = (TPTState) it.next();
202:                        state.set(allState.getState());
203:                    }
204:                }
205:            }
206:
207:            /**
208:             * Adds to the existing state table, state information for a particular
209:             * type of transfers.
210:             *
211:             * @param type   the type of transfer.
212:             */
213:            private void buildState(int type) {
214:                String property = (String) propertyTable().get(
215:                        new Integer(type));
216:                Set sites = getThirdPartySites((type > TPTState.ALL_TPT_TYPE) ? mProps
217:                        .getThirdPartySitesRemote(property)
218:                        : mProps.getThirdPartySites(property));
219:                String site;
220:                for (Iterator it = sites.iterator(); it.hasNext();) {
221:                    site = (String) it.next();
222:                    TPTState state = containsKey(site) ? get(site)
223:                            : new TPTState();
224:                    state.set(type);
225:                    put(site, state);
226:                }
227:            }
228:
229:            /**
230:             * Returns a boolean indicating whether to use third party transfers for
231:             * stage-in transfers or not.
232:             *
233:             * @return boolean
234:             */
235:            public boolean stageInThirdParty(String site) {
236:                return containsKey(site) ? get(site).get(
237:                        TPTState.STAGE_IN_TPT_TYPE) :
238:                //return the value for all sites
239:                        get(ALL_SITES).get(TPTState.STAGE_IN_TPT_TYPE);
240:            }
241:
242:            /**
243:             * Returns a boolean indicating whether to use third party transfers for
244:             * inter site transfers or not.
245:             *
246:             * @return boolean
247:             */
248:            public boolean interThirdParty(String site) {
249:                return containsKey(site) ? get(site).get(
250:                        TPTState.INTER_TPT_TYPE) :
251:                //return the value for all sites
252:                        get(ALL_SITES).get(TPTState.INTER_TPT_TYPE);
253:            }
254:
255:            /**
256:             * Returns a boolean indicating whether to use third party transfers for
257:             * stage-out transfers or not.
258:             *
259:             * @return boolean
260:             */
261:            public boolean stageOutThirdParty(String site) {
262:                return containsKey(site) ? get(site).get(
263:                        TPTState.STAGE_OUT_TPT_TYPE) :
264:                //return the value for all sites
265:                        get(ALL_SITES).get(TPTState.STAGE_OUT_TPT_TYPE);
266:            }
267:
268:            /**
269:             * Returns a boolean indicating whether to execute third party transfers for
270:             * stage-in on remote site or not.
271:             *
272:             * @return boolean
273:             */
274:            public boolean stageInThirdPartyRemote(String site) {
275:                return containsKey(site) ? get(site).get(
276:                        TPTState.STAGE_IN_TPT_REMOTE) :
277:                //return the value for all sites
278:                        get(ALL_SITES).get(TPTState.STAGE_IN_TPT_REMOTE);
279:            }
280:
281:            /**
282:             * Returns a boolean indicating whether to execute third party transfers for
283:             * inter site on remote site or not.
284:             *
285:             * @return boolean
286:             */
287:            public boolean interThirdPartyRemote(String site) {
288:                return containsKey(site) ? get(site).get(
289:                        TPTState.INTER_TPT_REMOTE) :
290:                //return the value for all sites
291:                        get(ALL_SITES).get(TPTState.INTER_TPT_REMOTE);
292:            }
293:
294:            /**
295:             * Returns a boolean indicating whether to execute third party transfers for
296:             * stage-out on remote site or not.
297:             *
298:             * @return boolean
299:             */
300:            public boolean stageOutThirdPartyRemote(String site) {
301:                return containsKey(site) ? get(site).get(
302:                        TPTState.STAGE_OUT_TPT_REMOTE) :
303:                //return the value for all sites
304:                        get(ALL_SITES).get(TPTState.STAGE_OUT_TPT_REMOTE);
305:            }
306:
307:            /**
308:             * Prints out the third party state for the various sites.
309:             */
310:            public void print() {
311:                StringBuffer sb = new StringBuffer();
312:                TPTState allSitesState = null;
313:                Object key;
314:                sb
315:                        .append("Site | SI_TPT_R, INTER_TPT_R, SO_TPT_R, SI_TPT, IN_TPT , SO_TPT");
316:                for (Iterator it = mStateMap.entrySet().iterator(); it
317:                        .hasNext();) {
318:                    Map.Entry entry = (Map.Entry) it.next();
319:                    key = entry.getKey();
320:                    if (key.equals(ALL_SITES)) {
321:                        //store value for printing in the end
322:                        allSitesState = (TPTState) entry.getValue();
323:                    } else {
324:                        sb.append('\n').append(key).append(" | ").append(
325:                                entry.getValue());
326:                    }
327:                }
328:                if (allSitesState != null) {
329:                    sb.append('\n').append(ALL_SITES).append("  ")
330:                            .append(" | ").append(allSitesState);
331:                }
332:                System.out.println(sb.toString());
333:            }
334:
335:            /**
336:             * Returns whether there is an entry for a particular site or not.
337:             *
338:             * @param site   the site handle for a site.
339:             *
340:             * @return boolean
341:             */
342:            private boolean containsKey(String site) {
343:                return mStateMap.containsKey(site);
344:            }
345:
346:            /**
347:             * Inserts an entry in to the State Map, that maintains state of various
348:             * sites.
349:             *
350:             * @param site   the site handle for a site.
351:             * @param state the thirdparty state for the site.
352:             */
353:            private void put(String site, TPTState state) {
354:                mStateMap.put(site, state);
355:            }
356:
357:            /**
358:             * Returns the TPT state for a particular site.
359:             *
360:             * @param site the site handle for the site.
361:             * @return state the third party state for the site if there is an entry,
362:             *         else null.
363:             */
364:            private TPTState get(String site) {
365:                Object state = mStateMap.get(site);
366:                return (state == null) ? null : (TPTState) state;
367:            }
368:
369:            /**
370:             * Returns a set of third party sites. An empty set is returned if value is
371:             * null.
372:             *
373:             * @param value  the value in the properties file.
374:             *
375:             * @return Set containing the names of the pools.
376:             */
377:            private Set getThirdPartySites(String value) {
378:                HashSet set = new HashSet();
379:                String site;
380:                if (value == null) {
381:                    return set;
382:                }
383:
384:                for (StringTokenizer st = new StringTokenizer(value, ","); st
385:                        .hasMoreTokens();) {
386:                    site = (String) st.nextToken();
387:                    /*
388:                    mLogger.log(site + " is a third party enabled site " +
389:                                "for " + desc + " transfers",
390:                                LogManager.DEBUG_MESSAGE_LEVEL);
391:                     */
392:                    set.add(site);
393:                }
394:                return set;
395:            }
396:
397:            /**
398:             * An inner class that holds the third party state for a particular site.
399:             * It designates whether a transfer needs to be third party or not, and in
400:             * addition whether it needs to be executed remotely or locally.
401:             */
402:            private class TPTState {
403:
404:                /**
405:                 * The constant to denote that a stage-in transfer is to be third party.
406:                 */
407:                public static final int STAGE_IN_TPT_TYPE = 0x1; //000001
408:
409:                /**
410:                 * The constant to denote that an inter site transfer is to be third party.
411:                 */
412:                public static final int INTER_TPT_TYPE = 0x2; //000010
413:
414:                /**
415:                 * The constant to denote that a stage-out transfer is to be third party.
416:                 */
417:                public static final int STAGE_OUT_TPT_TYPE = 0x4;//000100
418:
419:                /**
420:                 * The constant to denote that all transfers are to be third party.
421:                 */
422:                public static final int ALL_TPT_TYPE = 0x7; //000111
423:
424:                /**
425:                 * The constant to denote that a stage-in transfer is to be executed
426:                 * on the remote site.
427:                 */
428:                public static final int STAGE_IN_TPT_REMOTE = 0x8; //001000
429:
430:                /**
431:                 * The constant to denote that an inter site transfer is to be executed
432:                 * on the remote site.
433:                 */
434:                public static final int INTER_TPT_REMOTE = 0x10; //010000
435:
436:                /**
437:                 * The constant to denote that a stage-out transfer is to be executed
438:                 * on the remote site.
439:                 */
440:                public static final int STAGE_OUT_TPT_REMOTE = 0x20;//100000
441:
442:                /**
443:                 * The constant to denote that all transfers are to be executed
444:                 * on the remote site.
445:                 */
446:                public static final int ALL_TPT_REMOTE = 0x38; //111000
447:
448:                /**
449:                 * Stores the state as an integer.
450:                 */
451:                private int mState;
452:
453:                /**
454:                 * The default constructor.
455:                 */
456:                public TPTState() {
457:                    mState = 0x0;
458:                }
459:
460:                /**
461:                 * Returns the state.
462:                 *
463:                 * @return the state as an int
464:                 */
465:                public int getState() {
466:                    return mState;
467:                }
468:
469:                /**
470:                 * Sets a type of transfer to be third party.
471:                 *
472:                 * @param type the type of transfer to be set TPT
473:                 */
474:                public void set(int type) {
475:                    //no type checking for time being
476:                    mState = mState | type;
477:                }
478:
479:                /**
480:                 * Returns a boolean indicating whether the attribute passed is set
481:                 * in the transfer state or not.
482:                 * The attribute types are as constants in this class.
483:                 *
484:                 * @param type the attribute type.
485:                 */
486:                public boolean get(int type) {
487:                    return ((mState & type) == type);
488:                }
489:
490:                /**
491:                 * Returns a textual description of the state as
492:                 * (stageinRemote,interRemote,stageoutRemote,stageinTPT,interTPT,stageOutTPT).
493:                 *
494:                 * @return the textual description.
495:                 */
496:                public String toString() {
497:                    StringBuffer sb = new StringBuffer(36);
498:                    sb.append('(').append(this .get(this .STAGE_IN_TPT_REMOTE))
499:                            .append("  ").append(',').append(
500:                                    this .get(this .INTER_TPT_REMOTE)).append(
501:                                    "  ").append(',').append(
502:                                    this .get(this .STAGE_OUT_TPT_REMOTE))
503:                            .append("  ").append(',').append(
504:                                    this .get(this .STAGE_IN_TPT_TYPE)).append(
505:                                    "  ").append(',').append(
506:                                    this .get(this .INTER_TPT_TYPE)).append("  ")
507:                            .append(',').append(
508:                                    this .get(this .STAGE_OUT_TPT_TYPE)).append(
509:                                    ')');
510:                    return sb.toString();
511:                }
512:
513:            }
514:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.