EMMA Coverage Report (generated Mon Jul 11 13:15:38 KST 2005)
[all classes][org.apache.mina.io.datagram]

COVERAGE SUMMARY FOR SOURCE FILE [DatagramSession.java]

nameclass, %method, %block, %line, %
DatagramSession.java100% (1/1)79%  (15/19)79%  (115/146)77%  (37/48)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DatagramSession100% (1/1)79%  (15/19)79%  (115/146)77%  (37/48)
getLocalAddress (): SocketAddress 0%   (0/1)0%   (0/3)0%   (0/1)
getScheduledWriteRequests (): int 0%   (0/1)0%   (0/16)0%   (0/3)
getTransportType (): TransportType 0%   (0/1)0%   (0/2)0%   (0/1)
isConnected (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
close (boolean): void 100% (1/1)77%  (20/26)58%  (7/12)
DatagramSession (IoSessionManagerFilterChain, DatagramChannel, IoHandler): void 100% (1/1)100% (44/44)100% (11/11)
getChannel (): DatagramChannel 100% (1/1)100% (3/3)100% (1/1)
getConfig (): SessionConfig 100% (1/1)100% (3/3)100% (1/1)
getFilterChain (): IoFilterChain 100% (1/1)100% (3/3)100% (1/1)
getHandler (): IoHandler 100% (1/1)100% (3/3)100% (1/1)
getManagerFilterChain (): IoSessionManagerFilterChain 100% (1/1)100% (3/3)100% (1/1)
getRemoteAddress (): SocketAddress 100% (1/1)100% (3/3)100% (1/1)
getSelectionKey (): SelectionKey 100% (1/1)100% (3/3)100% (1/1)
getWriteBufferQueue (): Queue 100% (1/1)100% (3/3)100% (1/1)
getWriteMarkerQueue (): Queue 100% (1/1)100% (3/3)100% (1/1)
notifyClose (): void 100% (1/1)100% (9/9)100% (4/4)
setRemoteAddress (SocketAddress): void 100% (1/1)100% (4/4)100% (2/2)
setSelectionKey (SelectionKey): void 100% (1/1)100% (4/4)100% (2/2)
write (ByteBuffer, Object): void 100% (1/1)100% (7/7)100% (2/2)

1/*
2 *   @(#) $Id: DatagramSession.java 210062 2005-07-11 03:52:38Z trustin $
3 *
4 *   Copyright 2004 The Apache Software Foundation
5 *
6 *   Licensed under the Apache License, Version 2.0 (the "License");
7 *   you may not use this file except in compliance with the License.
8 *   You may obtain a copy of the License at
9 *
10 *       http://www.apache.org/licenses/LICENSE-2.0
11 *
12 *   Unless required by applicable law or agreed to in writing, software
13 *   distributed under the License is distributed on an "AS IS" BASIS,
14 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 *   See the License for the specific language governing permissions and
16 *   limitations under the License.
17 *
18 */
19package org.apache.mina.io.datagram;
20 
21import java.net.SocketAddress;
22import java.nio.channels.DatagramChannel;
23import java.nio.channels.SelectionKey;
24 
25import org.apache.mina.common.BaseSession;
26import org.apache.mina.common.ByteBuffer;
27import org.apache.mina.common.SessionConfig;
28import org.apache.mina.common.TransportType;
29import org.apache.mina.io.IoHandler;
30import org.apache.mina.io.IoFilterChain;
31import org.apache.mina.io.IoSession;
32import org.apache.mina.io.IoSessionFilterChain;
33import org.apache.mina.io.IoSessionManager;
34import org.apache.mina.io.IoSessionManagerFilterChain;
35import org.apache.mina.util.Queue;
36 
37/**
38 * An {@link IoSession} for datagram transport (UDP/IP).
39 * 
40 * @author Trustin Lee (trustin@apache.org)
41 * @version $Rev: 210062 $, $Date: 2005-07-11 12:52:38 +0900 $
42 */
43class DatagramSession extends BaseSession implements IoSession
44{
45    private final IoSessionManagerFilterChain managerFilterChain;
46    
47    private final IoSessionFilterChain filterChain;
48 
49    private final DatagramChannel ch;
50 
51    private final DatagramSessionConfig config;
52 
53    private final Queue writeBufferQueue;
54 
55    private final Queue writeMarkerQueue;
56 
57    private final IoHandler handler;
58 
59    private final SocketAddress localAddress;
60 
61    private SocketAddress remoteAddress;
62 
63    private SelectionKey key;
64    
65    private boolean disposed;
66 
67    /**
68     * Creates a new instance.
69     */
70    DatagramSession( IoSessionManagerFilterChain managerFilterChain,
71                     DatagramChannel ch, IoHandler defaultHandler )
72    {
73        this.managerFilterChain = managerFilterChain;
74        this.filterChain = new IoSessionFilterChain( managerFilterChain );
75        this.ch = ch;
76        this.config = new DatagramSessionConfig( ch );
77        this.writeBufferQueue = new Queue();
78        this.writeMarkerQueue = new Queue();
79        this.handler = defaultHandler;
80        this.remoteAddress = ch.socket().getRemoteSocketAddress();
81        this.localAddress = ch.socket().getLocalSocketAddress();
82    }
83 
84    IoSessionManagerFilterChain getManagerFilterChain()
85    {
86        return managerFilterChain;
87    }
88    
89    public IoFilterChain getFilterChain()
90    {
91        return filterChain;
92    }
93 
94    DatagramChannel getChannel()
95    {
96        return ch;
97    }
98 
99    SelectionKey getSelectionKey()
100    {
101        return key;
102    }
103 
104    void setSelectionKey( SelectionKey key )
105    {
106        this.key = key;
107    }
108 
109    public IoHandler getHandler()
110    {
111        return handler;
112    }
113    
114    synchronized void notifyClose()
115    {
116        if( !disposed )
117        {
118            disposed = true;
119            notify();
120        }
121    }
122 
123    public synchronized void close( boolean wait )
124    {
125        if( disposed )
126        {
127            return;
128        }
129 
130        IoSessionManager manager = managerFilterChain.getManager();
131        if( manager instanceof DatagramConnector )
132        {
133            ( ( DatagramConnector ) manager ).closeSession( this );
134            if( wait )
135            {
136                while( disposed )
137                {
138                    try
139                    {
140                        wait();
141                    }
142                    catch( InterruptedException e )
143                    {
144                    }
145                }
146            }
147        }
148    }
149 
150    Queue getWriteBufferQueue()
151    {
152        return writeBufferQueue;
153    }
154 
155    Queue getWriteMarkerQueue()
156    {
157        return writeMarkerQueue;
158    }
159 
160    public void write( ByteBuffer buf, Object marker )
161    {
162        filterChain.filterWrite( this, buf, marker );
163    }
164 
165    public int getScheduledWriteRequests()
166    {
167        synchronized( writeBufferQueue )
168        {
169            return writeBufferQueue.size();
170        }
171    }
172 
173    public TransportType getTransportType()
174    {
175        return TransportType.DATAGRAM;
176    }
177 
178    public boolean isConnected()
179    {
180        return ch.isConnected();
181    }
182 
183    public SessionConfig getConfig()
184    {
185        return config;
186    }
187 
188    public SocketAddress getRemoteAddress()
189    {
190        return remoteAddress;
191    }
192 
193    void setRemoteAddress( SocketAddress remoteAddress )
194    {
195        this.remoteAddress = remoteAddress;
196    }
197 
198    public SocketAddress getLocalAddress()
199    {
200        return localAddress;
201    }
202}

[all classes][org.apache.mina.io.datagram]
EMMA 2.0.4217 (C) Vladimir Roubtsov