EMMA Coverage Report (generated Sat Sep 03 11:42:34 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/88)0%   (0/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

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

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