Changeset 1153

Show
Ignore:
Timestamp:
12/04/07 00:55:53 (1 year ago)
Author:
alban
Message:

Added Ping message and idle session management. Fixes #161

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/source/org/kolaka/freecast/transport/cas/ConnectionAssistantServiceSkeleton.java

    r405 r1153  
    22 * FreeCast - streaming over Internet 
    33 * 
    4  * This code was developped by Alban Peignier (http://people.tryphon.org/~alban/)  
     4 * This code was developped by Alban Peignier (http://people.tryphon.org/~alban/) 
    55 * and contributors (their names can be found in the CONTRIBUTORS file). 
    66 * 
     
    3030import org.apache.mina.common.IoHandlerAdapter; 
    3131import org.apache.mina.common.IoSession; 
     32import org.apache.mina.common.IdleStatus; 
    3233import org.kolaka.freecast.transport.cas.ConnectionAssistantService.ConnectionHandler; 
    3334import org.kolaka.freecast.transport.cas.ConnectionAssistantService.Session; 
     
    4647                session.getFilterChain().addLast("codec", 
    4748                                ConnectionProtocolCodecFactory.FILTER); 
     49                session.setIdleTime(IdleStatus.BOTH_IDLE, 120); 
    4850        } 
    4951 
     
    5658 
    5759        public void sessionClosed(IoSession session) throws Exception { 
     60                LogFactory.getLog(getClass()).info("sessionClosed"); 
     61 
    5862                Session serviceSession = (Session) session.getAttachment(); 
    5963                serviceSession.close(); 
    6064        } 
     65 
     66        public void sessionIdle(IoSession session, IdleStatus status) throws Exception { 
     67                LogFactory.getLog(getClass()).info("sessionIdle"); 
     68    session.close(); 
     69  } 
    6170 
    6271        public void messageReceived(IoSession session, Object object) 
  • trunk/source/org/kolaka/freecast/transport/cas/ConnectionAssistantServiceStub.java

    r636 r1153  
    22 * FreeCast - streaming over Internet 
    33 * 
    4  * This code was developped by Alban Peignier (http://people.tryphon.org/~alban/)  
     4 * This code was developped by Alban Peignier (http://people.tryphon.org/~alban/) 
    55 * and contributors (their names can be found in the CONTRIBUTORS file). 
    66 * 
     
    3636import org.apache.mina.common.IoHandlerAdapter; 
    3737import org.apache.mina.common.IoSession; 
     38import org.apache.mina.common.IdleStatus; 
    3839import org.kolaka.freecast.transport.cas.ProtocolMessage.ConnectionRequest; 
    3940 
     
    9091                                        session.getFilterChain().addLast("codec", 
    9192                                                        ConnectionProtocolCodecFactory.FILTER); 
    92  
     93                                        session.setIdleTime(IdleStatus.BOTH_IDLE, 60); 
    9394                                } 
    9495 
     
    9899                                        processConnectionRequest(request.getPendingConnection()); 
    99100                                } 
     101 
     102                                public void sessionIdle(IoSession session, IdleStatus status) throws Exception { 
     103          protocolSession.write(new ProtocolMessage.Ping()); 
     104        } 
    100105 
    101106                                public void exceptionCaught(IoSession session, Throwable t) 
  • trunk/source/org/kolaka/freecast/transport/cas/ProtocolCodec.java

    r405 r1153  
    22 * FreeCast - streaming over Internet 
    33 * 
    4  * This code was developped by Alban Peignier (http://people.tryphon.org/~alban/)  
     4 * This code was developped by Alban Peignier (http://people.tryphon.org/~alban/) 
    55 * and contributors (their names can be found in the CONTRIBUTORS file). 
    66 * 
     
    3939import org.kolaka.freecast.transport.cas.ProtocolMessage.Registration; 
    4040import org.kolaka.freecast.transport.cas.ProtocolMessage.Type; 
     41import org.kolaka.freecast.transport.cas.ProtocolMessage.Ping; 
    4142 
    4243public class ProtocolCodec implements ProtocolEncoder, ProtocolDecoder { 
     
    6364                        PendingConnection connection = decodeConnection(buffer); 
    6465                        message = new ProtocolMessage.ConnectionRequest(connection); 
     66                } else if (type.equals(ProtocolMessage.Ping.TYPE)) { 
     67                        message = new ProtocolMessage.Ping(); 
    6568                } else { 
    6669                        throw new ProtocolDecoderException("Unsupported message type: " 
     
    8689                        ProtocolMessage.ConnectionMessage connectionMessage = (ConnectionMessage) message; 
    8790                        encodeConnection(buffer, connectionMessage.getPendingConnection()); 
     91                } else if (message instanceof Ping) { 
     92 
    8893                } else { 
    8994                        throw new ProtocolEncoderException("Unsupported message type: " 
  • trunk/source/org/kolaka/freecast/transport/cas/ProtocolMessage.java

    r405 r1153  
    22 * FreeCast - streaming over Internet 
    33 * 
    4  * This code was developped by Alban Peignier (http://people.tryphon.org/~alban/)  
     4 * This code was developped by Alban Peignier (http://people.tryphon.org/~alban/) 
    55 * and contributors (their names can be found in the CONTRIBUTORS file). 
    66 * 
     
    4444 
    4545                public static final Type CONNECTION_REQUEST = new Type("request", 2); 
     46 
     47                public static final Type PING = new Type("ping", 3); 
    4648 
    4749                Type(String name, int value) { 
     
    119121        } 
    120122 
     123        public static class Ping extends ProtocolMessage { 
     124 
     125                public static final Type TYPE = Type.PING; 
     126 
     127                public Ping() { 
     128                        super(); 
     129                } 
     130 
     131                public Type getType() { 
     132                        return TYPE; 
     133                } 
     134 
     135        } 
     136 
    121137        public abstract Type getType(); 
    122138