Source Code Cross Referenced for Sleep.java in  » Build » ANT » org » apache » tools » ant » taskdefs » 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 » Build » ANT » org.apache.tools.ant.taskdefs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:        package org.apache.tools.ant.taskdefs;
019:
020:        import org.apache.tools.ant.BuildException;
021:        import org.apache.tools.ant.Project;
022:        import org.apache.tools.ant.Task;
023:
024:        /**
025:         * Sleep, or pause, for a period of time.
026:         *
027:         * A task for sleeping a short period of time, useful when a
028:         * build or deployment process requires an interval between tasks.
029:         *<p>
030:         * A negative value can be supplied to any of attributes provided the total sleep time
031:         * is positive, pending fundamental changes in physics and JVM
032:         * execution times</p>
033:         * Note that sleep times are always hints to be interpreted by the OS how it feels
034:         * small times may either be ignored or rounded up to a minimum timeslice. Note
035:         * also that the system clocks often have a fairly low granularity too, which complicates
036:         * measuring how long a sleep actually took.</p>
037:         *
038:         * @since Ant 1.4
039:         * @ant.task category="utility"
040:         */
041:
042:        public class Sleep extends Task {
043:            /**
044:             * failure flag
045:             */
046:            private boolean failOnError = true;
047:
048:            /**
049:             * sleep seconds
050:             */
051:            private int seconds = 0;
052:
053:            /**
054:             * sleep hours
055:             */
056:            private int hours = 0;
057:            /**
058:             * sleep minutes
059:             */
060:            private int minutes = 0;
061:
062:            /**
063:             * sleep milliseconds
064:             */
065:            private int milliseconds = 0;
066:
067:            /**
068:             * Creates new instance
069:             */
070:            public Sleep() {
071:            }
072:
073:            /**
074:             * seconds to add to the sleep time
075:             *
076:             * @param seconds The new Seconds value
077:             */
078:            public void setSeconds(int seconds) {
079:                this .seconds = seconds;
080:            }
081:
082:            /**
083:             * hours to add to the sleep time.
084:             *
085:             * @param hours The new Hours value
086:             */
087:            public void setHours(int hours) {
088:                this .hours = hours;
089:            }
090:
091:            /**
092:             * minutes to add to the sleep time
093:             *
094:             * @param minutes The new Minutes value
095:             */
096:            public void setMinutes(int minutes) {
097:                this .minutes = minutes;
098:            }
099:
100:            /**
101:             * milliseconds to add to the sleep time
102:             *
103:             * @param milliseconds The new Milliseconds value
104:             */
105:            public void setMilliseconds(int milliseconds) {
106:                this .milliseconds = milliseconds;
107:            }
108:
109:            /**
110:             * sleep for a period of time
111:             *
112:             * @param millis time to sleep
113:             */
114:            public void doSleep(long millis) {
115:                try {
116:                    Thread.sleep(millis);
117:                } catch (InterruptedException ie) {
118:                    // Ignore Exception
119:                }
120:            }
121:
122:            /**
123:             * flag controlling whether to break the build on an error.
124:             *
125:             * @param failOnError The new FailOnError value
126:             */
127:            public void setFailOnError(boolean failOnError) {
128:                this .failOnError = failOnError;
129:            }
130:
131:            /**
132:             * return time to sleep
133:             *
134:             * @return sleep time. if below 0 then there is an error
135:             */
136:
137:            private long getSleepTime() {
138:                return ((((long) hours * 60) + minutes) * 60 + seconds) * 1000
139:                        + milliseconds;
140:            }
141:
142:            /**
143:             * verify parameters
144:             *
145:             * @throws BuildException if something is invalid
146:             */
147:            public void validate() throws BuildException {
148:                if (getSleepTime() < 0) {
149:                    throw new BuildException("Negative sleep periods are not "
150:                            + "supported");
151:                }
152:            }
153:
154:            /**
155:             * Executes this build task. Throws org.apache.tools.ant.BuildException
156:             * if there is an error during task execution.
157:             *
158:             * @exception BuildException Description of Exception
159:             */
160:            public void execute() throws BuildException {
161:                try {
162:                    validate();
163:                    long sleepTime = getSleepTime();
164:                    log("sleeping for " + sleepTime + " milliseconds",
165:                            Project.MSG_VERBOSE);
166:                    doSleep(sleepTime);
167:                } catch (Exception e) {
168:                    if (failOnError) {
169:                        throw new BuildException(e);
170:                    } else {
171:                        String text = e.toString();
172:                        log(text, Project.MSG_ERR);
173:                    }
174:                }
175:            }
176:
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.