1 20 package org.apache.mina.example.sumup.codec; 21 22 import java.util.Collections ; 23 import java.util.HashSet ; 24 import java.util.Set ; 25 26 import org.apache.mina.common.ByteBuffer; 27 import org.apache.mina.common.IoSession; 28 import org.apache.mina.example.sumup.message.AbstractMessage; 29 import org.apache.mina.example.sumup.message.AddMessage; 30 import org.apache.mina.filter.codec.demux.MessageEncoder; 31 32 38 public class AddMessageEncoder extends AbstractMessageEncoder { 39 private static final Set <Class <?>> TYPES; 40 41 static { 42 Set <Class <?>> types = new HashSet <Class <?>>(); 43 types.add(AddMessage.class); 44 TYPES = Collections.unmodifiableSet(types); 45 } 46 47 public AddMessageEncoder() { 48 super(Constants.ADD); 49 } 50 51 protected void encodeBody(IoSession session, AbstractMessage message, 52 ByteBuffer out) { 53 AddMessage m = (AddMessage) message; 54 out.putInt(m.getValue()); 55 } 56 57 public Set <Class <?>> getMessageTypes() { 58 return TYPES; 59 } 60 61 public void dispose() throws Exception { 62 } 63 } 64 | Popular Tags |