Source Code Cross Referenced for DummySession.java in  » Net » mina-2.0.0-M1 » org » apache » mina » common » 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 » Net » mina 2.0.0 M1 » org.apache.mina.common 
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:         */
020:        package org.apache.mina.common;
021:
022:        import java.net.SocketAddress;
023:        import java.util.List;
024:        import java.util.Set;
025:
026:        /**
027:         * A dummy {@link IoSession} for unit-testing or non-network-use of
028:         * the classes that depends on {@link IoSession}.
029:         * 
030:         * <h2>Overriding I/O request methods</h2>
031:         * All I/O request methods (i.e. {@link #close()}, {@link #write(Object)} and
032:         * {@link #setTrafficMask(TrafficMask)}) are final and therefore cannot be
033:         * overridden, but you can always add your custom {@link IoFilter} to the
034:         * {@link IoFilterChain} to intercept any I/O events and requests.
035:         *
036:         * @author The Apache MINA Project (dev@mina.apache.org)
037:         * @version $Rev: 607170 $, $Date: 2007-12-27 21:01:22 -0700 (Thu, 27 Dec 2007) $
038:         */
039:        public class DummySession extends AbstractIoSession {
040:
041:            private static final TransportMetadata TRANSPORT_METADATA = new DefaultTransportMetadata(
042:                    "mina", "dummy", false, false, SocketAddress.class,
043:                    IoSessionConfig.class, Object.class);
044:
045:            private static final SocketAddress ANONYMOUS_ADDRESS = new SocketAddress() {
046:                private static final long serialVersionUID = -496112902353454179L;
047:
048:                @Override
049:                public String toString() {
050:                    return "?";
051:                }
052:            };
053:
054:            private volatile IoService service;
055:
056:            private volatile IoSessionConfig config = new AbstractIoSessionConfig() {
057:                @Override
058:                protected void doSetAll(IoSessionConfig config) {
059:                }
060:            };
061:
062:            private final IoFilterChain filterChain = new DefaultIoFilterChain(
063:                    this );
064:            private final IoProcessor<IoSession> processor;
065:
066:            private volatile IoHandler handler = new IoHandlerAdapter();
067:            private volatile SocketAddress localAddress = ANONYMOUS_ADDRESS;
068:            private volatile SocketAddress remoteAddress = ANONYMOUS_ADDRESS;
069:            private volatile TransportMetadata transportMetadata = TRANSPORT_METADATA;
070:
071:            /**
072:             * Creates a new instance.
073:             */
074:            public DummySession() {
075:                // Initialize dummy service.
076:                IoAcceptor acceptor = new AbstractIoAcceptor(
077:                        new AbstractIoSessionConfig() {
078:                            @Override
079:                            protected void doSetAll(IoSessionConfig config) {
080:                            }
081:                        }) {
082:
083:                    @Override
084:                    protected Set<SocketAddress> bind0(
085:                            List<? extends SocketAddress> localAddresses)
086:                            throws Exception {
087:                        throw new UnsupportedOperationException();
088:                    }
089:
090:                    @Override
091:                    protected void unbind0(
092:                            List<? extends SocketAddress> localAddresses)
093:                            throws Exception {
094:                        throw new UnsupportedOperationException();
095:                    }
096:
097:                    public IoSession newSession(SocketAddress remoteAddress,
098:                            SocketAddress localAddress) {
099:                        throw new UnsupportedOperationException();
100:                    }
101:
102:                    public TransportMetadata getTransportMetadata() {
103:                        return TRANSPORT_METADATA;
104:                    }
105:
106:                    @Override
107:                    protected IoFuture dispose0() throws Exception {
108:                        return null;
109:                    }
110:                };
111:
112:                // Set meaningless default values.
113:                acceptor.setHandler(new IoHandlerAdapter());
114:
115:                this .service = acceptor;
116:
117:                this .processor = new IoProcessor<IoSession>() {
118:                    public void add(IoSession session) {
119:                    }
120:
121:                    public void flush(IoSession session) {
122:                        getFilterChain().fireMessageSent(
123:                                ((DummySession) session).getWriteRequestQueue()
124:                                        .poll(session));
125:                    }
126:
127:                    public void remove(IoSession session) {
128:                    }
129:
130:                    public void updateTrafficMask(IoSession session) {
131:                    }
132:
133:                    public void dispose() {
134:                    }
135:
136:                    public boolean isDisposed() {
137:                        return false;
138:                    }
139:
140:                    public boolean isDisposing() {
141:                        return false;
142:                    }
143:                };
144:
145:                try {
146:                    IoSessionDataStructureFactory factory = new DefaultIoSessionDataStructureFactory();
147:                    setAttributeMap(factory.getAttributeMap(this ));
148:                    setWriteRequestQueue(factory.getWriteRequestQueue(this ));
149:                } catch (Exception e) {
150:                    throw new InternalError();
151:                }
152:            }
153:
154:            public IoSessionConfig getConfig() {
155:                return config;
156:            }
157:
158:            /**
159:             * Sets the configuration of this session.
160:             */
161:            public void setConfig(IoSessionConfig config) {
162:                if (config == null) {
163:                    throw new NullPointerException("config");
164:                }
165:
166:                this .config = config;
167:            }
168:
169:            public IoFilterChain getFilterChain() {
170:                return filterChain;
171:            }
172:
173:            public IoHandler getHandler() {
174:                return handler;
175:            }
176:
177:            /**
178:             * Sets the {@link IoHandler} which handles this session.
179:             */
180:            public void setHandler(IoHandler handler) {
181:                if (handler == null) {
182:                    throw new NullPointerException("handler");
183:                }
184:
185:                this .handler = handler;
186:            }
187:
188:            public SocketAddress getLocalAddress() {
189:                return localAddress;
190:            }
191:
192:            public SocketAddress getRemoteAddress() {
193:                return remoteAddress;
194:            }
195:
196:            /**
197:             * Sets the socket address of local machine which is associated with
198:             * this session.
199:             */
200:            public void setLocalAddress(SocketAddress localAddress) {
201:                if (localAddress == null) {
202:                    throw new NullPointerException("localAddress");
203:                }
204:
205:                this .localAddress = localAddress;
206:            }
207:
208:            /**
209:             * Sets the socket address of remote peer.
210:             */
211:            public void setRemoteAddress(SocketAddress remoteAddress) {
212:                if (remoteAddress == null) {
213:                    throw new NullPointerException("remoteAddress");
214:                }
215:
216:                this .remoteAddress = remoteAddress;
217:            }
218:
219:            public IoService getService() {
220:                return service;
221:            }
222:
223:            /**
224:             * Sets the {@link IoService} which provides I/O service to this session.
225:             */
226:            public void setService(IoService service) {
227:                if (service == null) {
228:                    throw new NullPointerException("service");
229:                }
230:
231:                this .service = service;
232:            }
233:
234:            @Override
235:            protected final IoProcessor<IoSession> getProcessor() {
236:                return processor;
237:            }
238:
239:            public TransportMetadata getTransportMetadata() {
240:                return transportMetadata;
241:            }
242:
243:            /**
244:             * Sets the {@link TransportMetadata} that this session runs on.
245:             */
246:            public void setTransportMetadata(TransportMetadata transportMetadata) {
247:                if (transportMetadata == null) {
248:                    throw new NullPointerException("transportMetadata");
249:                }
250:
251:                this .transportMetadata = transportMetadata;
252:            }
253:
254:            @Override
255:            public void setScheduledWriteBytes(long byteCount) {
256:                super .setScheduledWriteBytes(byteCount);
257:            }
258:
259:            @Override
260:            public void setScheduledWriteMessages(int messages) {
261:                super .setScheduledWriteMessages(messages);
262:            }
263:
264:            /**
265:             * Update all statistical properties related with throughput.  By default
266:             * this method returns silently without updating the throughput properties
267:             * if they were calculated already within last 
268:             * {@link IoSessionConfig#getThroughputCalculationInterval() calculation interval}.
269:             * If, however, <tt>force</tt> is specified as <tt>true</tt>, this method
270:             * updates the throughput properties immediately.
271:             */
272:            public void updateThroughput(boolean force) {
273:                super.updateThroughput(System.currentTimeMillis(), force);
274:            }
275:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.