Source Code Cross Referenced for IDataHandler.java in  » Web-Server » xsocket » org » xsocket » connection » 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 » Web Server » xsocket » org.xsocket.connection 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        /*
02:         *  Copyright (c) xsocket.org, 2006 - 2008. All rights reserved.
03:         *
04:         *  This library is free software; you can redistribute it and/or
05:         *  modify it under the terms of the GNU Lesser General Public
06:         *  License as published by the Free Software Foundation; either
07:         *  version 2.1 of the License, or (at your option) any later version.
08:         *
09:         *  This library is distributed in the hope that it will be useful,
10:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12:         *  Lesser General Public License for more details.
13:         *
14:         *  You should have received a copy of the GNU Lesser General Public
15:         *  License along with this library; if not, write to the Free Software
16:         *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17:         *
18:         * Please refer to the LGPL license at: http://www.gnu.org/copyleft/lesser.txt
19:         * The latest copy of this software may be found on http://www.xsocket.org/
20:         */
21:        package org.xsocket.connection;
22:
23:        import java.io.IOException;
24:        import java.nio.BufferUnderflowException;
25:
26:        import org.xsocket.MaxReadSizeExceededException;
27:
28:        /**
29:         * Reads and processes the incoming data. This method will be called
30:         * each time when data is available. Because this depends on the
31:         * underlying tcp protocol, it is not predictable how often and
32:         * when this method will be call. Please note, that on network level
33:         * data can be fragmented on several TCP packets as well as data can
34:         * be bundled into one TCP packet. <br><br>
35:         *
36:         * Performing a write operation like <code>connection.write(“hello it’s me. What I have to say is….”)</code>
37:         * on the client side doesn’t mean that exact one onData call occurs on
38:         * the server side.  A common pattern to solve this is to identify logical
39:         * parts by a delimiter or a leading length field.
40:         * xSocket provides methods to support this pattern. E.g. the {@link INonBlockingConnection#readStringByDelimiter(String)}
41:         * method only returns a record if the whole part (identified by the delimiter) has
42:         * been received, or if not, a BufferUnderflowException will be thrown. In
43:         * contrast to {@link IBlockingConnection}, a {@link INonBlockingConnection} read
44:         * method always returns immediately and could thrown a BufferUnderflowException.
45:         * The {@link BufferUnderflowException} will be swallowed by the framework, if
46:         * the DataHandler doesn’t catch this exception. It is a common pattern
47:         * not to handle such an exception by the DataHandler.
48:         *
49:         * <pre>
50:         * public final class MyHandler implements IDataHandler, IConnectionScoped {
51:         *   ...
52:         *   public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
53:         *   	...
54:         *      // BufferUnderflowException will been thrown if delimiter has not been found.
55:         *      // A MaxReadSizeExceededException will be thrown if the max read size has been exceeded. Not handling this exception causes
56:         *      // that the server closes the underlying connection
57:         *      String command = connection.readStringByDelimiter("\r\n", "US-ASCII", 5000);
58:         *      ...
59:         *      connection.write(response, "US-ASCII");
60:         *      return true;
61:         *   }
62:         * }
63:         * </pre>
64:         *
65:         * @author grro@xsocket.org
66:         */
67:        public interface IDataHandler extends IHandler {
68:
69:            /**
70:             * processes the incoming data based on the given connection. <br><br>
71:             *
72:             * Please note, that the <code>onData</code> callback method could also be called
73:             * for an already closed connection. This occurs when data has been received
74:             * (and buffered internally) and the connection has been closed by the peer,
75:             * immediately. In this case the <code>isOpen</code> call within the <code>onData</code>
76:             * Method will return false. Reading of already received data would not fail.
77:             * To detect if a connection has been closed the callback method <code>onDisconnect</code>
78:             * should be implemented. The correct callback order will be managed by the xSocket.
79:             *
80:             * @param connection the underlying connection
81:             * @return true for positive result of handling, false for negative result of handling.
82:             *              The return value will be used by the {@link HandlerChain} to interrupted
83:             *              the chaining (if result is true)
84:             * @throws IOException If some other I/O error occurs. Throwing this exception causes that the underlying connection will be closed.
85:             * @throws BufferUnderflowException if more incoming data is required to process (e.g. delimiter hasn't yet received -> readByDelimiter methods or size of the available, received data is smaller than the required size -> readByLength). The BufferUnderflowException will be swallowed by the framework
86:             * @throws MaxReadSizeExceededException if the max read size has been reached (e.g. by calling method {@link INonBlockingConnection#readStringByDelimiter(String, int)}).
87:             *                                      Throwing this exception causes that the underlying connection will be closed.
88:             */
89:            public boolean onData(INonBlockingConnection connection)
90:                    throws IOException, BufferUnderflowException,
91:                    MaxReadSizeExceededException;
92:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.