Package org.apache.mina.examples.sumup.message

Examples of org.apache.mina.examples.sumup.message.ResultMessage


        int value = am.getValue();
        long expectedSum = ( long ) sum + value;
        if( expectedSum > Integer.MAX_VALUE || expectedSum < Integer.MIN_VALUE )
        {
            // if the sum overflows or underflows, return error message
            ResultMessage rm = new ResultMessage();
            rm.setSequence( am.getSequence() ); // copy sequence
            rm.setOk( false );
            session.write( rm );
        }
        else
        {
            // sum up
            sum = ( int ) expectedSum;
            session.setAttachment( new Integer( sum ) );

            // return the result message
            ResultMessage rm = new ResultMessage();
            rm.setSequence( am.getSequence() ); // copy sequence
            rm.setOk( true );
            rm.setValue( sum );
            session.write( rm );
        }
    }
View Full Code Here


    public void messageReceived( IoSession session, Object message )
    {
        // server only sends ResultMessage. otherwise, we will have to identify
        // its type using instanceof operator.
        ResultMessage rm = ( ResultMessage ) message;
        if( rm.isOk() )
        {
            // server returned OK code.
            // if received the result message which has the last sequence
            // number,
            // it is time to disconnect.
            if( rm.getSequence() == values.length - 1 )
            {
                // print the sum and disconnect.
                SessionLog.info( session, "The sum: " + rm.getValue() );
                session.close();
                finished = true;
            }
        }
        else
View Full Code Here

        int value = am.getValue();
        long expectedSum = ( long ) sum + value;
        if( expectedSum > Integer.MAX_VALUE || expectedSum < Integer.MIN_VALUE )
        {
            // if the sum overflows or underflows, return error message
            ResultMessage rm = new ResultMessage();
            rm.setSequence( am.getSequence() ); // copy sequence
            rm.setOk( false );
            session.write( rm );
        }
        else
        {
            // sum up
            sum = ( int ) expectedSum;
            session.setAttachment( new Integer( sum ) );

            // return the result message
            ResultMessage rm = new ResultMessage();
            rm.setSequence( am.getSequence() ); // copy sequence
            rm.setOk( true );
            rm.setValue( sum );
            session.write( rm );
        }
    }
View Full Code Here

    public void messageReceived( ProtocolSession session, Object message )
    {
        // server only sends ResultMessage. otherwise, we will have to identify
        // its type using instanceof operator.
        ResultMessage rm = ( ResultMessage ) message;
        if( rm.isOk() )
        {
            // server returned OK code.
            // if received the result message which has the last sequence
            // number,
            // it is time to disconnect.
            if( rm.getSequence() == values.length - 1 )
            {
                // print the sum and disconnect.
                SessionLog.info( session, "The sum: " + rm.getValue() );
                session.close();
                finished = true;
            }
        }
        else
View Full Code Here

            if( in.remaining() < Constants.RESULT_VALUE_LEN )
            {
                return null;
            }
           
            ResultMessage m = new ResultMessage();
            m.setOk( true );
            m.setValue( in.getInt() );
            readCode = false;
            return m;
        }
        else
        {
            ResultMessage m = new ResultMessage();
            m.setOk( false );
            readCode = false;
            return m;
        }
    }
View Full Code Here

        super( Constants.RESULT );
    }

    protected void encodeBody( ProtocolSession session, AbstractMessage message, ByteBuffer out )
    {
        ResultMessage m = ( ResultMessage ) message;
        if( m.isOk() )
        {
            out.putShort( ( short ) Constants.RESULT_OK );
            out.putInt( m.getValue() );
        }
        else
        {
            out.putShort( ( short ) Constants.RESULT_ERROR );
        }
View Full Code Here

        int value = am.getValue();
        long expectedSum = ( long ) sum + value;
        if( expectedSum > Integer.MAX_VALUE || expectedSum < Integer.MIN_VALUE )
        {
            // if the sum overflows or underflows, return error message
            ResultMessage rm = new ResultMessage();
            rm.setSequence( am.getSequence() ); // copy sequence
            rm.setOk( false );
            session.write( rm );
        }
        else
        {
            // sum up
            sum = ( int ) expectedSum;
            session.setAttachment( new Integer( sum ) );

            // return the result message
            ResultMessage rm = new ResultMessage();
            rm.setSequence( am.getSequence() ); // copy sequence
            rm.setOk( true );
            rm.setValue( sum );
            session.write( rm );
        }
    }
View Full Code Here

    public void messageReceived( IoSession session, Object message )
    {
        // server only sends ResultMessage. otherwise, we will have to identify
        // its type using instanceof operator.
        ResultMessage rm = ( ResultMessage ) message;
        if( rm.isOk() )
        {
            // server returned OK code.
            // if received the result message which has the last sequence
            // number,
            // it is time to disconnect.
            if( rm.getSequence() == values.length - 1 )
            {
                // print the sum and disconnect.
                SessionLog.info( session, "The sum: " + rm.getValue() );
                session.close();
                finished = true;
            }
        }
        else
View Full Code Here

            if( in.remaining() < Constants.RESULT_VALUE_LEN )
            {
                return null;
            }
           
            ResultMessage m = new ResultMessage();
            m.setOk( true );
            m.setValue( in.getInt() );
            readCode = false;
            return m;
        }
        else
        {
            ResultMessage m = new ResultMessage();
            m.setOk( false );
            readCode = false;
            return m;
        }
    }
View Full Code Here

        super( Constants.RESULT );
    }

    protected void encodeBody( ProtocolSession session, AbstractMessage message, ByteBuffer out )
    {
        ResultMessage m = ( ResultMessage ) message;
        if( m.isOk() )
        {
            out.putShort( ( short ) Constants.RESULT_OK );
            out.putInt( m.getValue() );
        }
        else
        {
            out.putShort( ( short ) Constants.RESULT_ERROR );
        }
View Full Code Here

TOP

Related Classes of org.apache.mina.examples.sumup.message.ResultMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.