Source Code Cross Referenced for TimerHandleImpl.java in  » EJB-Server-JBoss-4.2.1 » server » org » jboss » ejb » txtimer » 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 » EJB Server JBoss 4.2.1 » server » org.jboss.ejb.txtimer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.ejb.txtimer;
023:
024:        // $Id: TimerHandleImpl.java 57209 2006-09-26 12:21:57Z dimitris@jboss.org $
025:
026:        import javax.ejb.EJBException;
027:        import javax.ejb.NoSuchObjectLocalException;
028:        import javax.ejb.Timer;
029:        import javax.ejb.TimerHandle;
030:        import javax.management.ObjectName;
031:        import java.io.Serializable;
032:        import java.text.ParseException;
033:        import java.text.SimpleDateFormat;
034:        import java.util.Date;
035:        import java.util.StringTokenizer;
036:
037:        /**
038:         * An implementation of the TimerHandle
039:         *
040:         * @author Thomas.Diesler@jboss.org
041:         * @version $Revision: 57209 $
042:         * @since 07-Apr-2004
043:         */
044:        public class TimerHandleImpl implements  TimerHandle {
045:            /**
046:             * The date pattern used by this handle
047:             */
048:            public static final String DATE_PATTERN = "dd-MMM-yyyy HH:mm:ss.SSS";
049:
050:            // The initial txtimer properties
051:            private String timerId;
052:            private TimedObjectId timedObjectId;
053:            private Date firstTime;
054:            private long periode;
055:            private Serializable info;
056:            private int hashCode;
057:
058:            /**
059:             * Construct a handle from a timer
060:             */
061:            TimerHandleImpl(TimerImpl timer) {
062:                timerId = timer.getTimerId();
063:                timedObjectId = timer.getTimedObjectId();
064:                firstTime = timer.getFirstTime();
065:                periode = timer.getPeriode();
066:                info = timer.getInfoInternal();
067:            }
068:
069:            /**
070:             * Construct a handle from individual parameters
071:             */
072:            TimerHandleImpl(String timerId, TimedObjectId timedObjectId,
073:                    Date firstTime, long periode, Serializable info) {
074:                this .timerId = timerId;
075:                this .timedObjectId = timedObjectId;
076:                this .firstTime = firstTime;
077:                this .periode = periode;
078:                this .info = info;
079:            }
080:
081:            /**
082:             * Construct a handle from external form
083:             */
084:            private TimerHandleImpl(String externalForm) {
085:                if (externalForm.startsWith("[") == false
086:                        || externalForm.endsWith("]") == false)
087:                    throw new IllegalArgumentException(
088:                            "Square brackets expected arround: " + externalForm);
089:
090:                try {
091:                    // take first and last char off
092:                    String inStr = externalForm.substring(1, externalForm
093:                            .length() - 1);
094:
095:                    if (inStr.startsWith("id=") == false)
096:                        throw new IllegalArgumentException("Cannot parse: "
097:                                + externalForm);
098:
099:                    int targetIndex = inStr.indexOf(",target=");
100:                    int firstIndex = inStr.indexOf(",first=");
101:
102:                    String idStr = inStr.substring(3, targetIndex);
103:                    String targetStr = inStr.substring(targetIndex + 8,
104:                            firstIndex);
105:                    String restStr = inStr.substring(firstIndex + 1);
106:
107:                    timerId = idStr;
108:                    timedObjectId = TimedObjectId.parse(targetStr);
109:
110:                    StringTokenizer st = new StringTokenizer(restStr, ",=");
111:                    if (st.countTokens() % 2 != 0)
112:                        throw new IllegalArgumentException("Cannot parse: "
113:                                + externalForm);
114:
115:                    SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
116:
117:                    periode = -1;
118:
119:                    while (st.hasMoreTokens()) {
120:                        String key = st.nextToken();
121:                        String value = st.nextToken();
122:                        if (key.equals("first"))
123:                            firstTime = sdf.parse(value);
124:                        if (key.equals("periode"))
125:                            periode = new Long(value).longValue();
126:                    }
127:
128:                    if (firstTime == null || periode < 0)
129:                        throw new IllegalArgumentException("Cannot parse: "
130:                                + externalForm);
131:                } catch (ParseException e) {
132:                    throw new IllegalArgumentException(
133:                            "Cannot parse date/time in: " + externalForm);
134:                }
135:            }
136:
137:            /**
138:             * Parse the handle from external form.
139:             * "[toid=timedObjectId,first=firstTime,periode=periode]"
140:             */
141:            public static TimerHandleImpl parse(String externalForm) {
142:                return new TimerHandleImpl(externalForm);
143:            }
144:
145:            /**
146:             * Returns the external representation of the handle.
147:             * "[toid=timedObjectId,first=firstTime,periode=periode]"
148:             */
149:            public String toExternalForm() {
150:                SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
151:                String firstEvent = sdf.format(firstTime);
152:                return "[id=" + timerId + ",target=" + timedObjectId
153:                        + ",first=" + firstEvent + ",periode=" + periode + "]";
154:            }
155:
156:            public String getTimerId() {
157:                return timerId;
158:            }
159:
160:            public TimedObjectId getTimedObjectId() {
161:                return timedObjectId;
162:            }
163:
164:            public Date getFirstTime() {
165:                return firstTime;
166:            }
167:
168:            public long getPeriode() {
169:                return periode;
170:            }
171:
172:            public Serializable getInfo() {
173:                return info;
174:            }
175:
176:            /**
177:             * Obtain a reference to the txtimer represented by this handle.
178:             *
179:             * @return Timer which this handle represents
180:             * @throws IllegalStateException  If this method is invoked while the instance is in
181:             *                                a state that does not allow access to this method.
182:             * @throws javax.ejb.NoSuchObjectLocalException
183:             *                                If invoked on a txtimer that has expired or has been cancelled.
184:             * @throws javax.ejb.EJBException If this method could not complete due to a system-level failure.
185:             */
186:            public Timer getTimer() throws IllegalStateException,
187:                    NoSuchObjectLocalException, EJBException {
188:
189:                EJBTimerService ejbTimerService = EJBTimerServiceLocator
190:                        .getEjbTimerService();
191:                ObjectName containerId = timedObjectId.getContainerId();
192:                Object instancePk = timedObjectId.getInstancePk();
193:                TimerServiceImpl timerService = (TimerServiceImpl) ejbTimerService
194:                        .getTimerService(containerId, instancePk);
195:                if (timerService == null)
196:                    throw new NoSuchObjectLocalException(
197:                            "TimerService not available: " + timedObjectId);
198:
199:                TimerImpl timer = (TimerImpl) timerService.getTimer(this );
200:                if (timer == null || timer.isActive() == false)
201:                    throw new NoSuchObjectLocalException(
202:                            "Timer not available: " + timedObjectId);
203:
204:                return timer;
205:            }
206:
207:            /**
208:             * Return true if objectId, createDate, periode are equal
209:             */
210:            public boolean equals(Object obj) {
211:                if (obj == this )
212:                    return true;
213:                if (obj instanceof  TimerHandleImpl) {
214:                    TimerHandleImpl other = (TimerHandleImpl) obj;
215:                    return hashCode() == other.hashCode();
216:                }
217:                return false;
218:            }
219:
220:            /**
221:             * Hash code based on objectId, createDate, periode
222:             */
223:            public int hashCode() {
224:                if (hashCode == 0) {
225:                    hashCode = toExternalForm().hashCode();
226:                }
227:                return hashCode;
228:            }
229:
230:            /**
231:             * Returns a string representation of the object.
232:             */
233:            public String toString() {
234:                return toExternalForm();
235:            }
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.