Source Code Cross Referenced for LineInputEndPoint.java in  » Workflow-Engines » Dalma » dalma » endpoints » input » 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 » Dalma » dalma.endpoints.input 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package dalma.endpoints.input;
002:
003:        import dalma.Conversation;
004:        import dalma.Condition;
005:        import dalma.Engine;
006:        import dalma.impl.EndPointImpl;
007:        import dalma.spi.FiberSPI;
008:
009:        import java.io.BufferedReader;
010:        import java.io.IOException;
011:        import java.io.InputStreamReader;
012:        import java.util.ArrayList;
013:        import java.util.List;
014:
015:        /**
016:         * Waits for the user input.
017:         *
018:         * This is a singleton endPoint.
019:         *
020:         * @author Kohsuke Kawaguchi
021:         */
022:        public final class LineInputEndPoint extends EndPointImpl implements 
023:                Runnable {
024:
025:            /**
026:             * {@link Conversation}s waiting for input.
027:             */
028:            private static final List<LineCondition> queue = new ArrayList<LineCondition>();
029:
030:            private final Thread thread = new Thread(this );
031:
032:            public LineInputEndPoint() {
033:                super (LineInputEndPoint.class.getName());
034:            }
035:
036:            public void run() {
037:                try {
038:                    BufferedReader in = new BufferedReader(
039:                            new InputStreamReader(System.in));
040:                    String line;
041:                    while ((line = in.readLine()) != null) {
042:                        synchronized (queue) {
043:                            if (!queue.isEmpty()) {
044:                                // pick the conversation to be activated
045:                                LineCondition cond = queue.remove(0);
046:                                cond.activate(line);
047:                            }
048:                        }
049:                    }
050:                } catch (IOException e) {
051:                    throw new Error(e); // can never happen
052:                }
053:            }
054:
055:            protected void start() {
056:                // start the monitor thread
057:                thread.start();
058:            }
059:
060:            protected void stop() {
061:                thread.interrupt();
062:                try {
063:                    thread.join();
064:                } catch (InterruptedException e) {
065:                    ;
066:                }
067:            }
068:
069:            private final class LineCondition extends Condition<String> {
070:                public LineCondition() {
071:                }
072:
073:                public void onParked() {
074:                    synchronized (queue) {
075:                        queue.add(this );
076:                    }
077:                }
078:
079:                public void onLoad() {
080:                    onParked();
081:                }
082:
083:                public void interrupt() {
084:                    synchronized (queue) {
085:                        queue.remove(this );
086:                    }
087:                }
088:            }
089:
090:            /**
091:             * Wait for an user input.
092:             */
093:            // this method is invoked from conversations
094:            public static String waitForInput() {
095:                FiberSPI<?> fiber = FiberSPI.currentFiber(true);
096:                return fiber.suspend(createCondition(fiber));
097:            }
098:
099:            private static LineCondition createCondition(FiberSPI fiber) {
100:                LineCondition cond;
101:                synchronized (LineInputEndPoint.class) {
102:                    Engine engine = fiber.getOwner().getEngine();
103:                    LineInputEndPoint endPoint = (LineInputEndPoint) engine
104:                            .getEndPoint(LineInputEndPoint.class.getName());
105:                    cond = endPoint.new LineCondition();
106:                }
107:                return cond;
108:            }
109:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.