Source Code Cross Referenced for IdleHandler.java in  » Scripting » jacl » tcl » lang » 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 » Scripting » jacl » tcl.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * IdleHandler.java --
003:         *
004:         *	The API for defining idle event handler.
005:         *
006:         * Copyright (c) 1997 Sun Microsystems, Inc.
007:         *
008:         * See the file "license.terms" for information on usage and
009:         * redistribution of this file, and for a DISCLAIMER OF ALL
010:         * WARRANTIES.
011:         * 
012:         * RCS: @(#) $Id: IdleHandler.java,v 1.3 2006/06/12 04:00:18 mdejong Exp $
013:         *
014:         */
015:
016:        package tcl.lang;
017:
018:        /*
019:         * This abstract class is used to define idle handlers.
020:         */
021:
022:        public abstract class IdleHandler {
023:
024:            /*
025:             * Back pointer to the notifier that will fire this idle.
026:             */
027:
028:            Notifier notifier;
029:
030:            /*
031:             * True if the cancel() method has been called.
032:             */
033:
034:            boolean isCancelled;
035:
036:            /*
037:             * Used to distinguish older idle handlers from recently-created ones.
038:             */
039:
040:            int generation;
041:
042:            /*
043:             *----------------------------------------------------------------------
044:             *
045:             * IdleHandler --
046:             *
047:             *	Create a idle handler to be fired when the notifier is idle.
048:             *
049:             * Results:
050:             *	None.
051:             *
052:             * Side effects:
053:             *	The idle is registered in the list of idle handlers in the
054:             *	given notifier. When the notifier is idle, the
055:             *	processIdleEvent() method will be invoked exactly once inside
056:             *	the primary thread of the notifier.
057:             *
058:             *----------------------------------------------------------------------
059:             */
060:
061:            public IdleHandler(Notifier n) // The notifier to fire the event.
062:            {
063:                notifier = (Notifier) n;
064:                isCancelled = false;
065:
066:                synchronized (notifier) {
067:                    notifier.idleList.add(this );
068:                    generation = notifier.idleGeneration;
069:                    if (Thread.currentThread() != notifier.primaryThread) {
070:                        notifier.notifyAll();
071:                    }
072:                }
073:            }
074:
075:            /*
076:             *----------------------------------------------------------------------
077:             *
078:             * cancel --
079:             *
080:             *	Mark this idle handler as cancelled so that it won't be invoked.
081:             *
082:             * Results:
083:             *	None.
084:             *
085:             * Side effects:
086:             *	The idle handler is marked as cancelled so that its
087:             *	processIdleEvent() method will not be called. If the idle
088:             *	event has already fired, then nothing this call has no effect.
089:             *
090:             *----------------------------------------------------------------------
091:             */
092:
093:            public synchronized void cancel() {
094:                if (isCancelled) {
095:                    return;
096:                }
097:
098:                isCancelled = true;
099:
100:                synchronized (notifier) {
101:                    for (int i = 0; i < notifier.idleList.size(); i++) {
102:                        if (notifier.idleList.get(i) == this ) {
103:                            notifier.idleList.remove(i);
104:
105:                            /*
106:                             * We can return now because the same idle handler can
107:                             * be registered only once in the list of idles.
108:                             */
109:
110:                            return;
111:                        }
112:                    }
113:                }
114:            }
115:
116:            /*
117:             *----------------------------------------------------------------------
118:             *
119:             * invoke --
120:             *
121:             *	Execute the idle handler if it has not been cancelled. This
122:             *	method should be called by the notifier only.
123:             *
124:             *	Because the idle handler may be being cancelled by another
125:             *	thread, both this method and cancel() must be synchronized to
126:             *	ensure correctness.
127:             *
128:             * Results:
129:             *	0 if the handler was not executed because it was already
130:             *	cancelled, 1 otherwise.
131:             *
132:             * Side effects:
133:             *	The idle handler may have arbitrary side effects.
134:             *
135:             *----------------------------------------------------------------------
136:             */
137:
138:            synchronized final int invoke() {
139:                /*
140:                 * The idle handler may be cancelled after it was registered in
141:                 * the notifier. Check the isCancelled field to make sure it's not
142:                 * cancelled.
143:                 */
144:
145:                if (!isCancelled) {
146:                    processIdleEvent();
147:                    return 1;
148:                } else {
149:                    return 0;
150:                }
151:            }
152:
153:            /*
154:             *----------------------------------------------------------------------
155:             *
156:             * processIdleEvent --
157:             *
158:             *	This method is called when the idle is expired. Override
159:             *	This method to implement your own idle handlers.
160:             *
161:             * Results:
162:             *	None.
163:             *
164:             * Side effects:
165:             *	It can do anything.
166:             *
167:             *----------------------------------------------------------------------
168:             */
169:
170:            abstract public void processIdleEvent();
171:
172:            /*
173:             *----------------------------------------------------------------------
174:             *
175:             * toString --
176:             *
177:             *	This method prints a text description of the event for debugging.
178:             *
179:             *----------------------------------------------------------------------
180:             */
181:
182:            public String toString() {
183:                StringBuffer sb = new StringBuffer(64);
184:                sb.append("IdleHandler.generation is " + generation + "\n");
185:                return sb.toString();
186:            }
187:
188:        } // end IdleHandler
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.