Source Code Cross Referenced for XJob.java in  » XML-UI » xui32 » com » xoetrope » task » 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 » XML UI » xui32 » com.xoetrope.task 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.task;
002:
003:        import java.util.Date;
004:
005:        /**
006:         * Create a new job. A job is associated with an executable task and is run at
007:         * a defined interval or after a defined time.
008:         *
009:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
010:         * the GNU Public License (GPL), please see license.txt for more details. If
011:         * you make commercial use of this software you must purchase a commercial
012:         * license from Xoetrope.</p>
013:         * <p> $Revision: 1.4 $</p>
014:         */
015:        public class XJob extends Thread implements  XArguments {
016:            int id;
017:            Object className;
018:            int type;
019:            long interval;
020:            long sleepInterval;
021:            long startDate;
022:            Object obj;
023:            Object[] arguments;
024:            boolean keepRunning;
025:
026:            /**
027:             * Create a new job
028:             * @param jobId the ID by which the job will be identified
029:             * @param cls the XExecutable class
030:             * @param t the type
031:             * @param intrvl the interval
032:             * @param start the start time
033:             * @param args the arguments
034:             */
035:            public XJob(int jobId, Object cls, int t, long intrvl, long start,
036:                    Object[] args) {
037:                id = jobId;
038:                className = cls;
039:                type = t;
040:                interval = intrvl;
041:                sleepInterval = interval / 5l;
042:                if (sleepInterval < 200)
043:                    sleepInterval = 200;
044:                startDate = start;
045:
046:                if (args != null) {
047:                    arguments = new Object[args.length];
048:                    for (int i = 0; i < args.length; i++)
049:                        arguments[i] = args[i];
050:                }
051:
052:                keepRunning = true;
053:            }
054:
055:            /**
056:             * Run the job and execute the task when ready
057:             */
058:            public void run() {
059:                boolean jobExecuted = false;
060:                do {
061:                    if (new Date().getTime() > startDate) {
062:                        execute();
063:                        jobExecuted = true;
064:                        startDate += interval;
065:                    }
066:
067:                    try {
068:                        sleep(sleepInterval);
069:                    } catch (Exception e) {
070:                    }
071:                } while ((keepRunning)
072:                        && ((type > XScheduler.ONCE_OFF_JOB) || !jobExecuted));
073:            }
074:
075:            /**
076:             * Execute the task, the actual work of the callback or executable object
077:             */
078:            public void execute() {
079:                if (keepRunning) {
080:                    XExecutable exe = null;
081:                    try {
082:                        if (className instanceof  String)
083:                            exe = (XExecutable) Class.forName(
084:                                    ((String) className).trim()).newInstance();
085:                        else
086:                            exe = (XExecutable) className;
087:                        exe.execute(this );
088:                    } catch (Exception ex) {
089:                        ex.printStackTrace();
090:                    }
091:                }
092:            }
093:
094:            /**
095:             * End the job
096:             */
097:            public void kill() {
098:                keepRunning = false;
099:            }
100:
101:            /**
102:             * Get the number of arguments belonging/needed by to this job
103:             * @return the number of arguments
104:             */
105:            public int getNumArguments() {
106:                if (arguments == null)
107:                    return 0;
108:                return arguments.length;
109:            }
110:
111:            /**
112:             * Get an argument
113:             * @param index the index of the argument
114:             * @return the argument object
115:             */
116:            public Object getArgument(int index) {
117:                if (arguments == null)
118:                    return null;
119:                return arguments[index];
120:            }
121:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.