EMMA Coverage Report (generated Fri Oct 21 16:16:13 KST 2005)
[all classes][org.apache.mina.examples.sumup]

COVERAGE SUMMARY FOR SOURCE FILE [ServerSessionHandler.java]

nameclass, %method, %block, %line, %
ServerSessionHandler.java0%   (0/1)0%   (0/8)0%   (0/103)0%   (0/32)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ServerSessionHandler0%   (0/1)0%   (0/8)0%   (0/103)0%   (0/32)
ServerSessionHandler (): void 0%   (0/1)0%   (0/3)0%   (0/2)
exceptionCaught (ProtocolSession, Throwable): void 0%   (0/1)0%   (0/3)0%   (0/2)
messageReceived (ProtocolSession, Object): void 0%   (0/1)0%   (0/68)0%   (0/18)
messageSent (ProtocolSession, Object): void 0%   (0/1)0%   (0/1)0%   (0/1)
sessionClosed (ProtocolSession): void 0%   (0/1)0%   (0/1)0%   (0/1)
sessionCreated (ProtocolSession): void 0%   (0/1)0%   (0/8)0%   (0/2)
sessionIdle (ProtocolSession, IdleStatus): void 0%   (0/1)0%   (0/6)0%   (0/3)
sessionOpened (ProtocolSession): void 0%   (0/1)0%   (0/13)0%   (0/3)

1/*
2 *   @(#) $Id: ServerSessionHandler.java 327113 2005-10-21 06:59:15Z 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.examples.sumup;
20 
21import org.apache.mina.common.IdleStatus;
22import org.apache.mina.examples.sumup.message.AddMessage;
23import org.apache.mina.examples.sumup.message.ResultMessage;
24import org.apache.mina.protocol.ProtocolHandler;
25import org.apache.mina.protocol.ProtocolSession;
26import org.apache.mina.protocol.filter.ProtocolLoggingFilter;
27import org.apache.mina.util.SessionLog;
28 
29/**
30 * {@link ProtocolHandler} for SumUp server.
31 * 
32 * @author The Apache Directory Project
33 * @version $Rev: 327113 $, $Date: 2005-10-21 15:59:15 +0900 $
34 */
35public class ServerSessionHandler implements ProtocolHandler
36{
37 
38    public ServerSessionHandler()
39    {
40    }
41 
42    public void sessionCreated( ProtocolSession session ) throws Exception
43    {
44        session.getFilterChain().addLast(
45                "logger", new ProtocolLoggingFilter() );
46    }
47 
48    public void sessionOpened( ProtocolSession session )
49    {
50        // set idle time to 60 seconds
51        session.getConfig().setIdleTime( IdleStatus.BOTH_IDLE, 60 );
52 
53        // initial sum is zero
54        session.setAttachment( new Integer( 0 ) );
55    }
56 
57    public void sessionClosed( ProtocolSession session )
58    {
59    }
60 
61    public void messageReceived( ProtocolSession session, Object message )
62    {
63        // client only sends AddMessage. otherwise, we will have to identify
64        // its type using instanceof operator.
65        AddMessage am = ( AddMessage ) message;
66 
67        // add the value to the current sum.
68        int sum = ( ( Integer ) session.getAttachment() ).intValue();
69        int value = am.getValue();
70        long expectedSum = ( long ) sum + value;
71        if( expectedSum > Integer.MAX_VALUE || expectedSum < Integer.MIN_VALUE )
72        {
73            // if the sum overflows or underflows, return error message
74            ResultMessage rm = new ResultMessage();
75            rm.setSequence( am.getSequence() ); // copy sequence
76            rm.setOk( false );
77            session.write( rm );
78        }
79        else
80        {
81            // sum up
82            sum = ( int ) expectedSum;
83            session.setAttachment( new Integer( sum ) );
84 
85            // return the result message
86            ResultMessage rm = new ResultMessage();
87            rm.setSequence( am.getSequence() ); // copy sequence
88            rm.setOk( true );
89            rm.setValue( sum );
90            session.write( rm );
91        }
92    }
93 
94    public void messageSent( ProtocolSession session, Object message )
95    {
96    }
97 
98    public void sessionIdle( ProtocolSession session, IdleStatus status )
99    {
100        SessionLog.warn( session, "Disconnecting the idle." );
101        // disconnect an idle client
102        session.close();
103    }
104 
105    public void exceptionCaught( ProtocolSession session, Throwable cause )
106    {
107        // close the connection on exceptional situation
108        session.close();
109    }
110}

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