EMMA Coverage Report (generated Sat Nov 12 08:39:53 KST 2005)
[all classes][org.apache.mina.examples.sumup]

COVERAGE SUMMARY FOR SOURCE FILE [ClientSessionHandler.java]

nameclass, %method, %block, %line, %
ClientSessionHandler.java0%   (0/1)0%   (0/6)0%   (0/86)0%   (0/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ClientSessionHandler0%   (0/1)0%   (0/6)0%   (0/86)0%   (0/25)
ClientSessionHandler (int []): void 0%   (0/1)0%   (0/6)0%   (0/3)
exceptionCaught (ProtocolSession, Throwable): void 0%   (0/1)0%   (0/3)0%   (0/2)
isFinished (): boolean 0%   (0/1)0%   (0/3)0%   (0/1)
messageReceived (ProtocolSession, Object): void 0%   (0/1)0%   (0/40)0%   (0/11)
sessionCreated (ProtocolSession): void 0%   (0/1)0%   (0/8)0%   (0/2)
sessionOpened (ProtocolSession): void 0%   (0/1)0%   (0/26)0%   (0/6)

1/*
2 *   @(#) $Id: ClientSessionHandler.java 332218 2005-11-10 03:52:42Z 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.examples.sumup.message.AddMessage;
22import org.apache.mina.examples.sumup.message.ResultMessage;
23import org.apache.mina.protocol.ProtocolHandler;
24import org.apache.mina.protocol.ProtocolHandlerAdapter;
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 client.
31 * 
32 * @author The Apache Directory Project
33 * @version $Rev: 332218 $, $Date: 2005-11-10 12:52:42 +0900 $
34 */
35public class ClientSessionHandler extends ProtocolHandlerAdapter
36{
37    private final int[] values;
38 
39    private boolean finished;
40 
41    public ClientSessionHandler( int[] values )
42    {
43        this.values = values;
44    }
45 
46    public boolean isFinished()
47    {
48        return finished;
49    }
50 
51    public void sessionCreated( ProtocolSession session )
52    {
53        session.getFilterChain().addLast(
54                "logger", new ProtocolLoggingFilter() );
55    }
56 
57    public void sessionOpened( ProtocolSession session )
58    {
59        // send summation requests
60        for( int i = 0; i < values.length; i++ )
61        {
62            AddMessage m = new AddMessage();
63            m.setSequence( i );
64            m.setValue( values[ i ] );
65            session.write( m );
66        }
67    }
68 
69    public void messageReceived( ProtocolSession session, Object message )
70    {
71        // server only sends ResultMessage. otherwise, we will have to identify
72        // its type using instanceof operator.
73        ResultMessage rm = ( ResultMessage ) message;
74        if( rm.isOk() )
75        {
76            // server returned OK code.
77            // if received the result message which has the last sequence
78            // number,
79            // it is time to disconnect.
80            if( rm.getSequence() == values.length - 1 )
81            {
82                // print the sum and disconnect.
83                SessionLog.info( session, "The sum: " + rm.getValue() );
84                session.close();
85                finished = true;
86            }
87        }
88        else
89        {
90            // seever returned error code because of overflow, etc.
91            SessionLog.warn( session, "Server error, disconnecting..." );
92            session.close();
93            finished = true;
94        }
95    }
96 
97    public void exceptionCaught( ProtocolSession session, Throwable cause )
98    {
99        session.close();
100    }
101}

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