Source Code Cross Referenced for LoggingIOSession.java in  » Web-Services-AXIS2 » kernal » org » apache » axis2 » transport » nhttp » 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 Services AXIS2 » kernal » org.apache.axis2.transport.nhttp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:        package org.apache.axis2.transport.nhttp;
020:
021:        import java.io.IOException;
022:        import java.net.SocketAddress;
023:        import java.nio.ByteBuffer;
024:        import java.nio.channels.ByteChannel;
025:        import java.nio.channels.SelectionKey;
026:
027:        import org.apache.commons.logging.Log;
028:        import org.apache.commons.logging.LogFactory;
029:        import org.apache.http.nio.reactor.IOSession;
030:        import org.apache.http.nio.reactor.SessionBufferStatus;
031:
032:        /**
033:         * Decorator class intended to transparently extend an {@link IOSession} 
034:         * with basic event logging capabilities using Commons Logging. 
035:         */
036:        public class LoggingIOSession implements  IOSession {
037:
038:            private static int COUNT = 0;
039:
040:            private final Log log;
041:            private final IOSession session;
042:            private final ByteChannel channel;
043:            private final int id;
044:
045:            public LoggingIOSession(final IOSession session) {
046:                super ();
047:                if (session == null) {
048:                    throw new IllegalArgumentException(
049:                            "I/O session may not be null");
050:                }
051:                this .session = session;
052:                this .channel = new LoggingByteChannel();
053:                this .id = ++COUNT;
054:                this .log = LogFactory.getLog(session.getClass());
055:            }
056:
057:            public ByteChannel channel() {
058:                return this .channel;
059:            }
060:
061:            public SocketAddress getLocalAddress() {
062:                return this .session.getLocalAddress();
063:            }
064:
065:            public SocketAddress getRemoteAddress() {
066:                return this .session.getRemoteAddress();
067:            }
068:
069:            public int getEventMask() {
070:                return this .session.getEventMask();
071:            }
072:
073:            private static String formatOps(int ops) {
074:                StringBuffer buffer = new StringBuffer(6);
075:                buffer.append('[');
076:                if ((ops & SelectionKey.OP_READ) > 0) {
077:                    buffer.append('r');
078:                }
079:                if ((ops & SelectionKey.OP_WRITE) > 0) {
080:                    buffer.append('w');
081:                }
082:                if ((ops & SelectionKey.OP_ACCEPT) > 0) {
083:                    buffer.append('a');
084:                }
085:                if ((ops & SelectionKey.OP_CONNECT) > 0) {
086:                    buffer.append('c');
087:                }
088:                buffer.append(']');
089:                return buffer.toString();
090:            }
091:
092:            public void setEventMask(int ops) {
093:                if (this .log.isDebugEnabled()) {
094:                    this .log.debug("I/O session " + this .id + " "
095:                            + this .session + ": Set event mask "
096:                            + formatOps(ops));
097:                }
098:                this .session.setEventMask(ops);
099:            }
100:
101:            public void setEvent(int op) {
102:                if (this .log.isDebugEnabled()) {
103:                    this .log.debug("I/O session " + this .id + " "
104:                            + this .session + ": Set event " + formatOps(op));
105:                }
106:                this .session.setEvent(op);
107:            }
108:
109:            public void clearEvent(int op) {
110:                if (this .log.isDebugEnabled()) {
111:                    this .log.debug("I/O session " + this .id + " "
112:                            + this .session + ": Clear event " + formatOps(op));
113:                }
114:                this .session.clearEvent(op);
115:            }
116:
117:            public void close() {
118:                if (this .log.isDebugEnabled()) {
119:                    this .log.debug("I/O session " + this .id + " "
120:                            + this .session + ": Close");
121:                }
122:                this .session.close();
123:            }
124:
125:            public boolean isClosed() {
126:                return this .session.isClosed();
127:            }
128:
129:            public void shutdown() {
130:                if (this .log.isDebugEnabled()) {
131:                    this .log.debug("I/O session " + this .id + " "
132:                            + this .session + ": Shutdown");
133:                }
134:                this .session.shutdown();
135:            }
136:
137:            public int getSocketTimeout() {
138:                return this .session.getSocketTimeout();
139:            }
140:
141:            public void setSocketTimeout(int timeout) {
142:                if (this .log.isDebugEnabled()) {
143:                    this .log.debug("I/O session " + this .id + " "
144:                            + this .session + ": Set timeout " + timeout);
145:                }
146:                this .session.setSocketTimeout(timeout);
147:            }
148:
149:            public void setBufferStatus(final SessionBufferStatus status) {
150:                this .session.setBufferStatus(status);
151:            }
152:
153:            public boolean hasBufferedInput() {
154:                return this .session.hasBufferedInput();
155:            }
156:
157:            public boolean hasBufferedOutput() {
158:                return this .session.hasBufferedOutput();
159:            }
160:
161:            public Object getAttribute(final String name) {
162:                return this .session.getAttribute(name);
163:            }
164:
165:            public void setAttribute(final String name, final Object obj) {
166:                if (this .log.isDebugEnabled()) {
167:                    this .log.debug("I/O session " + this .id + " "
168:                            + this .session + ": Set attribute " + name);
169:                }
170:                this .session.setAttribute(name, obj);
171:            }
172:
173:            public Object removeAttribute(final String name) {
174:                if (this .log.isDebugEnabled()) {
175:                    this .log.debug("I/O session " + this .id + " "
176:                            + this .session + ": Remove attribute " + name);
177:                }
178:                return this .session.removeAttribute(name);
179:            }
180:
181:            class LoggingByteChannel implements  ByteChannel {
182:
183:                public int read(final ByteBuffer dst) throws IOException {
184:                    int bytesRead = session.channel().read(dst);
185:                    if (log.isDebugEnabled()) {
186:                        log.debug("I/O session " + id + " " + session + ": "
187:                                + bytesRead + " bytes read");
188:                    }
189:                    return bytesRead;
190:                }
191:
192:                public int write(final ByteBuffer src) throws IOException {
193:                    int byteWritten = session.channel().write(src);
194:                    if (log.isDebugEnabled()) {
195:                        log.debug("I/O session " + id + " " + session + ": "
196:                                + byteWritten + " bytes written");
197:                    }
198:                    return byteWritten;
199:                }
200:
201:                public void close() throws IOException {
202:                    if (log.isDebugEnabled()) {
203:                        log.debug("I/O session " + id + " " + session
204:                                + ": Channel close");
205:                    }
206:                    session.channel().close();
207:                }
208:
209:                public boolean isOpen() {
210:                    return session.channel().isOpen();
211:                }
212:
213:            }
214:
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.