Hi all,
i need your help.
I am using *apache mina 2.0 RC1* for my card game and
I am using OrderedThreadPoolExecutor for read and write server side.
chain.addLast("readExecutor", new ExecutorFilter(new
OrderedThreadPoolExecutor(), IoEventType.MESSAGE_RECEIVED));
chain.addLast("codec", new ProtocolCodecFilter(new
FlashCrossdomainCodec()));
chain.addLast("writeExecutor", new ExecutorFilter(new
OrderedThreadPoolExecutor(), IoEventType.WRITE));
Also my codec is a CumulativeProtocolDecoder with the following code:
public class *FlashDecoder *extends *CumulativeProtocolDecoder *{
private Map<Long, String> buffer = Collections.synchronizedMap(new
HashMap<Long, String>());
private static final Logger log =
LoggerFactory.getLogger(FlashCrossdomainDecoder.class);
@Override
protected boolean doDecode(IoSession session, IoBuffer in,
ProtocolDecoderOutput out) throws Exception {
StringBuffer msg = new StringBuffer();
while (in.hasRemaining()) {
byte[] data = new byte[in.remaining()];
in.get(data);
msg.append(new String(data));
}
if (msg.toString().codePointAt(msg.toString().length()-1) == '\0') {
if (buffer.containsKey(session.getId())) {
String res = buffer.get(session.getId()) + msg.toString();
res = res.trim();
out.write(res);
buffer.remove(session.getId());
} else {
String res = msg.toString();
res = res.trim();
out.write(res);
log.debug("[doDecode] out=" + res.trim());
return true;
}
} else {
if (buffer.containsKey(session.getId())) {
buffer.put(session.getId(), buffer.get(session.getId()) +
msg.toString());
} else {
buffer.put(session.getId(), msg.toString());
}
}
return false;
}
}
public class *FlashEncoder *extends ProtocolEncoderAdapter {
private static final Logger log =
LoggerFactory.getLogger(FlashCrossdomainEncoder.class);
public void encode(IoSession session, Object message,
ProtocolEncoderOutput out) throws Exception {
try {
out.write(IoBuffer.wrap(message.toString().getBytes()));
log.debug("[encode] message=" + message.toString().trim());
} catch (Throwable e) {
e.printStackTrace();
}
}
}
PROBLEM:
Sometimes the server seems to send a string but the client receives other or
(old) one !
Server Sent
17:48:23,790 DEBUG {pool-4-thread-2} a:? - [encode] message=<game g="4931"
d="2" s="2" a="0" h="turn" lr="check" ia="0"/>
17:48:23,891 DEBUG {pool-4-thread-4} a:? - [encode] message=<game g="4931"
d="2" s="2" a="0" h="turn" lr="check" ia="0"/>
Client Received
17:48:23,792 DEBUG {pool-6-thread-1} Handler:543 - << tob RECEIVED=<game
g="4931" d="2" s="2" a="0" h="turn" lr="check" ia="0"/>
here i don't see any other received data from server by antares only this:
17:48:24,174 DEBUG {pool-3-thread-1} Handler:543 - << antares RECEIVED=<game
g="4931" d="2" *s="1"* a="0" h="turn" lr="" ia="0"/>
So in order i receive:
<game g="4931" d="2" s="1" a="0" h="burningandturn" lr="check" ia="0"/>
<game g="4931" d="2" s="1" a="0" h="burningandturn" lr="check" ia="0"/>
<game g="4931" d="2" s="1" a="0" h="turn" lr="" ia="0"/>
<game g="4931" d="2" s="2" a="0" h="turn" lr="check" ia="0"/>
<game g="4931" d="2" *s="1"* a="0" h="turn" lr="" ia="0"/>
Please what is wrong ? I need to do something to the codec ?
Thanks! and i like so much Mina
Francesco