EMMA Coverage Report (generated Wed Jun 08 12:10:57 KST 2005)
[all classes][org.apache.mina.common]

COVERAGE SUMMARY FOR SOURCE FILE [BaseSession.java]

nameclass, %method, %block, %line, %
BaseSession.java100% (1/1)65%  (11/17)50%  (98/195)58%  (26/45)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BaseSession100% (1/1)65%  (11/17)50%  (98/195)58%  (26/45)
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)
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% (8/8)100% (3/3)
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)

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

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