Hi again,
first of all thanks to you all for your quick reply.
I tried to use the OrderedThreadPool, I still have the following
exception server side:
java.nio.BufferUnderflowException
at java.nio.HeapByteBuffer.get(HeapByteBuffer.java:127)
at
org.apache.mina.core.buffer.AbstractIoBuffer.get(AbstractIoBuffer.java:421)
at
org.apache.mina.core.buffer.AbstractIoBuffer.get(AbstractIoBuffer.java:833)
at com.eris4.diameter.types.OctetString.decode(OctetString.java:18)
at com.eris4.diameter.types.Address.decode(Address.java:17)
at
com.eris4.creditcontrol.commands.CapabilitiesExchangeRequest.decode(CapabilitiesExchangeRequest.java:238)
at
com.eris4.creditcontrol.mina.CreditControlServerDecoder.doDecode(CreditControlServerDecoder.java:45)
at
org.apache.mina.filter.codec.CumulativeProtocolDecoder.decode(CumulativeProtocolDecoder.java:173)
at
org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:224)
at
org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
at
org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:48)
at
org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:802)
at
org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:59)
at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
at
org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
at
org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
at
org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
at java.lang.Thread.run(Thread.java:595)
Here are my client and server configurations:
------------------------ SERVER -----------------------------
SocketAcceptor socketAcceptor = new
NioSocketAcceptor(Runtime.getRuntime().availableProcessors()*2);
socketAcceptor.setReuseAddress(true);
filterChainWorkerPool = new
OrderedThreadPoolExecutor(Runtime.getRuntime().availableProcessors()*2);
socketAcceptor.getFilterChain().addLast("executor", new
ExecutorFilter(filterChainWorkerPool));
socketAcceptor.getFilterChain().addLast("codec", new
ProtocolCodecFilter( getServerCodecFactory()));
SocketAddress address = new InetSocketAddress(port);
socketAcceptor.setHandler(this);
acceptor = socketAcceptor;
acceptor.bind(address);
--------------------------------------------------------------------
------------------------- CLIENT -----------------------------
int nbThread = Runtime.getRuntime().availableProcessors() * 2;
SocketConnector connector = new NioSocketConnector(nbThread);
filterChainWorkerPool = new OrderedThreadPoolExecutor(nbThread);
connector.getFilterChain().addLast("executor", new
ExecutorFilter(filterChainWorkerPool));
connector.getFilterChain().addLast("codec", new
ProtocolCodecFilter(getClientCodec()));
connector.getSessionConfig().setTcpNoDelay(true);
Handler handler= new Handler(exchangesMap);
connector.setHandler(handler);
--------------------------------------------------------------------
Am I doing something wrong???
Thanks,
Patrizio
Alexander Christian wrote:
Hi Patrizio,
I'm not sure if this is helpful for you, but I'm using this in front of my
PtorocolCodecFactory:
----
// add an executor service to handle the message reading in a threadpool
ExecutorService filterchainWorkerPool = new OrderedThreadPoolExecutor();
filterChain.addLast("executor", new ExecutorFilter(filterchainWorkerPool));
----
If I'm using an ordinary executor, I'm getting the same problems like you.
Since I'm using this special type of executor, the system runs fine.
You have to save the "filterchainWorkerPool " somewhere to shut it down
later if your application is going to terminate. Otherwise you have still
some threads alive and your application would not terminate.
br,
Alex
On Wed, 18 Feb 2009 11:49:16 +0100, Patrizio Munzi
<[email protected]> wrote:
Hi,
A few months ago I've implemented a TCP client/server application using
MINA 1.x.
My application was multi-thread using Multi-Thread model and it used to
work.
These days I was trying to move it from MINA 1.x to MINA 2.0.0-M4 in
order to understand if there was any performance improvement.
However, after all changes for backward incompatibility, I'm having a
lot of troubles with multi-thread execution.
I mean if I run it with a single thread it work well, instead in case of
multi-threads execution I have the following exception:
org.apache.mina.filter.codec.ProtocolDecoderException:
java.nio.BufferUnderflowException
I think it's something related to multi-threads codec interaction, but I
couldn't work it out.
I wonder if there is something to take care when implementing a protocol
codec in multi-threads.
Actually there's not a lot of documentation and guidelines in
multi-threads usage of mina framework and codec implementation.
I don't know, I'm talking about some step by step examples.
Any help and further discussion would be really appreciated..
Thanks,
Patrizio