Apache Directory Project - [mina] Changing Filters Durning Application Cycles

This is Interesting: Free IT Magazines  
Home > Archive > Apache Directory Project > May 2006 > [mina] Changing Filters Durning Application Cycles





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author [mina] Changing Filters Durning Application Cycles
Tyler Pitchford

2006-05-14, 1:11 pm

I can't seem to find an answer to this and I am getting very spotting
results (looks like threading issues). I'm tyring to build a
BitTorrent Filter for MINA, but I can't seem to get everything working
correctly.

To understand that situation, you'll need a little background on the
BT protocol. When connecting to a peer a "handshake" message is sent,
nothing unusual here, right? Well, sadly the handshake doesn't follow
the wire header format. The Handshake uses a singly byte for it's
header and the wire messages use a 4 byte header.

Anyway, to handle it "cleanly" (probably not the fastest, but nicely
architecturally), I developed a PeerWireHandshakeCodecFactory and a
PeerWireCodecFactory. I could just change the header length, once the
handshake was received, but I don't want to mix the handshake / wire
messages, because in my opinion they should be handled separately.
Anyway, I'm currently trying to do this is once the handshake response
is received (handshake part is working correctly), I call:

public void messageReceived(IoSession session, Object message){
if (message instanceof PeerWireHandshakeMessage) {
synchronized(session){
session.getFilterChain().remove("handshakeFilter");
ProtocolCodecFactory codec =3D new PeerWireCodecFactory();
session.getFilterChain().addFirst("peerWireFilter", new
ProtocolCodecFilter(codec));
}
}

The problem I'm seeing is that the PeerWire Encoders/Decoders never
seem to get called. I've only seen them called one time, while
debugged, which makes me think it's a threading issue. Any help /
advice would be lovely. I'm not opposed to changing the architecture,
if needed.

Cheers,
Tyler

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com