On 1 May 2006, at 14:59, peter royal wrote:
On Apr 28, 2006, at 6:28 AM, Frederic Soulier wrote:
So I already have a custom server that does all that but I'd like to
re-prototype the core of my server using MINA for maintainabilty
reasons
and to check what sort of perf can be achieved.
Can all this be done with ProtocolHandler and the likes?
You'll probably be creating your own IoFilter's, rather than using
the ones that MINA ships with, but what you describe is totally
possible in MINA.
-pete
Thx Pete.
I really dug into MINA (0.9.3) today and I managed to implement 1
message (and funnily enough it works!) using the SumUp examples as my
starting point.
The final system must be able to handle 30+ different messages of the
form:
short - msg type
int - internal system handle
int - length of msg body
byte[] - msg body encrypted
I can easily know whether I need more data or not as a pre-requisite
for a decodable message is to have the msg header=short+int+int
Once I get that I know whether I have the full msg payload (encrypted
body) by checking if I have at least this number of bytes in the buffer.
Now I guess I could have have 30+ decoders registered (using
DemuxingProtocolCodecFactory) and for each message I'd have something
like that:
1st decoder tests if message is decodable
if yes then 1st decoder decodes body
if no then 2nd decoder tests if message is decodable
if yes then 2nd decoder decodes body
if no then 3rd decoder tests if message is decodable
etc... etc...
But I have the *impression* it's not efficient.
Would it be better to have only 1 decoder and a case structure in
decode that would instantiate the right message based on the type.
Also ultimately the messages will be processed by
public void messageReceived(IoSession session, Object message)
in my IoHandler
Is it ok to have long running transactions in there?
[Threading]
This is the code I use to setup the IoAcceptor
IoAcceptor acceptor = new SocketAcceptor();
IoAcceptorConfig config = new SocketAcceptorConfig();
DefaultIoFilterChainBuilder chain = config.getFilterChain();
chain.addLast("ioLogger", new LoggingFilter());
acceptor.bind(new InetSocketAddress(PORT),
new ServerSessionHandler(this),
config);
Do I need to add a ThreadPoolFilter to the chain or is one
automatically setup?
Looking at the src BaseIoServiceConfig file it seems a
PooledThreadModel (with max size = 16) is the default if the user
doesn't defined one, right?
[Logging issue]
Finally I keep getting the warning from Log4j (log4j:WARN No
appenders could be found for logger) and I'm baffled as to why it
does that.
I have nlog4j-1.2.24.jar, slf4j-log4j12.jar and log4j.properties (or
log4j.xml) in my classpath at runtime.
I get the message when MINA's LoggingFilter tries to log in something
from my IoHandler where I've added it to the filter chain.
public void sessionCreated(IoSession session) throws Exception
{
ProtocolCodecFactory codec = new MessagesProtocolCodecFactory();
session.getFilterChain().addFirst("protocolFilter", new
ProtocolCodecFilter(codec));
session.getFilterChain().addLast("sessionLogger", new
LoggingFilter());
}
Some comments:
- I really like what I've seen so far and most of my problems
come from not knowing exactly how to use the framework
- The getting started stuff on the web site and the fact I'm
using the unstable version confuses things :)
Thx for any help.
--
Frederic P. Soulier
OpenPGP key available on http://pgpkeys.mit.edu/
1024D/BA6700ED 49A6 8E8E 4230 8D41 1ADE B649 3203 1DD2 BA67 00ED