directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r209239 - in /directory/network: branches/0.7/xdocs/ trunk/src/examples/org/apache/mina/examples/netcat/ trunk/src/examples/org/apache/mina/examples/sumup/ trunk/src/examples/org/apache/mina/examples/sumup/codec/ trunk/src/examples/org/apac...
Date Tue, 05 Jul 2005 08:07:23 GMT
Author: trustin
Date: Tue Jul  5 01:07:19 2005
New Revision: 209239

URL: http://svn.apache.org/viewcvs?rev=209239&view=rev
Log:
* Added the migrated SumUp example to trunk, too.
* Fixed some typo errors in getting_started.xml



Added:
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java   (with props)
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ClientSessionHandler.java   (with props)
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java   (with props)
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ServerSessionHandler.java   (with props)
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageDecoder.java   (with props)
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageEncoder.java   (with props)
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageDecoder.java   (with props)
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageEncoder.java   (with props)
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/Constants.java   (with props)
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageDecoder.java   (with props)
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageEncoder.java   (with props)
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/SumUpProtocolCodecFactory.java   (with props)
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AbstractMessage.java   (with props)
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AddMessage.java   (with props)
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/ResultMessage.java   (with props)
Modified:
    directory/network/branches/0.7/xdocs/getting_started.xml
    directory/network/trunk/src/examples/org/apache/mina/examples/netcat/Main.java
    directory/network/trunk/src/java/org/apache/mina/common/BaseIoConnectorConfig.java
    directory/network/trunk/src/java/org/apache/mina/common/IoConnectorConfig.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java
    directory/network/trunk/xdocs/getting_started.xml

Modified: directory/network/branches/0.7/xdocs/getting_started.xml
URL: http://svn.apache.org/viewcvs/directory/network/branches/0.7/xdocs/getting_started.xml?rev=209239&r1=209238&r2=209239&view=diff
==============================================================================
--- directory/network/branches/0.7/xdocs/getting_started.xml (original)
+++ directory/network/branches/0.7/xdocs/getting_started.xml Tue Jul  5 01:07:19 2005
@@ -33,9 +33,9 @@
               <td>Server</td>
             </tr>
             <tr>
-              <td><a target="classFrame" href="xref-examples/org/apache/mina/examples/sumup/package-summary.html">Reverser</a></td>
-              <td>DemuxingProtocolCodecFactory</td>
-              <td>Server</td>
+              <td><a target="classFrame" href="xref-examples/org/apache/mina/examples/sumup/package-summary.html">SumUp server</a></td>
+              <td>High-level protocol layer and DemuxingProtocolCodec</td>
+              <td>Both</td>
             </tr>
             <tr>
               <td><a target="classFrame" href="xref-examples/org/apache/mina/examples/echoserver/package-summary.html">Echo server</a></td>

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/netcat/Main.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/netcat/Main.java?rev=209239&r1=209238&r2=209239&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/netcat/Main.java (original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/netcat/Main.java Tue Jul  5 01:07:19 2005
@@ -45,7 +45,7 @@
         SocketConnector connector = new SocketConnector();
 
         // Set connect timeout.
-        ( ( IoConnectorConfig ) connector.getConfig() ).setDefaultConnectTimeout( 30 );
+        ( ( IoConnectorConfig ) connector.getConfig() ).setConnectTimeout( 30 );
         
         // Start communication.
         connector.connect( 

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,102 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+
+import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoConnectorConfig;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.ThreadPoolFilter;
+import org.apache.mina.transport.socket.nio.SocketConnector;
+
+/**
+ * (<strong>Entry Point</strong>) Starts SumUp client.
+ * 
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public class Client
+{
+    private static final String HOSTNAME = "localhost";
+    private static final int PORT = 8080;
+    private static final int CONNECT_TIMEOUT = 30; // seconds
+
+    public static void main( String[] args ) throws Throwable
+    {
+        if( args.length == 0 )
+        {
+            System.out.println( "Please specify the list of any integers" );
+            return;
+        }
+
+        // prepare values to sum up
+        int[] values = new int[ args.length ];
+        for( int i = 0; i < args.length; i++ )
+        {
+            values[ i ] = Integer.parseInt( args[ i ] );
+        }
+
+        // Create I/O and Protocol thread pool filter.
+        // I/O thread pool performs encoding and decoding of messages.
+        // Protocol thread pool performs actual protocol flow.
+        ThreadPoolFilter ioThreadPoolFilter = new ThreadPoolFilter();
+        ThreadPoolFilter protocolThreadPoolFilter = new ThreadPoolFilter();
+        IoConnector connector = new SocketConnector();
+        connector.getFilterChain().addFirst(
+                "ioThreadPool", ioThreadPoolFilter );
+        connector.getFilterChain().addLast(
+                "protocolThreadPool", protocolThreadPoolFilter );
+
+        // Set connect timeout.
+        ( ( IoConnectorConfig ) connector.getConfig() ).setConnectTimeout( CONNECT_TIMEOUT );
+        
+        IoSession session;
+        for( ;; )
+        {
+            try
+            {
+                ConnectFuture future = connector.connect(
+                        new InetSocketAddress( HOSTNAME, PORT ),
+                        new ClientSessionHandler( values ) );
+                
+                future.join();
+                session = future.getSession();
+                break;
+            }
+            catch( IOException e )
+            {
+                System.err.println( "Failed to connect." );
+                e.printStackTrace();
+                Thread.sleep( 5000 );
+            }
+        }
+
+        // wait until the summation is done
+        while( session.isConnected() )
+        {
+            Thread.sleep( 100 );
+        }
+        
+        // Clear the filter chain so that they are deinitialized.
+        connector.getFilterChain().clear();
+    }
+}

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ClientSessionHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ClientSessionHandler.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ClientSessionHandler.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ClientSessionHandler.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,107 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup;
+
+import java.util.logging.Level;
+
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.examples.sumup.codec.SumUpProtocolCodecFactory;
+import org.apache.mina.examples.sumup.message.AddMessage;
+import org.apache.mina.examples.sumup.message.ResultMessage;
+import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.util.SessionLog;
+
+/**
+ * {@link IoHandler} for SumUp client.
+ * 
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public class ClientSessionHandler extends IoHandlerAdapter
+{
+    private final int[] values;
+    private boolean finished;
+
+    public ClientSessionHandler( int[] values )
+    {
+        this.values = values;
+    }
+
+    public boolean isFinished()
+    {
+        return finished;
+    }
+
+    public void sessionCreated( IoSession session ) throws Exception
+    {
+        session.getFilterChain().addFirst(
+                "protocolFilter", new ProtocolCodecFilter(
+                        new SumUpProtocolCodecFactory( false ) ) );
+        session.getFilterChain().addLast(
+                "logger", new LoggingFilter() );
+    }
+
+    public void sessionOpened( IoSession session )
+    {
+        // send summation requests
+        for( int i = 0; i < values.length; i++ )
+        {
+            AddMessage m = new AddMessage();
+            m.setSequence( i );
+            m.setValue( values[ i ] );
+            session.write( m );
+        }
+    }
+
+    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.log( Level.INFO, session, "The sum: " + rm.getValue() );
+                session.close();
+                finished = true;
+            }
+        }
+        else
+        {
+            // seever returned error code because of overflow, etc.
+            SessionLog.log( Level.WARNING, session, "Server error, disconnecting..." );
+            session.close();
+            finished = true;
+        }
+    }
+
+    public void exceptionCaught( IoSession session, Throwable cause )
+    {
+        session.close();
+    }
+}
\ No newline at end of file

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ClientSessionHandler.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,47 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup;
+
+import org.apache.mina.common.TransportType;
+import org.apache.mina.registry.Service;
+import org.apache.mina.registry.ServiceRegistry;
+import org.apache.mina.registry.SimpleServiceRegistry;
+
+/**
+ * (<strong>Entry Point</strong>) Starts SumUp server.
+ * 
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public class Server
+{
+    private static final int SERVER_PORT = 8080;
+
+    public static void main( String[] args ) throws Throwable
+    {
+        // Create ServiceRegistry.
+        ServiceRegistry registry = new SimpleServiceRegistry();
+
+        registry.bind(
+                new Service( "sumUp", TransportType.SOCKET, SERVER_PORT ),
+                new ServerSessionHandler() );
+
+        System.out.println( "Listening on port " + SERVER_PORT );
+    }
+}

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ServerSessionHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ServerSessionHandler.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ServerSessionHandler.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ServerSessionHandler.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,117 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup;
+
+import java.util.logging.Level;
+
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.examples.sumup.codec.SumUpProtocolCodecFactory;
+import org.apache.mina.examples.sumup.message.AddMessage;
+import org.apache.mina.examples.sumup.message.ResultMessage;
+import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.util.SessionLog;
+
+/**
+ * {@link IoHandler} for SumUp server.
+ * 
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public class ServerSessionHandler implements IoHandler
+{
+
+    public ServerSessionHandler()
+    {
+    }
+
+    public void sessionCreated( IoSession session ) throws Exception
+    {
+        session.getFilterChain().addFirst(
+                "protocolFilter", new ProtocolCodecFilter(
+                        new SumUpProtocolCodecFactory( true ) ) );
+        session.getFilterChain().addLast(
+                "logger", new LoggingFilter() );
+    }
+
+    public void sessionOpened( IoSession session )
+    {
+        // set idle time to 60 seconds
+        session.getConfig().setIdleTime( IdleStatus.BOTH_IDLE, 60 );
+
+        // initial sum is zero
+        session.setAttachment( new Integer( 0 ) );
+    }
+
+    public void sessionClosed( IoSession session )
+    {
+    }
+
+    public void messageReceived( IoSession session, Object message )
+    {
+        // client only sends AddMessage. otherwise, we will have to identify
+        // its type using instanceof operator.
+        AddMessage am = ( AddMessage ) message;
+
+        // add the value to the current sum.
+        int sum = ( ( Integer ) session.getAttachment() ).intValue();
+        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 );
+        }
+    }
+
+    public void messageSent( IoSession session, Object message )
+    {
+    }
+
+    public void sessionIdle( IoSession session, IdleStatus status )
+    {
+        SessionLog.log( Level.WARNING, session, "Disconnecting the idle." );
+        // disconnect an idle client
+        session.close();
+    }
+
+    public void exceptionCaught( IoSession session, Throwable cause )
+    {
+        // close the connection on exceptional situation
+        session.close();
+    }
+}
\ No newline at end of file

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ServerSessionHandler.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageDecoder.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageDecoder.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageDecoder.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,97 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup.codec;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.examples.sumup.message.AbstractMessage;
+import org.apache.mina.filter.codec.MessageDecoder;
+import org.apache.mina.filter.codec.MessageDecoderResult;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.filter.codec.ProtocolViolationException;
+
+/**
+ * A {@link MessageDecoder} that decodes message header and forwards
+ * the decoding of body to a subclass.
+ *
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractMessageDecoder implements MessageDecoder
+{
+    private final int type;
+    
+    private int sequence;
+    private boolean readHeader;
+    
+    protected AbstractMessageDecoder( int type )
+    {
+        this.type = type;
+    }
+
+    public MessageDecoderResult decodable( IoSession session, ByteBuffer in )
+    {
+        // Return NEED_DATA if the whole header is not read yet.
+        if( in.remaining() < Constants.HEADER_LEN )
+        {
+            return MessageDecoderResult.NEED_DATA;
+        }
+        
+        // Return OK if type and bodyLength matches.
+        if( type == in.getShort() )
+        {
+            return MessageDecoderResult.OK;
+        }
+        
+        // Return NOT_OK if not matches.
+        return MessageDecoderResult.NOT_OK;
+    }
+
+    public MessageDecoderResult decode( IoSession session, ByteBuffer in, ProtocolDecoderOutput out ) throws ProtocolViolationException
+    {
+        // Try to skip header if not read.
+        if( !readHeader )
+        {
+            in.getShort(); // Skip 'type'.
+            sequence = in.getInt(); // Get 'sequence'.
+            readHeader = true;
+        }
+        
+        // Try to decode body
+        AbstractMessage m = decodeBody( session, in );
+        // Return NEED_DATA if the body is not fully read.
+        if( m == null )
+        {
+            return MessageDecoderResult.NEED_DATA;
+        }
+        else
+        {
+            readHeader = false; // reset readHeader for the next decode
+        }
+        m.setSequence( sequence );
+        out.write( m );
+        
+        return MessageDecoderResult.OK; 
+    }
+    
+    /**
+     * @return <tt>null</tt> if the whole body is not read yet
+     */
+    protected abstract AbstractMessage decodeBody( IoSession session, ByteBuffer in );
+}

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageDecoder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageEncoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageEncoder.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageEncoder.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageEncoder.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,61 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup.codec;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.examples.sumup.message.AbstractMessage;
+import org.apache.mina.filter.codec.MessageEncoder;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.apache.mina.filter.codec.ProtocolViolationException;
+
+/**
+ * A {@link MessageEncoder} that encodes message header and forwards
+ * the encoding of body to a subclass.
+ *
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractMessageEncoder implements MessageEncoder
+{
+    private final int type;
+
+    protected AbstractMessageEncoder( int type )
+    {
+        this.type = type;
+    }
+
+    public void encode( IoSession session, Object message, ProtocolEncoderOutput out ) throws ProtocolViolationException
+    {
+        AbstractMessage m = ( AbstractMessage ) message ;
+        ByteBuffer buf = ByteBuffer.allocate( 16 );
+        buf.setAutoExpand( true ); // Enable auto-expand for easier encoding
+        
+        // Encode a header
+        buf.putShort( ( short ) type );
+        buf.putInt( m.getSequence() );
+        
+        // Encode a body
+        encodeBody( session, m, buf );
+        buf.flip();
+        out.write( buf );
+    }
+    
+    protected abstract void encodeBody( IoSession session, AbstractMessage message, ByteBuffer out );
+}

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageEncoder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageDecoder.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageDecoder.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageDecoder.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,52 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup.codec;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.examples.sumup.message.AbstractMessage;
+import org.apache.mina.examples.sumup.message.AddMessage;
+import org.apache.mina.filter.codec.MessageDecoder;
+
+/**
+ * A {@link MessageDecoder} that decodes {@link AddMessage}.
+ *
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public class AddMessageDecoder extends AbstractMessageDecoder
+{
+
+    public AddMessageDecoder()
+    {
+        super( Constants.ADD );
+    }
+
+    protected AbstractMessage decodeBody( IoSession session, ByteBuffer in )
+    {
+        if( in.remaining() < Constants.ADD_BODY_LEN )
+        {
+            return null;
+        }
+
+        AddMessage m = new AddMessage();
+        m.setValue( in.getInt() );
+        return m;
+    }
+}

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageDecoder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageEncoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageEncoder.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageEncoder.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageEncoder.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,63 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup.codec;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.examples.sumup.message.AbstractMessage;
+import org.apache.mina.examples.sumup.message.AddMessage;
+import org.apache.mina.filter.codec.MessageEncoder;
+
+/**
+ * A {@link MessageEncoder} that encodes {@link AddMessage}.
+ *
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public class AddMessageEncoder extends AbstractMessageEncoder
+{
+    private static final Set TYPES;
+   
+    static
+    {
+        Set types = new HashSet();
+        types.add( AddMessage.class );
+        TYPES = Collections.unmodifiableSet( types );
+    }
+
+    public AddMessageEncoder()
+    {
+        super( Constants.ADD );
+    }
+
+    protected void encodeBody( IoSession session, AbstractMessage message, ByteBuffer out )
+    {
+        AddMessage m = ( AddMessage ) message;
+        out.putInt( m.getValue() );
+    }
+
+    public Set getMessageTypes()
+    {
+        return TYPES;
+    }
+}

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageEncoder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/Constants.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/Constants.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/Constants.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/Constants.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,44 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup.codec;
+
+/**
+ * Provides SumUp protocol constants.
+ * 
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public class Constants
+{
+    public static final int TYPE_LEN = 2;
+    public static final int SEQUENCE_LEN = 4;
+    public static final int HEADER_LEN = TYPE_LEN + SEQUENCE_LEN;
+    public static final int BODY_LEN = 12;
+    public static final int RESULT = 0;
+    public static final int ADD = 1;
+    public static final int RESULT_CODE_LEN = 2;
+    public static final int RESULT_VALUE_LEN = 4;
+    public static final int ADD_BODY_LEN = 4;
+    public static final int RESULT_OK = 0;
+    public static final int RESULT_ERROR = 1;
+
+    private Constants()
+    {
+    }
+}

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/Constants.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageDecoder.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageDecoder.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageDecoder.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,77 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup.codec;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.examples.sumup.message.AbstractMessage;
+import org.apache.mina.examples.sumup.message.ResultMessage;
+import org.apache.mina.filter.codec.MessageDecoder;
+
+/**
+ * A {@link MessageDecoder} that decodes {@link ResultMessage}.
+ *
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public class ResultMessageDecoder extends AbstractMessageDecoder
+{
+    private int code;
+    private boolean readCode;
+    
+    public ResultMessageDecoder()
+    {
+        super( Constants.RESULT );
+    }
+
+    protected AbstractMessage decodeBody( IoSession session, ByteBuffer in )
+    {
+        if( !readCode )
+        {
+            if( in.remaining() < Constants.RESULT_CODE_LEN )
+            {
+                return null; // Need more data.
+            }
+            
+            code = in.getShort();
+            readCode = true;
+        }
+        
+        if( code == Constants.RESULT_OK )
+        {
+            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;
+        }
+    }
+}

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageDecoder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageEncoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageEncoder.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageEncoder.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageEncoder.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,72 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup.codec;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.examples.sumup.message.AbstractMessage;
+import org.apache.mina.examples.sumup.message.ResultMessage;
+import org.apache.mina.filter.codec.MessageEncoder;
+
+/**
+ * A {@link MessageEncoder} that encodes {@link ResultMessage}.
+ *
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public class ResultMessageEncoder extends AbstractMessageEncoder
+{
+    private static final Set TYPES;
+    
+    static
+    {
+        Set types = new HashSet();
+        types.add( ResultMessage.class );
+        TYPES = Collections.unmodifiableSet( types );
+    }
+
+    public ResultMessageEncoder()
+    {
+        super( Constants.RESULT );
+    }
+
+    protected void encodeBody( IoSession 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 );
+        }
+    }
+
+    public Set getMessageTypes()
+    {
+        return TYPES;
+    }
+
+}

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageEncoder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/SumUpProtocolCodecFactory.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/SumUpProtocolCodecFactory.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/SumUpProtocolCodecFactory.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/SumUpProtocolCodecFactory.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,47 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup.codec;
+
+import org.apache.mina.filter.codec.DemuxingProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+
+/**
+ * A {@link ProtocolCodecFactory} that provides a protocol codec for
+ * SumUp protocol.
+ *
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public class SumUpProtocolCodecFactory extends DemuxingProtocolCodecFactory
+{
+
+    public SumUpProtocolCodecFactory( boolean server )
+    {
+        if( server )
+        {
+            super.register( AddMessageDecoder.class );
+            super.register( ResultMessageEncoder.class );
+        }
+        else // Client
+        {
+            super.register( AddMessageEncoder.class );
+            super.register( ResultMessageDecoder.class );
+        }
+    }
+}

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/SumUpProtocolCodecFactory.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AbstractMessage.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AbstractMessage.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AbstractMessage.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AbstractMessage.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,40 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup.message;
+
+/**
+ * A base message for SumUp protocol messages.
+ * 
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractMessage
+{
+    private int sequence;
+
+    public int getSequence()
+    {
+        return sequence;
+    }
+
+    public void setSequence( int sequence )
+    {
+        this.sequence = sequence;
+    }
+}
\ No newline at end of file

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AbstractMessage.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AddMessage.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AddMessage.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AddMessage.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AddMessage.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,50 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup.message;
+
+/**
+ * <code>ADD</code> message in SumUp protocol.
+ * 
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public class AddMessage extends AbstractMessage
+{
+    private int value;
+
+    public AddMessage()
+    {
+    }
+
+    public int getValue()
+    {
+        return value;
+    }
+
+    public void setValue( int value )
+    {
+        this.value = value;
+    }
+
+    public String toString()
+    {
+        // it is a good practice to create toString() method on message classes.
+        return getSequence() + ":ADD(" + value + ')';
+    }
+}

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AddMessage.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/ResultMessage.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/ResultMessage.java?rev=209239&view=auto
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/ResultMessage.java (added)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/ResultMessage.java Tue Jul  5 01:07:19 2005
@@ -0,0 +1,67 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.sumup.message;
+
+/**
+ * <code>RESULT</code> message in SumUp protocol.
+ * 
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public class ResultMessage extends AbstractMessage
+{
+    private boolean ok;
+    private int value;
+
+    public ResultMessage()
+    {
+    }
+
+    public boolean isOk()
+    {
+        return ok;
+    }
+
+    public void setOk( boolean ok )
+    {
+        this.ok = ok;
+    }
+
+    public int getValue()
+    {
+        return value;
+    }
+
+    public void setValue( int value )
+    {
+        this.value = value;
+    }
+
+    public String toString()
+    {
+        if( ok )
+        {
+            return getSequence() + ":RESULT(" + value + ')';
+        }
+        else
+        {
+            return getSequence() + ":RESULT(ERROR)";
+        }
+    }
+}
\ No newline at end of file

Propchange: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/ResultMessage.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/network/trunk/src/java/org/apache/mina/common/BaseIoConnectorConfig.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/BaseIoConnectorConfig.java?rev=209239&r1=209238&r2=209239&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/BaseIoConnectorConfig.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/BaseIoConnectorConfig.java Tue Jul  5 01:07:19 2005
@@ -32,17 +32,17 @@
     {
     }
 
-    public int getDefaultConnectTimeout()
+    public int getConnectTimeout()
     {
         return defaultConnectTimeout;
     }
 
-    public long getDefaultConnectTimeoutMillis()
+    public long getConnectTimeoutMillis()
     {
         return defaultConnectTimeout * 1000L;
     }
 
-    public void setDefaultConnectTimeout( int defaultConnectTimeout )
+    public void setConnectTimeout( int defaultConnectTimeout )
     {
         if( defaultConnectTimeout <= 0 )
         {

Modified: directory/network/trunk/src/java/org/apache/mina/common/IoConnectorConfig.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/IoConnectorConfig.java?rev=209239&r1=209238&r2=209239&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/IoConnectorConfig.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/IoConnectorConfig.java Tue Jul  5 01:07:19 2005
@@ -28,17 +28,17 @@
 public interface IoConnectorConfig extends IoSessionManagerConfig
 {
     /**
-     * Returns the default connect timeout in seconds.
+     * Returns the connect timeout in seconds.
      */
-    int getDefaultConnectTimeout();
+    int getConnectTimeout();
 
     /**
-     * Returns the default connect timeout in milliseconds.
+     * Returns the connect timeout in milliseconds.
      */
-    long getDefaultConnectTimeoutMillis();
+    long getConnectTimeoutMillis();
 
     /**
-     * Sets the default connect timeout in seconds.
+     * Sets the connect timeout in seconds.
      */
-    void setDefaultConnectTimeout( int defaultConnectTimeout );
+    void setConnectTimeout( int defaultConnectTimeout );
 }

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java?rev=209239&r1=209238&r2=209239&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java Tue Jul  5 01:07:19 2005
@@ -120,7 +120,7 @@
             }
         }
         
-        ConnectionRequest request = new ConnectionRequest( ch, config.getDefaultConnectTimeout(), handler );
+        ConnectionRequest request = new ConnectionRequest( ch, config.getConnectTimeout(), handler );
         synchronized( this )
         {
             synchronized( connectQueue )

Modified: directory/network/trunk/xdocs/getting_started.xml
URL: http://svn.apache.org/viewcvs/directory/network/trunk/xdocs/getting_started.xml?rev=209239&r1=209238&r2=209239&view=diff
==============================================================================
--- directory/network/trunk/xdocs/getting_started.xml (original)
+++ directory/network/trunk/xdocs/getting_started.xml Tue Jul  5 01:07:19 2005
@@ -33,6 +33,11 @@
               <td>Server</td>
             </tr>
             <tr>
+              <td><a target="classFrame" href="xref-examples/org/apache/mina/examples/sumup/package-summary.html">SumUp server</a></td>
+              <td>High-level protocol layer and DemuxingProtocolCodec</td>
+              <td>Both</td>
+            </tr>
+            <tr>
               <td><a target="classFrame" href="xref-examples/org/apache/mina/examples/echoserver/package-summary.html">Echo server</a></td>
               <td>Low-level I/O layer and SSL support</td>
               <td>Server</td>



Mime
View raw message