EMMA Coverage Report (generated Sat Sep 03 11:42:34 KST 2005)
[all classes][org.apache.mina.common]

COVERAGE SUMMARY FOR SOURCE FILE [BaseSession.java]

nameclass, %method, %block, %line, %
BaseSession.java100% (1/1)63%  (12/19)53%  (111/211)59%  (29/49)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BaseSession100% (1/1)63%  (12/19)53%  (111/211)59%  (29/49)
getAttachment (): Object 0%   (0/1)0%   (0/5)0%   (0/1)
getAttributeKeys (): Set 0%   (0/1)0%   (0/16)0%   (0/3)
getReadBytes (): long 0%   (0/1)0%   (0/3)0%   (0/1)
getWrittenBytes (): long 0%   (0/1)0%   (0/3)0%   (0/1)
getWrittenWriteRequests (): long 0%   (0/1)0%   (0/3)0%   (0/1)
isIdle (IdleStatus): boolean 0%   (0/1)0%   (0/30)0%   (0/7)
setAttachment (Object): Object 0%   (0/1)0%   (0/18)0%   (0/3)
setIdle (IdleStatus, boolean): void 100% (1/1)65%  (22/34)88%  (7/8)
removeAttribute (String): Object 100% (1/1)71%  (12/17)67%  (2/3)
setAttribute (String, Object): Object 100% (1/1)72%  (13/18)67%  (2/3)
BaseSession (): void 100% (1/1)100% (14/14)100% (4/4)
close (): void 100% (1/1)100% (4/4)100% (2/2)
getAttribute (String): Object 100% (1/1)100% (5/5)100% (1/1)
getLastIoTime (): long 100% (1/1)100% (6/6)100% (1/1)
getLastReadTime (): long 100% (1/1)100% (3/3)100% (1/1)
getLastWriteTime (): long 100% (1/1)100% (3/3)100% (1/1)
increaseReadBytes (int): void 100% (1/1)100% (11/11)100% (3/3)
increaseWrittenBytes (int): void 100% (1/1)100% (11/11)100% (3/3)
increaseWrittenWriteRequests (): void 100% (1/1)100% (7/7)100% (2/2)

1/*
2 *   @(#) $Id: BaseSession.java 264677 2005-08-30 02:44:35Z 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.common;
20 
21import java.util.HashMap;
22import java.util.Map;
23import java.util.Set;
24 
25import org.apache.mina.common.IdleStatus;
26import org.apache.mina.common.Session;
27 
28/**
29 * Base implementation of {@link Session}.
30 * 
31 * @author Trustin Lee (trustin@apache.org)
32 * @version $Rev: 264677 $, $Date: 2005-08-30 11:44:35 +0900 $
33 */
34public abstract class BaseSession implements Session
35{
36    private final Map attributes = new HashMap();
37 
38    private long readBytes;
39    private long writtenBytes;
40    private long writtenWriteRequests;
41    
42    private long lastReadTime;
43    private long lastWriteTime;
44 
45    private boolean idleForBoth;
46    private boolean idleForRead;
47    private boolean idleForWrite;
48 
49 
50    protected BaseSession()
51    {
52        lastReadTime = lastWriteTime = System.currentTimeMillis();
53    }
54    
55    public void close()
56    {
57        this.close( false );
58    }
59 
60    public Object getAttachment()
61    {
62        return attributes.get( "" );
63    }
64 
65    public Object setAttachment( Object attachment )
66    {
67        synchronized( attributes )
68        {
69            return attributes.put( "", attachment );
70        }
71    }
72 
73    public Object getAttribute( String key )
74    {
75        return attributes.get( key );
76    }
77 
78    public Object setAttribute( String key, Object value )
79    {
80        synchronized( attributes )
81        {
82            return attributes.put( key, value );
83        }
84    }
85    
86    public Object removeAttribute( String key )
87    {
88        synchronized( attributes )
89        {
90            return attributes.remove( key );
91        }
92    }
93 
94    public Set getAttributeKeys() {
95        synchronized( attributes )
96        {
97            return attributes.keySet();
98        }
99    }
100    
101    public long getReadBytes()
102    {
103        return readBytes;
104    }
105 
106    public long getWrittenBytes()
107    {
108        return writtenBytes;
109    }
110 
111    public long getWrittenWriteRequests()
112    {
113        return writtenWriteRequests;
114    }
115    
116    public void increaseReadBytes( int increment )
117    {
118        readBytes += increment;
119        lastReadTime = System.currentTimeMillis();
120    }
121 
122    public void increaseWrittenBytes( int increment )
123    {
124        writtenBytes += increment;
125        lastWriteTime = System.currentTimeMillis();
126    }
127 
128    public void increaseWrittenWriteRequests()
129    {
130        writtenWriteRequests ++;
131    }
132 
133    public long getLastIoTime()
134    {
135        return Math.max( lastReadTime, lastWriteTime );
136    }
137 
138    public long getLastReadTime()
139    {
140        return lastReadTime;
141    }
142 
143    public long getLastWriteTime()
144    {
145        return lastWriteTime;
146    }
147 
148    public boolean isIdle( IdleStatus status )
149    {
150        if( status == IdleStatus.BOTH_IDLE )
151            return idleForBoth;
152 
153        if( status == IdleStatus.READER_IDLE )
154            return idleForRead;
155 
156        if( status == IdleStatus.WRITER_IDLE )
157            return idleForWrite;
158 
159        throw new IllegalArgumentException( "Unknown idle status: " + status );
160    }
161 
162    public void setIdle( IdleStatus status, boolean value )
163    {
164        if( status == IdleStatus.BOTH_IDLE )
165            idleForBoth = value;
166        else if( status == IdleStatus.READER_IDLE )
167            idleForRead = value;
168        else if( status == IdleStatus.WRITER_IDLE )
169            idleForWrite = value;
170        else
171            throw new IllegalArgumentException( "Unknown idle status: "
172                                                + status );
173    }
174}

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